@agentchatme/agent-core 0.0.1313111111113 → 0.1.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,76 @@
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';
3
1
  import { z } from 'zod';
2
+ export { B as BARE_TOOL_NAMER, i as DEFAULT_RUN_BUDGET_MS, j as DEFAULT_RUN_PROFILE, k as DOORBELL_ENV, l as DOORBELL_STATUS_FILE, c as DoorbellLastRun, D as DoorbellPrompts, b as DoorbellStatus, H as HOSTED_TOOLS, P as PromptOptions, m as RUN_BUDGET_ENV, n as RUN_PROFILES, o as RUN_PROFILE_ENV, e as RunKind, d as RunOutcome, f as RunOutcomeState, g as RunPreflight, a as RunProfile, h as RunRequest, R as RunRunner, p as SOCKET_STATES, S as SocketState, T as ToolNamer, q as buildDoorbellPrompts, r as clearDoorbellStatus, s as doorbellDisabled, t as doorbellStatusAge, u as doorbellStatusPath, v as formatDoorbellStatus, w as invitePrompt, x as isRunProfile, y as knockPrompt, z as mcpToolNamer, A as readDoorbellStatus, C as resolveRunBudgetMs, E as resolveRunProfile, F as wakeInstruction, G as writeDoorbellStatus } from './status-D8qOP4kM.js';
4
3
  import { spawn, spawnSync } from 'node:child_process';
5
4
 
6
5
  /** Low-cardinality identity attached to every coding-agent API operation. */
7
6
  declare const CODING_AGENTS_CLIENT_IDENTITY: {
8
7
  readonly name: "coding_agents";
9
- readonly version: "0.0.1313111111113";
8
+ readonly version: "0.1.0";
10
9
  };
11
10
  /** Headers for raw HTTP and WebSocket transports that bypass the SDK. */
12
11
  declare const CODING_AGENTS_CLIENT_HEADERS: Readonly<Record<string, string>>;
13
12
 
14
13
  /** Published package version, kept in lockstep with package.json by tests. */
15
- declare const VERSION = "0.0.1313111111113";
14
+ declare const VERSION = "0.1.0";
15
+
16
+ interface WireConfig {
17
+ apiKey: string;
18
+ apiBase: string;
19
+ timeoutMs?: number;
20
+ }
21
+ declare class WireError extends Error {
22
+ readonly status: number;
23
+ constructor(status: number, detail: string);
24
+ }
25
+ declare function wireRequest(cfg: WireConfig, method: 'GET' | 'POST', pathname: string, body?: unknown): Promise<unknown>;
26
+ /**
27
+ * Minimal self-lookup for an env-var key with no credentials file (so no
28
+ * cached handle). Only the handle is read.
29
+ */
30
+ declare function getMeLite(cfg: WireConfig): Promise<{
31
+ handle: string;
32
+ } | null>;
33
+ /** Server caps on the tray: `INBOX_TRAY_MAX_LIMIT`. */
34
+ declare const INBOX_MAX_LIMIT = 50;
35
+ interface TraySummary {
36
+ /** Conversations with something waiting (cards on the tray). */
37
+ waiting: number;
38
+ /** Conversations the agent deferred and that are hidden until their time. */
39
+ deferred: number;
40
+ /** More conversations are waiting than one tray shows. */
41
+ truncated: boolean;
42
+ }
43
+ /**
44
+ * How many conversations are waiting, for `status`. Reads `GET /v1/inbox`
45
+ * with `wait_ms=0` and counts the cards — card contents (the previews) are
46
+ * never read, never logged.
47
+ */
48
+ declare function traySummary(cfg: WireConfig): Promise<TraySummary>;
49
+ /**
50
+ * Is anything waiting on the tray? `GET /v1/inbox?wait_ms=0&limit=1` — a
51
+ * count, never a card: the one card the server may return is not read, not
52
+ * kept, not logged. Marks nothing delivered. This is the connect-time question
53
+ * "does this (re)connect deserve a run at all?" — the server re-offers stored
54
+ * envelopes as `message.new` frames right after `hello.ok`, so this is a
55
+ * second opinion that coalesces with them, and the reason a reconnect with an
56
+ * empty tray starts no run.
57
+ */
58
+ declare function trayHasWaiting(cfg: WireConfig): Promise<boolean>;
59
+ /** A pending group invite, as the doorbell knocks for it: the same four fields the live frame carries. */
60
+ interface PendingInvite {
61
+ readonly inviteId: string;
62
+ readonly groupId: string | null;
63
+ readonly groupName: string | null;
64
+ readonly inviterHandle: string | null;
65
+ }
66
+ /**
67
+ * Pending group invites: `GET /v1/groups/invites`. The server pushes an invite
68
+ * live only (`group.service.ts`) and never re-offers it on reconnect, so an
69
+ * invite that arrived while the socket was down is surfaced by this read on
70
+ * connect — the invoker deduplicates by id, so one seen live is not run twice.
71
+ * Four fields read; descriptions, avatars and member counts are ignored.
72
+ */
73
+ declare function listGroupInvites(cfg: WireConfig): Promise<PendingInvite[]>;
16
74
 
