@agentchatme/agent-core 0.7.1 → 0.8.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.
@@ -1,4 +1,4 @@
1
- import { TextsRuntime, AgentChatClientIdentity, SignupFlow, integration } from 'agentchatme';
1
+ import { TextsRuntime, AgentChatClientIdentity, Texts, integration, SignupFlow } from 'agentchatme';
2
2
  import { z } from 'zod';
3
3
 
4
4
  declare const LEASE_RENEW_MS = 10000;
@@ -95,6 +95,16 @@ interface IntegrationClient {
95
95
  * names itself here, and `runtime` stays what the texts are rendered for.
96
96
  */
97
97
  readonly name?: string;
98
+ /**
99
+ * The runtime this integration runs inside and its version, as
100
+ * `<runtime>/<version>` (`claude-code/2.1.332`; `hostIdentityOf`): `host`
101
+ * in X-AgentChat-Platform. Absent when it could not be read.
102
+ */
103
+ readonly host?: string;
104
+ /** This identity home's install id (`ensureInstallId`): `install` in X-AgentChat-Platform. */
105
+ readonly installId?: string;
106
+ /** How this integration was installed, only when known for sure (`installMethodOf`): `method`. */
107
+ readonly installMethod?: string;
98
108
  }
99
109
  /** The name this client identifies as: its own `name`, else its runtime. */
100
110
  declare function clientNameOf(client: IntegrationClient): string;
@@ -104,9 +114,536 @@ declare function clientNameOf(client: IntegrationClient): string;
104
114
  * runtime name is passed through as-is; the union widens on the SDK side.
105
115
  */
106
116
  declare function clientIdentityOf(client: IntegrationClient): AgentChatClientIdentity;
107
- /** The same identity as headers, for the one raw request this package still makes (the MCP probe). */
117
+ /**
118
+ * `<runtime>/<version>` from a runtime's own version output (`claude
119
+ * --version` → `2.1.332 (Claude Code)`, `codex --version` → `codex-cli
120
+ * 0.154.0`): the first `x.y.z` in it. Null when it holds none.
121
+ */
122
+ declare function hostIdentityOf(runtime: string, versionOutput: string): string | null;
123
+ /**
124
+ * How the code at `modulePath` was installed, only when that is certain from
125
+ * where it runs: `npx` for npm's exec cache (`…/_npx/<hash>/node_modules/…`).
126
+ * Null otherwise (a global install, a checkout, a copy the service runs):
127
+ * the method is left out rather than guessed.
128
+ */
129
+ declare function installMethodOf(modulePath: string): string | null;
130
+ /**
131
+ * The client headers placed in a runtime's own tool configuration (the MCP
132
+ * entries a run reads), where they stay until the next placement. They name
133
+ * the integration and its version only: X-AgentChat-Platform is per request
134
+ * (the SDK sends it on every call it makes, the hosted-tools probe included),
135
+ * and a platform written into a config file would go stale there.
136
+ */
108
137
  declare function clientHeadersOf(client: IntegrationClient): Record<string, string>;
109
138
 
