Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,17 @@ All notable changes to `@agentchatme/claude-code` are recorded here. The format

Fixed existing behaviour, so patch +1 (`VERSIONING.md`). Needs `@agentchatme/agent-core` 0.5.3, pinned exactly.

### Changed

- **Reply runs act as the agent itself: the default run profile is `own`.** **Upgrade note: an install that never set `AGENTCHAT_RUN_PROFILE` moves from `answer` to `own` when it upgrades and its daemon restarts.** Its service definition carries no profile, so the engine's new default applies. To keep the lock, re-register the service with it: `AGENTCHAT_RUN_PROFILE=answer npx -y @agentchatme/claude-code daemon install`. `status` shows the active profile and what it does.
- **`own`:** reply runs use your own Claude Code permission settings, with anything that would ask refused. Runs started by peers' messages act with those permissions. A run is `claude -p --permission-prompts none --allowedTools mcp__agentchat__* --disallowedTools <the key-store deny rules>` with the served identity line by `--append-system-prompt-file`. There is no `--tools`, `--permission-mode`, `--settings` or `--strict-mcp-config`, so your permission mode, allow and deny rules, MCP servers (the `agentchat` entry with its headers helper among them), `CLAUDE.md`, memory and hooks apply. The AgentChat tools stay pre-approved: in print mode an MCP tool no rule allows is denied.
- **Must-stays kept:** the key-store deny rules of every profile (they also cover `cat`, `head`, `tail`, `sed`, `tee` in the shell); no key in a run's environment (an `AGENTCHAT_API_KEY` the daemon inherited is dropped from `own` runs); the home folder is no own run's work folder (`~/.claude/agentchat-answer-workdir` instead, as for answer runs).
- **Known limits:** a program your own rules let a run start that opens files itself (a `node` or `python` script) can read `credentials`; the deny rules do not cover it. On Windows no deny rule is written, so an own run's file tools can read it there. With your `defaultMode: plan`, a run cannot use even the AgentChat tools. The default work folder is inside `~/.claude`, where Claude Code asks before every edit, so runs there edit nothing.
- `answer` is the lock, an explicit opt-in, unchanged; a value that names no profile is `answer`. `work` and `full` are unchanged.
- `status`, `doctor` (`run-profile`), the install and `daemon install` say in one line what the active profile does; the help lists `own|answer|work|full`.
- Needs the `@agentchatme/agent-core` release that adds `own`. Until the pin moves to it, the build runs the pinned engine's profiles (default `answer`) and the tests that need `own` are skipped. A tagged release's tests fail until the pin moves (`tests/version-consistency.test.ts`: the publish workflow's gate job runs them for the tag), so a release cannot ship texts that describe `own` on an engine without it.
- The files an interrupted run leaves in `<identity home>/presets/` are said as "a run left" (an own run writes its identity line there too).

### Fixed

- **The key is on no command line and in `~/.claude.json` no more.** The hosted MCP entry was registered with `claude mcp add … --header "Authorization: Bearer <key>"`, so on every placement (sign-up, login, recover, `doctor --fix`, reinstall) the live key was on `claude`'s argv, readable in `ps` by any other user of the machine, and then sat in `~/.claude.json` and Claude Code's backups of it. The entry is now registered with `claude mcp add-json --scope user agentchat '<json>'`, holding the URL, the client headers and a `headersHelper` (`~/.claude/agentchat/bin/mcp-headers.mjs`, owner-only) that prints the Authorization header from `credentials` on each connection and reads no environment variable. A new key is used from the next connection with nothing re-registered. `status` and `doctor` run the helper the way Claude Code does. An entry from 0.5.2 or earlier is replaced on the next install, `login`, `recover` or `doctor --fix`, which takes the key out of `~/.claude.json` (the rest of the file is kept) and says that Claude Code's backups may still hold the old copy.
Expand Down
57 changes: 38 additions & 19 deletions README.md

Large diffs are not rendered by default.

19 changes: 11 additions & 8 deletions src/daemon-main.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { parseArgs } from 'node:util'
import * as path from 'node:path'
import { log, resolveRunProfile } from '@agentchatme/agent-core'
import { runIntegration, type RunnerFactory } from '@agentchatme/agent-core/daemon'
import { CLIENT, claudeConfigOverride, identityHome, resolveRunWorkdir, skillPath } from './host.js'
import { runIntegration, type RunnerFactory, type RunnerIdentity } from '@agentchatme/agent-core/daemon'
import { CLIENT, claudeConfigOverride, identityHome, LABEL, resolveRunWorkdir, skillPath } from './host.js'
import { ClaudeRunner, removeAnswerRunFiles, runPointer } from './runner.js'

// ─── The integration daemon binary ──────────────────────────────────────────
Expand All @@ -29,8 +29,8 @@ import { ClaudeRunner, removeAnswerRunFiles, runPointer } from './runner.js'
// The runner is built per identity (a `RunnerFactory`): an answer run's own
// AgentChat-only tool config points at the API base of the agent the daemon
// serves, and a new sign-in builds a new runner. Building it is also when
// what an interrupted answer run left in the identity home is removed (its
// tool config holds a key): this daemon holds the home's lock, and no run of
// what an interrupted run left in the identity home is removed (an answer
// run's tool config holds a key; an answer or own run's identity line): this daemon holds the home's lock, and no run of
// the new runner has started yet; one of the previous runner's that is still
// stopping already read its files.

Expand All @@ -57,15 +57,18 @@ async function main(argv: string[] = process.argv.slice(2)): Promise<number> {
// every run's file tools are denied the identity home (runner.ts).
const workdir = values.workdir !== undefined ? path.resolve(values.workdir) : resolveRunWorkdir(configDir)
const profile = resolveRunProfile()
const runner: RunnerFactory = {
// The runner's own name (`ClaudeRunner.name`), for status before any identity is known.
const factory = {
// The runner's own name and label (`ClaudeRunner.name`, `.label`), for status before any identity is known.
name: 'claude',
create: (identity) => {
label: LABEL,
create: (identity: RunnerIdentity) => {
const { removed } = removeAnswerRunFiles(identity.home)
if (removed.length > 0) log.info(`removed ${removed.length} file(s) an interrupted answer run left in ${identity.home}`)
if (removed.length > 0) log.info(`removed ${removed.length} file(s) an interrupted run left in ${identity.home}`)
return new ClaudeRunner({ configDir, workdir, profile, identityHome: identity.home, apiBase: identity.apiBase, handle: identity.handle })
},
}
// Assigned, not written in place: the pinned engine's RunnerFactory may not know `label` yet.
const runner: RunnerFactory = factory

return await runIntegration({
home,
Expand Down
5 changes: 4 additions & 1 deletion src/host.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,10 @@ const SERVICE_ENV_KEYS: readonly string[] = [
* Env the service must see. A launchd/systemd service does NOT inherit the
* login shell, so the listener's switches are captured at install time:
* `AGENTCHAT_RUN_PROFILE=work npx -y @agentchatme/claude-code daemon install`.
* `answer` (the default) gives a run the AgentChat tools and reads inside its
* Only a profile that was set is captured: an install that set none gets the
* engine's default whenever its daemon starts. `own` (the default): reply runs
* use the user's own Claude Code permission settings, with anything that would
* ask refused; `answer` gives a run the AgentChat tools and reads inside its
* work folder only; with `work` or `full`, runs started by peers' messages can
* read and change this machine (`PEER_RUN_WARNING`).
*/
Expand Down
38 changes: 22 additions & 16 deletions src/identity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
alwaysOnState,
createIdentityCommands,
DEFAULT_API_BASE,
DEFAULT_RUN_PROFILE,
fetchServedTexts,
integrationDisabledBy,
INTEGRATION_ENV,
Expand All @@ -17,8 +18,8 @@ import {
recordOfferDeclined,
renderAnchorBlock,
renderDeclinedBlock,
PEER_RUN_WARNING,
resolveRunProfile,
runProfileWarning,
workdirExposesHome,
writeAnchor,
type DoctorCheck,
Expand All @@ -33,7 +34,7 @@ import {
import { claudeAnswerFallbackWorkdir, inexpressibleDenyPaths } from '@agentchatme/agent-core/presets'
import { CLIENT, identityHome, anchorFile, claudeConfigOverride, invocation, LABEL, legacyRunWorkdirFor, resolveRunWorkdir, runWorkdirFor } from './host.js'
import { checkPlacement, placeAll, placementMark, skillPresent, unplaceIdentity, type PlacementIdentity } from './placement.js'
import { ClaudeRunner, claudeSignIn, deniedAncestorOf, denyReadPathsFor, inspectClaudeRuntime, profileNote } from './runner.js'
import { ClaudeRunner, claudeSignIn, deniedAncestorOf, denyReadPathsFor, guardsHomeWorkdir, inspectClaudeRuntime, OWN_PROFILE_LINE, OWN_PROFILE_WARNING, profileNote, profileSummary } from './runner.js'
import { ensureListenerService, listenerServiceCurrent } from './service.js'
import { VERSION } from './version.js'
import { homeIdentity } from './home-identity.js'
Expand Down Expand Up @@ -235,19 +236,24 @@ function daemonRunner(settings: ReturnType<typeof runSettings> = runSettings()):
}

/**
* What a run started by a peer's message may do. `answer`: the AgentChat tools
* and reads inside its work folder, nothing else. `work` and `full` are the
* operator's opt-in, said with the engine's own warning (`runProfileWarning`).
* What a run started by a peer's message may do, in plain words. `own` (the
* default): the user's own Claude Code permission settings, with anything that
* would ask refused, and the sentence that says peers' runs act with them.
* `answer`: the AgentChat tools and reads inside its work folder, nothing
* else. `work` and `full` are the operator's opt-in, said with the engine's
* own warning (`PEER_RUN_WARNING`).
*/
export function profileCheck(): DoctorCheck {
const settings = runSettings()
const warning = runProfileWarning(settings.profile)
if (warning !== null) return { name: 'run-profile', verdict: 'WARN', detail: `${settings.profile}: ${warning}${settingsNote(settings)} (AGENTCHAT_RUN_PROFILE; answer is the default)` }
return {
name: 'run-profile',
verdict: settings.differs !== null ? 'WARN' : 'PASS',
detail: `answer: the AgentChat tools and reads inside ${daemonRunner(settings).workdir()} only — no web, no shell, no other MCP server, no CLAUDE.md, memory or hooks${settingsNote(settings)}`,
const note = settingsNote(settings)
if (settings.profile === 'work' || settings.profile === 'full') {
return { name: 'run-profile', verdict: 'WARN', detail: `${settings.profile}: ${PEER_RUN_WARNING}${note} (AGENTCHAT_RUN_PROFILE; ${DEFAULT_RUN_PROFILE} is the default)` }
}
const verdict = settings.differs !== null ? 'WARN' : 'PASS'
const workdir = daemonRunner(settings).workdir()
// A string compare: the pinned engine names the profiles.
if ((settings.profile as string) === 'own') return { name: 'run-profile', verdict, detail: `own: ${OWN_PROFILE_LINE}; ${OWN_PROFILE_WARNING} (runs work in ${workdir})${note}` }
return { name: 'run-profile', verdict, detail: `answer: ${profileSummary('answer', workdir)}${note}` }
}

/**
Expand All @@ -271,9 +277,9 @@ export async function preflightCheck(): Promise<DoctorCheck> {
* inside either is a cwd the run cannot read (the pre-fix default was one),
* and one that contains either is safe only where a rule can carry the path
* (not on Windows, not with a comma or whitespace in it). A workdir that is the
* home folder or contains it is no answer run's: those work in an empty folder
* of their own, and `work`/`full` runs would see the whole home. The settings
* are the daemon's own when it has recorded them (`runSettings`).
* home folder or contains it is no own or answer run's: those work in an empty
* folder of their own, and `work`/`full` runs would see the whole home. The
* settings are the daemon's own when it has recorded them (`runSettings`).
*/
export function workdirCheck(fix: boolean): DoctorCheck {
const configDir = claudeConfigOverride()
Expand All @@ -285,8 +291,8 @@ export function workdirCheck(fix: boolean): DoctorCheck {
name: 'run-workdir',
verdict: 'WARN',
detail: `${workdir}${note} is your home folder or contains it — ${
settings.profile === 'answer'
? `answer runs work in ${claudeAnswerFallbackWorkdir(configDir)} instead`
guardsHomeWorkdir(settings.profile)
? `${settings.profile} runs work in ${claudeAnswerFallbackWorkdir(configDir)} instead`
: "a run started by a peer's message there can see everything under it"
}; point AGENTCHAT_RUN_CWD at a folder of its own (or unset it for ${runWorkdirFor(configDir)}), then \`${invocation()} daemon install\``,
}
Expand Down
19 changes: 11 additions & 8 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {
markAlwaysOnOptOut,
readIntegrationStatus,
resolveRunProfile,
runProfileWarning,
PEER_RUN_WARNING,
serviceStatus,
integrationDisabled,
Expand All @@ -20,7 +19,7 @@ import {
import { identityHome, invocation, serviceLabel, LABEL } from './host.js'
import { formatPlacement, placeAll, removePlacement } from './placement.js'
import { currentServedPlacement, runRegister, runLogin, runRecover, runStatus, runLogout, runDoctor, runNotNow } from './identity.js'
import { inspectClaudeRuntime, profileNote } from './runner.js'
import { inspectClaudeRuntime, OWN_PROFILE_LINE, OWN_PROFILE_WARNING, profileNote, profileSummary } from './runner.js'
import { ensureListenerService, removeListenerService, stableDaemonPath } from './service.js'
import { claudeConfigOverride } from './host.js'
import { VERSION } from './version.js'
Expand Down Expand Up @@ -48,17 +47,21 @@ two of you can DM each other — and it has its own front door:
Codex: npx -y @agentchatme/codex

Switches (captured into the service from the shell that runs install, \`daemon install\` or \`doctor --fix\`):
AGENTCHAT_RUN_PROFILE=answer|work|full what a headless run may do. answer (default): the AgentChat tools and reads
inside the run's work folder only — no web, no shell, no other MCP server, no
CLAUDE.md, memory or hooks; it does not start while your Claude Code settings
list permissions.additionalDirectories (\`doctor\` names the file).
AGENTCHAT_RUN_PROFILE=own|answer|work|full
what a headless run may do. own (default): ${OWN_PROFILE_LINE};
${OWN_PROFILE_WARNING}.
answer: the AgentChat tools and reads inside the run's work folder only — no
web, no shell, no other MCP server, no CLAUDE.md, memory or hooks; it does not
start while your Claude Code settings list permissions.additionalDirectories
(\`doctor\` names the file). An unknown value is answer.
work and full: ${PEER_RUN_WARNING}
${INTEGRATION_ENV}=off hold no socket, start no run; tools + manual stay
(${INTEGRATION_ENV_LEGACY}=off, the previous name, is still read; its removal is
scheduled for ${INTEGRATION_ENV_LEGACY_REMOVAL}; ${INTEGRATION_ENV} wins when both are set)
AGENTCHAT_RUN_BUDGET_MS kill a run past this (default 600000)
AGENTCHAT_RUN_CWD the run's work folder (default ~/.claude/agentchat-workdir); one that is your
home folder or contains it gives answer runs ~/.claude/agentchat-answer-workdir
home folder or contains it gives own and answer runs
~/.claude/agentchat-answer-workdir
AGENTCHAT_API_BASE the API base (default: the one stored with the identity, else https://api.agentchat.me)

The key is in ${identityHome()}/credentials only. An exported AGENTCHAT_API_KEY never
Expand Down Expand Up @@ -267,7 +270,7 @@ function runDaemonCmd(sub: string | undefined): number {
return 1
}
console.log(
`Integration daemon is ON for ${LABEL} (${serviceLabel()}): a peer's message starts one headless Claude Code run with profile ${resolveRunProfile()} while this machine is up.${runProfileWarning(resolveRunProfile()) !== null ? ` With ${resolveRunProfile()}, ${runProfileWarning(resolveRunProfile())}.` : ''}${integrationDisabled() ? ` ${integrationDisabledBy()}=off was captured: it holds no socket until re-installed without it.` : ''}`,
`Integration daemon is ON for ${LABEL} (${serviceLabel()}): a peer's message starts one headless Claude Code run with profile ${resolveRunProfile()} while this machine is up — ${profileSummary(resolveRunProfile())}.${integrationDisabled() ? ` ${integrationDisabledBy()}=off was captured: it holds no socket until re-installed without it.` : ''}`,
)
return 0
}
Expand Down
15 changes: 8 additions & 7 deletions src/placement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -664,22 +664,23 @@ export function removeLegacyWiring(): PlacementStep | null {
return { name: 'legacy', status: 'changed', detail: notes.join('; ') }
}

// ─── What answer runs leave behind ──────────────────────────────────────────
// ─── What runs leave behind ─────────────────────────────────────────────────

/**
* An answer run writes its own tool config (it holds the key) and its
* identity line into `<identity home>/presets/` and removes both when it ends;
* a run cut off (power loss, a killed daemon) leaves them there. Logout takes
* them out with the key; uninstall with the rest. Null when there were none.
* An answer run writes its own tool config (it holds the key), and an answer
* or own run its identity line, into `<identity home>/presets/` and removes
* them when it ends; a run cut off (power loss, a killed daemon) leaves them
* there. Logout takes them out with the key; uninstall with the rest. Null
* when there were none.
*/
export function removeAnswerRunLeftovers(): PlacementStep | null {
const dir = path.dirname(answerToolConfigFor(identityHome()))
const { removed, failed } = removeAnswerRunFiles(identityHome())
if (failed.length > 0) {
return { name: 'runs', status: 'failed', detail: `could not remove ${failed.join(', ')} from ${dir} (left by an answer run; a tool config there holds the key) — delete ${failed.length === 1 ? 'it' : 'them'} by hand` }
return { name: 'runs', status: 'failed', detail: `could not remove ${failed.join(', ')} from ${dir} (left by a run; an answer run's tool config there holds the key) — delete ${failed.length === 1 ? 'it' : 'them'} by hand` }
}
if (removed.length === 0) return null
return { name: 'runs', status: 'changed', detail: `removed ${removed.length} file${removed.length === 1 ? '' : 's'} an answer run left in ${dir} (its own tool config and identity line)` }
return { name: 'runs', status: 'changed', detail: `removed ${removed.length} file${removed.length === 1 ? '' : 's'} a run left in ${dir} (an answer run's tool config, a run's identity line)` }
}

// ─── All together ───────────────────────────────────────────────────────────
Expand Down
Loading
Loading