@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.
package/dist/index.d.ts CHANGED
@@ -1,13 +1,186 @@
1
- import { I as IntegrationClient, H as HostProfile, c as Lease, L as LeaseOptions, d as LeaseAttempt, e as LeaseHolder } from './served-manual-Bg-y_MEy.js';
2
- export { C as CheckManualOptions, f as Credentials, D as DEFAULT_API_BASE, g as DoctorCheck, h as DoctorContext, F as FAILED_CYCLE_OUTCOMES, i as INTEGRATION_STATUS_FILE, j as INTEGRATION_STATUS_STALE_MS, k as IntegrationCouldNotProcess, l as IntegrationCycle, m as IntegrationLastRun, n as IntegrationPausedConversation, b as IntegrationRunsFailing, o as IntegrationStandby, a as IntegrationStatus, p as IntegrationUnservable, q as LEASE_RENEW_MS, r as LEASE_STALE_MS, s as LEGACY_STATUS_FILE, t as MANUAL_FETCH_TIMEOUT_MS, u as MANUAL_MAX_BYTES, v as MANUAL_MAX_REDIRECTS, w as ManualCheck, x as ManualCheckState, M as ManualFetch, y as ManualSyncResult, z as ManualSyncState, P as PendingRegistration, A as PendingSignup, R as REPEATED_FAILED_CYCLES, B as ResolveIdentityOptions, E as ResolvedIdentity, G as SOCKET_STATES, J as ServedManual, S as SocketState, K as StatusContext, N as SyncManualOptions, T as TextsStatus, V as Verdict, O as acquireLease, Q as anchorLabelOf, U as bootedAt, W as checkManual, X as clearCredentials, Y as clearIntegrationStatus, Z as clearPending, _ as clientHeadersOf, $ as clientIdentityOf, a0 as clientNameOf, a1 as credentialsPath, a2 as describeCouldNotProcessCounts, a3 as describeManualSync, a4 as describePausedConversations, a5 as envApiKey, a6 as envKeyConflict, a7 as failedCyclesInARow, a8 as formatIntegrationStatus, a9 as fromKitResult, aa as holderLive, ab as integrationStatusAge, ac as integrationStatusFresh, ad as integrationStatusPath, ae as integrationStatusStaleFor, af as leaseHolder, ag as parseLease, ah as pendingPath, ai as pidAlive, aj as readCredentials, ak as readIntegrationStatus, al as readManualVersion, am as readPending, an as repeatedFailedRuns, ao as resetLeaseObservations, ap as resolveIdentity, aq as runtimeCheckFailingNow, ar as statePath, as as syncManual, at as writeCredentials, au as writeIntegrationStatus, av as writePending } from './served-manual-Bg-y_MEy.js';
3
- import { AgentChatClient, Texts, TextsRuntime, integration } from 'agentchatme';
1
+ import { P as PendingSignup, i as ListenerEnsure, j as PlacementProblem, I as IntegrationClient, H as HostProfile, k as Lease, L as LeaseOptions, l as LeaseAttempt, m as LeaseHolder } from './listener-report-V3oMkCj2.js';
2
+ export { a as AnchorLoadNote, A as AnchorServedLine, n as CheckManualOptions, o as Credentials, D as DEFAULT_API_BASE, p as DoctorCheck, q as DoctorContext, F as FAILED_CYCLE_OUTCOMES, r as FollowIdentityAnchorOptions, s as HOST_FILE, t as IDENTITY_ANCHOR_ATTEMPTS, u as INSTALL_ID_FILE, v as INTEGRATION_STATUS_FILE, w as INTEGRATION_STATUS_STALE_MS, x as IdentityAnchorOutcome, y as IdentityAnchorResult, z as IdentityBlockState, B as IdentityBlockStateName, E as IdentityBlockStateOptions, G as IntegrationCouldNotProcess, J as IntegrationCycle, K as IntegrationIdentityLine, N as IntegrationLastRun, O as IntegrationListenerReport, Q as IntegrationPausedConversation, f as IntegrationRunsFailing, R as IntegrationStandby, d as IntegrationStatus, T as IntegrationUnservable, U as LEASE_RENEW_MS, V as LEASE_STALE_MS, W as LEGACY_STATUS_FILE, X as LISTENER_ID_FILE, Y as ListenerStoppedResult, Z as MANUAL, _ as MANUAL_FETCH_TIMEOUT_MS, $ as MANUAL_FILENAME, a0 as MANUAL_MAX_BYTES, a1 as MANUAL_MAX_REDIRECTS, a2 as MANUAL_SKILL_NAME, a3 as MANUAL_URL, a4 as ManualCheck, a5 as ManualCheckState, c as ManualFetch, M as ManualPointer, a6 as ManualSyncResult, a7 as ManualSyncState, a8 as PendingRegistration, a9 as PlacementOutput, aa as PlacementReport, ab as REPEATED_FAILED_CYCLES, ac as ReportListenerStoppedOptions, ad as ResolveIdentityOptions, ae as ResolvedIdentity, af as SOCKET_STATES, ag as STOPPED_REPORT_TIMEOUT_MS, ah as ServedManual, S as SocketState, ai as StatusContext, aj as SyncManualOptions, ak as TextsStatus, al as Verdict, am as acquireLease, an as anchorLabelOf, ao as bootedAt, ap as checkManual, aq as clearCredentials, ar as clearInstallId, as as clearIntegrationStatus, at as clearPending, au as clientHeadersOf, av as clientIdentityOf, aw as clientNameOf, ax as credentialsPath, ay as describeCouldNotProcessCounts, az as describeIdentityBlock, aA as describeListenerStopped, aB as describeManualSync, aC as describePausedConversations, aD as ensureInstallId, aE as envApiKey, aF as envKeyConflict, aG as failedCyclesInARow, aH as followIdentityAnchor, aI as formatIntegrationStatus, aJ as fromKitResult, aK as holderLive, aL as hostIdentityOf, aM as identityBlockState, aN as installIdPath, aO as installMethodOf, aP as integrationStatusAge, aQ as integrationStatusFresh, aR as integrationStatusPath, aS as integrationStatusStaleFor, aT as leaseHolder, aU as listenerIdPath, aV as manualFrontMatter, aW as manualPointer, aX as manualVersion, aY as newInstallId, aZ as parseLease, a_ as pendingPath, a$ as pidAlive, b0 as placementReportOf, b1 as readCredentials, b2 as readInstallId, b3 as readIntegrationStatus, b4 as readListenerInstanceId, b5 as readManualVersion, b6 as readPending, b7 as readRememberedHost, b8 as rememberHost, b9 as repeatedFailedRuns, ba as reportListenerStopped, bb as resetLeaseObservations, bc as resolveIdentity, bd as resolveManualPointer, be as runtimeCheckFailingNow, bf as servedManualUrl, bg as statePath, bh as syncManual, bi as writeCredentials, bj as writeIntegrationStatus, bk as writePending } from './listener-report-V3oMkCj2.js';
3
+ import { AgentChatClient, Texts, TextsRuntime, integration, AgentChatClientIdentity } from 'agentchatme';
4
4
  import { z } from 'zod';