139
+ /**
140
+ * Where the manual is when no served texts are in hand: the offline floor for
141
+ * a first install, never the address a run is pointed at while texts are
142
+ * (`servedManualUrl`).
143
+ */
144
+ declare const MANUAL_URL = "https://agentchat.me/skill.md";
145
+ /** The skill name every runtime sees: `<skills dir>/agentchat/SKILL.md`. */
146
+ declare const MANUAL_SKILL_NAME = "agentchat";
147
+ declare const MANUAL_FILENAME = "SKILL.md";
148
+ /** The bundled copy, byte for byte (the fallback; the served manual is the source). */
149
+ declare const MANUAL: string;
150
+ /**
151
+ * The YAML front matter's top-level `key: value` fields, or null when the text
152
+ * does not open with a front matter block. Deliberately not a YAML parser:
153
+ * the manual's front matter is flat, and nothing here interprets more of a
154
+ * downloaded text than its name and version. A leading byte-order mark and
155
+ * CRLF line endings (a file saved by a Windows editor) read the same as LF.
156
+ */
157
+ declare function manualFrontMatter(raw: string): ReadonlyMap<string, string> | null;
158
+ /** The `version:` field of the manual's YAML front matter, or null. */
159
+ declare function manualVersion(text?: string): string | null;
160
+ /**
161
+ * Where the served texts say the manual is (`texts.manual.url`), or
162
+ * `MANUAL_URL` when no texts are in hand. Only an address a run can follow
163
+ * counts, under the manual download's own rule: an absolute `https:` URL, or
164
+ * plain `http:` to loopback (a development server). Anything else — another
165
+ * scheme, a relative path, credentials in it, whitespace or a control
166
+ * character in it (more than an address) — reads as none.
167
+ */
168
+ declare function servedManualUrl(texts: Pick<Texts, 'manual'> | null | undefined): string;
169
+ /**
170
+ * The one pointer line a run prompt ends with. `location` is how THIS runtime
171
+ * reaches its copy of the manual (a skill name, a path) — the integration knows
172
+ * that, this package does not. `url` is where the served texts say the manual
173
+ * is (`servedManualUrl`); `MANUAL_URL` only when none are in hand.
174
+ */
175
+ declare function manualPointer(location: string, url?: string): string;
176
+ /**
177
+ * The pointer a run prompt ends with, as an integration hands it to the
178
+ * daemon: a function of the manual's address, called for each run with the
179
+ * address the texts in hand announce (`servedManualUrl`), so the line follows
180
+ * the served texts. A plain string is used as it is (an empty one adds
181
+ * nothing).
182
+ */
183
+ type ManualPointer = string | ((manualUrl: string) => string);
184
+ /** The pointer line for a run, with the manual's address the texts in hand announce. */
185
+ declare function resolveManualPointer(pointer: ManualPointer, texts: Pick<Texts, 'manual'> | null | undefined): string;
186
+
187
+ /** The kit's outcomes (`integration.anchor.FollowOutcome`): `updated`, `unchanged`, `absent`, `setup_offer`, `hand_edited`, `other_agent`, `several_blocks`, `edited_meanwhile`, `failed`. */
188
+ type IdentityAnchorOutcome = Awaited<ReturnType<typeof integration.anchor.follow>>['outcome'];
189
+ interface IdentityAnchorResult {
190
+ readonly outcome: IdentityAnchorOutcome;
191
+ readonly path: string;
192
+ /** The handle the block is AgentChat's for (for `other_agent`, the other agent's); null otherwise. */
193
+ readonly claimed: string | null;
194
+ /** What happened, in words, for the log and the status file — with the repair, where one applies. */
195
+ readonly detail: string;
196
+ }
197
+ interface FollowIdentityAnchorOptions {
198
+ /** The host's always-loaded instruction file. */
199
+ readonly filePath: string;
200
+ /** The agent this daemon serves. */
201
+ readonly handle: string;
202
+ /** The served identity line (`texts.identity_line`). */
203
+ readonly identityLine: string;
204
+ /** The served `identity_line_template`: a block with no handle line whose text is this, filled in, is AgentChat's. */
205
+ readonly template?: string | null;
206
+ /** Test seam: the kit's `beforeWrite` (the new text flushed beside the file, before the file is read again for the rename). */
207
+ readonly beforeWrite?: () => void | Promise<void>;
208
+ }
209
+ /** Decisions in all before a file that keeps changing is left for now (the kit's `FOLLOW_ATTEMPTS`). */
210
+ declare const IDENTITY_ANCHOR_ATTEMPTS: number;
211
+ /**
212
+ * Bring this agent's identity block in `filePath` to the served line: the
213
+ * kit's `follow`, with this package's setup offer recognised and the repair
214
+ * named. Never creates a block (nor the file), never touches one that is not
215
+ * this agent's, and never throws.
216
+ */
217
+ declare function followIdentityAnchor(options: FollowIdentityAnchorOptions): Promise<IdentityAnchorResult>;
218
+ /** The served line a host's `anchorLoadNote` judges another file's block against (the texts in hand; nulls when none are). */
219
+ interface AnchorServedLine {
220
+ readonly identityLine: string | null;
221
+ readonly template: string | null;
222
+ }
223
+ /**
224
+ * What a host says when its runtime loads another file in the instruction
225
+ * file's place (`HostProfile.anchorLoadNote`): one clause naming the file
226
+ * the runtime loads, and whether the identity line it gets there is the
227
+ * served one. Said by `status`, `doctor` and every daemon follow; nothing
228
+ * writes that other file.
229
+ */
230
+ interface AnchorLoadNote {
231
+ /** One clause, naming the file the runtime loads, and what to do when `ok` is false. */
232
+ readonly note: string;
233
+ /**
234
+ * True: the runtime loads the served identity line all the same (from the
235
+ * other file); the note is said, nothing is wrong. False: it loads no
236
+ * identity line, or an older one — never a PASS.
237
+ */
238
+ readonly ok: boolean;
239
+ }
240
+ /**
241
+ * - `current` — this agent's block, the served one (`checked: false`: no usable served line in hand to compare with);
242
+ * - `stale` — this agent's block, older text or an older shape;
243
+ * - `missing` — no file, or no AgentChat block in it;
244
+ * - `setup_offer`, `hand_edited`, `other_agent`, `several_blocks` — as the follow says;
245
+ * - `unreadable` — the file exists but cannot be read (permissions, a symlink loop, not UTF-8).
246
+ */
247
+ type IdentityBlockStateName = 'current' | 'stale' | 'missing' | 'setup_offer' | 'hand_edited' | 'other_agent' | 'several_blocks' | 'unreadable';
248
+ interface IdentityBlockState {
249
+ readonly state: IdentityBlockStateName;
250
+ /** `doctor`'s verdict: PASS only for the served block where the runtime loads it; FAIL when the file cannot be read; WARN otherwise. */
251
+ readonly verdict: 'PASS' | 'WARN' | 'FAIL';
252
+ /** A usable served line was in hand, so currency was compared (false: `current` means this agent's block, unchecked). */
253
+ readonly checked: boolean;
254
+ /** The handle the block is AgentChat's for (the kit's `owner`), or null. */
255
+ readonly claimed: string | null;
256
+ /** What the host says about the file its runtime loads instead (`anchorLoadNote`), or null when it loads this one. */
257
+ readonly loadNote: AnchorLoadNote | null;
258
+ /** That note when the runtime does not get the served line (`loadNote.ok` false), else null: what `status --json` carries as `anchor_not_loaded`. */
259
+ readonly notLoaded: string | null;
260
+ /** What the block is, in one clause, naming the file (no repair: `describeIdentityBlock` adds it). */
261
+ readonly what: string;
262
+ }
263
+ interface IdentityBlockStateOptions {
264
+ readonly handle: string;
265
+ readonly identityLine: string | null;
266
+ readonly template: string | null;
267
+ /** The host's note on the file its runtime loads instead (`anchorLoadNote`); null when it loads this one. */
268
+ readonly loadNote?: AnchorLoadNote | null;
269
+ }
270
+ /**
271
+ * What the block in `filePath` is, read the way the daemon decides (the
272
+ * kit's `decide`; its `owner` when no usable served line is in hand), for
273
+ * `status` and `doctor`. Never throws: a file that cannot be read is
274
+ * `unreadable`.
275
+ */
276
+ declare function identityBlockState(filePath: string, options: IdentityBlockStateOptions): IdentityBlockState;
277
+ /**
278
+ * The one sentence `status` and `doctor` say about the block: what it is,
279
+ * the repair (`fix`: the command that places the served block, e.g.
280
+ * `npx -y @agentchatme/example doctor --fix`), and the host's note on the
281
+ * file its runtime loads instead, when there is one. The repair is said only
282
+ * where it changes something: not for the served block, nor for a file it
283
+ * cannot read.
284
+ */
285
+ declare function describeIdentityBlock(state: IdentityBlockState, fix: string): string;
286
+
287
+ declare const DEFAULT_API_BASE = "https://api.agentchat.me";
288
+ declare const CredentialsSchema: z.ZodObject<{
289
+ api_key: z.ZodString;
290
+ handle: z.ZodString;
291
+ api_base: z.ZodOptional<z.ZodString>;
292
+ created_at: z.ZodOptional<z.ZodString>;
293
+ }, "strip", z.ZodTypeAny, {
294
+ api_key: string;
295
+ handle: string;
296
+ api_base?: string | undefined;
297
+ created_at?: string | undefined;
298
+ }, {
299
+ api_key: string;
300
+ handle: string;
301
+ api_base?: string | undefined;
302
+ created_at?: string | undefined;
303
+ }>;
304
+ type Credentials = z.infer<typeof CredentialsSchema>;
305
+ interface ResolvedIdentity {
306
+ apiKey: string;
307
+ apiBase: string;
308
+ /** Handle is only known when it came from the credentials file. */
309
+ handle: string | null;
310
+ source: 'env' | 'file';
311
+ }
312
+ declare function credentialsPath(home: string): string;
313
+ declare function pendingPath(home: string): string;
314
+ declare function statePath(home: string): string;
315
+ /** Read the credential stored in `home`, or null when absent/malformed. */
316
+ declare function readCredentials(home: string): Credentials | null;
317
+ /**
318
+ * The identity an integration should act as, for one specific home: the
319
+ * home's `credentials`, else `AGENTCHAT_API_KEY` when the home holds no key.
320
+ * `AGENTCHAT_API_BASE` overrides the base URL. Neither is host-specific, so
321
+ * both are read from the environment.
322
+ */
323
+ interface ResolveIdentityOptions {
324
+ /**
325
+ * Whether `AGENTCHAT_API_KEY` may stand in for a home that holds no key
326
+ * (default true). It never overrides a key the home holds. A resident
327
+ * listener passes false: the agent it serves is the one its home holds,
328
+ * whatever happens to be exported in the shell that started it.
329
+ */
330
+ readonly envKey?: boolean;
331
+ }
332
+ /** `AGENTCHAT_API_KEY` from the environment when it is set and well-formed, else null. */
333
+ declare function envApiKey(env?: NodeJS.ProcessEnv): string | null;
334
+ declare function resolveIdentity(home: string, options?: ResolveIdentityOptions): ResolvedIdentity | null;
335
+ /**
336
+ * One sentence when an exported `AGENTCHAT_API_KEY` is not the key `home`
337
+ * holds, else null (none exported, the same key, or a home with no key, where
338
+ * the exported one stands in). Never contains either key. The caller adds
339
+ * what to do in its own words.
340
+ */
341
+ declare function envKeyConflict(home: string, env?: NodeJS.ProcessEnv): string | null;
342
+ declare function writeCredentials(home: string, creds: Credentials): void;
343
+ declare const INSTALL_ID_FILE = "install-id";
344
+ declare function installIdPath(home: string): string;
345
+ /** The home's install id, or null when there is none (or the file holds something else). Never creates one. */
346
+ declare function readInstallId(home: string): string | null;
347
+ /** A new install id: `ins_` and 22 base64url characters from 16 random bytes. */
348
+ declare function newInstallId(): string;
349
+ /**
350
+ * The home's install id, made once: created with an exclusive open, so two
351
+ * commands starting at the same moment agree on one (the second reads the
352
+ * first's). A file that holds something else is replaced. Null when the home
353
+ * cannot be written; never throws.
354
+ */
355
+ declare function ensureInstallId(home: string): string | null;
356
+ declare const HOST_FILE = "runtime-host";
357
+ /** The host a command last read here, or null. */
358
+ declare function readRememberedHost(home: string): string | null;
359
+ /** Keep the host a command read (when it changed). Never throws. */
360
+ declare function rememberHost(home: string, host: string): void;
361
+ /** Remove the home's install id (uninstall). True when there was one. */
362
+ declare function clearInstallId(home: string): boolean;
363
+ /** Delete the credential and any half-finished registration in `home`.
364
+ * Touches nothing outside `home` — that is the caller's whole agent.
365
+ * The install id stays: the same install may sign in again. */
366
+ declare function clearCredentials(home: string): boolean;
367
+ interface PendingSignup {
368
+ kind: 'register' | 'recover';
369
+ /** The server's flow object, as its last answer gave it. */
370
+ flow: SignupFlow;
371
+ /** When that answer arrived (ISO-8601): `expires_in_s` and `resend_after_s` count from here. */
372
+ received_at: string;
373
+ /** What the start call sent. */
374
+ email: string;
375
+ handle?: string;
376
+ display_name?: string;
377
+ description?: string;
378
+ /** The API base the start call went to, when not the default. */
379
+ api_base?: string;
380
+ }
381
+ /** @deprecated Renamed to {@link PendingSignup}; kept so existing imports keep compiling. */
382
+ type PendingRegistration = PendingSignup;
383
+ declare function readPending(home: string): PendingSignup | null;
384
+ declare function writePending(home: string, pending: PendingSignup): void;
385
+ declare function clearPending(home: string): void;
386
+
387
+ /** What the served texts announce: `Texts['manual']`, with the optional integrity hash. */
388
+ type ServedManual = integration.ServedManual;
389
+ declare const MANUAL_MAX_BYTES: number;
390
+ declare const MANUAL_FETCH_TIMEOUT_MS: 10000;
391
+ declare const MANUAL_MAX_REDIRECTS: 3;
392
+ /** `fetch`'s shape, injectable for tests. Defaults to the platform's own; called with `redirect: 'manual'`. */
393
+ type ManualFetch = integration.ManualFetch;
394
+ /**
395
+ * - `current` — the file already is the announced manual (version, and hash when announced); nothing fetched.
396
+ * - `updated` — the announced manual was written (downloaded, or the bundled copy when it is that manual).
397
+ * - `kept` — the existing file was left as it was: nothing announced to compare with, or no verified copy could be had.
398
+ * - `fallback` — no file existed and nothing verified could be had: the bundled copy was written.
399
+ * - `failed` — no file existed and none could be written.
400
+ */
401
+ type ManualSyncState = integration.ManualSyncState;
402
+ interface ManualSyncResult extends Omit<integration.ManualSyncResult, 'source'> {
403
+ /** Where the written bytes came from, when some were written. */
404
+ readonly source: 'download' | 'bundled' | null;
405
+ }
406
+ interface SyncManualOptions {
407
+ /** The skill file, e.g. `<skills dir>/agentchat/SKILL.md`. The integration knows where; this package never derives it. */
408
+ readonly path: string;
409
+ /** `texts.manual` from the served texts (or their identity-home cache); null when none are in hand. */
410
+ readonly served: ServedManual | null;
411
+ /**
412
+ * The API base the texts were fetched from (the identity's `api_base`). It
413
+ * decides where a download may go; null (unknown) or a plain-HTTP base off
414
+ * loopback means no download at all.
415
+ */
416
+ readonly apiBase: string | null;
417
+ readonly fetch?: ManualFetch;
418
+ readonly timeoutMs?: number;
419
+ readonly maxBytes?: number;
420
+ readonly signal?: AbortSignal;
421
+ }
422
+ /** The version the file at `file` carries, or null when it is missing or names none. */
423
+ declare function readManualVersion(file: string): string | null;
424
+ /** A kit result in this package's words (the fallback is the bundled copy). */
425
+ declare function fromKitResult(result: integration.ManualSyncResult): ManualSyncResult;
426
+ /**
427
+ * Bring the skill file at `path` to the announced manual (the kit's
428
+ * `syncManual`, the bundled copy as fallback). Never throws.
429
+ */
430
+ declare function syncManual(options: SyncManualOptions): Promise<ManualSyncResult>;
431
+ declare function describeManualSync(result: ManualSyncResult): string;
432
+ type ManualCheckState = 'current' | 'stale' | 'unchecked' | 'missing';
433
+ interface ManualCheck {
434
+ readonly state: ManualCheckState;
435
+ readonly path: string;
436
+ readonly version: string | null;
437
+ readonly served: string | null;
438
+ /** current → PASS; stale or unchecked → WARN (the agent still has a manual); missing → FAIL. */
439
+ readonly verdict: Verdict;
440
+ /** `current (2.2.1)`, `stale (have 2.1.2, served 2.2.1)`, `unchecked (have 2.2.1; …)`, `missing`. */
441
+ readonly summary: string;
442
+ /** The summary and the file. */
443
+ readonly detail: string;
444
+ }
445
+ interface CheckManualOptions {
446
+ readonly path: string;
447
+ /** What the served texts announce; null when none are in hand. */
448
+ readonly served: ServedManual | null;
449
+ /** The API base the texts came from; a base no download would be made from is named in the summary. */
450
+ readonly apiBase: string | null;
451
+ }
452
+ /** Compare the skill file with the announced manual. Reads one file; no network. */
453
+ declare function checkManual(options: CheckManualOptions): ManualCheck;
454
+
455
+ type Verdict = 'PASS' | 'WARN' | 'FAIL';
456
+ interface DoctorCheck {
457
+ name: string;
458
+ verdict: Verdict;
459
+ detail: string;
460
+ }
461
+ /** What the shared `status` hands a host's extra lines: what it already fetched from the served texts (one fetch per command). */
462
+ interface StatusContext {
463
+ identityLine: string | null;
464
+ /**
465
+ * The served `identity_line_template` from the same texts, or null when none
466
+ * are in hand: what `readAnchorHandleAt` recognises an unmarked block by, in
467
+ * whatever words the server serves today.
468
+ */
469
+ identityLineTemplate: string | null;
470
+ /** The manual the served texts announce (`texts.manual`), or null when none are in hand — what `checkManual` compares the skill file with. */
471
+ manual: ServedManual | null;
472
+ }
473
+ /** What the shared doctor hands a host's extra checks. */
474
+ interface DoctorContext {
475
+ fix?: boolean;
476
+ /** The served identity line for this agent, or null when the server could not be reached and nothing is cached. */
477
+ identityLine: string | null;
478
+ /** The served `identity_line_template`, or null when none are in hand (see `StatusContext`). */
479
+ identityLineTemplate: string | null;
480
+ /** The manual the served texts announce, or null when none are in hand (`--fix` syncs the skill file to it). */
481
+ manual: ServedManual | null;
482
+ }
483
+ /**
484
+ * A placement problem that keeps the agent's runs from having the AgentChat
485
+ * tools: the hosted tool server could not be registered, or a registration
486
+ * this integration did not write stands in its place. The setup verdict says
487
+ * it as `tools_missing`, in the host's words.
488
+ */
489
+ interface PlacementProblem {
490
+ /** What is wrong and what to do, in plain words that name the exact command, or what to ask the person. */
491
+ readonly text: string;
492
+ /** The command to run next; absent: `doctor --fix` (or none, when only the person can resolve it). */
493
+ readonly command?: string;
494
+ /** Only the person can resolve it (their own registration stands in the way: ask before touching it). */
495
+ readonly needsPerson?: boolean;
496
+ /** What to ask the person, when `needsPerson`. */
497
+ readonly ask?: string;
498
+ /** The facts, as found. */
499
+ readonly detail?: string;
500
+ }
501
+ /** What `place` (and `extraStatus`) may return instead of bare lines: the lines, and the problem that blocks the tools, or null. */
502
+ interface PlacementReport {
503
+ readonly lines: string[];
504
+ readonly problem: PlacementProblem | null;
505
+ }
506
+ /** Lines, or lines with a placement problem: a host that returns bare lines reports no problem. */
507
+ type PlacementOutput = string[] | PlacementReport;
508
+ /** A host's lines and problem, whichever shape it returned. */
509
+ declare function placementReportOf(output: PlacementOutput): PlacementReport;
510
+ /**
511
+ * What `ensureListener` did.
512
+ *
513
+ * installed registered now (it was missing, stale, or another release's);
514
+ * current already registered and current: nothing was done;
515
+ * opted_out the person switched it off (`daemon disable`, `uninstall`): nothing was done;
516
+ * failed it could not be registered (`detail` says why).
517
+ */
518
+ interface ListenerEnsure {
519
+ readonly outcome: 'installed' | 'current' | 'opted_out' | 'failed';
520
+ /** The service's name for `installed` / `current` (e.g. `agentchatd-claude-code`); why, for `failed`; null otherwise. */
521
+ readonly detail: string | null;
522
+ }
523
+ /**
524
+ * Everything the shared identity commands need to know about ONE coding agent.
525
+ *
526
+ * This is the seam. The register / login / recover / status / logout / doctor
527
+ * flows are the same everywhere because they are a contract with the AgentChat
528
+ * server; what differs per host is only what is described here. An integration
529
+ * builds one of these and gets the commands back.
530
+ *
531
+ * Note what is NOT here: any way to name a *different* host. A profile
532
+ * describes the caller and nothing else, so a command built from it cannot
533
+ * reach another agent's files. That is the same property the per-repo split
534
+ * gives, kept intact while the flow itself is shared once.
535
+ *
536
+ * The path-ish fields are functions, not strings: `CODEX_HOME` and friends are
537
+ * read per call, and evaluating them at module load would freeze a value the
538
+ * user can still change.
539
+ */
540
+ interface HostProfile {
541
+ /** Human name for output, e.g. `Claude Code`. */
542
+ label: string;
543
+ /** Stable machine identifier for `--json`, e.g. `claude-code`. */
544
+ id: string;
545
+ /** How this integration names itself to the server: the texts runtime and its own version. */
546
+ client: IntegrationClient;
547
+ /** THE identity home for this agent. */
548
+ home(): string;
549
+ /**
550
+ * This host's always-loaded instruction file. Absent for a front door whose
551
+ * runtime has none it can place a line in (the `agentchat` listener runs an
552
+ * owner's command): no identity line is placed, checked or removed.
553
+ */
554
+ anchorFile?(): string;
555
+ /**
556
+ * For a runtime that reads another file in `anchorFile()`'s place when
557
+ * that one exists: which file it loads now, and whether the identity line
558
+ * it gets there is the served one (`served`, the texts in hand), or null
559
+ * when it loads `anchorFile()`. `status` and `doctor` say it (never a PASS
560
+ * when `ok` is false), and the daemon's follow of the identity line says
561
+ * it too. Nothing writes into that other file: it is the user's.
562
+ */
563
+ anchorLoadNote?(handle: string, served: AnchorServedLine): AnchorLoadNote | null;
564
+ /** Exactly what a user types to reach this integration. */
565
+ invocation(): string;
566
+ /**
567
+ * The identity block this host places for `handle` from the served identity
568
+ * line (normally `renderAnchorBlock`, the kit's shape with the handle line).
569
+ * Throws when the line does not name the handle; nothing is written then.
570
+ */
571
+ renderAnchor(identityLine: string, handle: string): string;
572
+ /**
573
+ * What to call the anchor in output. Defaults to the instruction file's own
574
+ * basename (`CLAUDE.md`, `AGENTS.md`), which is what a user actually looks
575
+ * for on disk.
576
+ */
577
+ anchorLabel?: string;
578
+ /**
579
+ * Whether this host is wired up enough for an anchor to mean anything.
580
+ * An integration uses this so it never writes an identity block announcing
581
+ * a phone number before its own placement is actually in place.
582
+ */
583
+ isWired?(): boolean;
584
+ /**
585
+ * Place the integration's texts for a freshly established identity: the
586
+ * identity line, the manual, the hosted tool server with the key, and
587
+ * whatever the key's home is on this runtime. Called after register, login
588
+ * and recover (every time the key changes), and by `doctor --fix`.
589
+ * `identityLine` is the served line for this agent (fetched just before,
590
+ * or the cached one), or null when neither could be had — the host then
591
+ * leaves the anchor for `doctor --fix` and says so. `manual` is what the
592
+ * same texts announce (`syncManual` brings the skill file to it), or null.
593
+ * Returns report lines, or the lines with the placement problem that keeps
594
+ * runs from having the AgentChat tools (`PlacementReport`): with a problem,
595
+ * the listener is not registered and the setup verdict is `tools_missing`.
596
+ * When absent, only the anchor is written.
597
+ */
598
+ place?(handle: string, apiKey: string, identityLine: string | null, manual: ServedManual | null): PlacementOutput | Promise<PlacementOutput>;
599
+ /**
600
+ * Have this host's listener service — the resident daemon that holds the
601
+ * socket and starts a run when a peer writes — registered and current,
602
+ * unless the person switched it off. Never throws. Called by the shared
603
+ * flow after `place`: register and recover on their code leg, login, and
604
+ * doctor --fix. A host that has it turns its listener on with
605
+ * `<invocation> daemon install`; the shared commands then wait for the
606
+ * listener to connect and say the setup verdict (`Setup: <state> — …`).
607
+ * Absent (a front door with no service of its own to place, such as the
608
+ * `agentchat` CLI): no listener is placed, waited for or judged.
609
+ */
610
+ ensureListener?(): ListenerEnsure | Promise<ListenerEnsure>;
611
+ /**
612
+ * The runtime this integration runs inside and its version,
613
+ * `<runtime>/<version>` (`hostIdentityOf(runtime, <its --version output>)`),
614
+ * or null when it cannot be read. Asked once per command (bounded); it is
615
+ * the `host` member of X-AgentChat-Platform and nothing else.
616
+ */
617
+ host?(): string | null | Promise<string | null>;
618
+ /**
619
+ * Undo `place` for the identity being signed out: remove the key from the
620
+ * tool server registration and anything else that would still authenticate
621
+ * as the old identity. The anchor is removed by the shared flow. Returns
622
+ * report lines.
623
+ *
624
+ * `identity` is the identity AS IT WAS BEFORE the credential was cleared
625
+ * (its key and API base), or null when there was none: a host recognises
626
+ * its own registration by that key and that server, and guessing either
627
+ * after the fact left a non-default `api_base` entry classified as foreign
628
+ * and the key still registered.
629
+ */
630
+ unplace?(identity: ResolvedIdentity | null): string[];
631
+ /** Host-specific doctor checks, appended after the shared ones. */
632
+ extraDoctorChecks?(context: DoctorContext): DoctorCheck[] | Promise<DoctorCheck[]>;
633
+ /**
634
+ * Host-specific `status` lines (placement, probes), printed after the shared
635
+ * ones in text mode. The served identity line and manual come along so the
636
+ * host does not fetch `/v1/texts` a second time. May return the lines with
637
+ * the placement problem its checks found (`PlacementReport`), which the
638
+ * setup verdict says as `tools_missing`.
639
+ */
640
+ extraStatus?(context: StatusContext): PlacementOutput | Promise<PlacementOutput>;
641
+ /** Extra lines printed after a successful logout. */
642
+ logoutHints?(): string[];
643
+ }
644
+ /** The label to use for this host's anchor in user-facing output. */
645
+ declare function anchorLabelOf(profile: HostProfile): string;
646
+
110
647
  declare const INTEGRATION_STATUS_FILE = "integration.status.json";
