@agentchatme/agent-core 0.0.13131111111131 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -1,18 +1,30 @@
1
- import { H as HostCopy, a as TurnDisposition } from './adapter-types-DrrsKZYk.js';
2
- export { f as AlwaysOnState, A as AutonomyMode, g as FullAutonomyPolicy, h as HEARTBEAT_FILE, M as MessageContext, P as PendingReason, i as PendingRequest, j as RecordPendingRequestInput, k as SyncRow, W as WireConfig, l as WireError, m as allowFullAutonomyAgent, n as alwaysOnHealth, o as alwaysOnOptedOut, p as alwaysOnState, q as alwaysOnWanted, r as autonomyPath, s as beat, t as claimReply, u as claimReplyBatch, v as clearAlwaysOnInstalledVersion, w as clearAlwaysOnOptOut, x as clearAlwaysOnWanted, y as clearForegroundTurn, z as clearSessionActive, B as contextOf, C as formatAlwaysOnDown, D as formatPendingRequestsNotice, E as formatPendingRequestsSystemMessage, G as formatRegistrationOffer, I as formatSessionStart, J as formatStopPickup, K as fullAutonomyAllows, L as getMeLite, N as getPendingRequest, O as idle, Q as lastDeliveryId, U as listPendingRequests, V as markAlwaysOnInstalledVersion, X as markAlwaysOnOptOut, Y as markAlwaysOnWanted, Z as markForegroundTurn, _ as markSessionActive, $ as normalizeAgentHandle, a0 as pendingRequestId, a1 as pendingRequestsFingerprint, a2 as readAlwaysOnInstalledVersion, a3 as readFullAutonomyPolicy, a4 as recordPendingRequest, a5 as removeFullAutonomyAgent, a6 as renderDeclinedBlock, a7 as renderUnregisteredBlock, a8 as resolvePendingRequest, a9 as setFullAutonomyMode, aa as syncAck, ab as syncPeek, ac as writeFullAutonomyPolicy } from './adapter-types-DrrsKZYk.js';
1
+ import { I as IntegrationClient } from './prompts-B0UL03Hu.js';
2
+ export { C as CachedTexts, l as DEFAULT_RUN_BUDGET_MS, m as DEFAULT_RUN_PROFILE, F as FetchIdentityLineOptions, n as INTEGRATION_ENV, o as INTEGRATION_ENV_LEGACY, p as INTEGRATION_STATUS_FILE, e as IntegrationLastRun, b as IntegrationStatus, L as LEGACY_STATUS_FILE, q as LoadTextsOptions, r as LoadedTexts, s as RUN_BUDGET_ENV, t as RUN_PROFILES, u as RUN_PROFILE_ENV, g as RunKind, f as RunOutcome, h as RunOutcomeState, i as RunPreflight, a as RunProfile, c as RunPrompts, j as RunRequest, R as RunRunner, v as SOCKET_STATES, S as SocketState, w as TEXTS_CACHE_FILE, x as TEXTS_REFRESH_MS, y as TEXTS_RETRY_MS, z as TextsClient, A as TextsSource, B as TextsStatus, T as TextsStore, E as TextsStoreOptions, G as buildRunPrompts, H as clearIntegrationStatus, J as clientHeadersOf, K as clientIdentityOf, M as fetchIdentityLine, N as formatIntegrationStatus, O as integrationDisabled, P as integrationDisabledBy, Q as integrationStatusAge, U as integrationStatusPath, V as isRunProfile, X as loadTexts, Y as readCachedTexts, Z as readIntegrationStatus, _ as resolveRunBudgetMs, $ as resolveRunProfile, a0 as textsCachePath, a1 as writeCachedTexts, a2 as writeIntegrationStatus } from './prompts-B0UL03Hu.js';
3
+ import { AgentChatClient, Texts } from 'agentchatme';
3
4
  import { z } from 'zod';
4
5
  import { spawn, spawnSync } from 'node:child_process';
5
6
 
6
- /** Low-cardinality identity attached to every coding-agent API operation. */
7
- declare const CODING_AGENTS_CLIENT_IDENTITY: {
8
- readonly name: "coding_agents";
9
- readonly version: "0.0.13131111111131";
10
- };
11
- /** Headers for raw HTTP and WebSocket transports that bypass the SDK. */
12
- declare const CODING_AGENTS_CLIENT_HEADERS: Readonly<Record<string, string>>;
13
-
14
7
  /** Published package version, kept in lockstep with package.json by tests. */
15
- declare const VERSION = "0.0.13131111111131";
8
+ declare const VERSION = "0.2.0";
9
+
10
+ type TrayClient = Pick<AgentChatClient, 'inbox'>;
11
+ interface TraySummary {
12
+ /** Conversations with something waiting (cards on the tray). */
13
+ waiting: number;
14
+ /** Conversations the agent deferred and that are hidden until their time. */
15
+ deferred: number;
16
+ /** More conversations are waiting than one tray shows. */
17
+ truncated: boolean;
18
+ }
19
+ /** How many conversations are waiting, for `status`. One tray page, counted. */
20
+ declare function traySummary(client: TrayClient): Promise<TraySummary>;
21
+ /**
22
+ * Is anything waiting on the tray? `GET /v1/inbox?limit=1` — a count, never a
23
+ * card: the one card the server may return is not read. This is the question
24
+ * asked before every wake run: "does this wake deserve a run at all?" — the
25
+ * reason a reconnect with an empty tray starts no run.
26
+ */
27
+ declare function trayHasWaiting(client: TrayClient): Promise<boolean>;
16
28
 