5
5
  import { g as RunRequest } from './runner-BLvFalN4.js';
6
6
  export { D as DEFAULT_RUN_BUDGET_MS, k as DEFAULT_RUN_PROFILE, F as FALLBACK_RUN_PROFILE, I as INTEGRATION_ENV, l as INTEGRATION_ENV_LEGACY, m as INTEGRATION_ENV_LEGACY_REMOVAL, O as OWN_RUN_WARNING, P as PEER_RUN_WARNING, n as RUN_BUDGET_ENV, o as RUN_PROFILES, p as RUN_PROFILE_ENV, d as RunKind, c as RunOutcome, e as RunOutcomeState, f as RunPreflight, q as RunPreflightOptions, a as RunProfile, b as RunRunner, h as RunWake, i as RunnerFactory, j as RunnerIdentity, R as RunnerSource, r as describeRunProfile, s as integrationDisabled, t as integrationDisabledBy, u as isRunProfile, v as isRunnerFactory, w as ownProfileLine, x as resolveRunBudgetMs, y as resolveRunProfile, z as runProfileWarning, A as workdirExposesHome } from './runner-BLvFalN4.js';
7
7
  import { spawn, spawnSync } from 'node:child_process';
8
8
 
9
+ /** A listener registered, or a key saved, this recently is still coming up: not "down". The daemon follows a credential within 5 s; a service manager's cold start can take far longer than that. */
10
+ declare const SETUP_GRACE_MS = 90000;
11
+ declare const SETUP_STATES: readonly ["no_account", "code_pending", "code_expired", "key_refused", "suspended", "unreachable", "paused", "tools_missing", "listener_off", "listener_missing", "listener_down", "listener_starting", "listener_failing", "ready"];
12
+ type SetupState = (typeof SETUP_STATES)[number];
13
+ interface SetupVerdict {
14
+ readonly state: SetupState;
15
+ /** What is the case and what to do, in plain words with the exact command: the text after `Setup: <state> — `. */
16
+ readonly next: string;
17
+ /** The exact command to run next, or null (done, or the next step is the person's). */
18
+ readonly command: string | null;
19
+ /** Only the person can do the next step (sign the runtime in, turn the listener back on, …). */
20
+ readonly needs_person: boolean;
21
+ /** What to ask the person, in plain words; null when there is nothing to ask. Also set when the person may be needed (the emailed code, when the inbox is not yours to read). */
22
+ readonly ask: string | null;
23
+ /** The facts behind it, as found: the listener's own error, the server's words, a note. Null when none. */
24
+ readonly detail: string | null;
25
+ /**
26
+ * One word for why, within the state (`^[a-z][a-z0-9_]{0,31}$`): the
27
+ * runtime's reason kind (`not_signed_in`, `runtime_missing`, …),
28
+ * `opted_out`, `standby`, `older_listener`, `not_seen`, …; null when the
29
+ * state says it all. What setup telemetry sends beside the state.
30
+ */
31
+ readonly reason: string | null;
32
+ }
33
+ /** The verdict in one line. */
34
+ declare function formatSetupVerdict(verdict: SetupVerdict): string;
35
+ /** `reachability` as far as the verdict reads it (contract v1 §3.12). Unknown states and fields are kept as words or ignored. */
36
+ interface ReachabilityView {
37
+ readonly state: string;
38
+ readonly via: string | null;
39
+ readonly problemKind: string | null;
40
+ readonly problemText: string | null;
41
+ readonly text: string | null;
42
+ }
43
+ /**
44
+ * The `reachability` a `GET /v1/agents/me` answer carries, or null: absent
45
+ * (a server before it, or one that could not read it), or not in a shape
46
+ * this release reads. Never required.
47
+ */
48
+ declare function reachabilityOf(me: unknown): ReachabilityView | null;
49
+ /** The server's answer to `GET /v1/agents/me`, for the verdict. */
50
+ type ServerView = {
51
+ readonly kind: 'ok';
52
+ readonly handle: string;
53
+ readonly reachability: ReachabilityView | null;
54
+ } | {
55
+ readonly kind: 'refused';
56
+ readonly detail: string;
57
+ } | {
58
+ readonly kind: 'suspended';
59
+ readonly detail: string;
60
+ } | {
61
+ readonly kind: 'unreachable';
62
+ readonly detail: string;
63
+ };
64
+ /** What the listener's daemon last said for the current credential. */
65
+ type DaemonWord =
66
+ /** Nothing for this credential: no status, one written before the key was saved, or one too old with no daemon alive. */
67
+ {
68
+ readonly kind: 'none';
69
+ }
70
+ /** Installed with the integration switched off (`AGENTCHAT_INTEGRATION=off`): no socket, no run. */
71
+ | {
72
+ readonly kind: 'off';
73
+ } | {
74
+ readonly kind: 'ready';
75
+ readonly runsFailing: {
76
+ readonly reason: string;
77
+ readonly since: string;
78
+ } | null;
79
+ readonly runtimeCheckFailing: boolean;
80
+ } | {
81
+ readonly kind: 'standby';
82
+ readonly home: string | null;
83
+ readonly pid: number | null;
84
+ } | {
85
+ readonly kind: 'unservable';
86
+ readonly reason: 'key_refused' | 'runs_failing';
87
+ readonly detail: string;
88
+ }
89
+ /** It could not start: the runtime is not ready, the server could not be asked, … (`last_error`). */
90
+ | {
91
+ readonly kind: 'start_failure';
92
+ readonly detail: string;
93
+ } | {
94
+ readonly kind: 'blocked';
95
+ readonly detail: string | null;
96
+ } | {
97
+ readonly kind: 'connecting';
98
+ };
99
+ interface ListenerReading {
100
+ /** The person switched it off (`daemon disable`, `uninstall`). */
101
+ readonly optedOut: boolean;
102
+ /** A service was registered for this home (`always-on.wanted`). */
103
+ readonly wanted: boolean;
104
+ /** The release the registered service runs, or null when not recorded. */
105
+ readonly installedVersion: string | null;
106
+ readonly daemon: DaemonWord;
107
+ /** A daemon process holds this home's lease now (renewed every 10 s). */
108
+ readonly alive: boolean;
109
+ /** Registered or signed in within `SETUP_GRACE_MS`. */
110
+ readonly withinGrace: boolean;
111
+ /** When the daemon last wrote its status, or null. */
112
+ readonly lastAliveAt: string | null;
113
+ }
114
+ interface ReadListenerOptions {
115
+ readonly now?: number;
116
+ /**
117
+ * The daemon process that held this home's lease before a command
118
+ * registered the service again (`daemonPidOf`, read just before): what it
119
+ * wrote is not the new process's word, however recent.
120
+ */
121
+ readonly replacedPid?: number | null;
122
+ }
123
+ /** The pid of the daemon that holds this home's lease now, or null. */
124
+ declare function daemonPidOf(home: string): number | null;
125
+ /**
126
+ * The listener as its own files say it, for `handle`: the always-on markers,
127
+ * the daemon's status file (only when it was written for the credential the
128
+ * home holds now and names this handle), and the home's lease (a daemon
129
+ * process alive: its status is written once while it keeps failing to
130
+ * start, so an old file is not proof it is gone; and a "ready" from a process
131
+ * that is gone is not one). Pure reads; never throws.
132
+ */
133
+ declare function readListener(home: string, handle: string | null, options?: ReadListenerOptions): ListenerReading;
134
+ /**
135
+ * Why a listener cannot start runs, in the server's words for it (contract
136
+ * v1 §3.13 `reason_kind`): what the verdict says to the agent, and what a
137
+ * listener report sends. Read from the runtime check's own words, which the
138
+ * presets in this package write (`claude is not signed in …`, `codex login
139
+ * status failed: …`, `… not found on PATH …`, `…; AgentChat requires … >= …`).
140
+ */
141
+ type ListenerReasonKind = 'not_signed_in' | 'runtime_missing' | 'runtime_outdated' | 'runtime_check_failed' | 'other';
142
+ declare function listenerReasonKindOf(detail: string): ListenerReasonKind;
143
+ interface SetupInputs {
144
+ /** What a user types to reach this integration. */
145
+ readonly invocation: string;
146
+ /** The runtime's name for people (`Claude Code`). */
147
+ readonly label: string;
148
+ /** This build's version: a registered service from an older one is noted. */
149
+ readonly version: string;
150
+ /** The identity home (named when the key is only in the environment). */
151
+ readonly home: string;
152
+ /** The identity the home names now, or null. */
153
+ readonly identity: {
154
+ readonly handle: string | null;
155
+ readonly source: 'file' | 'env';
156
+ } | null;
157
+ readonly pending: PendingSignup | null;
158
+ /** The server's answer; null when it was not asked (no identity). */
159
+ readonly server: ServerView | null;
160
+ /** The listener; null for a host that places none (the verdict then stops at the account). */
161
+ readonly listener: ListenerReading | null;
162
+ /** What this command's `ensureListener` did, if it ran. */
163
+ readonly ensure?: ListenerEnsure | null;
164
+ /** A placement problem that keeps runs from having the AgentChat tools. */
165
+ readonly tools?: PlacementProblem | null;
166
+ /** Said right after a sign-in: the ready text ends with the one thing to tell the person. */
167
+ readonly afterSignIn?: boolean;
168
+ readonly now?: number;
169
+ }
170
+ /**
171
+ * Whether release `a` is newer than `b` (`x.y.z`, slot by slot, numerically);
172
+ * false when either cannot be read. What the verdict calls an older listener,
173
+ * and what a host's implicit ensure never replaces (no downgrade).
174
+ */
175
+ declare function newerRelease(a: string | null, b: string | null): boolean;
176
+ /**
177
+ * The setup verdict from plain inputs; null when there is nothing this host
178
+ * can judge (no listener of its own, and the account is fine).
179
+ */
180
+ declare function setupVerdict(i: SetupInputs): SetupVerdict | null;
181
+
9
182
  /** Published package version, kept in lockstep with package.json by tests. */