111
648
  /** The file a daemon before the rename writes; read when the current one is absent. */
112
649
  declare const LEGACY_STATUS_FILE = "doorbell.status.json";
@@ -214,6 +751,57 @@ interface IntegrationStatus {
214
751
  last_ok_run_at?: string | null;
215
752
  /** Could not process: the kit's reports and the server's answers, and the conversations paused for this agent. Null or absent from an older daemon. */
216
753
  could_not_process?: IntegrationCouldNotProcess | null;
754
+ /**
755
+ * What the daemon last did with the identity block in the host's
756
+ * instruction file when the served texts changed (`followIdentityAnchor`).
757
+ * Null or absent when the daemon is not given one (the CLI places none),
758
+ * before the first texts, or from an older daemon.
759
+ */
760
+ identity_line?: IntegrationIdentityLine | null;
761
+ /**
762
+ * The listener report (contract v1 §3.13): what this listener tells
763
+ * AgentChat about itself, and whether AgentChat holds it. Null or absent
764
+ * while it reports nothing (a standby, a home that gave the agent up,
765
+ * switched off, signed out) or from an older daemon.
766
+ */
767
+ listener_report?: IntegrationListenerReport | null;
768
+ }
769
+ /** The listener report as the status file keeps it (the kit reporter's `status()`). */
770
+ interface IntegrationListenerReport {
771
+ /** This install's id (`<home>/listener-id`). */
772
+ readonly instance_id: string;
773
+ /** What the listener says now: `ok`, `runs_failing`, `not_ready`; null before it has said anything. */
774
+ readonly state: string | null;
775
+ /** Its reason, for `runs_failing` and `not_ready`; null otherwise. */
776
+ readonly reason_kind: string | null;
777
+ /** The last report AgentChat accepted, and when (this machine's clock); null before one. */
778
+ readonly reported: {
779
+ readonly state: string;
780
+ readonly reason_kind: string | null;
781
+ readonly at: string;
782
+ } | null;
783
+ /** True while AgentChat does not hold `state` yet. */
784
+ readonly pending: boolean;
785
+ /** Attempts that failed since the last accepted report, and the last failure. */
786
+ readonly failures: number;
787
+ readonly last_error: string | null;
788
+ /** When the next attempt is due, or null when none is. */
789
+ readonly next_attempt_at: string | null;
790
+ }
791
+ /** The identity block's last follow of the served identity line. */
792
+ interface IntegrationIdentityLine {
793
+ /** `updated`, `unchanged`, `absent`, `setup_offer`, `hand_edited`, `other_agent`, `several_blocks`, `edited_meanwhile` or `failed` (`IdentityAnchorOutcome`). */
794
+ readonly outcome: string;
795
+ /** The instruction file. */
796
+ readonly path: string;
797
+ /** When it was done. */
798
+ readonly at: string;
799
+ /** The served text set's version it followed. */
800
+ readonly texts_version: string;
801
+ /** What happened, in words. */
802
+ readonly detail: string;
803
+ /** Why the runtime does not load the file now (a file it reads in its place), or null; absent from a file an older daemon wrote. */
804
+ readonly not_loaded?: string | null;
217
805
  }