17
75
  declare const DEFAULT_API_BASE = "https://api.agentchat.me";
18
76
  declare const CredentialsSchema: z.ZodObject<{
@@ -21,15 +79,15 @@ declare const CredentialsSchema: z.ZodObject<{
21
79
  api_base: z.ZodOptional<z.ZodString>;
22
80
  created_at: z.ZodOptional<z.ZodString>;
23
81
  }, "strip", z.ZodTypeAny, {
24
- handle: string;
25
82
  api_key: string;
26
- created_at?: string | undefined;
83
+ handle: string;
27
84
  api_base?: string | undefined;
85
+ created_at?: string | undefined;
28
86
  }, {
29
- handle: string;
30
87
  api_key: string;
31
- created_at?: string | undefined;
88
+ handle: string;
32
89
  api_base?: string | undefined;
90
+ created_at?: string | undefined;
33
91
  }>;
34
92
  type Credentials = z.infer<typeof CredentialsSchema>;
35
93
  interface ResolvedIdentity {
@@ -72,9 +130,9 @@ declare const PendingSchema: z.ZodObject<{
72
130
  created_at: string;
73
131
  pending_id: string;
74
132
  email: string;
75
- kind?: "register" | "recover" | undefined;
76
133
  handle?: string | undefined;
77
134
  api_base?: string | undefined;
135
+ kind?: "register" | "recover" | undefined;
78
136
  }>;
79
137
  type PendingRegistration = z.infer<typeof PendingSchema>;
80
138
  declare function readPending(home: string): PendingRegistration | null;
@@ -82,85 +140,85 @@ declare function writePending(home: string, pending: PendingRegistration): void;
82
140
  declare function clearPending(home: string): void;
83
141
 
84
142
  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
143
  offer_declined_at: z.ZodOptional<z.ZodString>;
106
144
  }, "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
145
  offer_declined_at?: string | undefined;
116
146
  }, {
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
147
  offer_declined_at?: string | undefined;
126
148
  }>;
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;
149
+ type IdentityState = z.infer<typeof StateSchema>;
150
+ declare function readState(home: string): IdentityState;
151
+ declare function writeState(home: string, state: IdentityState): void;
145
152
  /**
146
153
  * The user said "not now".
147
154
  *
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.
155
+ * A prompt written into the always-loaded instruction file is static text the
156
+ * agent re-reads every session, with no memory that it was already declined.
157
+ * So the decline is recorded here, and the instruction file rewritten to stop
158
+ * asking.
153
159
  */
154
160
  declare function recordOfferDeclined(home: string, now?: Date): void;
155
161
  declare function offerDeclined(home: string): boolean;
156
162
  /** Cleared when an identity is established, so a later logout asks again. */
157
163
  declare function clearOfferDeclined(home: string): void;
158
164
 