17
29
  declare const DEFAULT_API_BASE = "https://api.agentchat.me";
18
30
  declare const CredentialsSchema: z.ZodObject<{
@@ -21,15 +33,15 @@ declare const CredentialsSchema: z.ZodObject<{
21
33
  api_base: z.ZodOptional<z.ZodString>;
22
34
  created_at: z.ZodOptional<z.ZodString>;
23
35
  }, "strip", z.ZodTypeAny, {
24
- handle: string;
25
36
  api_key: string;
26
- created_at?: string | undefined;
37
+ handle: string;
27
38
  api_base?: string | undefined;
39
+ created_at?: string | undefined;
28
40
  }, {
29
- handle: string;
30
41
  api_key: string;
31
- created_at?: string | undefined;
42
+ handle: string;
32
43
  api_base?: string | undefined;
44
+ created_at?: string | undefined;
33
45
  }>;
34
46
  type Credentials = z.infer<typeof CredentialsSchema>;
35
47
  interface ResolvedIdentity {
@@ -72,9 +84,9 @@ declare const PendingSchema: z.ZodObject<{
72
84
  created_at: string;
73
85
  pending_id: string;
74
86
  email: string;
75
- kind?: "register" | "recover" | undefined;
76
87
  handle?: string | undefined;
77
88
  api_base?: string | undefined;
89
+ kind?: "register" | "recover" | undefined;
78
90
  }>;
79
91
  type PendingRegistration = z.infer<typeof PendingSchema>;
80
92
  declare function readPending(home: string): PendingRegistration | null;
@@ -82,86 +94,82 @@ declare function writePending(home: string, pending: PendingRegistration): void;
82
94
  declare function clearPending(home: string): void;
83
95
 
84
96
  declare const StateSchema: z.ZodObject<{
85
- sessions: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodObject<{
86
- continuations: z.ZodNumber;
87
- updated_at: z.ZodString;
88
- pending_ack: z.ZodOptional<z.ZodString>;
89
- pending_ack_requires_continuation: z.ZodOptional<z.ZodBoolean>;
90
- pending_notice_fingerprint: z.ZodOptional<z.ZodString>;
91
- }, "strip", z.ZodTypeAny, {
92
- continuations: number;
93
- updated_at: string;
94
- pending_ack?: string | undefined;
95
- pending_ack_requires_continuation?: boolean | undefined;
96
- pending_notice_fingerprint?: string | undefined;
97
- }, {
98
- continuations: number;
99
- updated_at: string;
100
- pending_ack?: string | undefined;
101
- pending_ack_requires_continuation?: boolean | undefined;
102
- pending_notice_fingerprint?: string | undefined;
103
- }>>>;
104
- last_offer_at: z.ZodOptional<z.ZodString>;
105
97
  offer_declined_at: z.ZodOptional<z.ZodString>;
106
98
  }, "strip", z.ZodTypeAny, {
107
- sessions: Record<string, {
108
- continuations: number;
109
- updated_at: string;
110
- pending_ack?: string | undefined;
111
- pending_ack_requires_continuation?: boolean | undefined;
112
- pending_notice_fingerprint?: string | undefined;
113
- }>;
114
- last_offer_at?: string | undefined;
115
99
  offer_declined_at?: string | undefined;
116
100
  }, {
117
- sessions?: Record<string, {
118
- continuations: number;
119
- updated_at: string;
120
- pending_ack?: string | undefined;
121
- pending_ack_requires_continuation?: boolean | undefined;
122
- pending_notice_fingerprint?: string | undefined;
123
- }> | undefined;
124
- last_offer_at?: string | undefined;
125
101
  offer_declined_at?: string | undefined;
126
102
  }>;
127
- type HookState = z.infer<typeof StateSchema>;
128
- declare function readState(home: string): HookState;
129
- declare function writeState(home: string, state: HookState): void;
130
- declare function getContinuations(home: string, sessionKey: string): number;
131
- declare function recordContinuation(home: string, sessionKey: string, now?: Date): number;
132
- /**
133
- * Give a session a fresh continuation budget. Called by the session-start
134
- * hook: resuming a capped session is a new sitting, and its stop hook
135
- * should be allowed to pick messages up again.
136
- */
137
- declare function resetSession(home: string, sessionKey: string): void;
138
- declare function setPendingAck(home: string, sessionKey: string, cursor: string, now?: Date, requiresContinuation?: boolean): void;
139
- /** Read-and-clear the pending cursor for a session (completed-turn boundary). */
140
- declare function takePendingAck(home: string, sessionKey: string, now?: Date): string | null;
141
- declare function pendingNoticeNeeded(home: string, sessionKey: string, fingerprint: string): boolean;
142
- declare function recordPendingNotice(home: string, sessionKey: string, fingerprint: string, now?: Date): void;
143
- declare function shouldOfferRegistration(home: string, now?: Date): boolean;
144
- declare function recordRegistrationOffer(home: string, now?: Date): void;
103
+ type IdentityState = z.infer<typeof StateSchema>;
104
+ declare function readState(home: string): IdentityState;
105
+ declare function writeState(home: string, state: IdentityState): void;
145
106
  /**
146
107
  * The user said "not now".
147
108
  *
148
- * A hook-injected offer could rely on a 24-hour cooldown, because the hook
149
- * re-runs and can consult state. A prompt written into the always-loaded
150
- * instruction file cannot: it is static text the agent re-reads every session,
151
- * with no memory that it was already declined. So the decline has to be
152
- * recorded here, and the instruction file rewritten to stop asking.
109
+ * A prompt written into the always-loaded instruction file is static text the
110
+ * agent re-reads every session, with no memory that it was already declined.
111
+ * So the decline is recorded here, and the instruction file rewritten to stop
112
+ * asking.
153
113
  */
154
114
  declare function recordOfferDeclined(home: string, now?: Date): void;
155
115
  declare function offerDeclined(home: string): boolean;
156
116
  /** Cleared when an identity is established, so a later logout asks again. */
157
117
  declare function clearOfferDeclined(home: string): void;
158
118
 
119
+ declare const MANUAL_URL = "https://agentchat.me/skill.md";
120
+ /** The skill name every runtime sees: `<skills dir>/agentchat/SKILL.md`. */
121
+ declare const MANUAL_SKILL_NAME = "agentchat";
122
+ declare const MANUAL_FILENAME = "SKILL.md";
123
+ /** The manual, byte for byte. */
124
+ declare const MANUAL: string;
125
+ /** The `version:` field of the manual's YAML front matter, or null. */
126
+ declare function manualVersion(text?: string): string | null;
127
+ /**
128
+ * The one pointer line a run prompt ends with. `location` is how THIS runtime
129
+ * reaches the bundled copy (a skill name, a path) — the integration knows that,
130
+ * this package does not.
131
+ */
132
+ declare function manualPointer(location: string): string;
133
+
134
+ /** The identity line, ready to place, from a served (or cached) texts response. */
135
+ declare function identityLineOf(texts: Pick<Texts, 'identity_line'>): string;
136
+ /** Handles are canonical lowercase on the wire; a leading `@` is display only. */
137
+ declare function normalizeHandle(handle: string): string;
138
+
139
+ /**
140
+ * How ONE integration names itself in user-facing copy.
141
+ *
142
+ * There is deliberately no `--platform` anywhere in this module. An
143
+ * integration's CLI acts on exactly one agent — its own — so a flag naming
144
+ * which agent to act on has nothing to select between.
145
+ */
146
+ interface HostCopy {
147
+ /** Exactly what the user types, e.g. `npx -y @agentchatme/codex`. */
148
+ invoke: string;
149
+ /** Human label for the host, e.g. `Codex` or `Claude Code`. */
150
+ label: string;
151
+ }
152
+ /**
153
+ * "You have AgentChat but no handle — offer to set one up."
154
+ *
155
+ * Deliberately bounded: static text is re-read every session, so without an
156
+ * explicit stop condition an agent would raise it forever. `--not-now` records
157
+ * the decline and rewrites this block to the silent variant below.
158
+ */
159
+ declare function renderUnregisteredBlock(copy: HostCopy): string;
160
+ /**
161
+ * The silent variant, written after `--not-now`.
162
+ *
163
+ * Still states the fact — an agent asked "am I on AgentChat?" should be able to
164
+ * answer, and a user who changes their mind should find the command — but it
165
+ * gives no instruction to act on, so there is nothing to nag with.
166
+ */
167
+ declare function renderDeclinedBlock(copy: HostCopy): string;
168
+
159
169
  declare const ANCHOR_START = "<!-- agentchat:start -->";
160
170
  declare const ANCHOR_END = "<!-- agentchat:end -->";
161
- /** The default identity block. Integrations whose host wants richer copy
162
- * (Codex folds etiquette in, since its skills are on-demand) render their
163
- * own and pass it to `writeAnchor` instead. */
164
- declare function renderAnchorBlock(handle: string): string;
171
+ /** The identity block: the served identity line, as fetched for this agent, between the markers. */
172
+ declare function renderAnchorBlock(identityLine: string): string;
165
173
  type AnchorAction = 'written' | 'removed' | 'noop';
166
174
  /**
167
175
  * Upsert `block` into the file at `filePath`, creating it if needed.
@@ -173,104 +181,42 @@ type AnchorAction = 'written' | 'removed' | 'noop';
173
181
  declare function writeAnchor(filePath: string, block: string, expectHandle?: string): AnchorAction;
174
182
  declare function removeAnchorAt(filePath: string): AnchorAction;
175
183
  declare function hasAnchorAt(filePath: string): boolean;
184
+ /** Whether the file's block is exactly the block for this served identity line. */
185
+ declare function anchorIsCurrentAt(filePath: string, identityLine: string): boolean;
176
186
  /**
177
187
  * The handle a file's anchor block currently CLAIMS, or null if there is no
178
- * block. Every anchor rendering states it as `**@handle**`, so one pattern
179
- * covers them all.
180
- *
181
- * Lets an integration catch an anchor that disagrees with its own credential —
182
- * an agent told it is @a while authenticating as @b hands peers an address
183
- * that reaches someone else. Matched loosely (not against the canonical handle
184
- * rule) precisely so a WRONG value is still read back and reported rather than
185
- * silently treated as "no anchor".
188
+ * block. Lets an integration catch an anchor that disagrees with its own
189
+ * credential — an agent told it is @a while authenticating as @b hands peers an
190
+ * address that reaches someone else. Matched loosely precisely so a WRONG
191
+ * value is still read back and reported rather than treated as "no anchor".
186
192
  */
187
193
  declare function readAnchorHandleAt(filePath: string): string | null;
188
194
  declare function readAnchorHandleFrom(text: string): string | null;
189
195
  declare function upsertAnchorBlock(existing: string, block: string): string;
190
196
  declare function stripAnchorBlock(existing: string): string;
191
197
 
192
- interface HookInput {
193
- sessionId: string;
194
- /** Claude Code SessionStart source: startup | resume | clear | compact | fork.
195
- * Undefined on other hosts/events. */
196
- source: string | undefined;
197
- /**
198
- * Whether this Stop belongs to the continuation created by a prior Stop
199
- * decision. Both harnesses expose this as `stop_hook_active`.
200
- */
201
- stopHookActive?: boolean;
202
- }
203
- declare function readHookInput(stream?: NodeJS.ReadStream): Promise<HookInput>;
204
-
205
- interface HookContext {
206
- /** THIS integration's identity home. Never resolved here. */
207
- home: string;
208
- /** How this integration names itself in user-facing copy. */
209
- copy: HostCopy;
210
- }
211
- interface SessionStartResult {
212
- /** Text to inject into the session, or null for "say nothing". */
213
- context: string | null;
214
- /** Deterministic text for the host's user-visible hook surface. */
215
- notification: string | null;
216
- /** Record the notice only after the integration printed it successfully. */
217
- stage: () => void;
218
- }
219
- interface UserPromptResult {
220
- /** Text to add to this prompt, or null when the inbox has nothing new. */
221
- context: string | null;
222
- /** Deterministic text for the host's user-visible hook surface. */
223
- notification: string | null;
224
- /**
225
- * Persist the surfaced cursor locally. Call only after the host has accepted
226
- * `context`; the following Stop is the first boundary allowed to ACK it.
227
- */
228
- stage: () => void;
229
- }
230
- interface StopResult {
231
- /** Text to continue the session with, or null to let it stop. */
232
- reason: string | null;
233
- /**
234
- * Persist the surfaced cursor locally. Call this ONLY after the host has
235
- * actually been given `reason`. The following Stop commits it remotely.
236
- */
237
- stage: () => void;
238
- }
239
- declare function hooksDisabled(): boolean;
240
- declare function sessionStart(ctx: HookContext, input: HookInput): Promise<SessionStartResult>;
241
- /**
242
- * A prompt is about to run. Claim and inject the inbox at this real turn
243
- * boundary, then stage its cursor only after the host accepts our output.
244
- */
245
- declare function userPrompt(ctx: HookContext, input: HookInput): Promise<UserPromptResult>;
246
- declare function stop(ctx: HookContext, input: HookInput): Promise<StopResult>;
247
- /** A host session is closing. Release only its own foreground lease. */
248
- declare function sessionEnd(ctx: HookContext, input: HookInput): Promise<void>;
249
-
250
- /**
251
- * How one host wants hook output shaped. Each integration owns its own — every
252
- * coding agent expects a different envelope, and a shared module choosing
253
- * between them would be one more place to pick the wrong one.
254
- */
255
- interface HookDialect {
256
- sessionStartOutput(context: string, notification: string | null): Record<string, unknown>;
257
- userPromptOutput(context: string, notification: string | null): Record<string, unknown>;
258
- stopOutput(reason: string): Record<string, unknown>;
259
- printJson(payload: Record<string, unknown>): void;
260
- }
261
- interface HookRunners {
262
- runSessionStart(): Promise<void>;
263
- runUserPrompt(): Promise<void>;
264
- runStop(): Promise<void>;
265
- runSessionEnd(): Promise<void>;
198
+ declare const HOSTED_MCP_PATH = "/mcp";
199
+ declare function hostedMcpUrl(apiBase: string): string;
200
+ interface McpProbeResult {
201
+ readonly ok: boolean;
202
+ readonly status?: number;
203
+ readonly serverName?: string;
204
+ readonly serverVersion?: string;
205
+ readonly protocolVersion?: string;
206
+ readonly error?: string;
266
207
  }
267
- /**
268
- * Build the four hook entrypoints for one coding agent.
269
- *
270
- * `context` is a factory, not a value: the hooks run in a fresh process where
271
- * the host's env (`CODEX_HOME` and friends) must be read at call time.
272
- */
273
- declare function createHookRunners(context: () => HookContext, dialect: HookDialect): HookRunners;
208
+ declare function probeHostedMcp(params: {
209
+ apiKey: string;
210
+ apiBase: string;
211
+ /** How this integration identifies to the server (headers on the probe). */
212
+ client: IntegrationClient;
213
+ /** MCP `clientInfo.name`; defaults to the runtime name. */
214
+ clientName?: string;
215
+ /** MCP `clientInfo.version`; defaults to the integration's version. */
216
+ clientVersion?: string;
217
+ timeoutMs?: number;
218
+ fetch?: typeof fetch;
219
+ }): Promise<McpProbeResult>;
274
220
 
275
221
  type Verdict = 'PASS' | 'WARN' | 'FAIL';
276
222
  interface DoctorCheck {
@@ -278,6 +224,16 @@ interface DoctorCheck {
278
224
  verdict: Verdict;
279
225
  detail: string;
280
226
  }
227
+ /** What the shared `status` hands a host's extra lines: the served identity line it already fetched (one fetch per command). */
228
+ interface StatusContext {
229
+ identityLine: string | null;
230
+ }
231
+ /** What the shared doctor hands a host's extra checks. */
232
+ interface DoctorContext {
233
+ fix?: boolean;
234
+ /** The served identity line for this agent, or null when the server could not be reached and nothing is cached. */
235
+ identityLine: string | null;
236
+ }
281
237
  /**
282
238
  * Everything the shared identity commands need to know about ONE coding agent.
283
239
  *
@@ -300,14 +256,16 @@ interface HostProfile {
300
256
  label: string;
301
257
  /** Stable machine identifier for `--json`, e.g. `claude-code`. */
302
258
  id: string;
259
+ /** How this integration names itself to the server: the texts runtime and its own version. */
260
+ client: IntegrationClient;
303
261
  /** THE identity home for this agent. */
304
262
  home(): string;
305
263
  /** This host's always-loaded instruction file. */
306
264
  anchorFile(): string;
307
265
  /** Exactly what a user types to reach this integration. */
308
266
  invocation(): string;
309
- /** Render the anchor block body this host wants. */
310
- renderAnchor(handle: string): string;
267
+ /** Render the anchor block body this host wants from the served identity line (normally `renderAnchorBlock`). */
268
+ renderAnchor(identityLine: string): string;
311
269
  /**
312
270
  * What to call the anchor in output. Defaults to the instruction file's own
313
271
  * basename (`CLAUDE.md`, `AGENTS.md`), which is what a user actually looks
@@ -317,14 +275,41 @@ interface HostProfile {
317
275
  /**
318
276
  * Whether this host is wired up enough for an anchor to mean anything.
319
277
  * An integration uses this so it never writes an identity block announcing
320
- * a phone number before its own MCP, hooks, and durable bundle are actually
321
- * in place.
278
+ * a phone number before its own placement is actually in place.
322
279
  */
323
280
  isWired?(): boolean;
281
+ /**
282
+ * Place the integration's texts for a freshly established identity: the
283
+ * identity line, the manual, the hosted tool server with the key, and
284
+ * whatever the key's home is on this runtime. Called after register, login
285
+ * and recover (every time the key changes), and by `doctor --fix`.
286
+ * `identityLine` is the served line for this agent (fetched just before,
287
+ * or the cached one), or null when neither could be had — the host then
288
+ * leaves the anchor for `doctor --fix` and says so. Returns report lines.
289
+ * When absent, only the anchor is written.
290
+ */
291
+ place?(handle: string, apiKey: string, identityLine: string | null): string[];
292
+ /**
293
+ * Undo `place` for the identity being signed out: remove the key from the
294
+ * tool server registration and anything else that would still authenticate
295
+ * as the old identity. The anchor is removed by the shared flow. Returns
296
+ * report lines.
297
+ *
298
+ * `identity` is the identity AS IT WAS BEFORE the credential was cleared
299
+ * (its key and API base), or null when there was none: a host recognises
300
+ * its own registration by that key and that server, and guessing either
301
+ * after the fact left a non-default `api_base` entry classified as foreign
302
+ * and the key still registered.
303
+ */
304
+ unplace?(identity: ResolvedIdentity | null): string[];
324
305
  /** Host-specific doctor checks, appended after the shared ones. */
325
- extraDoctorChecks?(opts: {
326
- fix?: boolean;
327
- }): DoctorCheck[];
306
+ extraDoctorChecks?(context: DoctorContext): DoctorCheck[];
307
+ /**
308
+ * Host-specific `status` lines (placement, probes), printed after the shared
309
+ * ones in text mode. The served identity line comes along so the host does
310
+ * not fetch `/v1/texts` a second time.
311
+ */
312
+ extraStatus?(context: StatusContext): string[] | Promise<string[]>;
328
313
  /** Extra lines printed after a successful logout. */
329
314
  logoutHints?(): string[];
330
315
  }
@@ -355,17 +340,6 @@ interface RecoverOpts {
355
340
  interface DoctorOpts {
356
341
  fix?: boolean;
357
342
  }
358
- interface AutonomyCommandOpts {
359
- action?: string;
360
- handle?: string;
361
- yes?: boolean;
362
- json?: boolean;
363
- }
364
- interface PendingCommandOpts {
365
- action?: string;
366
- id?: string;
367
- json?: boolean;
368
- }
369
343
  interface IdentityCommands {
370
344
  runRegister(opts: RegisterOpts): Promise<number>;
371
345
  runLogin(opts: {
@@ -376,56 +350,69 @@ interface IdentityCommands {
376
350
  runStatus(opts: {
377
351
  json?: boolean;
378
352
  }): Promise<number>;
379
- runAutonomy(opts: AutonomyCommandOpts): Promise<number>;
380
- runPendingRequests(opts: PendingCommandOpts): Promise<number>;
381
353
  runLogout(): number;
382
354
  runDoctor(opts?: DoctorOpts): Promise<number>;
383
355
  }
384
356
  /** Build the identity command set for one coding agent. */
385
357
  declare function createIdentityCommands(profile: HostProfile): IdentityCommands;
386
358
 
387
- interface ManualCopy extends HostCopy {
388
- /** The other coding agent most likely to share this machine, for the
389
- * one-identity-per-agent explanation. */
390
- peerLabel: string;
391
- /** How a user installs THAT peer, so the explanation is actionable. */
392
- peerInvoke: string;
393
- }
359
+ declare const HEARTBEAT_FILE = "daemon.heartbeat";
360
+ /** Record that the user wants always-on for this agent.
361
+ *
362
+ * The file's MTIME is load-bearing: `alwaysOnState` uses it as the moment
363
+ * registration happened, so a service that was just installed is not reported
364
+ * as broken before its daemon has had time to draw breath. */
365
+ declare function markAlwaysOnWanted(home: string): void;
366
+ /** Forget the intent (user chose session-only, or uninstalled). */
367
+ declare function clearAlwaysOnWanted(home: string): void;
368
+ declare function alwaysOnWanted(home: string): boolean;
369
+ declare function readAlwaysOnInstalledVersion(home: string): string | null;
370
+ declare function markAlwaysOnInstalledVersion(home: string, version: string): void;
371
+ declare function clearAlwaysOnInstalledVersion(home: string): void;
372
+ /** Remember that the user switched always-on off. Survives re-install. */
373
+ declare function markAlwaysOnOptOut(home: string): void;
374
+ /** Cleared only by an explicit `daemon install` — never implicitly. */
375
+ declare function clearAlwaysOnOptOut(home: string): void;
376
+ declare function alwaysOnOptedOut(home: string): boolean;
377
+ /** Touch the liveness beacon. Called by the running daemon. */
378
+ declare function beat(home: string): void;
379
+ /** Clear the beacon. The daemon calls this whenever it is resident but NOT
380
+ * connected, so "idle" is never mistaken for "beating". */
381
+ declare function idle(home: string): void;
382
+ /**
383
+ * Always-on has THREE states, not two.
384
+ *
385
+ * It used to be a boolean pair, which could not tell "idle because nobody is
386
+ * signed in" apart from "installed and broken" — so a signed-out user would be
387
+ * nagged every session about a daemon that was behaving exactly as intended.
388
+ *
389
+ * off — the service is not installed (or was explicitly disabled).
390
+ * idle — installed and resident, but there is no identity to serve.
391
+ * Correct and quiet: the daemon is waiting for a sign-in.
392
+ * starting — registered moments ago and not beating yet. Also quiet: the
393
+ * service manager has not finished bringing it up.
394
+ * connected — holding the wire; the beacon is fresh.
395
+ * down — there IS an identity and the service is installed, but nothing
396
+ * is beating. The only state worth telling a session about.
397
+ *
398
+ * Pure reads, no subprocess, never throws.
399
+ */
400
+ type AlwaysOnState = 'off' | 'idle' | 'starting' | 'connected' | 'down';
401
+ declare function alwaysOnState(home: string): AlwaysOnState;
394
402
  /**
395
- * The full manual. `frontMatter` adds YAML front matter for hosts whose skill
396
- * loader requires it (Claude Code); hosts that read it as a plain file omit it.
403
+ * Back-compatible view for callers that only need "should I warn?".
404
+ * `healthy` is false ONLY in the `down` state — an idle daemon is healthy.
397
405
  */
398
- declare function renderManual(copy: ManualCopy, opts?: {
399
- frontMatter?: boolean;
400
- }): string;
406
+ declare function alwaysOnHealth(home: string): {
407
+ wanted: boolean;
408
+ healthy: boolean;
409
+ };
401
410
 
402
411
  interface LockHandle {
403
412
  release(): void;
404
413
  }
405
414
  declare function acquireLeaderLock(home: string): LockHandle | null;
406
415
 
407
- interface DaemonActivity {
408
- id: string;
409
- recorded_at: string;
410
- self_handle: string;
411
- source: 'always_on';
412
- conversation_id: string;
413
- peer_agents: string[];
414
- inbound_message_ids: string[];
415
- outcome: TurnDisposition;
416
- }
417
- interface RecordDaemonActivityInput {
418
- selfHandle: string;
419
- conversationId: string;
420
- peerAgents: string[];
421
- inboundMessageIds: string[];
422
- outcome: TurnDisposition;
423
- }
424
- declare function recordDaemonActivity(home: string, input: RecordDaemonActivityInput): DaemonActivity | null;
425
- declare function peekDaemonActivities(home: string, limit?: number): DaemonActivity[];
426
- declare function ackDaemonActivities(home: string, ids: string[]): void;
427
- declare function formatDaemonActivities(records: DaemonActivity[]): string | null;
428
-
429
416
  /**
430
417
  * Enough to ADDRESS an already-installed service. Removing one or reading its
431
418
  * status needs only its name — deliberately a narrower type than install, so
@@ -433,10 +420,24 @@ declare function formatDaemonActivities(records: DaemonActivity[]): string | nul
433
420
  * no use for.
434
421
  */
435
422
  interface ServiceRef {
436
- /** Unit/service name, e.g. `agentchatd-codex`. Must be unique per integration. */
423
+ /** Unit/service name, e.g. `agentchatd-codex` — from `serviceLabelFor`, so unique per identity home. */
437
424
  label: string;
438
425
  home: string;
426
+ /**
427
+ * Labels this service replaces (e.g. the plain label a relocated home was
428
+ * installed under before labels were per home). On install and uninstall,
429
+ * a superseded service whose definition serves THIS home is removed; one
430
+ * serving another home is left alone.
431
+ */
432
+ supersedes?: readonly string[];
439
433
  }
434
+ /**
435
+ * The service label for an identity home: `base` for the integration's
436
+ * default home (so existing installs keep their label), `base-<8 hex>` — a
437
+ * stable hash of the resolved path — for any other. Two configs of one
438
+ * integration on one machine then never share a launchd/systemd job.
439
+ */
440
+ declare function serviceLabelFor(base: string, home: string, defaultHome: string): string;
440
441
  interface ServiceOpts extends ServiceRef {
441
442
  /**
442
443
  * Absolute path to the integration's DAEMON bundle — the script this service
@@ -470,11 +471,37 @@ interface Plan {
470
471
  env: Record<string, string>;
471
472
  }
472
473
  declare function planForTest(opts: ServiceOpts): Plan;
474
+ type ServiceCommandRunner = (cmd: string, args: string[]) => {
475
+ ok: boolean;
476
+ out: string;
477
+ };
478
+ /**
479
+ * Tests only: answer `launchctl` / `systemctl` / `loginctl` with a fake, so a
480
+ * test can exercise the ownership guard without reaching the real service
481
+ * manager. `null` restores the real one.
482
+ */
483
+ declare function setServiceCommandRunnerForTests(runner: ServiceCommandRunner | null): void;
484
+ /**
485
+ * The identity home a service definition serves: the `--home` argument of
486
+ * its command. `plist` — a launchd plist (ProgramArguments); `launchctl` —
487
+ * `launchctl print` or `launchctl list <label>` output (one argument per
488
+ * line); `systemd` — a unit file (ExecStart). Null when there is none.
489
+ */
490
+ declare function parseServiceHome(text: string, format: 'plist' | 'launchctl' | 'systemd'): string | null;
473
491
  /** Quote one systemd command/environment word, including specifier escaping. */
474
492
  declare function systemdQuote(value: string): string;
475
493
  declare function systemdUnit(p: Plan): string;
476
494
  declare function xmlEscape(value: string): string;
477
495
  declare function launchdPlist(p: Plan): string;
496
+ /** The host as service management sees it. `wsl` is Linux under WSL2 (Windows Startup launcher, not systemd). */
497
+ type ServiceHostOs = 'linux' | 'darwin' | 'win32' | 'wsl' | 'other';
498
+ /**
499
+ * Tests only: pretend to be another host so the Linux and Windows command
500
+ * sequences can be pinned on any CI runner. Paths and the real service
501
+ * manager are never reached: pair it with a fake command runner and
502
+ * `AGENTCHATD_SERVICE_NO_START=1`.
503
+ */
504
+ declare function setServiceHostOsForTests(hostOs: ServiceHostOs | null): void;
478
505
  declare function installService(opts: ServiceOpts): void;
479
506
  declare function uninstallService(opts: ServiceRef): void;
480
507
  declare function serviceStatus(opts: ServiceRef): string;
@@ -489,22 +516,6 @@ declare const log: {
489
516
  debug: (msg: string) => void;
490
517
  };
491
518
 
492
- /** Coarse, human-facing age of a duration in ms. Never negative (a slightly
493
- * future timestamp from clock skew reads as "just now"). */
494
- declare function relativeAge(ms: number): string;
495
- /** "2026-07-24 14:32 UTC" — minute precision, timezone stated explicitly so an
496
- * agent never has to guess. `t` is an epoch-ms instant, so this is pure. */
497
- declare function absoluteUtc(t: number): string;
498
- /** Relative age only, e.g. "3 minutes ago". Empty string if `createdAt` is
499
- * missing or unparseable — callers append it conditionally so a bad/absent
500
- * timestamp degrades to today's timestamp-less line rather than "time unknown"
501
- * noise in a scan-list digest. */
502
- declare function relativeWhen(createdAt: string | undefined, now?: number): string;
503
- /** Relative age + absolute UTC, e.g. "3 minutes ago (2026-07-24 14:32 UTC)".
504
- * Falls back to "at an unknown time" when the stamp is missing/unparseable so
505
- * a single-message wake still reads as a sentence. */
506
- declare function formatWhen(createdAt: string | undefined, now?: number): string;
507
-
508
519
  declare function atomicWriteFile(filePath: string, data: string, mode?: number): void;
509
520
  /** Crash-safe file replacement for shipped executable bundles. */
510
521
  declare function atomicCopyFile(source: string, destination: string, mode?: number): void;
@@ -513,4 +524,4 @@ declare function readJsonFile<T>(filePath: string): T | null;
513
524
  declare const spawnCommand: typeof spawn;
514
525
  declare const spawnCommandSync: typeof spawnSync;
515
526
 
516
- export { ANCHOR_END, ANCHOR_START, type AnchorAction, type AutonomyCommandOpts, CODING_AGENTS_CLIENT_HEADERS, CODING_AGENTS_CLIENT_IDENTITY, type Credentials, DEFAULT_API_BASE, type DaemonActivity, type DoctorCheck, type DoctorOpts, type HookContext, type HookDialect, type HookInput, type HookRunners, type HookState, HostCopy, type HostProfile, type IdentityCommands, type LockHandle, type ManualCopy, type PendingCommandOpts, type PendingRegistration, type Plan, type RecordDaemonActivityInput, type RecoverOpts, type RegisterOpts, type ResolvedIdentity, type ServiceOpts, type ServiceRef, type SessionStartResult, type StopResult, type UserPromptResult, VERSION, type Verdict, absoluteUtc, ackDaemonActivities, acquireLeaderLock, anchorLabelOf, atomicCopyFile, atomicWriteFile, clearCredentials, clearOfferDeclined, clearPending, createHookRunners, createIdentityCommands, credentialsPath, formatDaemonActivities, formatWhen, getContinuations, hasAnchorAt, hooksDisabled, installService, launchdPlist, log, offerDeclined, peekDaemonActivities, pendingNoticeNeeded, pendingPath, planForTest, readAnchorHandleAt, readAnchorHandleFrom, readCredentials, readHookInput, readJsonFile, readPending, readState, recordContinuation, recordDaemonActivity, recordOfferDeclined, recordPendingNotice, recordRegistrationOffer, relativeAge, relativeWhen, removeAnchorAt, renderAnchorBlock, renderManual, resetSession, resolveIdentity, serviceDefinitionCurrent, serviceInstalled, serviceStatus, sessionEnd, sessionStart, setPendingAck, shouldOfferRegistration, spawnCommand, spawnCommandSync, statePath, stop, stripAnchorBlock, systemdQuote, systemdUnit, takePendingAck, uninstallService, upsertAnchorBlock, userPrompt, writeAnchor, writeCredentials, writePending, writeState, xmlEscape };
527
+ export { ANCHOR_END, ANCHOR_START, type AlwaysOnState, type AnchorAction, type Credentials, DEFAULT_API_BASE, type DoctorCheck, type DoctorContext, type DoctorOpts, HEARTBEAT_FILE, HOSTED_MCP_PATH, type HostCopy, type HostProfile, type IdentityCommands, type IdentityState, IntegrationClient, type LockHandle, MANUAL, MANUAL_FILENAME, MANUAL_SKILL_NAME, MANUAL_URL, type McpProbeResult, type PendingRegistration, type Plan, type RecoverOpts, type RegisterOpts, type ResolvedIdentity, type ServiceCommandRunner, type ServiceHostOs, type ServiceOpts, type ServiceRef, type StatusContext, type TrayClient, type TraySummary, VERSION, type Verdict, acquireLeaderLock, alwaysOnHealth, alwaysOnOptedOut, alwaysOnState, alwaysOnWanted, anchorIsCurrentAt, anchorLabelOf, atomicCopyFile, atomicWriteFile, beat, clearAlwaysOnInstalledVersion, clearAlwaysOnOptOut, clearAlwaysOnWanted, clearCredentials, clearOfferDeclined, clearPending, createIdentityCommands, credentialsPath, hasAnchorAt, hostedMcpUrl, identityLineOf, idle, installService, launchdPlist, log, manualPointer, manualVersion, markAlwaysOnInstalledVersion, markAlwaysOnOptOut, markAlwaysOnWanted, normalizeHandle, offerDeclined, parseServiceHome, pendingPath, planForTest, probeHostedMcp, readAlwaysOnInstalledVersion, readAnchorHandleAt, readAnchorHandleFrom, readCredentials, readJsonFile, readPending, readState, recordOfferDeclined, removeAnchorAt, renderAnchorBlock, renderDeclinedBlock, renderUnregisteredBlock, resolveIdentity, serviceDefinitionCurrent, serviceInstalled, serviceLabelFor, serviceStatus, setServiceCommandRunnerForTests, setServiceHostOsForTests, spawnCommand, spawnCommandSync, statePath, stripAnchorBlock, systemdQuote, systemdUnit, trayHasWaiting, traySummary, uninstallService, upsertAnchorBlock, writeAnchor, writeCredentials, writePending, writeState, xmlEscape };