@agentchatme/agent-core 0.3.0 → 0.4.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,630 +0,0 @@
1
- import { TextsRuntime, AgentChatClientIdentity, AgentChatClient, Texts } from 'agentchatme';
2
- import { z } from 'zod';
3
-
4
- interface IntegrationClient {
5
- readonly runtime: TextsRuntime;
6
- readonly version: string;
7
- }
8
- /**
9
- * The SDK's client identity for this integration. The SDK types client names
10
- * as a closed union and the server normalises whatever arrives, so the
11
- * runtime name is passed through as-is; the union widens on the SDK side.
12
- */
13
- declare function clientIdentityOf(client: IntegrationClient): AgentChatClientIdentity;
14
- /** The same identity as headers, for the one raw request this package still makes (the MCP probe). */
15
- declare function clientHeadersOf(client: IntegrationClient): Record<string, string>;
16
-
17
- declare const RUN_PROFILES: readonly ["answer", "work", "full"];
18
- type RunProfile = (typeof RUN_PROFILES)[number];
19
- declare const RUN_PROFILE_ENV = "AGENTCHAT_RUN_PROFILE";
20
- declare const DEFAULT_RUN_PROFILE: RunProfile;
21
- declare function isRunProfile(value: unknown): value is RunProfile;
22
- /** `AGENTCHAT_RUN_PROFILE`, defaulting to `answer`; an unknown value is `answer` too. */
23
- declare function resolveRunProfile(env?: NodeJS.ProcessEnv): RunProfile;
24
- /** The one switch: `AGENTCHAT_INTEGRATION=off` holds no socket and starts no run. Tools and manual stay. */
25
- declare const INTEGRATION_ENV = "AGENTCHAT_INTEGRATION";
26
- /**
27
- * The previous spelling of the switch. Honoured for one release: a service
28
- * installed before the rename captured it into its unit file, and that unit
29
- * must keep meaning what the operator set.
30
- */
31
- declare const INTEGRATION_ENV_LEGACY = "AGENTCHAT_DOORBELL";
32
- /** Which switch turned the integration off, or null when it is on. The new spelling wins when both are set. */
33
- declare function integrationDisabledBy(env?: NodeJS.ProcessEnv): string | null;
34
- declare function integrationDisabled(env?: NodeJS.ProcessEnv): boolean;
35
- /** A run's time budget. Killed past it; that counts as a failed run. */
36
- declare const RUN_BUDGET_ENV = "AGENTCHAT_RUN_BUDGET_MS";
37
- declare const DEFAULT_RUN_BUDGET_MS: number;
38
- declare function resolveRunBudgetMs(env?: NodeJS.ProcessEnv): number;
39
-
40
- type RunKind = 'wake' | 'invite';
41
- interface RunRequest {
42
- readonly kind: RunKind;
43
- /** The prompt for this kind of run: the served text, then the manual pointer (`buildRunPrompts`). */
44
- readonly prompt: string;
45
- /** Unique per run; for logs and for runtimes that want a session name. */
46
- readonly runId: string;
47
- /** The run is killed past this budget and counts as failed. */
48
- readonly budgetMs: number;
49
- /**
50
- * Aborted when the integration is stopping (daemon shutdown, identity
51
- * change). A runner passes it to `spawnRun`, which SIGTERMs the
52
- * run's process group and SIGKILLs after a grace; the outcome is `failed`
53
- * with an "interrupted" detail. Optional so a runner that cannot interrupt
54
- * still satisfies the contract.
55
- */
56
- readonly signal?: AbortSignal;
57
- /**
58
- * Called once, as soon as the runtime's process has been started. The
59
- * invoker records a group invite as offered at this moment — not when the
60
- * run ends — so a run cut short by a shutdown or a crash still counts as
61
- * the invite's one offer from this machine. A runner built on `spawnRun`
62
- * passes it through; a runner that cannot tell may leave it uncalled, and
63
- * the invoker then records the offer when the run ends instead.
64
- */
65
- readonly onStarted?: () => void;
66
- }
67
- /**
68
- * `not_started` — the runtime never got going: binary missing, or a non-zero
69
- * exit with NOTHING ON STDOUT (an auth gate, a bad flag, a missing config —
70
- * all of which print their complaint on stderr and quit; stderr does not
71
- * count as output). `failed` — it produced output and exited non-zero, or was
72
- * interrupted. `timed_out` — it ran past its budget and was killed. `ok` —
73
- * exit 0. Anything but `ok` schedules the retry ladder.
74
- */
75
- type RunOutcomeState = 'ok' | 'failed' | 'timed_out' | 'not_started';
76
- interface RunOutcome {
77
- readonly state: RunOutcomeState;
78
- readonly exitCode: number | null;
79
- readonly durationMs: number;
80
- /** Bounded, credential-redacted diagnostic. Never message content. */
81
- readonly detail?: string;
82
- }
83
- interface RunPreflight {
84
- ok: boolean;
85
- detail?: string;
86
- }
87
- interface RunRunner {
88
- /** Short runtime name for logs and status, e.g. the CLI's binary name. */
89
- readonly name: string;
90
- /**
91
- * Is the runtime usable right now (binary present, signed in)? Called
92
- * before the socket is held, and — after the retry ladder is exhausted —
93
- * periodically, so a runtime that comes back (the user signs in again)
94
- * earns one re-wake without waiting for the next peer.
95
- */
96
- preflight(): Promise<RunPreflight>;
97
- /** Start one run and wait for it. Never throws — returns an outcome. */
98
- start(request: RunRequest): Promise<RunOutcome>;
99
- }
100
-
101
- declare const INTEGRATION_STATUS_FILE = "integration.status.json";
102
- /** The file a daemon before the rename writes; read when the current one is absent. */
103
- declare const LEGACY_STATUS_FILE = "doorbell.status.json";
104
- /**
105
- * The socket word. `blocked` is the SDK's own word for it (`RealtimeState`):
106
- * the server refused the credential on the hello and a fresh hello is tried
107
- * every 10–15 min until one is accepted — not an end state. Daemons before
108
- * this release wrote `terminal` for it; readers map that on the way in.
109
- */
110
- declare const SOCKET_STATES: readonly ["off", "idle", "connecting", "ready", "reconnecting", "blocked", "closed"];
111
- type SocketState = (typeof SOCKET_STATES)[number];
112
- type TextsSource$1 = 'server' | 'cache' | 'none';
113
- interface TextsStatus {
114
- /** Where the texts a run starts with came from. */
115
- source: TextsSource$1;
116
- fetched_at: string | null;
117
- /** The served text set's version. */
118
- version: string | null;
119
- manual_version: string | null;
120
- }
121
- interface IntegrationLastRun {
122
- kind: 'wake' | 'invite';
123
- started_at: string;
124
- ended_at: string;
125
- state: 'ok' | 'failed' | 'timed_out' | 'not_started';
126
- exit_code: number | null;
127
- duration_ms: number;
128
- detail: string | null;
129
- }
130
- interface IntegrationStatus {
131
- version: 2;
132
- updated_at: string;
133
- pid: number;
134
- runtime: string | null;
135
- handle: string | null;
136
- profile: string;
137
- socket: SocketState;
138
- wakes: number;
139
- wakes_absorbed: number;
140
- invites: number;
141
- runs_started: number;
142
- runs_ok: number;
143
- runs_failed: number;
144
- runs_timed_out: number;
145
- runs_not_started: number;
146
- /** Wakes whose tray count came back empty, so no run started. */
147
- runs_skipped_empty: number;
148
- last_run: IntegrationLastRun | null;
149
- retry_rung: number;
150
- retry_due_at: string | null;
151
- last_error: string | null;
152
- texts: TextsStatus | null;
153
- }
154
- declare function integrationStatusPath(home: string): string;
155
- /** Best effort: the status file is diagnostics, never a dependency of waking. */
156
- declare function writeIntegrationStatus(home: string, status: IntegrationStatus): void;
157
- /** The current file, or — when a daemon from before the rename is the one running — the file it writes. */
158
- declare function readIntegrationStatus(home: string): IntegrationStatus | null;
159
- /** Remove both spellings: a stale legacy file must not outlive the daemon that wrote it. */
160
- declare function clearIntegrationStatus(home: string): void;
161
- /** Age of the status file, in ms, or null when absent. */
162
- declare function integrationStatusAge(status: IntegrationStatus | null, now?: number): number | null;
163
- /** Human lines for `status`. Pure. */
164
- declare function formatIntegrationStatus(status: IntegrationStatus | null, now?: number): string[];
165
-
166
- declare const DEFAULT_WAKE_DEBOUNCE_MS = 2000;
167
- type TimerHandle = ReturnType<typeof setTimeout>;
168
- interface WakeCoalescerOptions {
169
- readonly onFire: () => void;
170
- readonly debounceMs?: number;
171
- /** Clock and timers are injectable so tests never wait on real time. */
172
- readonly now?: () => number;
173
- readonly setTimeout?: (fn: () => void, ms: number) => TimerHandle;
174
- readonly clearTimeout?: (handle: TimerHandle) => void;
175
- }
176
- declare class WakeCoalescer {
177
- private readonly onFire;
178
- private readonly debounceMs;
179
- private readonly now;
180
- private readonly _setTimeout;
181
- private readonly _clearTimeout;
182
- private timer;
183
- private delayed;
184
- private delayedDeadline;
185
- private stopped;
186
- wakes: number;
187
- absorbed: number;
188
- fires: number;
189
- constructor(options: WakeCoalescerOptions);
190
- /** True while a debounce timer is armed. */
191
- get armed(): boolean;
192
- /** True while a retry wake is scheduled and has not fired. */
193
- get delayedPending(): boolean;
194
- /** Epoch ms of the pending retry wake, or null. */
195
- get delayedDue(): number | null;
196
- /** A wake: arm the timer if none is armed; otherwise absorb. */
197
- wake(): void;
198
- /** A delayed wake (retry ladder). The sooner pending deadline is kept. */
199
- wakeAfter(delayMs: number): void;
200
- /**
201
- * Drop a pending retry wake, if there is one; returns whether there was.
202
- * The debounce timer and later wakes are unaffected. For when nothing is
203
- * owed any more — a run read the whole tray, or the tray was found empty —
204
- * so the retry would only ring for a backlog that is already handled.
205
- */
206
- cancelDelayed(): boolean;
207
- /** Cancel everything; later wakes are ignored. */
208
- stop(): void;
209
- private fire;
210
- }
211
-
212
- declare const TEXTS_CACHE_FILE = "texts.json";
213
- declare const TEXTS_REFRESH_MS: number;
214
- /** After a failed refresh: try again sooner than the daily timer. */
215
- declare const TEXTS_RETRY_MS = 3600000;
216
- type TextsSource = 'server' | 'cache' | 'none';
217
- interface CachedTexts {
218
- readonly fetched_at: string;
219
- readonly runtime: string;
220
- readonly texts: Texts;
221
- }
222
- declare function textsCachePath(home: string): string;
223
- /** The last response cached for this runtime, or null. A cache for another runtime is not this one's. */
224
- declare function readCachedTexts(home: string, runtime: TextsRuntime): CachedTexts | null;
225
- /** Best effort: the cache is a convenience for an offline start, never a dependency of a fetch. */
226
- declare function writeCachedTexts(home: string, runtime: TextsRuntime, texts: Texts, fetchedAt: Date): void;
227
- type TextsClient = Pick<AgentChatClient, 'texts'>;
228
- interface LoadedTexts {
229
- readonly texts: Texts;
230
- readonly source: 'server' | 'cache';
231
- readonly fetched_at: string;
232
- }
233
- interface LoadTextsOptions {
234
- readonly home: string;
235
- readonly runtime: TextsRuntime;
236
- readonly client: TextsClient;
237
- readonly timeoutMs?: number;
238
- readonly now?: () => Date;
239
- }
240
- /**
241
- * One fetch with the cache as fallback — what a CLI command does before it
242
- * places the identity line or checks it. Null only when the server could not
243
- * be reached and nothing was ever cached for this runtime.
244
- */
245
- declare function loadTexts(options: LoadTextsOptions): Promise<LoadedTexts | null>;
246
- interface FetchIdentityLineOptions {
247
- readonly home: string;
248
- readonly apiKey: string;
249
- readonly apiBase: string;
250
- readonly client: IntegrationClient;
251
- readonly timeoutMs?: number;
252
- }
253
- type FetchServedTextsOptions = FetchIdentityLineOptions;
254
- /**
255
- * The served texts for this agent, for an integration's own install and
256
- * placement paths: one fetch through an SDK client built here, the cache as
257
- * fallback, null when neither answers. The identity commands do the same
258
- * before `place`; this is the same read for callers that have no client.
259
- */
260
- declare function fetchServedTexts(options: FetchServedTextsOptions): Promise<LoadedTexts | null>;
261
- /** `fetchServedTexts`, reduced to the identity line. */
262
- declare function fetchIdentityLine(options: FetchIdentityLineOptions): Promise<string | null>;
263
- interface TextsStoreOptions {
264
- readonly home: string;
265
- readonly runtime: TextsRuntime;
266
- readonly client: TextsClient;
267
- readonly refreshMs?: number;
268
- readonly retryMs?: number;
269
- readonly timeoutMs?: number;
270
- /** Called after every change in what `current()` or `source` answer (a status writer hangs off this). */
271
- readonly onChange?: () => void;
272
- readonly now?: () => Date;
273
- readonly setTimeout?: (fn: () => void, ms: number) => TimerHandle;
274
- readonly clearTimeout?: (handle: TimerHandle) => void;
275
- }
276
- /**
277
- * The daemon's copy of the texts: fetched at start, refreshed on a timer, read
278
- * from the identity-home cache when the server cannot be reached, and fetched
279
- * on first use when the start fetch failed.
280
- */
281
- declare class TextsStore {
282
- readonly runtime: TextsRuntime;
283
- private readonly home;
284
- private readonly client;
285
- private readonly refreshMs;
286
- private readonly retryMs;
287
- private readonly timeoutMs;
288
- private readonly onChange;
289
- private readonly now;
290
- private readonly _setTimeout;
291
- private readonly _clearTimeout;
292
- private texts;
293
- private _source;
294
- private _fetchedAt;
295
- private inFlight;
296
- private timer;
297
- private stopped;
298
- private lastFailure;
299
- private serverSeen;
300
- constructor(options: TextsStoreOptions);
301
- /** Where the current texts came from: the server (this process), the on-disk cache, or nowhere yet. */
302
- get source(): TextsSource;
303
- /** When the current texts were fetched from the server (by this process or the one that cached them). */
304
- get fetchedAt(): string | null;
305
- /** The texts in hand, without a network call. */
306
- current(): Texts | null;
307
- /**
308
- * The start-time fetch, then the refresh timer. Returns once the first
309
- * attempt has settled, so a run that starts right after `start()` has the
310
- * freshest text available; a failure is logged once and does not throw —
311
- * the daemon starts anyway, on the cache if there is one.
312
- */
313
- start(): Promise<void>;
314
- stop(): void;
315
- /**
316
- * Fetch now (coalescing a fetch already in flight), cache on success, arm
317
- * the next refresh either way. Resolves whether the server answered.
318
- */
319
- refresh(): Promise<boolean>;
320
- /**
321
- * The texts for a run: what is in hand, after one more fetch attempt if the
322
- * server has not answered yet in this process. Null only when the server is
323
- * unreachable and nothing was ever cached — the run then does not start and
324
- * the wake retries on the ladder.
325
- */
326
- ensure(): Promise<Texts | null>;
327
- private fetchOnce;
328
- private arm;
329
- }
330
-
331
- declare const DEFAULT_API_BASE = "https://api.agentchat.me";
332
- declare const CredentialsSchema: z.ZodObject<{
333
- api_key: z.ZodString;
334
- handle: z.ZodString;
335
- api_base: z.ZodOptional<z.ZodString>;
336
- created_at: z.ZodOptional<z.ZodString>;
337
- }, "strip", z.ZodTypeAny, {
338
- api_key: string;
339
- handle: string;
340
- api_base?: string | undefined;
341
- created_at?: string | undefined;
342
- }, {
343
- api_key: string;
344
- handle: string;
345
- api_base?: string | undefined;
346
- created_at?: string | undefined;
347
- }>;
348
- type Credentials = z.infer<typeof CredentialsSchema>;
349
- interface ResolvedIdentity {
350
- apiKey: string;
351
- apiBase: string;
352
- /** Handle is only known when it came from the credentials file. */
353
- handle: string | null;
354
- source: 'env' | 'file';
355
- }
356
- declare function credentialsPath(home: string): string;
357
- declare function pendingPath(home: string): string;
358
- declare function statePath(home: string): string;
359
- /** Read the credential stored in `home`, or null when absent/malformed. */
360
- declare function readCredentials(home: string): Credentials | null;
361
- /**
362
- * The identity an integration should act as, for one specific home.
363
- * `AGENTCHAT_API_KEY` overrides the file; `AGENTCHAT_API_BASE` overrides the
364
- * base URL. Neither is host-specific, so both are read from the environment.
365
- */
366
- declare function resolveIdentity(home: string): ResolvedIdentity | null;
367
- declare function writeCredentials(home: string, creds: Credentials): void;
368
- /** Delete the credential and any half-finished registration in `home`.
369
- * Touches nothing outside `home` — that is the caller's whole agent. */
370
- declare function clearCredentials(home: string): boolean;
371
- declare const PendingSchema: z.ZodObject<{
372
- kind: z.ZodDefault<z.ZodEnum<["register", "recover"]>>;
373
- pending_id: z.ZodString;
374
- email: z.ZodString;
375
- handle: z.ZodOptional<z.ZodString>;
376
- api_base: z.ZodOptional<z.ZodString>;
377
- created_at: z.ZodString;
378
- }, "strip", z.ZodTypeAny, {
379
- created_at: string;
380
- kind: "register" | "recover";
381
- pending_id: string;
382
- email: string;
383
- handle?: string | undefined;
384
- api_base?: string | undefined;
385
- }, {
386
- created_at: string;
387
- pending_id: string;
388
- email: string;
389
- handle?: string | undefined;
390
- api_base?: string | undefined;
391
- kind?: "register" | "recover" | undefined;
392
- }>;
393
- type PendingRegistration = z.infer<typeof PendingSchema>;
394
- declare function readPending(home: string): PendingRegistration | null;
395
- declare function writePending(home: string, pending: PendingRegistration): void;
396
- declare function clearPending(home: string): void;
397
-
398
- type Verdict = 'PASS' | 'WARN' | 'FAIL';
399
- interface DoctorCheck {
400
- name: string;
401
- verdict: Verdict;
402
- detail: string;
403
- }
404
- /** What the shared `status` hands a host's extra lines: what it already fetched from the served texts (one fetch per command). */
405
- interface StatusContext {
406
- identityLine: string | null;
407
- /** The manual the served texts announce (`texts.manual`), or null when none are in hand — what `checkManual` compares the skill file with. */
408
- manual: ServedManual | null;
409
- }
410
- /** What the shared doctor hands a host's extra checks. */
411
- interface DoctorContext {
412
- fix?: boolean;
413
- /** The served identity line for this agent, or null when the server could not be reached and nothing is cached. */
414
- identityLine: string | null;
415
- /** The manual the served texts announce, or null when none are in hand (`--fix` syncs the skill file to it). */
416
- manual: ServedManual | null;
417
- }
418
- /**
419
- * Everything the shared identity commands need to know about ONE coding agent.
420
- *
421
- * This is the seam. The register / login / recover / status / logout / doctor
422
- * flows are the same everywhere because they are a contract with the AgentChat
423
- * server; what differs per host is only what is described here. An integration
424
- * builds one of these and gets the commands back.
425
- *
426
- * Note what is NOT here: any way to name a *different* host. A profile
427
- * describes the caller and nothing else, so a command built from it cannot
428
- * reach another agent's files. That is the same property the per-repo split
429
- * gives, kept intact while the flow itself is shared once.
430
- *
431
- * The path-ish fields are functions, not strings: `CODEX_HOME` and friends are
432
- * read per call, and evaluating them at module load would freeze a value the
433
- * user can still change.
434
- */
435
- interface HostProfile {
436
- /** Human name for output, e.g. `Claude Code`. */
437
- label: string;
438
- /** Stable machine identifier for `--json`, e.g. `claude-code`. */
439
- id: string;
440
- /** How this integration names itself to the server: the texts runtime and its own version. */
441
- client: IntegrationClient;
442
- /** THE identity home for this agent. */
443
- home(): string;
444
- /** This host's always-loaded instruction file. */
445
- anchorFile(): string;
446
- /** Exactly what a user types to reach this integration. */
447
- invocation(): string;
448
- /** Render the anchor block body this host wants from the served identity line (normally `renderAnchorBlock`). */
449
- renderAnchor(identityLine: string): string;
450
- /**
451
- * What to call the anchor in output. Defaults to the instruction file's own
452
- * basename (`CLAUDE.md`, `AGENTS.md`), which is what a user actually looks
453
- * for on disk.
454
- */
455
- anchorLabel?: string;
456
- /**
457
- * Whether this host is wired up enough for an anchor to mean anything.
458
- * An integration uses this so it never writes an identity block announcing
459
- * a phone number before its own placement is actually in place.
460
- */
461
- isWired?(): boolean;
462
- /**
463
- * Place the integration's texts for a freshly established identity: the
464
- * identity line, the manual, the hosted tool server with the key, and
465
- * whatever the key's home is on this runtime. Called after register, login
466
- * and recover (every time the key changes), and by `doctor --fix`.
467
- * `identityLine` is the served line for this agent (fetched just before,
468
- * or the cached one), or null when neither could be had — the host then
469
- * leaves the anchor for `doctor --fix` and says so. `manual` is what the
470
- * same texts announce (`syncManual` brings the skill file to it), or null.
471
- * Returns report lines. When absent, only the anchor is written.
472
- */
473
- place?(handle: string, apiKey: string, identityLine: string | null, manual: ServedManual | null): string[] | Promise<string[]>;
474
- /**
475
- * Undo `place` for the identity being signed out: remove the key from the
476
- * tool server registration and anything else that would still authenticate
477
- * as the old identity. The anchor is removed by the shared flow. Returns
478
- * report lines.
479
- *
480
- * `identity` is the identity AS IT WAS BEFORE the credential was cleared
481
- * (its key and API base), or null when there was none: a host recognises
482
- * its own registration by that key and that server, and guessing either
483
- * after the fact left a non-default `api_base` entry classified as foreign
484
- * and the key still registered.
485
- */
486
- unplace?(identity: ResolvedIdentity | null): string[];
487
- /** Host-specific doctor checks, appended after the shared ones. */
488
- extraDoctorChecks?(context: DoctorContext): DoctorCheck[] | Promise<DoctorCheck[]>;
489
- /**
490
- * Host-specific `status` lines (placement, probes), printed after the shared
491
- * ones in text mode. The served identity line and manual come along so the
492
- * host does not fetch `/v1/texts` a second time.
493
- */
494
- extraStatus?(context: StatusContext): string[] | Promise<string[]>;
495
- /** Extra lines printed after a successful logout. */
496
- logoutHints?(): string[];
497
- }
498
- /** The label to use for this host's anchor in user-facing output. */
499
- declare function anchorLabelOf(profile: HostProfile): string;
500
-
501
- /** What the served texts announce: `Texts['manual']`, with the optional integrity hash. */
502
- interface ServedManual {
503
- readonly url: string;
504
- readonly version: string;
505
- /** Hex sha256 of the served bytes. When present, a download must match it and a file is current only if it does. */
506
- readonly sha256?: string;
507
- }
508
- /** The manual is ~60 KB; anything past this is not the manual. */
509
- declare const MANUAL_MAX_BYTES: number;
510
- /** One attempt, every hop included; an installer or a refresh must not wait out a black-holed network. */
511
- declare const MANUAL_FETCH_TIMEOUT_MS = 10000;
512
- /** Redirects followed (each one checked) before giving up. */
513
- declare const MANUAL_MAX_REDIRECTS = 3;
514
- /** `fetch`'s shape, injectable for tests. Defaults to the platform's own; called with `redirect: 'manual'`. */
515
- type ManualFetch = (url: string, init: RequestInit) => Promise<Response>;
516
- /**
517
- * - `current` — the file already is the announced manual (version, and hash when announced); nothing fetched.
518
- * - `updated` — the announced manual was written (downloaded, or the bundled copy when it is that manual).
519
- * - `kept` — the existing file was left as it was: nothing announced to compare with, or no verified copy could be had.
520
- * - `fallback` — no file existed and nothing verified could be had: the bundled copy was written.
521
- * - `failed` — no file existed and none could be written.
522
- */
523
- type ManualSyncState = 'current' | 'updated' | 'kept' | 'fallback' | 'failed';
524
- interface ManualSyncResult {
525
- readonly state: ManualSyncState;
526
- readonly path: string;
527
- /** The version the file carries after the sync; null when there is no file or it names none. */
528
- readonly version: string | null;
529
- /** The version the file carried before; null when there was none. */
530
- readonly previous: string | null;
531
- /** The file before carried the announced version but not the announced bytes (its sha256 differed). */
532
- readonly tampered: boolean;
533
- /** The announced version; null when nothing was announced (no served texts in hand). */
534
- readonly served: string | null;
535
- /** The announced address. */
536
- readonly url: string | null;
537
- /** Where the written bytes came from, when some were written. */
538
- readonly source: 'download' | 'bundled' | null;
539
- /** Whether the file changed. */
540
- readonly written: boolean;
541
- /** Whether the file now is the announced manual; null when nothing was announced. */
542
- readonly upToDate: boolean | null;
543
- /** Why the announced manual is not on disk (`kept` / `fallback` / `failed`), else null. */
544
- readonly error: string | null;
545
- }
546
- interface SyncManualOptions {
547
- /** The skill file, e.g. `<skills dir>/agentchat/SKILL.md`. The integration knows where; this package never derives it. */
548
- readonly path: string;
549
- /** `texts.manual` from the served texts (or their identity-home cache); null when none are in hand. */
550
- readonly served: ServedManual | null;
551
- /**
552
- * The API base the texts were fetched from (the identity's `api_base`). It
553
- * decides where a download may go; null (unknown) or a plain-HTTP base off
554
- * loopback means no download at all.
555
- */
556
- readonly apiBase: string | null;
557
- readonly fetch?: ManualFetch;
558
- readonly timeoutMs?: number;
559
- readonly maxBytes?: number;
560
- readonly signal?: AbortSignal;
561
- }
562
- /** The version the file at `file` carries, or null when it is missing or names none. */
563
- declare function readManualVersion(file: string): string | null;
564
- /**
565
- * Bring the skill file at `path` to the announced manual. Never throws; the
566
- * result says what happened and, when the announced manual is not on disk,
567
- * why. See the module comment for the rules.
568
- */
569
- declare function syncManual(options: SyncManualOptions): Promise<ManualSyncResult>;
570
- /** One human line for an installer's report. */
571
- declare function describeManualSync(result: ManualSyncResult): string;
572
- type ManualCheckState = 'current' | 'stale' | 'unchecked' | 'missing';
573
- interface ManualCheck {
574
- readonly state: ManualCheckState;
575
- readonly path: string;
576
- readonly version: string | null;
577
- readonly served: string | null;
578
- /** current → PASS; stale or unchecked → WARN (the agent still has a manual); missing → FAIL. */
579
- readonly verdict: Verdict;
580
- /** `current (2.2.1)`, `stale (have 2.1.2, served 2.2.1)`, `unchecked (have 2.2.1; …)`, `missing`. */
581
- readonly summary: string;
582
- /** The summary and the file. */
583
- readonly detail: string;
584
- }
585
- interface CheckManualOptions {
586
- readonly path: string;
587
- /** What the served texts announce; null when none are in hand. */
588
- readonly served: ServedManual | null;
589
- /** The API base the texts came from; a base no download would be made from is named in the summary. */
590
- readonly apiBase: string | null;
591
- }
592
- /** Compare the skill file with the announced manual. Reads one file; no network. */
593
- declare function checkManual(options: CheckManualOptions): ManualCheck;
594
- interface ManualFollowerOptions {
595
- readonly path: string;
596
- /** The API base the daemon fetches the texts from. */
597
- readonly apiBase: string;
598
- readonly fetch?: ManualFetch;
599
- readonly timeoutMs?: number;
600
- }
601
- /**
602
- * Keeps the skill file at the manual the served texts announce, for a
603
- * resident daemon. `follow` is called whenever the texts in hand change (the
604
- * start fetch, every refresh, a failed refresh falling back to the cache), so
605
- * it runs on the texts' own cadence: daily, hourly while the server does not
606
- * answer. When the file already is the announced manual it reads one file and
607
- * stops. Calls are serialised; a download in flight is aborted by `stop`. A
608
- * failure is logged once per condition, not once per attempt.
609
- */
610
- declare class ManualFollower {
611
- private readonly options;
612
- private readonly controller;
613
- private chain;
614
- private lastFailure;
615
- constructor(options: ManualFollowerOptions);
616
- follow(served: ServedManual | null): Promise<ManualSyncResult | null>;
617
- stop(): void;
618
- private report;
619
- }
620
-
621
- interface RunPrompts {
622
- /** What a wake run starts with. */
623
- readonly wake: string;
624
- /** What a group-invite run starts with. Invites are not on the tray and are never auto-accepted. */
625
- readonly invite: string;
626
- }
627
- /** The served texts, then the one pointer line (`manualPointer(...)`). */
628
- declare function buildRunPrompts(texts: Pick<Texts, 'wake_instruction' | 'invite_prompt'>, manualPointer: string): RunPrompts;
629
-
630
- export { TEXTS_CACHE_FILE as $, MANUAL_MAX_REDIRECTS as A, type ManualCheck as B, type CachedTexts as C, DEFAULT_WAKE_DEBOUNCE_MS as D, type ManualCheckState as E, type FetchIdentityLineOptions as F, ManualFollower as G, type HostProfile as H, type IntegrationClient as I, type ManualFollowerOptions as J, type ManualSyncResult as K, LEGACY_STATUS_FILE as L, type ManualFetch as M, type ManualSyncState as N, RUN_BUDGET_ENV as O, type PendingRegistration as P, RUN_PROFILES as Q, type RunRunner as R, type SocketState as S, TextsStore as T, RUN_PROFILE_ENV as U, type ResolvedIdentity as V, WakeCoalescer as W, SOCKET_STATES as X, type ServedManual as Y, type StatusContext as Z, type SyncManualOptions as _, type RunProfile as a, TEXTS_REFRESH_MS as a0, TEXTS_RETRY_MS as a1, type TextsClient as a2, type TextsSource as a3, type TextsStatus as a4, type TextsStoreOptions as a5, type Verdict as a6, anchorLabelOf as a7, buildRunPrompts as a8, checkManual as a9, syncManual as aA, textsCachePath as aB, writeCachedTexts as aC, writeCredentials as aD, writeIntegrationStatus as aE, writePending as aF, clearCredentials as aa, clearIntegrationStatus as ab, clearPending as ac, clientHeadersOf as ad, clientIdentityOf as ae, credentialsPath as af, describeManualSync as ag, fetchIdentityLine as ah, fetchServedTexts as ai, formatIntegrationStatus as aj, integrationDisabled as ak, integrationDisabledBy as al, integrationStatusAge as am, integrationStatusPath as an, isRunProfile as ao, loadTexts as ap, pendingPath as aq, readCachedTexts as ar, readCredentials as as, readIntegrationStatus as at, readManualVersion as au, readPending as av, resolveIdentity as aw, resolveRunBudgetMs as ax, resolveRunProfile as ay, statePath as az, type IntegrationStatus as b, type RunPrompts as c, type TimerHandle as d, type IntegrationLastRun as e, type RunOutcome as f, type RunKind as g, type RunOutcomeState as h, type RunPreflight as i, type RunRequest as j, type WakeCoalescerOptions as k, type CheckManualOptions as l, type Credentials as m, DEFAULT_API_BASE as n, DEFAULT_RUN_BUDGET_MS as o, DEFAULT_RUN_PROFILE as p, type DoctorCheck as q, type DoctorContext as r, type FetchServedTextsOptions as s, INTEGRATION_ENV as t, INTEGRATION_ENV_LEGACY as u, INTEGRATION_STATUS_FILE as v, type LoadTextsOptions as w, type LoadedTexts as x, MANUAL_FETCH_TIMEOUT_MS as y, MANUAL_MAX_BYTES as z };