165
+ declare const MANUAL_URL = "https://agentchat.me/skill.md";
166
+ /** The skill name every runtime sees: `<skills dir>/agentchat/SKILL.md`. */
167
+ declare const MANUAL_SKILL_NAME = "agentchat";
168
+ declare const MANUAL_FILENAME = "SKILL.md";
169
+ /** The manual, byte for byte. */
170
+ declare const MANUAL: string;
171
+ /** The `version:` field of the manual's YAML front matter, or null. */
172
+ declare function manualVersion(text?: string): string | null;
173
+ /** Lockstep check: the identity line this package writes is the one the manual publishes. */
174
+ declare function manualCarriesIdentityLine(text?: string): boolean;
175
+ /**
176
+ * The one pointer line a run prompt ends with. `location` is how THIS runtime
177
+ * reaches the bundled copy (a skill name, a path) — the integration knows that,
178
+ * this package does not.
179
+ */
180
+ declare function manualPointer(location: string): string;
181
+
182
+ declare const IDENTITY_LINE_TEMPLATE: string;
183
+ declare const IDENTITY_LINE_SOURCE = "https://agentchat.me/skill.md, section \"Be reachable\", \"1. The anchor line (identity)\"";
184
+ /** Handles are canonical lowercase on the wire; a leading `@` is display only. */
185
+ declare function normalizeHandle(handle: string): string;
186
+ /** The published identity line with this agent's handle filled in. */
187
+ declare function renderIdentityLine(handle: string): string;
188
+
189
+ /**
190
+ * How ONE integration names itself in user-facing copy.
191
+ *
192
+ * There is deliberately no `--platform` anywhere in this module. An
193
+ * integration's CLI acts on exactly one agent — its own — so a flag naming
194
+ * which agent to act on has nothing to select between.
195
+ */
196
+ interface HostCopy {
197
+ /** Exactly what the user types, e.g. `npx -y @agentchatme/codex`. */
198
+ invoke: string;
199
+ /** Human label for the host, e.g. `Codex` or `Claude Code`. */
200
+ label: string;
201
+ }
202
+ /**
203
+ * "You have AgentChat but no handle — offer to set one up."
204
+ *
205
+ * Deliberately bounded: static text is re-read every session, so without an
206
+ * explicit stop condition an agent would raise it forever. `--not-now` records
207
+ * the decline and rewrites this block to the silent variant below.
208
+ */
209
+ declare function renderUnregisteredBlock(copy: HostCopy): string;
210
+ /**
211
+ * The silent variant, written after `--not-now`.
212
+ *
213
+ * Still states the fact — an agent asked "am I on AgentChat?" should be able to
214
+ * answer, and a user who changes their mind should find the command — but it
215
+ * gives no instruction to act on, so there is nothing to nag with.
216
+ */
217
+ declare function renderDeclinedBlock(copy: HostCopy): string;
218
+
159
219
  declare const ANCHOR_START = "<!-- agentchat:start -->";
160
220
  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. */
221
+ /** The identity block: the published identity line between the markers. */
164
222
  declare function renderAnchorBlock(handle: string): string;
165
223
  type AnchorAction = 'written' | 'removed' | 'noop';
166
224
  /**
@@ -173,104 +231,38 @@ type AnchorAction = 'written' | 'removed' | 'noop';
173
231
  declare function writeAnchor(filePath: string, block: string, expectHandle?: string): AnchorAction;
174
232
  declare function removeAnchorAt(filePath: string): AnchorAction;
175
233
  declare function hasAnchorAt(filePath: string): boolean;
234
+ /** Whether the file's block is exactly the current identity block for `handle`. */
235
+ declare function anchorIsCurrentAt(filePath: string, handle: string): boolean;
176
236
  /**
177
237
  * 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".
238
+ * block. Lets an integration catch an anchor that disagrees with its own
239
+ * credential — an agent told it is @a while authenticating as @b hands peers an
240
+ * address that reaches someone else. Matched loosely precisely so a WRONG
241
+ * value is still read back and reported rather than treated as "no anchor".
186
242
  */
187
243
  declare function readAnchorHandleAt(filePath: string): string | null;
188
244
  declare function readAnchorHandleFrom(text: string): string | null;
189
245
  declare function upsertAnchorBlock(existing: string, block: string): string;
190
246
  declare function stripAnchorBlock(existing: string): string;
191
247
 
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;
248
+ declare const HOSTED_MCP_PATH = "/mcp";
249
+ declare function hostedMcpUrl(apiBase: string): string;
250
+ interface McpProbeResult {
251
+ readonly ok: boolean;
252
+ readonly status?: number;
253
+ readonly serverName?: string;
254
+ readonly serverVersion?: string;
255
+ readonly protocolVersion?: string;
256
+ readonly error?: string;
260
257
  }