218
806
  /** A conversation paused for this agent (the server's 24 h mute, source `could_not_process`). */
219
807
  interface IntegrationPausedConversation {
@@ -352,273 +940,88 @@ declare function describeCouldNotProcessCounts(c: IntegrationCouldNotProcess, no
352
940
  declare function runtimeCheckFailingNow(status: Pick<IntegrationStatus, 'could_not_process' | 'last_ok_run_at'> | null): boolean;
353
941
  /** Runs in a row that did not get done, when that is a pattern (`REPEATED_FAILED_CYCLES` or more) and no runtime reason explains it; null otherwise. */
354
942
  declare function repeatedFailedRuns(status: Pick<IntegrationStatus, 'failed_runs_in_a_row' | 'runs_failing' | 'unservable'> | null): number | null;
355
- /** Human lines for `status`. Pure. */
356
943
  declare function formatIntegrationStatus(status: IntegrationStatus | null, now?: number): string[];
357
944
 
358
- declare const DEFAULT_API_BASE = "https://api.agentchat.me";
359
- declare const CredentialsSchema: z.ZodObject<{
360
- api_key: z.ZodString;
361
- handle: z.ZodString;
362
- api_base: z.ZodOptional<z.ZodString>;
363
- created_at: z.ZodOptional<z.ZodString>;
364
- }, "strip", z.ZodTypeAny, {
365
- api_key: string;
366
- handle: string;
367
- api_base?: string | undefined;
368
- created_at?: string | undefined;
369
- }, {
370
- api_key: string;
371
- handle: string;
372
- api_base?: string | undefined;
373
- created_at?: string | undefined;
374
- }>;
375
- type Credentials = z.infer<typeof CredentialsSchema>;
376
- interface ResolvedIdentity {
377
- apiKey: string;
378
- apiBase: string;
379
- /** Handle is only known when it came from the credentials file. */
380
- handle: string | null;
381
- source: 'env' | 'file';
382
- }
383
- declare function credentialsPath(home: string): string;
384
- declare function pendingPath(home: string): string;
385
- declare function statePath(home: string): string;
386
- /** Read the credential stored in `home`, or null when absent/malformed. */
387
- declare function readCredentials(home: string): Credentials | null;
388
- /**
389
- * The identity an integration should act as, for one specific home: the
390
- * home's `credentials`, else `AGENTCHAT_API_KEY` when the home holds no key.
391
- * `AGENTCHAT_API_BASE` overrides the base URL. Neither is host-specific, so
392
- * both are read from the environment.
393
- */
394
- interface ResolveIdentityOptions {
395
- /**
396
- * Whether `AGENTCHAT_API_KEY` may stand in for a home that holds no key
397
- * (default true). It never overrides a key the home holds. A resident
398
- * listener passes false: the agent it serves is the one its home holds,
399
- * whatever happens to be exported in the shell that started it.
400
- */
401
- readonly envKey?: boolean;
402
- }
403
- /** `AGENTCHAT_API_KEY` from the environment when it is set and well-formed, else null. */
404
- declare function envApiKey(env?: NodeJS.ProcessEnv): string | null;
405
- declare function resolveIdentity(home: string, options?: ResolveIdentityOptions): ResolvedIdentity | null;
406
- /**
407
- * One sentence when an exported `AGENTCHAT_API_KEY` is not the key `home`
408
- * holds, else null (none exported, the same key, or a home with no key, where
409
- * the exported one stands in). Never contains either key. The caller adds
410
- * what to do in its own words.
411
- */
412
- declare function envKeyConflict(home: string, env?: NodeJS.ProcessEnv): string | null;
413
- declare function writeCredentials(home: string, creds: Credentials): void;
414
- /** Delete the credential and any half-finished registration in `home`.
415
- * Touches nothing outside `home` — that is the caller's whole agent. */
416
- declare function clearCredentials(home: string): boolean;
417
- interface PendingSignup {
418
- kind: 'register' | 'recover';
419
- /** The server's flow object, as its last answer gave it. */
420
- flow: SignupFlow;
421
- /** When that answer arrived (ISO-8601): `expires_in_s` and `resend_after_s` count from here. */
422
- received_at: string;
423
- /** What the start call sent. */
424
- email: string;
425
- handle?: string;
426
- display_name?: string;
427
- description?: string;
428
- /** The API base the start call went to, when not the default. */
429
- api_base?: string;
430
- }
431
- /** @deprecated Renamed to {@link PendingSignup}; kept so existing imports keep compiling. */
432
- type PendingRegistration = PendingSignup;
433
- declare function readPending(home: string): PendingSignup | null;
434
- declare function writePending(home: string, pending: PendingSignup): void;
435
- declare function clearPending(home: string): void;
436
-
437
- type Verdict = 'PASS' | 'WARN' | 'FAIL';
438
- interface DoctorCheck {
439
- name: string;
440
- verdict: Verdict;
441
- detail: string;
442
- }
443
- /** What the shared `status` hands a host's extra lines: what it already fetched from the served texts (one fetch per command). */
444
- interface StatusContext {
445
- identityLine: string | null;
446
- /**
447
- * The served `identity_line_template` from the same texts, or null when none
448
- * are in hand: what `readAnchorHandleAt` recognises an unmarked block by, in
449
- * whatever words the server serves today.
450
- */
451
- identityLineTemplate: string | null;
452
- /** The manual the served texts announce (`texts.manual`), or null when none are in hand — what `checkManual` compares the skill file with. */
453
- manual: ServedManual | null;
454
- }
455
- /** What the shared doctor hands a host's extra checks. */
456
- interface DoctorContext {
457
- fix?: boolean;
458
- /** The served identity line for this agent, or null when the server could not be reached and nothing is cached. */
459
- identityLine: string | null;
460
- /** The served `identity_line_template`, or null when none are in hand (see `StatusContext`). */
461
- identityLineTemplate: string | null;
462
- /** The manual the served texts announce, or null when none are in hand (`--fix` syncs the skill file to it). */
463
- manual: ServedManual | null;
464
- }
945
+ /** The file in the identity home that keeps this install's listener id. */
946
+ declare const LISTENER_ID_FILE = "listener-id";
947
+ /** `<home>/listener-id`. */
948
+ declare function listenerIdPath(home: string): string;
465
949
  /**
466
- * Everything the shared identity commands need to know about ONE coding agent.
467
- *
468
- * This is the seam. The register / login / recover / status / logout / doctor
469
- * flows are the same everywhere because they are a contract with the AgentChat
470
- * server; what differs per host is only what is described here. An integration
471
- * builds one of these and gets the commands back.
472
- *
473
- * Note what is NOT here: any way to name a *different* host. A profile
474
- * describes the caller and nothing else, so a command built from it cannot
475
- * reach another agent's files. That is the same property the per-repo split
476
- * gives, kept intact while the flow itself is shared once.
477
- *
478
- * The path-ish fields are functions, not strings: `CODEX_HOME` and friends are
479
- * read per call, and evaluating them at module load would freeze a value the
480
- * user can still change.
950
+ * The home's listener id, made once and reused (the kit's
951
+ * `listenerInstanceId`), or null when the home can keep none (said at warn):
952
+ * the listener then serves without reporting.
481
953
  */
482
- interface HostProfile {
483
- /** Human name for output, e.g. `Claude Code`. */
484
- label: string;
485
- /** Stable machine identifier for `--json`, e.g. `claude-code`. */
486
- id: string;
487
- /** How this integration names itself to the server: the texts runtime and its own version. */
488
- client: IntegrationClient;
489
- /** THE identity home for this agent. */
490
- home(): string;
491
- /**
492
- * This host's always-loaded instruction file. Absent for a front door whose
493
- * runtime has none it can place a line in (the `agentchat` listener runs an
494
- * owner's command): no identity line is placed, checked or removed.
495
- */
496
- anchorFile?(): string;
497
- /** Exactly what a user types to reach this integration. */
498
- invocation(): string;
499
- /**
500
- * The identity block this host places for `handle` from the served identity
501
- * line (normally `renderAnchorBlock`, the kit's shape with the handle line).
502
- * Throws when the line does not name the handle; nothing is written then.
503
- */
504
- renderAnchor(identityLine: string, handle: string): string;
505
- /**
506
- * What to call the anchor in output. Defaults to the instruction file's own
507
- * basename (`CLAUDE.md`, `AGENTS.md`), which is what a user actually looks
508
- * for on disk.
509
- */
510
- anchorLabel?: string;
511
- /**
512
- * Whether this host is wired up enough for an anchor to mean anything.
513
- * An integration uses this so it never writes an identity block announcing
514
- * a phone number before its own placement is actually in place.
515
- */
516
- isWired?(): boolean;
517
- /**
518
- * Place the integration's texts for a freshly established identity: the
519
- * identity line, the manual, the hosted tool server with the key, and
520
- * whatever the key's home is on this runtime. Called after register, login
521
- * and recover (every time the key changes), and by `doctor --fix`.
522
- * `identityLine` is the served line for this agent (fetched just before,
523
- * or the cached one), or null when neither could be had — the host then
524
- * leaves the anchor for `doctor --fix` and says so. `manual` is what the
525
- * same texts announce (`syncManual` brings the skill file to it), or null.
526
- * Returns report lines. When absent, only the anchor is written.
527
- */
528
- place?(handle: string, apiKey: string, identityLine: string | null, manual: ServedManual | null): string[] | Promise<string[]>;
529
- /**
530
- * Undo `place` for the identity being signed out: remove the key from the
531
- * tool server registration and anything else that would still authenticate
532
- * as the old identity. The anchor is removed by the shared flow. Returns
533
- * report lines.
534
- *
535
- * `identity` is the identity AS IT WAS BEFORE the credential was cleared
536
- * (its key and API base), or null when there was none: a host recognises
537
- * its own registration by that key and that server, and guessing either
538
- * after the fact left a non-default `api_base` entry classified as foreign
539
- * and the key still registered.
540
- */
541
- unplace?(identity: ResolvedIdentity | null): string[];
542
- /** Host-specific doctor checks, appended after the shared ones. */
543
- extraDoctorChecks?(context: DoctorContext): DoctorCheck[] | Promise<DoctorCheck[]>;
544
- /**
545
- * Host-specific `status` lines (placement, probes), printed after the shared
546
- * ones in text mode. The served identity line and manual come along so the
547
- * host does not fetch `/v1/texts` a second time.
548
- */
549
- extraStatus?(context: StatusContext): string[] | Promise<string[]>;
550
- /** Extra lines printed after a successful logout. */
551
- logoutHints?(): string[];
954
+ declare function ensureListenerInstanceId(home: string): Promise<string | null>;
955
+ /** The home's listener id when a listener made one; null otherwise. Never creates one. */
956
+ declare function readListenerInstanceId(home: string): string | null;
957
+ /** What the integration tells AgentChat through: the kit's `ListenerReporter` (a fake in tests). */
958
+ type ListenerReportSink = Pick<integration.ListenerReporter, 'set' | 'status'>;
959
+ /** The kit reporter's timing (test seams; a listener uses the kit's defaults). */
960
+ type ListenerReportTiming = Pick<integration.ListenerReporterOptions, 'coalesceMs' | 'minIntervalMs' | 'retryMs' | 'retryMaxMs' | 'resendMs'>;
961
+ /** What a command waits for its `stopped` report, at most. */
962
+ declare const STOPPED_REPORT_TIMEOUT_MS = 5000;
963
+ interface KeyedIdentity {
964
+ readonly apiKey: string;
965
+ readonly apiBase: string;
552
966
  }
553
- /** The label to use for this host's anchor in user-facing output. */
554
- declare function anchorLabelOf(profile: HostProfile): string;
555
-
556
- /** What the served texts announce: `Texts['manual']`, with the optional integrity hash. */
557
- type ServedManual = integration.ServedManual;
558
- declare const MANUAL_MAX_BYTES: number;
559
- declare const MANUAL_FETCH_TIMEOUT_MS: 10000;
560
- declare const MANUAL_MAX_REDIRECTS: 3;
561
- /** `fetch`'s shape, injectable for tests. Defaults to the platform's own; called with `redirect: 'manual'`. */
562
- type ManualFetch = integration.ManualFetch;
563
- /**
564
- * - `current` — the file already is the announced manual (version, and hash when announced); nothing fetched.
565
- * - `updated` — the announced manual was written (downloaded, or the bundled copy when it is that manual).
566
- * - `kept` — the existing file was left as it was: nothing announced to compare with, or no verified copy could be had.
567
- * - `fallback` — no file existed and nothing verified could be had: the bundled copy was written.
568
- * - `failed` — no file existed and none could be written.
569
- */
570
- type ManualSyncState = integration.ManualSyncState;
571
- interface ManualSyncResult extends Omit<integration.ManualSyncResult, 'source'> {
572
- /** Where the written bytes came from, when some were written. */
573
- readonly source: 'download' | 'bundled' | null;
967
+ interface CreateListenerReporterOptions extends KeyedIdentity {
968
+ readonly client: IntegrationClient;
969
+ readonly instanceId: string;
970
+ /** Test seam: what sends the reports (default: a client for this identity). */
971
+ readonly api?: integration.ListenerReportClient;
972
+ readonly timing?: ListenerReportTiming;
574
973
  }
575
- interface SyncManualOptions {
576
- /** The skill file, e.g. `<skills dir>/agentchat/SKILL.md`. The integration knows where; this package never derives it. */
577
- readonly path: string;
578
- /** `texts.manual` from the served texts (or their identity-home cache); null when none are in hand. */
579
- readonly served: ServedManual | null;
974
+ /** The daemon's reporter for one identity: a failure is said at warn, once per new failure, and retried by the kit. */
975
+ declare function createListenerReporter(options: CreateListenerReporterOptions): integration.ListenerReporter;
976
+ interface ReportListenerStoppedOptions {
977
+ /** The identity home whose listener stops. */
978
+ readonly home: string;
979
+ /** How the integration names itself to the server. */
980
+ readonly client: IntegrationClient;
580
981
  /**
581
- * The API base the texts were fetched from (the identity's `api_base`). It
582
- * decides where a download may go; null (unknown) or a plain-HTTP base off
583
- * loopback means no download at all.
982
+ * The agent that home's listener serves (its key, base and handle, as
983
+ * `resolveIdentity` gives it); null: nothing to report. Only a key the home
984
+ * holds counts (`source: 'file'`): an exported key is not what the home's
985
+ * listener serves (a service never carries one).
584
986
  */
585
- readonly apiBase: string | null;
586
- readonly fetch?: ManualFetch;
987
+ readonly identity: (KeyedIdentity & {
988
+ readonly handle: string | null;
989
+ readonly source?: 'file' | 'env';
990
+ }) | null;
991
+ /** The one attempt's bound (default `STOPPED_REPORT_TIMEOUT_MS`). */
587
992
  readonly timeoutMs?: number;
588
- readonly maxBytes?: number;
589
- readonly signal?: AbortSignal;
993
+ /** Test seam: what sends the report. */
994
+ readonly api?: integration.ListenerReportClient;
590
995
  }
591
- /** The version the file at `file` carries, or null when it is missing or names none. */
592
- declare function readManualVersion(file: string): string | null;
593
- /** A kit result in this package's words (the fallback is the bundled copy). */
594
- declare function fromKitResult(result: integration.ManualSyncResult): ManualSyncResult;
595
996
  /**
596
- * Bring the skill file at `path` to the announced manual (the kit's
597
- * `syncManual`, the bundled copy as fallback). Never throws.
997
+ * What came of a `stopped` report: `reported` (AgentChat holds it),
998
+ * `failed` (it does not: `detail` says why; it then reads the listener as
999
+ * offline once its socket is gone), or `skipped`: `no_identity` (no key
1000
+ * the home holds),
1001
+ * `no_listener` (no listener of this home ever reported: there is nothing
1002
+ * to stop), `standby` (another home's listener serves this agent: a
1003
+ * standby reports nothing).
598
1004
  */
599
- declare function syncManual(options: SyncManualOptions): Promise<ManualSyncResult>;
600
- declare function describeManualSync(result: ManualSyncResult): string;
601
- type ManualCheckState = 'current' | 'stale' | 'unchecked' | 'missing';
602
- interface ManualCheck {
603
- readonly state: ManualCheckState;
604
- readonly path: string;
605
- readonly version: string | null;
606
- readonly served: string | null;
607
- /** current → PASS; stale or unchecked → WARN (the agent still has a manual); missing → FAIL. */
608
- readonly verdict: Verdict;
609
- /** `current (2.2.1)`, `stale (have 2.1.2, served 2.2.1)`, `unchecked (have 2.2.1; …)`, `missing`. */
610
- readonly summary: string;
611
- /** The summary and the file. */
1005
+ type ListenerStoppedResult = {
1006
+ readonly outcome: 'reported';
1007
+ } | {
1008
+ readonly outcome: 'failed';
612
1009
  readonly detail: string;
613
- }
614
- interface CheckManualOptions {
615
- readonly path: string;
616
- /** What the served texts announce; null when none are in hand. */
617
- readonly served: ServedManual | null;
618
- /** The API base the texts came from; a base no download would be made from is named in the summary. */
619
- readonly apiBase: string | null;
620
- }
621
- /** Compare the skill file with the announced manual. Reads one file; no network. */
622
- declare function checkManual(options: CheckManualOptions): ManualCheck;
1010
+ } | {
1011
+ readonly outcome: 'skipped';
1012
+ readonly reason: 'no_identity' | 'no_listener' | 'standby';
1013
+ };
1014
+ /**
1015
+ * Tell AgentChat this home's listener stops on purpose (`stopped`, contract
1016
+ * v1 §3.13), so the agent reads as switched off rather than as a computer
1017
+ * that is off. For the commands that end it — `logout`, `uninstall`, `daemon
1018
+ * disable` — and called BEFORE the key or the service goes: the report needs
1019
+ * the key, and it must come before the listener closes its socket. One
1020
+ * attempt, bounded by `timeoutMs`; never throws (the command goes on either
1021
+ * way).
1022
+ */
1023
+ declare function reportListenerStopped(options: ReportListenerStoppedOptions): Promise<ListenerStoppedResult>;
1024
+ /** The line a command prints for a `stopped` report (no indent), or null when there was nothing to report. */
1025
+ declare function describeListenerStopped(result: ListenerStoppedResult): string | null;
623
1026
 
624
- export { clientIdentityOf as $, type PendingSignup as A, type ResolveIdentityOptions as B, type CheckManualOptions as C, DEFAULT_API_BASE as D, type ResolvedIdentity as E, FAILED_CYCLE_OUTCOMES as F, SOCKET_STATES as G, type HostProfile as H, type IntegrationClient as I, type ServedManual as J, type StatusContext as K, type LeaseOptions as L, type ManualFetch as M, type SyncManualOptions as N, acquireLease as O, type PendingRegistration as P, anchorLabelOf as Q, REPEATED_FAILED_CYCLES as R, type SocketState as S, type TextsStatus as T, bootedAt as U, type Verdict as V, checkManual as W, clearCredentials as X, clearIntegrationStatus as Y, clearPending as Z, clientHeadersOf as _, type IntegrationStatus as a, clientNameOf as a0, credentialsPath as a1, describeCouldNotProcessCounts as a2, describeManualSync as a3, describePausedConversations as a4, envApiKey as a5, envKeyConflict as a6, failedCyclesInARow as a7, formatIntegrationStatus as a8, fromKitResult as a9, holderLive as aa, integrationStatusAge as ab, integrationStatusFresh as ac, integrationStatusPath as ad, integrationStatusStaleFor as ae, leaseHolder as af, parseLease as ag, pendingPath as ah, pidAlive as ai, readCredentials as aj, readIntegrationStatus as ak, readManualVersion as al, readPending as am, repeatedFailedRuns as an, resetLeaseObservations as ao, resolveIdentity as ap, runtimeCheckFailingNow as aq, statePath as ar, syncManual as as, writeCredentials as at, writeIntegrationStatus as au, writePending as av, type IntegrationRunsFailing as b, type Lease as c, type LeaseAttempt as d, type LeaseHolder as e, type Credentials as f, type DoctorCheck as g, type DoctorContext as h, INTEGRATION_STATUS_FILE as i, INTEGRATION_STATUS_STALE_MS as j, type IntegrationCouldNotProcess as k, type IntegrationCycle as l, type IntegrationLastRun as m, type IntegrationPausedConversation as n, type IntegrationStandby as o, type IntegrationUnservable as p, LEASE_RENEW_MS as q, LEASE_STALE_MS as r, LEGACY_STATUS_FILE as s, MANUAL_FETCH_TIMEOUT_MS as t, MANUAL_MAX_BYTES as u, MANUAL_MAX_REDIRECTS as v, type ManualCheck as w, type ManualCheckState as x, type ManualSyncResult as y, type ManualSyncState as z };
1027
+ export { MANUAL_FILENAME as $, type AnchorServedLine as A, type IdentityBlockStateName as B, type CreateListenerReporterOptions as C, DEFAULT_API_BASE as D, type IdentityBlockStateOptions as E, FAILED_CYCLE_OUTCOMES as F, type IntegrationCouldNotProcess as G, type HostProfile as H, type IntegrationClient as I, type IntegrationCycle as J, type IntegrationIdentityLine as K, type LeaseOptions as L, type ManualPointer as M, type IntegrationLastRun as N, type IntegrationListenerReport as O, type PendingSignup as P, type IntegrationPausedConversation as Q, type IntegrationStandby as R, type SocketState as S, type IntegrationUnservable as T, LEASE_RENEW_MS as U, LEASE_STALE_MS as V, LEGACY_STATUS_FILE as W, LISTENER_ID_FILE as X, type ListenerStoppedResult as Y, MANUAL as Z, MANUAL_FETCH_TIMEOUT_MS as _, type AnchorLoadNote as a, pidAlive as a$, MANUAL_MAX_BYTES as a0, MANUAL_MAX_REDIRECTS as a1, MANUAL_SKILL_NAME as a2, MANUAL_URL as a3, type ManualCheck as a4, type ManualCheckState as a5, type ManualSyncResult as a6, type ManualSyncState as a7, type PendingRegistration as a8, type PlacementOutput as a9, describeListenerStopped as aA, describeManualSync as aB, describePausedConversations as aC, ensureInstallId as aD, envApiKey as aE, envKeyConflict as aF, failedCyclesInARow as aG, followIdentityAnchor as aH, formatIntegrationStatus as aI, fromKitResult as aJ, holderLive as aK, hostIdentityOf as aL, identityBlockState as aM, installIdPath as aN, installMethodOf as aO, integrationStatusAge as aP, integrationStatusFresh as aQ, integrationStatusPath as aR, integrationStatusStaleFor as aS, leaseHolder as aT, listenerIdPath as aU, manualFrontMatter as aV, manualPointer as aW, manualVersion as aX, newInstallId as aY, parseLease as aZ, pendingPath as a_, type PlacementReport as aa, REPEATED_FAILED_CYCLES as ab, type ReportListenerStoppedOptions as ac, type ResolveIdentityOptions as ad, type ResolvedIdentity as ae, SOCKET_STATES as af, STOPPED_REPORT_TIMEOUT_MS as ag, type ServedManual as ah, type StatusContext as ai, type SyncManualOptions as aj, type TextsStatus as ak, type Verdict as al, acquireLease as am, anchorLabelOf as an, bootedAt as ao, checkManual as ap, clearCredentials as aq, clearInstallId as ar, clearIntegrationStatus as as, clearPending as at, clientHeadersOf as au, clientIdentityOf as av, clientNameOf as aw, credentialsPath as ax, describeCouldNotProcessCounts as ay, describeIdentityBlock as az, type ListenerReportTiming as b, placementReportOf as b0, readCredentials as b1, readInstallId as b2, readIntegrationStatus as b3, readListenerInstanceId as b4, readManualVersion as b5, readPending as b6, readRememberedHost as b7, rememberHost as b8, repeatedFailedRuns as b9, reportListenerStopped as ba, resetLeaseObservations as bb, resolveIdentity as bc, resolveManualPointer as bd, runtimeCheckFailingNow as be, servedManualUrl as bf, statePath as bg, syncManual as bh, writeCredentials as bi, writeIntegrationStatus as bj, writePending as bk, type ManualFetch as c, type IntegrationStatus as d, type ListenerReportSink as e, type IntegrationRunsFailing as f, createListenerReporter as g, ensureListenerInstanceId as h, type ListenerEnsure as i, type PlacementProblem as j, type Lease as k, type LeaseAttempt as l, type LeaseHolder as m, type CheckManualOptions as n, type Credentials as o, type DoctorCheck as p, type DoctorContext as q, type FollowIdentityAnchorOptions as r, HOST_FILE as s, IDENTITY_ANCHOR_ATTEMPTS as t, INSTALL_ID_FILE as u, INTEGRATION_STATUS_FILE as v, INTEGRATION_STATUS_STALE_MS as w, type IdentityAnchorOutcome as x, type IdentityAnchorResult as y, type IdentityBlockState as z };