10
- declare const VERSION = "0.7.1";
183
+ declare const VERSION = "0.8.0";
11
184
 
12
185
  type TrayClient = Pick<AgentChatClient, 'inbox'>;
13
186
  interface TraySummary {
@@ -91,29 +264,6 @@ declare function offerDeclined(home: string): boolean;
91
264
  /** Cleared when an identity is established, so a later logout asks again. */
92
265
  declare function clearOfferDeclined(home: string): void;
93
266
 
94
- declare const MANUAL_URL = "https://agentchat.me/skill.md";
95
- /** The skill name every runtime sees: `<skills dir>/agentchat/SKILL.md`. */
96
- declare const MANUAL_SKILL_NAME = "agentchat";
97
- declare const MANUAL_FILENAME = "SKILL.md";
98
- /** The bundled copy, byte for byte (the fallback; the served manual is the source). */
99
- declare const MANUAL: string;
100
- /**
101
- * The YAML front matter's top-level `key: value` fields, or null when the text
102
- * does not open with a front matter block. Deliberately not a YAML parser:
103
- * the manual's front matter is flat, and nothing here interprets more of a
104
- * downloaded text than its name and version. A leading byte-order mark and
105
- * CRLF line endings (a file saved by a Windows editor) read the same as LF.
106
- */
107
- declare function manualFrontMatter(raw: string): ReadonlyMap<string, string> | null;
108
- /** The `version:` field of the manual's YAML front matter, or null. */
109
- declare function manualVersion(text?: string): string | null;
110
- /**
111
- * The one pointer line a run prompt ends with. `location` is how THIS runtime
112
- * reaches its copy of the manual (a skill name, a path) — the integration knows
113
- * that, this package does not.
114
- */
115
- declare function manualPointer(location: string): string;
116
-
117
267
  /** The identity line, ready to place, from a served (or cached) texts response. */
118
268
  declare function identityLineOf(texts: Pick<Texts, 'identity_line'>): string;
119
269
  /** Handles are canonical lowercase on the wire; a leading `@` is display only. The kit's (`integration.anchor.normalizeHandle`). */
@@ -141,9 +291,12 @@ interface HostCopy {
141
291
  *
142
292
  * It names the commands and nothing of the server's: no handle rules, no
143
293
  * code length, no scripted answer for a failure. Each command prints the
144
- * server's sentence and the command to run next, and the agent relays the one
145
- * and runs the other, so a rule that moves on the server never leaves a stale
146
- * copy in every instruction file.
294
+ * server's sentence and the command to run next, and ends with the setup
295
+ * verdict (`Setup: <state> — …`: done, the exact next command, or the one
296
+ * thing to ask the person), so a rule that moves on the server never leaves a
297
+ * stale copy in every instruction file. An existing key goes in through a
298
+ * file on stdin (`login --api-key - < <file>`): never into the conversation,
299
+ * never on a command line.
147
300
  */
148
301
  declare function renderUnregisteredBlock(copy: HostCopy): string;
149
302
  /**
@@ -154,6 +307,16 @@ declare function renderUnregisteredBlock(copy: HostCopy): string;
154
307
  * gives no instruction to act on, so there is nothing to nag with.
155
308
  */
156
309
  declare function renderDeclinedBlock(copy: HostCopy): string;
310
+ /**
311
+ * Whether a block's body (between the fences, as `kit.anchor.find` reads it)
312
+ * is the wizard's: the offer (its first line is `UNREGISTERED_HEADING`) or
313
+ * the silent variant (`DECLINED_HEADING`, then a line that opens with the
314
+ * variant's first sentence). Whatever host wrote it: the host's name is not
315
+ * part of what is compared. Neither carries a handle; registering replaces
316
+ * them (`writeAnchor`), and nothing that follows the served texts touches
317
+ * either (`followIdentityAnchor`).
318
+ */
319
+ declare function isSetupOfferBody(body: string): boolean;
157
320
 
158
321
  declare const ANCHOR_START: string;
159
322
  declare const ANCHOR_END: string;
@@ -165,20 +328,125 @@ declare const ANCHOR_END: string;
165
328
  * line of it is a marker. Nothing is written then.
166
329
  */
167
330
  declare function renderAnchorBlock(identityLine: string, handle: string): string;
168
- type AnchorAction = 'written' | 'removed' | 'noop';
331
+ /** `kept`: the file holds a block that is not this agent's (nor the setup offer), and nothing was written. */
332
+ type AnchorAction = 'written' | 'removed' | 'noop' | 'kept';
169
333
  /**
170
- * Put `block` in the file at `filePath`, in place of the first AgentChat block
171
- * of any known shape (every other one is removed), or after the file's own
172
- * text when there is none. Creates the file if needed. The rest of the file is
173
- * kept as it was, except that the blank lines next to the block become
174
- * exactly one; the write is atomic (see `writeInstructionFile`).
334
+ * Put `block` in the file at `filePath` — only where it takes nothing of
335
+ * anyone's: after the file's own text when there is no AgentChat block, or in
336
+ * place of the setup offer (or its declined variant), or — with
337
+ * `expectHandle` — in place of that agent's own block (the kit's strict
338
+ * `owner`). Any other block (edited by hand, another agent's, more than one
339
+ * block) is left exactly as it is, and the result is `kept`. Creates the file
340
+ * if needed. The rest of the file is kept as it was (the blank lines next to
341
+ * the block become exactly one; line breaks, whether it ends with one, a
342
+ * byte-order mark); the write is atomic (see `writeInstructionFile`).
343
+ * Placing the identity line follows its own policy (`placeAnchorAt`).
175
344
  *
176
345
  * With `expectHandle`, throws — writing nothing — unless the block names that
177
346
  * handle, and throws if the file does not read back as written.
178
347
  */
179
348
  declare function writeAnchor(filePath: string, block: string, expectHandle?: string): AnchorAction;
180
- /** Remove every AgentChat block (current or legacy) from the file; the rest stays as it was. */
181
- declare function removeAnchorAt(filePath: string): AnchorAction;
349
+ /**
350
+ * - `placed` — there was no AgentChat block (or only the setup offer): the identity block is in the file now;
351
+ * - `updated` — this agent's block held other text, or the served text in an older shape: it holds the served block now;
352
+ * - `unchanged` — it already is the served block;
353
+ * - `replaced_other` — (setup) another agent's block was there: it is this agent's now, and said;
354
+ * - `other_agent` — (repair) another agent's block is there: left as it is;
355
+ * - `hand_edited` — the block is not AgentChat's (edited by hand): left as it is;
356
+ * - `several_blocks` — more than one AgentChat block: left as it is;
357
+ * - `failed` — the served line does not name this agent (or holds a marker line): nothing written.
358
+ */
359
+ type PlaceAnchorOutcome = 'placed' | 'updated' | 'unchanged' | 'replaced_other' | 'other_agent' | 'hand_edited' | 'several_blocks' | 'failed';
360
+ interface PlaceAnchorOptions {
361
+ readonly handle: string;
362
+ /** The served identity line for this agent. */
363
+ readonly identityLine: string;
364
+ /** The served `identity_line_template`, when in hand: a block with no handle line in exactly its words is AgentChat's. */
365
+ readonly template?: string | null;
366
+ /**
367
+ * `setup` (install, register, login, recover): another agent's block is
368
+ * replaced, and said — the key just set is the agent this file is for.
369
+ * `repair` (`doctor --fix`): another agent's block is refused — the key or
370
+ * the file is wrong, and which is for the person to say.
371
+ */
372
+ readonly mode: 'setup' | 'repair';
373
+ /** The command that repairs, as the user types it (`npx -y @agentchatme/example doctor --fix`), for the remedy a left block names. */
374
+ readonly fix?: string;
375
+ }
376
+ interface PlaceAnchorResult {
377
+ readonly outcome: PlaceAnchorOutcome;
378
+ /** Something was written. */
379
+ readonly written: boolean;
380
+ /** The handle the block in the file was AgentChat's for, before (for `replaced_other` / `other_agent`, the other agent's); null otherwise. */
381
+ readonly claimed: string | null;
382
+ /** What happened, in words, naming the file — with the remedy for a block that was left. */
383
+ readonly detail: string;
384
+ }
385
+ /**
386
+ * Place this agent's identity block in `filePath` (the served line, `handle`)
387
+ * under the one policy every integration follows: a person's words are only
388
+ * replaced once they delete the block themselves. The kit's `decide` (and so
389
+ * its strict `owner`) says what the file holds:
390
+ *
391
+ * - no block, or the setup offer: placed;
392
+ * - this agent's block: updated (or unchanged);
393
+ * - edited by hand: left, with the remedy (delete that block, then run `doctor --fix`);
394
+ * - another agent's: `setup` replaces it and says so; `repair` leaves it (fix the key, or remove that block);
395
+ * - more than one block: left, with the remedy.
396
+ *
397
+ * Creates the file when there is none. The write is atomic and keeps the
398
+ * user's text (`writeInstructionFile`); the result is read back. Throws when
399
+ * the file exists but cannot be read or written, as `hasAnchorAt` does.
400
+ */
401
+ declare function placeAnchorAt(filePath: string, options: PlaceAnchorOptions): PlaceAnchorResult;
402
+ /** Whose identity block a removal may take out: this agent's (the served line and template recognise its unmarked blocks exactly). */
403
+ interface RemoveAnchorOptions {
404
+ /** The agent being signed out or uninstalled; null when the home holds none (then only the setup offer is AgentChat's to remove). */
405
+ readonly handle: string | null;
406
+ /** The served identity line, when texts are in hand (the identity-home cache will do). */
407
+ readonly identityLine?: string | null;
408
+ /** The served `identity_line_template`, when in hand. */
409
+ readonly template?: string | null;
410
+ }
411
+ interface RemoveAnchorResult {
412
+ /** `removed`: AgentChat's block for this agent (or the setup offer) is gone; `kept`: a block that is not was left; `noop`: no file, or no block. */
413
+ readonly action: 'removed' | 'noop' | 'kept';
414
+ /** Why a block was left: edited by hand, another agent's, or more than one block (which are this agent's is not certain). */
415
+ readonly kept: 'hand_edited' | 'other_agent' | 'several_blocks' | null;
416
+ /** The handle the block is AgentChat's for (the kit's `owner`), or null. */
417
+ readonly claimed: string | null;
418
+ /** What was done, in words, naming the file. */
419
+ readonly detail: string;
420
+ }
421
+ /**
422
+ * Take AgentChat out of the file — only what AgentChat placed for this
423
+ * agent: its identity block (the kit's strict `owner` is `handle`: its handle
424
+ * line, or a whole text that is exactly a served one), or the wizard's setup
425
+ * offer or its declined variant. A block edited by hand, another agent's
426
+ * block, or a file with more than one AgentChat block is left exactly as it
427
+ * is, and the result says so. The rest of the file is kept as it was (line
428
+ * breaks, whether it ends with one, a byte-order mark; the blank lines next
429
+ * to the block become exactly one), and the write is atomic
430
+ * (`writeInstructionFile`). Throws when the file exists but cannot be read
431
+ * or written, as `hasAnchorAt` does.
432
+ */
433
+ declare function removeAnchorAt(filePath: string, options: RemoveAnchorOptions): RemoveAnchorResult;
434
+ interface WriteOfferResult {
435
+ /** `written`: the offer (or its declined variant) is in the file; `kept`: a block that is not AgentChat's offer is there, and was left. */
436
+ readonly action: 'written' | 'kept';
437
+ readonly detail: string;
438
+ }
439
+ /**
440
+ * Put the wizard's offer (or its declined variant, `block`) in the file —
441
+ * only where it takes nothing of anyone's: after the file's own text when
442
+ * there is no AgentChat block, or in place of the offer or declined block
443
+ * already there. Any other block (this or another agent's identity block, one
444
+ * edited by hand, more than one block) is left exactly as it is, and the
445
+ * result says so. Logout writes the offer after taking this agent's block
446
+ * out (`removeAnchorAt`), so a block it left stays. Throws as
447
+ * `writeAnchor` does.
448
+ */
449
+ declare function writeOfferAt(filePath: string, block: string): WriteOfferResult;
182
450
  /**
183
451
  * Whether the file holds an AgentChat block of any known shape (the identity
184
452
  * block, a legacy one, or the wizard's offer). Throws when the file exists but
@@ -196,23 +464,23 @@ declare function hasAnchorAt(filePath: string): boolean;
196
464
  */
197
465
  declare function anchorIsCurrentAt(filePath: string, identityLine: string, handle: string): boolean;
198
466
  /**
199
- * The handle a file's block currently CLAIMS, or null when there is no block
200
- * or it names no handle that can be read (the wizard's offer, most
201
- * hand-edited blocks). Lets an integration catch a block that disagrees with
202
- * its own credential — an agent told it is @a while authenticating as @b
203
- * hands peers an address that reaches someone else — so a WRONG handle is
204
- * read back, not treated as "no anchor".
467
+ * The handle a file's block is AgentChat's for, or null when there is no
468
+ * block or it is not AgentChat's (the wizard's offer, a block edited by
469
+ * hand). The kit's strict reading (`integration.anchor.owner`): the handle of
470
+ * its handle line, or — with none — the handle its whole text is EXACTLY a
471
+ * served text for (the served template filled in, or an identity line served
472
+ * before). A sentence of the user's that says "I am @<handle>" names no
473
+ * owner: the kit's loose `find` reading is display only. Lets an integration
474
+ * catch a block that disagrees with its own credential — an agent told it is
475
+ * @a while authenticating as @b hands peers an address that reaches someone
476
+ * else — so a WRONG handle is read back, not treated as "no anchor".
477
+ * (`identityBlockState` says the whole verdict in one sentence.)
205
478
  *
206
479
  * `template` is the served `identity_line_template` (null when no texts are
207
- * in hand): it recognises an unmarked block in whatever words the server
208
- * serves today; without it, the handle line and the two wordings earlier
209
- * releases wrote are still read. A hand-edited block whose words happen to
210
- * follow one of those (`I am happy … on AgentChat`) reads as claiming that
211
- * word: the kit's wording match does not require the `@`. Throws as
212
- * `hasAnchorAt` does.
480
+ * in hand). Throws as `hasAnchorAt` does.
213
481
  */
214
- declare function readAnchorHandleAt(filePath: string, template: string | null): string | null;
215
- declare function readAnchorHandleFrom(text: string, template: string | null): string | null;
482
+ declare function readAnchorHandleAt(filePath: string, template?: string | null): string | null;
483
+ declare function readAnchorHandleFrom(text: string, template?: string | null): string | null;
216
484
  /** `existing` with `block` in place of the first block (current or legacy) and every other block removed; `kit.anchor.replace`. */
217
485
  declare function upsertAnchorBlock(existing: string, block: string): string;
218
486
  /** `existing` without any block (current or legacy); `kit.anchor.remove`. */
@@ -288,6 +556,104 @@ declare class PausedConversations {
288
556
  private persist;
289
557
  }
290
558
 
559
+ declare const TELEMETRY_ENV = "AGENTCHAT_TELEMETRY";
560
+ declare const TELEMETRY_PATH = "/v1/telemetry";
561
+ declare const TELEMETRY_VERSION: 1;
562
+ /** The most a command waits for its event to be taken. */
563
+ declare const TELEMETRY_TIMEOUT_MS = 1500;
564
+ /** The commands a `setup_verdict` names (the server's closed list). */
565
+ type SetupCommand = 'install' | 'register' | 'login' | 'recover' | 'doctor' | 'status' | 'uninstall' | 'daemon' | 'other';
566
+ interface SetupVerdictEvent {
567
+ readonly name: 'setup_verdict';
568
+ readonly at: string;
569
+ readonly props: {
570
+ readonly state: string;
571
+ readonly command: SetupCommand;
572
+ readonly needs_person: boolean;
573
+ readonly reason?: string;
574
+ readonly exit_code: number;
575
+ readonly duration_ms: number;
576
+ };
577
+ }
578
+ interface TelemetryBody {
579
+ readonly version: typeof TELEMETRY_VERSION;
580
+ readonly events: readonly SetupVerdictEvent[];
581
+ }
582
+ /** One request, as a sender gets it. */
583
+ interface TelemetryRequest {
584
+ readonly apiBase: string;
585
+ /** The identity's key, or null: the event is then anonymous (the install id names it). */
586
+ readonly apiKey: string | null;
587
+ /** What the request names itself with (the SDK turns it into the client headers and X-AgentChat-Platform). */
588
+ readonly clientIdentity: AgentChatClientIdentity;
589
+ readonly body: TelemetryBody;
590
+ /** Aborted when the time is up. */
591
+ readonly signal: AbortSignal;
592
+ }
593
+ /** Sends one request; may throw (the caller swallows it). */
594
+ type TelemetrySender = (request: TelemetryRequest) => Promise<void>;
595
+ /** `AGENTCHAT_TELEMETRY` set to `off`, `0` or `false` (any case). */
596
+ declare function telemetryOff(env?: NodeJS.ProcessEnv): boolean;
597
+ /** The event for a verdict a command said. */
598
+ declare function setupVerdictEvent(verdict: SetupVerdict, facts: {
599
+ command: SetupCommand;
600
+ exitCode: number;
601
+ startedAt: number;
602
+ now?: number;
603
+ }): SetupVerdictEvent;
604
+ /**
605
+ * The network sender: one attempt through the SDK's transport, so the request
606
+ * carries exactly the headers every SDK call does (no copy of them here).
607
+ */
608
+ declare const httpTelemetrySender: TelemetrySender;
609
+ interface SendSetupVerdictOptions {
610
+ readonly command: SetupCommand;
611
+ readonly exitCode: number;
612
+ readonly startedAt: number;
613
+ readonly apiBase: string;
614
+ readonly apiKey: string | null;
615
+ readonly clientIdentity: AgentChatClientIdentity;
616
+ /** Default: the network (`httpTelemetrySender`), or nothing at all under AGENTCHAT_SERVICE_DRY_RUN. */
617
+ readonly sender?: TelemetrySender;
618
+ readonly env?: NodeJS.ProcessEnv;
619
+ readonly timeoutMs?: number;
620
+ }
621
+ /**
622
+ * Tell AgentChat what a command said. Resolves within the timeout whatever
623
+ * happens; never throws, never prints. Nothing is sent when telemetry is
624
+ * off, or when there is neither an install id nor a key to name the sender.
625
+ */
626
+ declare function sendSetupVerdict(verdict: SetupVerdict, opts: SendSetupVerdictOptions): Promise<void>;
627
+
628
+ /** How long an account command waits for the listener to connect: the daemon follows a new key within 5 s, then checks its runtime and opens the socket. */
629
+ declare const SETUP_WAIT_MS = 30000;
630
+ /** Test seams for `createIdentityCommands`. */
631
+ interface IdentityCommandOptions {
632
+ /** How long account commands wait for the listener to connect (default `SETUP_WAIT_MS`). */
633
+ setupWaitMs?: number;
634
+ /** How often the wait looks (default 500 ms). */
635
+ setupPollMs?: number;
636
+ /** Whether no service manager is used, so no listener will start and nothing is waited for (default: `AGENTCHAT_SERVICE_DRY_RUN`). */
637
+ serviceDryRun?: boolean;
638
+ /** Where setup telemetry goes (default: the network, or nowhere under AGENTCHAT_SERVICE_DRY_RUN). */
639
+ telemetrySender?: TelemetrySender;
640
+ }
641
+ /** What a host's install hands `reportSetup` (its own command, measured by it). */
642
+ interface ReportSetupOptions {
643
+ command: SetupCommand;
644
+ exitCode: number;
645
+ /** When the command started (ms since the epoch). */
646
+ startedAt: number;
647
+ }
648
+ /** What `confirmSetup` takes from a host's install. */
649
+ interface ConfirmSetupOptions {
650
+ /** What the install's `ensureListener` did, or null when it did not run (a placement step failed). */
651
+ ensure?: ListenerEnsure | null;
652
+ /** A placement problem that keeps runs from having the AgentChat tools. */
653
+ tools?: PlacementProblem | null;
654
+ /** The daemon pid that held the home's lease before the install's `ensureListener` (`daemonPidOf`): after `installed`, what it wrote is not the new process's word. */
655
+ replacedPid?: number | null;
656
+ }
291
657
  interface RegisterOpts {
292
658
  email?: string;
293
659
  handle?: string;
@@ -324,11 +690,24 @@ interface IdentityCommands {
324
690
  runStatus(opts: {
325
691
  json?: boolean;
326
692
  }): Promise<number>;
327
- runLogout(): number;
693
+ /** Async: it tells AgentChat the listener stopped (contract v1 §3.13) before the key goes. */
694
+ runLogout(): Promise<number>;
328
695
  runDoctor(opts?: DoctorOpts): Promise<number>;
696
+ /**
697
+ * For a host's install: wait for the listener when there is an identity and
698
+ * it was registered (`ensure`), then print the setup verdict as the last
699
+ * line. Returns the verdict, or null when there is none to say.
700
+ */
701
+ confirmSetup(opts?: ConfirmSetupOptions): Promise<SetupVerdict | null>;
702
+ /**
703
+ * For a host's install, after it knows its exit code: send setup telemetry
704
+ * for the verdict this process said last (`confirmSetup`), if any. Never
705
+ * prints, never throws, bounded (`TELEMETRY_TIMEOUT_MS`).
706
+ */
707
+ reportSetup(opts: ReportSetupOptions): Promise<void>;
329
708
  }
330
709
  /** Build the identity command set for one coding agent. */
331
- declare function createIdentityCommands(profile: HostProfile): IdentityCommands;
710
+ declare function createIdentityCommands(profile: HostProfile, options?: IdentityCommandOptions): IdentityCommands;
332
711
 
333
712
  declare const HEARTBEAT_FILE = "daemon.heartbeat";
334
713
  /** Record that the user wants always-on for this agent.
@@ -572,4 +951,4 @@ interface ProbeOptions {
572
951
  declare const PROBE_KILL_WAIT_MS = 5000;
573
952
  declare function runProbe(command: string, args: readonly string[], options: ProbeOptions): Promise<ProbeResult>;
574
953
 
575
- export { AGENT_LOCK_DIR_ENV, ANCHOR_END, ANCHOR_START, type AlwaysOnState, type AnchorAction, COULD_NOT_PROCESS_FILE, type CachedTexts, DAEMON_LOCK_FILE, type DoctorOpts, type FetchIdentityLineOptions, type FetchServedTextsOptions, HEARTBEAT_FILE, HOSTED_MCP_PATH, type HostCopy, HostProfile, type IdentityCommands, type IdentityState, IntegrationClient, Lease, LeaseAttempt, LeaseHolder, LeaseOptions, type LoadTextsOptions, type LoadedTexts, type LockHandle, MANUAL, MANUAL_FILENAME, MANUAL_SKILL_NAME, MANUAL_URL, type McpProbeResult, PROBE_KILL_WAIT_MS, type PausedConversation, PausedConversations, type Plan, type ProbeOptions, type ProbeResult, RUN_CONTEXT_ENV, type RecoverOpts, type RegisterOpts, RunRequest, STANDBY_MARKER_FRESH_MS, type ServiceCommandRunner, type ServiceHostOs, type ServiceOpts, type ServiceRef, TEXTS_CACHE_FILE, type TextsClient, type TextsSource, type TrayClient, type TraySummary, VERSION, acquireAgentLock, acquireLeaderLock, agentLockDir, agentLockPath, agentLockRefusal, alwaysOnHealth, alwaysOnOptedOut, alwaysOnState, alwaysOnWanted, anchorIsCurrentAt, atomicCopyFile, atomicWriteFile, beat, clearAlwaysOnInstalledVersion, clearAlwaysOnOptOut, clearAlwaysOnWanted, clearOfferDeclined, clearStandby, couldNotProcessPath, createIdentityCommands, fetchIdentityLine, fetchServedTexts, hasAnchorAt, hostedMcpUrl, identityLineOf, idle, installService, launchdPlist, loadTexts, log, manualFrontMatter, manualPointer, manualVersion, markAlwaysOnInstalledVersion, markAlwaysOnOptOut, markAlwaysOnWanted, markStandby, normalizeHandle, offerDeclined, parseServiceHome, planForTest, probeHostedMcp, readAlwaysOnInstalledVersion, readAnchorHandleAt, readAnchorHandleFrom, readCachedTexts, readJsonFile, readState, recordOfferDeclined, removeAnchorAt, renderAnchorBlock, renderDeclinedBlock, renderUnregisteredBlock, runContextEnv, runProbe, serviceDefinitionCurrent, serviceInstalled, serviceLabelFor, serviceStatus, setServiceCommandRunnerForTests, setServiceHostOsForTests, spawnCommand, spawnCommandSync, standbyMarkerPath, standbyWaiting, stripAnchorBlock, systemdQuote, systemdUnit, textsCachePath, traySummary, uninstallService, upsertAnchorBlock, writeAnchor, writeState, xmlEscape };
954
+ export { AGENT_LOCK_DIR_ENV, ANCHOR_END, ANCHOR_START, type AlwaysOnState, type AnchorAction, COULD_NOT_PROCESS_FILE, type CachedTexts, type ConfirmSetupOptions, DAEMON_LOCK_FILE, type DaemonWord, type DoctorOpts, type FetchIdentityLineOptions, type FetchServedTextsOptions, HEARTBEAT_FILE, HOSTED_MCP_PATH, type HostCopy, HostProfile, type IdentityCommandOptions, type IdentityCommands, type IdentityState, IntegrationClient, Lease, LeaseAttempt, LeaseHolder, LeaseOptions, ListenerEnsure, type ListenerReading, type ListenerReasonKind, type LoadTextsOptions, type LoadedTexts, type LockHandle, type McpProbeResult, PROBE_KILL_WAIT_MS, type PausedConversation, PausedConversations, PendingSignup, type PlaceAnchorOptions, type PlaceAnchorOutcome, type PlaceAnchorResult, PlacementProblem, type Plan, type ProbeOptions, type ProbeResult, RUN_CONTEXT_ENV, type ReachabilityView, type ReadListenerOptions, type RecoverOpts, type RegisterOpts, type RemoveAnchorOptions, type RemoveAnchorResult, type ReportSetupOptions, RunRequest, SETUP_GRACE_MS, SETUP_STATES, SETUP_WAIT_MS, STANDBY_MARKER_FRESH_MS, type SendSetupVerdictOptions, type ServerView, type ServiceCommandRunner, type ServiceHostOs, type ServiceOpts, type ServiceRef, type SetupCommand, type SetupInputs, type SetupState, type SetupVerdict, type SetupVerdictEvent, TELEMETRY_ENV, TELEMETRY_PATH, TELEMETRY_TIMEOUT_MS, TELEMETRY_VERSION, TEXTS_CACHE_FILE, type TelemetryBody, type TelemetryRequest, type TelemetrySender, type TextsClient, type TextsSource, type TrayClient, type TraySummary, VERSION, type WriteOfferResult, acquireAgentLock, acquireLeaderLock, agentLockDir, agentLockPath, agentLockRefusal, alwaysOnHealth, alwaysOnOptedOut, alwaysOnState, alwaysOnWanted, anchorIsCurrentAt, atomicCopyFile, atomicWriteFile, beat, clearAlwaysOnInstalledVersion, clearAlwaysOnOptOut, clearAlwaysOnWanted, clearOfferDeclined, clearStandby, couldNotProcessPath, createIdentityCommands, daemonPidOf, fetchIdentityLine, fetchServedTexts, formatSetupVerdict, hasAnchorAt, hostedMcpUrl, httpTelemetrySender, identityLineOf, idle, installService, isSetupOfferBody, launchdPlist, listenerReasonKindOf, loadTexts, log, markAlwaysOnInstalledVersion, markAlwaysOnOptOut, markAlwaysOnWanted, markStandby, newerRelease, normalizeHandle, offerDeclined, parseServiceHome, placeAnchorAt, planForTest, probeHostedMcp, reachabilityOf, readAlwaysOnInstalledVersion, readAnchorHandleAt, readAnchorHandleFrom, readCachedTexts, readJsonFile, readListener, readState, recordOfferDeclined, removeAnchorAt, renderAnchorBlock, renderDeclinedBlock, renderUnregisteredBlock, runContextEnv, runProbe, sendSetupVerdict, serviceDefinitionCurrent, serviceInstalled, serviceLabelFor, serviceStatus, setServiceCommandRunnerForTests, setServiceHostOsForTests, setupVerdict, setupVerdictEvent, spawnCommand, spawnCommandSync, standbyMarkerPath, standbyWaiting, stripAnchorBlock, systemdQuote, systemdUnit, telemetryOff, textsCachePath, traySummary, uninstallService, upsertAnchorBlock, writeAnchor, writeOfferAt, writeState, xmlEscape };