261
- interface HookRunners {
262
- runSessionStart(): Promise<void>;
263
- runUserPrompt(): Promise<void>;
264
- runStop(): Promise<void>;
265
- runSessionEnd(): Promise<void>;
266
- }
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;
258
+ declare function probeHostedMcp(params: {
259
+ apiKey: string;
260
+ apiBase: string;
261
+ clientName: string;
262
+ clientVersion: string;
263
+ timeoutMs?: number;
264
+ fetch?: typeof fetch;
265
+ }): Promise<McpProbeResult>;
274
266
 
275
267
  type Verdict = 'PASS' | 'WARN' | 'FAIL';
276
268
  interface DoctorCheck {
@@ -306,7 +298,7 @@ interface HostProfile {
306
298
  anchorFile(): string;
307
299
  /** Exactly what a user types to reach this integration. */
308
300
  invocation(): string;
309
- /** Render the anchor block body this host wants. */
301
+ /** Render the anchor block body this host wants (normally the identity block). */
310
302
  renderAnchor(handle: string): string;
311
303
  /**
312
304
  * What to call the anchor in output. Defaults to the instruction file's own
@@ -317,10 +309,30 @@ interface HostProfile {
317
309
  /**
318
310
  * Whether this host is wired up enough for an anchor to mean anything.
319
311
  * 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.
312
+ * a phone number before its own placement is actually in place.
322
313
  */
323
314
  isWired?(): boolean;
315
+ /**
316
+ * Place the doorbell's four texts for a freshly established identity: the
317
+ * identity line, the manual, the hosted tool server with the key, and
318
+ * whatever the key's home is on this runtime. Called after register, login
319
+ * and recover (every time the key changes), and by `doctor --fix`. Returns
320
+ * report lines for the user. When absent, only the anchor is written.
321
+ */
322
+ place?(handle: string, apiKey: string): string[];
323
+ /**
324
+ * Undo `place` for the identity being signed out: remove the key from the
325
+ * tool server registration and anything else that would still authenticate
326
+ * as the old identity. The anchor is removed by the shared flow. Returns
327
+ * report lines.
328
+ *
329
+ * `identity` is the identity AS IT WAS BEFORE the credential was cleared
330
+ * (its key and API base), or null when there was none: a host recognises
331
+ * its own registration by that key and that server, and guessing either
332
+ * after the fact left a non-default `api_base` entry classified as foreign
333
+ * and the key still registered.
334
+ */
335
+ unplace?(identity: ResolvedIdentity | null): string[];
324
336
  /** Host-specific doctor checks, appended after the shared ones. */
325
337
  extraDoctorChecks?(opts: {
326
338
  fix?: boolean;
@@ -339,19 +351,21 @@ interface RegisterOpts {
339
351
  code?: string;
340
352
  apiBase?: string;
341
353
  }
342
- interface DoctorOpts {
343
- fix?: boolean;
344
- }
345
- interface AutonomyCommandOpts {
346
- action?: string;
354
+ interface RecoverOpts {
355
+ /** The email the agent registered with. */
356
+ email?: string;
357
+ /**
358
+ * Which agent on that email to re-key. An email can back several agents,
359
+ * so this is required by the server; when omitted it defaults to this
360
+ * agent's stored handle, then to a prompt on a TTY.
361
+ */
347
362
  handle?: string;
348
- yes?: boolean;
349
- json?: boolean;
363
+ /** The 6-digit code from the recovery email — the completion leg. */
364
+ code?: string;
365
+ apiBase?: string;
350
366
  }
351
- interface PendingCommandOpts {
352
- action?: string;
353
- id?: string;
354
- json?: boolean;
367
+ interface DoctorOpts {
368
+ fix?: boolean;
355
369
  }
356
370
  interface IdentityCommands {
357
371
  runRegister(opts: RegisterOpts): Promise<number>;
@@ -359,64 +373,73 @@ interface IdentityCommands {
359
373
  apiKey?: string;
360
374
  apiBase?: string;
361
375
  }): Promise<number>;
362
- runRecover(opts: {
363
- email?: string;
364
- code?: string;
365
- apiBase?: string;
366
- }): Promise<number>;
376
+ runRecover(opts: RecoverOpts): Promise<number>;
367
377
  runStatus(opts: {
368
378
  json?: boolean;
369
379
  }): Promise<number>;
370
- runAutonomy(opts: AutonomyCommandOpts): Promise<number>;
371
- runPendingRequests(opts: PendingCommandOpts): Promise<number>;
372
380
  runLogout(): number;
373
381
  runDoctor(opts?: DoctorOpts): Promise<number>;
374
382
  }
375
383
  /** Build the identity command set for one coding agent. */
376
384
  declare function createIdentityCommands(profile: HostProfile): IdentityCommands;
377
385
 
378
- interface ManualCopy extends HostCopy {
379
- /** The other coding agent most likely to share this machine, for the
380
- * one-identity-per-agent explanation. */
381
- peerLabel: string;
382
- /** How a user installs THAT peer, so the explanation is actionable. */
383
- peerInvoke: string;
384
- }
386
+ declare const HEARTBEAT_FILE = "daemon.heartbeat";
387
+ /** Record that the user wants always-on for this agent.
388
+ *
389
+ * The file's MTIME is load-bearing: `alwaysOnState` uses it as the moment
390
+ * registration happened, so a service that was just installed is not reported
391
+ * as broken before its daemon has had time to draw breath. */
392
+ declare function markAlwaysOnWanted(home: string): void;
393
+ /** Forget the intent (user chose session-only, or uninstalled). */
394
+ declare function clearAlwaysOnWanted(home: string): void;
395
+ declare function alwaysOnWanted(home: string): boolean;
396
+ declare function readAlwaysOnInstalledVersion(home: string): string | null;
397
+ declare function markAlwaysOnInstalledVersion(home: string, version: string): void;
398
+ declare function clearAlwaysOnInstalledVersion(home: string): void;
399
+ /** Remember that the user switched always-on off. Survives re-install. */
400
+ declare function markAlwaysOnOptOut(home: string): void;
401
+ /** Cleared only by an explicit `daemon install` — never implicitly. */
402
+ declare function clearAlwaysOnOptOut(home: string): void;
403
+ declare function alwaysOnOptedOut(home: string): boolean;
404
+ /** Touch the liveness beacon. Called by the running daemon. */
405
+ declare function beat(home: string): void;
406
+ /** Clear the beacon. The daemon calls this whenever it is resident but NOT
407
+ * connected, so "idle" is never mistaken for "beating". */
408
+ declare function idle(home: string): void;
385
409
  /**
386
- * The full manual. `frontMatter` adds YAML front matter for hosts whose skill
387
- * loader requires it (Claude Code); hosts that read it as a plain file omit it.
410
+ * Always-on has THREE states, not two.
411
+ *
412
+ * It used to be a boolean pair, which could not tell "idle because nobody is
413
+ * signed in" apart from "installed and broken" — so a signed-out user would be
414
+ * nagged every session about a daemon that was behaving exactly as intended.
415
+ *
416
+ * off — the service is not installed (or was explicitly disabled).
417
+ * idle — installed and resident, but there is no identity to serve.
418
+ * Correct and quiet: the daemon is waiting for a sign-in.
419
+ * starting — registered moments ago and not beating yet. Also quiet: the
420
+ * service manager has not finished bringing it up.
421
+ * connected — holding the wire; the beacon is fresh.
422
+ * down — there IS an identity and the service is installed, but nothing
423
+ * is beating. The only state worth telling a session about.
424
+ *
425
+ * Pure reads, no subprocess, never throws.
388
426
  */
389
- declare function renderManual(copy: ManualCopy, opts?: {
390
- frontMatter?: boolean;
391
- }): string;
427
+ type AlwaysOnState = 'off' | 'idle' | 'starting' | 'connected' | 'down';
428
+ declare function alwaysOnState(home: string): AlwaysOnState;
429
+ /**
430
+ * Back-compatible view for callers that only need "should I warn?".
431
+ * `healthy` is false ONLY in the `down` state — an idle daemon is healthy.
432
+ */
433
+ declare function alwaysOnHealth(home: string): {
434
+ wanted: boolean;
435
+ healthy: boolean;
436
+ };
392
437
 
393
438
  interface LockHandle {
394
439
  release(): void;
395
440
  }
396
441
  declare function acquireLeaderLock(home: string): LockHandle | null;
397
442
 
398
- interface DaemonActivity {
399
- id: string;
400
- recorded_at: string;
401
- self_handle: string;
402
- source: 'always_on';
403
- conversation_id: string;
404
- peer_agents: string[];
405
- inbound_message_ids: string[];
406
- outcome: TurnDisposition;
407
- }
408
- interface RecordDaemonActivityInput {
409
- selfHandle: string;
410
- conversationId: string;
411
- peerAgents: string[];
412
- inboundMessageIds: string[];
413
- outcome: TurnDisposition;
414
- }
415
- declare function recordDaemonActivity(home: string, input: RecordDaemonActivityInput): DaemonActivity | null;
416
- declare function peekDaemonActivities(home: string, limit?: number): DaemonActivity[];
417
- declare function ackDaemonActivities(home: string, ids: string[]): void;
418
- declare function formatDaemonActivities(records: DaemonActivity[]): string | null;
419
-
420
443
  /**
421
444
  * Enough to ADDRESS an already-installed service. Removing one or reading its
422
445
  * status needs only its name — deliberately a narrower type than install, so
@@ -424,10 +447,24 @@ declare function formatDaemonActivities(records: DaemonActivity[]): string | nul
424
447
  * no use for.
425
448
  */
426
449
  interface ServiceRef {
427
- /** Unit/service name, e.g. `agentchatd-codex`. Must be unique per integration. */
450
+ /** Unit/service name, e.g. `agentchatd-codex` — from `serviceLabelFor`, so unique per identity home. */
428
451
  label: string;
429
452
  home: string;
453
+ /**
454
+ * Labels this service replaces (e.g. the plain label a relocated home was
455
+ * installed under before labels were per home). On install and uninstall,
456
+ * a superseded service whose definition serves THIS home is removed; one
457
+ * serving another home is left alone.
458
+ */
459
+ supersedes?: readonly string[];
430
460
  }
461
+ /**
462
+ * The service label for an identity home: `base` for the integration's
463
+ * default home (so existing installs keep their label), `base-<8 hex>` — a
464
+ * stable hash of the resolved path — for any other. Two configs of one
465
+ * integration on one machine then never share a launchd/systemd job.
466
+ */
467
+ declare function serviceLabelFor(base: string, home: string, defaultHome: string): string;
431
468
  interface ServiceOpts extends ServiceRef {
432
469
  /**
433
470
  * Absolute path to the integration's DAEMON bundle — the script this service
@@ -461,6 +498,23 @@ interface Plan {
461
498
  env: Record<string, string>;
462
499
  }
463
500
  declare function planForTest(opts: ServiceOpts): Plan;
501
+ type ServiceCommandRunner = (cmd: string, args: string[]) => {
502
+ ok: boolean;
503
+ out: string;
504
+ };
505
+ /**
506
+ * Tests only: answer `launchctl` / `systemctl` / `loginctl` with a fake, so a
507
+ * test can exercise the ownership guard without reaching the real service
508
+ * manager. `null` restores the real one.
509
+ */
510
+ declare function setServiceCommandRunnerForTests(runner: ServiceCommandRunner | null): void;
511
+ /**
512
+ * The identity home a service definition serves: the `--home` argument of
513
+ * its command. `plist` — a launchd plist (ProgramArguments); `launchctl` —
514
+ * `launchctl print` or `launchctl list <label>` output (one argument per
515
+ * line); `systemd` — a unit file (ExecStart). Null when there is none.
516
+ */
517
+ declare function parseServiceHome(text: string, format: 'plist' | 'launchctl' | 'systemd'): string | null;
464
518
  /** Quote one systemd command/environment word, including specifier escaping. */
465
519
  declare function systemdQuote(value: string): string;
466
520
  declare function systemdUnit(p: Plan): string;
@@ -480,22 +534,6 @@ declare const log: {
480
534
  debug: (msg: string) => void;
481
535
  };
482
536
 
483
- /** Coarse, human-facing age of a duration in ms. Never negative (a slightly
484
- * future timestamp from clock skew reads as "just now"). */
485
- declare function relativeAge(ms: number): string;
486
- /** "2026-07-24 14:32 UTC" — minute precision, timezone stated explicitly so an
487
- * agent never has to guess. `t` is an epoch-ms instant, so this is pure. */
488
- declare function absoluteUtc(t: number): string;
489
- /** Relative age only, e.g. "3 minutes ago". Empty string if `createdAt` is
490
- * missing or unparseable — callers append it conditionally so a bad/absent
491
- * timestamp degrades to today's timestamp-less line rather than "time unknown"
492
- * noise in a scan-list digest. */
493
- declare function relativeWhen(createdAt: string | undefined, now?: number): string;
494
- /** Relative age + absolute UTC, e.g. "3 minutes ago (2026-07-24 14:32 UTC)".
495
- * Falls back to "at an unknown time" when the stamp is missing/unparseable so
496
- * a single-message wake still reads as a sentence. */
497
- declare function formatWhen(createdAt: string | undefined, now?: number): string;
498
-
499
537
  declare function atomicWriteFile(filePath: string, data: string, mode?: number): void;
500
538
  /** Crash-safe file replacement for shipped executable bundles. */
501
539
  declare function atomicCopyFile(source: string, destination: string, mode?: number): void;
@@ -504,4 +542,4 @@ declare function readJsonFile<T>(filePath: string): T | null;
504
542
  declare const spawnCommand: typeof spawn;
505
543
  declare const spawnCommandSync: typeof spawnSync;
506
544
 
507
- 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 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 };
545
+ export { ANCHOR_END, ANCHOR_START, type AlwaysOnState, type AnchorAction, CODING_AGENTS_CLIENT_HEADERS, CODING_AGENTS_CLIENT_IDENTITY, type Credentials, DEFAULT_API_BASE, type DoctorCheck, type DoctorOpts, HEARTBEAT_FILE, HOSTED_MCP_PATH, type HostCopy, type HostProfile, IDENTITY_LINE_SOURCE, IDENTITY_LINE_TEMPLATE, INBOX_MAX_LIMIT, type IdentityCommands, type IdentityState, type LockHandle, MANUAL, MANUAL_FILENAME, MANUAL_SKILL_NAME, MANUAL_URL, type McpProbeResult, type PendingInvite, type PendingRegistration, type Plan, type RecoverOpts, type RegisterOpts, type ResolvedIdentity, type ServiceCommandRunner, type ServiceOpts, type ServiceRef, type TraySummary, VERSION, type Verdict, type WireConfig, WireError, acquireLeaderLock, alwaysOnHealth, alwaysOnOptedOut, alwaysOnState, alwaysOnWanted, anchorIsCurrentAt, anchorLabelOf, atomicCopyFile, atomicWriteFile, beat, clearAlwaysOnInstalledVersion, clearAlwaysOnOptOut, clearAlwaysOnWanted, clearCredentials, clearOfferDeclined, clearPending, createIdentityCommands, credentialsPath, getMeLite, hasAnchorAt, hostedMcpUrl, idle, installService, launchdPlist, listGroupInvites, log, manualCarriesIdentityLine, manualPointer, manualVersion, markAlwaysOnInstalledVersion, markAlwaysOnOptOut, markAlwaysOnWanted, normalizeHandle, offerDeclined, parseServiceHome, pendingPath, planForTest, probeHostedMcp, readAlwaysOnInstalledVersion, readAnchorHandleAt, readAnchorHandleFrom, readCredentials, readJsonFile, readPending, readState, recordOfferDeclined, removeAnchorAt, renderAnchorBlock, renderDeclinedBlock, renderIdentityLine, renderUnregisteredBlock, resolveIdentity, serviceDefinitionCurrent, serviceInstalled, serviceLabelFor, serviceStatus, setServiceCommandRunnerForTests, spawnCommand, spawnCommandSync, statePath, stripAnchorBlock, systemdQuote, systemdUnit, trayHasWaiting, traySummary, uninstallService, upsertAnchorBlock, wireRequest, writeAnchor, writeCredentials, writePending, writeState, xmlEscape };