@agentchatme/agent-core 0.7.0 → 0.7.3

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,6 +1,6 @@
1
- import { I as IntegrationClient, L as LeaseOptions, M as ManualFetch, a as IntegrationStatus, b as IntegrationRunsFailing, S as SocketState } from './served-manual-RAIaRcr2.js';
2
- import { R as RunnerSource, a as RunProfile, b as RunRunner, c as RunOutcome } from './runner-BjCgl4bV.js';
3
- export { d as RunKind, e as RunOutcomeState, f as RunPreflight, g as RunRequest, h as RunWake, i as RunnerFactory, j as RunnerIdentity } from './runner-BjCgl4bV.js';
1
+ import { I as IntegrationClient, M as ManualPointer, A as AnchorServedLine, a as AnchorLoadNote, L as LeaseOptions, b as ManualFetch, c as IntegrationStatus, d as IntegrationRunsFailing, S as SocketState } from './served-manual-CwxBzpwQ.js';
2
+ import { R as RunnerSource, a as RunProfile, b as RunRunner, c as RunOutcome } from './runner-BLvFalN4.js';
3
+ export { d as RunKind, e as RunOutcomeState, f as RunPreflight, g as RunRequest, h as RunWake, i as RunnerFactory, j as RunnerIdentity } from './runner-BLvFalN4.js';
4
4
  import { AgentChatClient, RealtimeClient, BlockedInfo, RealtimeState } from 'agentchatme';
5
5
  import 'zod';
6
6
 
@@ -11,8 +11,14 @@ interface RunIntegrationOpts {
11
11
  runner: RunnerSource;
12
12
  /** How this integration names itself to the server: the texts runtime and its own version. */
13
13
  client: IntegrationClient;
14
- /** The one pointer line a run prompt ends with: how THIS runtime reaches its copy of the manual (`manualPointer(...)`). */
15
- manualPointer: string;
14
+ /**
15
+ * The one pointer line a run prompt ends with: how THIS runtime reaches its
16
+ * copy of the manual. A function of the manual's address
17
+ * (`(url) => manualPointer(location, url)`) is called for each run with the
18
+ * address the served texts announce, so the line follows them; a plain
19
+ * string is used as it is.
20
+ */
21
+ manualPointer: ManualPointer;
16
22
  /**
17
23
  * The skill file that follows the served manual (`<skills dir>/agentchat/SKILL.md`):
18
24
  * whenever the texts in hand announce a version the file does not carry, the
@@ -20,6 +26,17 @@ interface RunIntegrationOpts {
20
26
  * daemon leaves the manual to the CLI's install and `doctor --fix`.
21
27
  */
22
28
  manualPath?: string;
29
+ /**
30
+ * The host's always-loaded instruction file (the one install places the
31
+ * identity line in): whenever the served texts change, this agent's own
32
+ * identity block there is brought to the served line — never created where
33
+ * there is none, never one that is another agent's, the setup offer, or
34
+ * edited by hand (`followIdentityAnchor`). Absent, the block is left to the
35
+ * CLI's install and `doctor --fix`.
36
+ */
37
+ anchorPath?: string;
38
+ /** Which file the runtime loads in `anchorPath`'s place, and whether its identity line is the served one, or null (see `IntegrationOptions.anchorLoadNote`). */
39
+ anchorLoadNote?: (handle: string, served: AnchorServedLine) => AnchorLoadNote | null;
23
40
  /** Scratch dir for runs. The integration decides where; this package never derives one. */
24
41
  workdir: string;
25
42
  /** Defaults to `AGENTCHAT_RUN_PROFILE` (`resolveRunProfile`: unset is `own`, a value that names no profile is `answer`). */
@@ -123,8 +140,27 @@ interface IntegrationOptions {
123
140
  readonly runner: RunRunner;
124
141
  /** How this integration names itself to the server (texts runtime + its version). */
125
142
  readonly client: IntegrationClient;
126
- /** The one pointer line a run prompt ends with (`manualPointer(...)`). */
127
- readonly manualPointer: string;
143
+ /**
144
+ * The one pointer line a run prompt ends with: a function of the manual's
145
+ * address (`(url) => manualPointer(location, url)`), called with the address
146
+ * the texts in hand announce; a plain string is used as it is.
147
+ */
148
+ readonly manualPointer: ManualPointer;
149
+ /**
150
+ * The host's always-loaded instruction file, whose AgentChat identity block
151
+ * follows the served identity line from then on (`followIdentityAnchor`).
152
+ * Absent, the block is left to the CLI's install and `doctor --fix`.
153
+ */
154
+ readonly anchorPath?: string;
155
+ /**
156
+ * For a runtime that reads another file in `anchorPath`'s place when that
157
+ * one exists: which file it loads, and whether the identity line there is
158
+ * the served one (judged against the texts being followed), or null when
159
+ * it loads `anchorPath` (`HostProfile.anchorLoadNote`). Said with every
160
+ * follow; when `ok` is false, at warn and as the status file's
161
+ * `identity_line.not_loaded`. Nothing is written into that other file.
162
+ */
163
+ readonly anchorLoadNote?: (handle: string, served: AnchorServedLine) => AnchorLoadNote | null;
128
164
  /** The skill file that follows the served manual (`<skills dir>/agentchat/SKILL.md`); absent, the manual is left to the CLI. */
129
165
  readonly manualPath?: string;
130
166
  /** Injectable for tests; the manual download's `fetch`. */
@@ -171,6 +207,8 @@ interface IntegrationOptions {
171
207
  readonly conversationRuns?: boolean;
172
208
  /** Injectable for tests; `RUNTIME_CHECK_DEADLINE_MS`. */
173
209
  readonly runtimeCheckDeadlineMs?: number;
210
+ /** Injectable for tests: how soon the served texts are fetched again after a fetch (the kit's 24 h). */
211
+ readonly textsRefreshMs?: number;
174
212
  }
175
213
  declare class Integration {
176
214
  private readonly options;
@@ -213,6 +251,10 @@ declare class Integration {
213
251
  private readonly paused;
214
252
  /** The runner's runtime check in flight: concurrent asks share it. */
215
253
  private runtimeCheckInFlight;
254
+ /** What the identity block's last follow did (status `identity_line`); null without `anchorPath`, or before the first texts. */
255
+ private identityLine;
256
+ /** The follows of the identity line, one after another (each texts change queues one; a stop waits for the one in flight). */
257
+ private follows;
216
258
  constructor(options: IntegrationOptions);
217
259
  start(): Promise<void>;
218
260
  /**
@@ -270,6 +312,13 @@ declare class Integration {
270
312
  * pause ends; any other answer for that conversation ends what was kept.
271
313
  */
272
314
  private onProcessingFailure;
315
+ /**
316
+ * The identity block follows the served identity line: on each texts
317
+ * change, this agent's own block in the host's instruction file is brought
318
+ * to the line served now (`followIdentityAnchor`, under its rules). Said in
319
+ * the log and the status file (`identity_line`); never throws.
320
+ */
321
+ private followIdentityLine;
273
322
  private writeStatus;
274
323
  }
275
324
 
@@ -10,14 +10,16 @@ import {
10
10
  credentialsPath,
11
11
  describeManualSync,
12
12
  envKeyConflict,
13
+ followIdentityAnchor,
13
14
  idle,
14
15
  isRunnerFactory,
15
16
  markStandby,
16
17
  resolveIdentity,
18
+ resolveManualPointer,
17
19
  standbyWaiting,
18
20
  textsCachePath,
19
21
  writeIntegrationStatus
20
- } from "./chunk-NYSMAN4N.js";
22
+ } from "./chunk-FPAOQGMV.js";
21
23
  import {
22
24
  INTEGRATION_ENV,
23
25
  INTEGRATION_ENV_LEGACY,
@@ -32,7 +34,7 @@ import {
32
34
  resolveRunProfile,
33
35
  spawnRun,
34
36
  sweepWindowsDescendants
35
- } from "./chunk-C2ARQLZ7.js";
37
+ } from "./chunk-5KMQ23O6.js";
36
38
 
37
39
  // src/integration/run.ts
38
40
  import * as path2 from "path";
@@ -180,10 +182,12 @@ var Integration = class {
180
182
  client: this.api,
181
183
  runtime: client.runtime,
182
184
  filePath: textsCachePath(cfg.home),
183
- onError: (err) => log.warn(err.message)
185
+ onError: (err) => log.warn(err.message),
186
+ ...options.textsRefreshMs !== void 0 ? { refreshMs: options.textsRefreshMs } : {}
184
187
  });
185
188
  this.texts.onChange((texts, source) => {
186
189
  log.info(`texts ${source === "server" ? "fetched" : "read from the cache"} for ${client.runtime} (texts v${texts.version}, manual ${texts.manual.version})`);
190
+ this.follows = this.follows.then(() => this.followIdentityLine(texts));
187
191
  this.writeStatus();
188
192
  });
189
193
  this.manual = options.manualPath === void 0 ? null : new kit.ManualSync({
@@ -290,6 +294,10 @@ var Integration = class {
290
294
  paused;
291
295
  /** The runner's runtime check in flight: concurrent asks share it. */
292
296
  runtimeCheckInFlight = null;
297
+ /** What the identity block's last follow did (status `identity_line`); null without `anchorPath`, or before the first texts. */
298
+ identityLine = null;
299
+ /** The follows of the identity line, one after another (each texts change queues one; a stop waits for the one in flight). */
300
+ follows = Promise.resolve();
293
301
  async start() {
294
302
  const pre = await withDeadline(this.options.runner.preflight(), PREFLIGHT_DEADLINE_MS, () => ({
295
303
  ok: false,
@@ -300,6 +308,7 @@ var Integration = class {
300
308
  `integration up as @${this.options.cfg.handle} via ${this.options.runner.name} (${this.options.client.runtime} ${this.options.client.version}), profile ${this.options.profile}; fetching the served texts, then holding the socket`
301
309
  );
302
310
  await this.texts.start();
311
+ await this.follows;
303
312
  if (this.stopping) return;
304
313
  void this.manual?.start();
305
314
  await this.loop.start();
@@ -322,7 +331,7 @@ var Integration = class {
322
331
  if (this.heartbeatTimer) clearInterval(this.heartbeatTimer);
323
332
  if (this.statusTimer) clearInterval(this.statusTimer);
324
333
  this.recheckAbort.abort();
325
- this.stopped = Promise.all([this.loop.stop(), this.recheckInFlight ?? Promise.resolve()]).then(() => void 0);
334
+ this.stopped = Promise.all([this.loop.stop(), this.recheckInFlight ?? Promise.resolve(), this.follows]).then(() => void 0);
326
335
  this.texts.stop();
327
336
  this.manual?.stop();
328
337
  this.socket = "closed";
@@ -392,6 +401,7 @@ var Integration = class {
392
401
  version: texts?.version ?? null,
393
402
  manual_version: texts?.manual.version ?? null
394
403
  },
404
+ identity_line: this.identityLine,
395
405
  capabilities: status.socket === null ? null : status.socket.capabilities,
396
406
  intake_paused: status.socket === null ? null : status.socket.intakePaused,
397
407
  recent_cycles: status.recentCycles.map((cycle) => ({
@@ -423,7 +433,14 @@ var Integration = class {
423
433
  const onAbort = () => controller.abort();
424
434
  if (request.signal.aborted) controller.abort();
425
435
  else request.signal.addEventListener("abort", onAbort, { once: true });
426
- const identityLine = this.texts.current()?.identity_line;
436
+ const texts = this.texts.current();
437
+ const identityLine = texts?.identity_line;
438
+ let pointer = "";
439
+ try {
440
+ pointer = resolveManualPointer(this.options.manualPointer, texts);
441
+ } catch (err) {
442
+ log.warn(`run pointer: the integration's pointer function threw (${err instanceof Error ? err.message : String(err)}); the run starts without the line`);
443
+ }
427
444
  let outcome;
428
445
  try {
429
446
  outcome = await withDeadline(
@@ -432,9 +449,9 @@ var Integration = class {
432
449
  ...conversationId !== void 0 ? { conversationId } : {},
433
450
  wake,
434
451
  // No pointer, no trailing blank lines.
435
- prompt: this.options.manualPointer.trim().length > 0 ? `${request.prompt}
452
+ prompt: pointer.trim().length > 0 ? `${request.prompt}
436
453
 
437
- ${this.options.manualPointer}` : request.prompt,
454
+ ${pointer}` : request.prompt,
438
455
  runId,
439
456
  ...identityLine !== void 0 && identityLine.trim().length > 0 ? { identityLine } : {},
440
457
  budgetMs,
@@ -487,14 +504,15 @@ ${this.options.manualPointer}` : request.prompt,
487
504
  }
488
505
  if (outcome.state !== "ok") {
489
506
  log.warn(
490
- `run ${outcome.state} ${subject}${outcome.detail ? `: ${outcome.detail}` : ""} \u2014 ${kind === "conversation" ? "its card stays on the tray; if the runtime otherwise works, the failure is reported (could not process) and the server decides what follows" : "the cards stay on the tray; the next wake (or the server's re-wake) finds them"}`
507
+ `run ${outcome.state} ${subject}${outcome.detail ? `: ${outcome.detail}` : ""} \u2014 ${kind !== "conversation" ? "the cards stay on the tray; the next wake (or the server's re-wake) finds them" : outcome.state === "failed" && outcome.silent === true ? "its card stays on the tray; a silent failure counts as a timeout: it is reported (could not process) only once another conversation's run completes, and the server decides what follows" : "its card stays on the tray; if the runtime otherwise works, the failure is reported (could not process) and the server decides what follows"}`
491
508
  );
492
509
  }
493
510
  this.noteRunHealth(outcome, this.lastRun.ended_at);
494
511
  this.writeStatus();
495
512
  if (outcome.state === "ok") return { status: "completed" };
496
513
  if (outcome.state === "not_started") return { status: "not_started", ...outcome.detail !== void 0 ? { detail: outcome.detail } : {} };
497
- return { status: "failed", ...outcome.state === "timed_out" ? { timedOut: true } : {}, ...outcome.detail !== void 0 ? { detail: outcome.detail } : {} };
514
+ const timedOut = outcome.state === "timed_out" || outcome.state === "failed" && outcome.silent === true;
515
+ return { status: "failed", ...timedOut ? { timedOut: true } : {}, ...outcome.detail !== void 0 ? { detail: outcome.detail } : {} };
498
516
  }
499
517
  /**
500
518
  * The runner's runtime check (a minimal model call, no peer content, no
@@ -671,7 +689,7 @@ ${this.options.manualPointer}` : request.prompt,
671
689
  if (result === null) {
672
690
  log.warn(`could not process: ${what} \u2014 the report failed (${event.error ?? "no detail"}); nothing more is done for it now: its card stays on the tray and the server re-wakes it`);
673
691
  } else {
674
- const hidden = result.hidden_message_ids.length;
692
+ const hidden = result.hidden_count ?? result.hidden_message_ids.length;
675
693
  const answered = result.action === "retry" ? "retry (the first failure for these messages)" : result.action === "hidden" ? `hidden (${hidden} message(s) are now a note for this agent, still unread)` : result.action === "paused" ? `paused until ${result.paused_until ?? "?"}${hidden > 0 ? ` (${hidden} more message(s) hidden)` : ""} \u2014 no run starts there until then` : "none (nothing left to act on)";
676
694
  const next = event.next === "rerun" ? "it runs again after the others" : event.next === "running" ? "its next run is under way already" : event.next === "rerun_capped" ? "not run again in this cycle (3 re-runs already); the server re-wakes it" : "nothing more for it";
677
695
  (result.action === "paused" ? log.warn : log.info)(`could not process: ${what} \u2192 server: ${answered}; ${next}`);
@@ -680,6 +698,57 @@ ${this.options.manualPointer}` : request.prompt,
680
698
  }
681
699
  this.writeStatus();
682
700
  }
701
+ /**
702
+ * The identity block follows the served identity line: on each texts
703
+ * change, this agent's own block in the host's instruction file is brought
704
+ * to the line served now (`followIdentityAnchor`, under its rules). Said in
705
+ * the log and the status file (`identity_line`); never throws.
706
+ */
707
+ async followIdentityLine(texts) {
708
+ const filePath = this.options.anchorPath;
709
+ if (filePath === void 0 || this.stopping) return;
710
+ let result;
711
+ try {
712
+ result = await followIdentityAnchor({
713
+ filePath,
714
+ handle: this.options.cfg.handle,
715
+ identityLine: texts.identity_line,
716
+ template: texts.identity_line_template
717
+ });
718
+ } catch (err) {
719
+ result = { outcome: "failed", path: filePath, claimed: null, detail: `could not follow the identity line in ${filePath}: ${err instanceof Error ? err.message : String(err)}` };
720
+ }
721
+ let loadNote = null;
722
+ try {
723
+ loadNote = this.options.anchorLoadNote?.(this.options.cfg.handle, { identityLine: texts.identity_line, template: texts.identity_line_template }) ?? null;
724
+ } catch {
725
+ loadNote = null;
726
+ }
727
+ const notLoaded = loadNote !== null && !loadNote.ok ? loadNote.note : null;
728
+ const detail = loadNote === null ? result.detail : `${result.detail}; ${loadNote.note}`;
729
+ this.identityLine = { outcome: result.outcome, path: result.path, at: (/* @__PURE__ */ new Date()).toISOString(), texts_version: texts.version, detail, not_loaded: notLoaded };
730
+ const line = `identity line: ${result.outcome} \u2014 ${detail}`;
731
+ this.writeStatus();
732
+ if (notLoaded !== null && result.outcome !== "other_agent") {
733
+ log.warn(line);
734
+ return;
735
+ }
736
+ switch (result.outcome) {
737
+ case "updated":
738
+ case "absent":
739
+ case "hand_edited":
740
+ log.info(line);
741
+ break;
742
+ case "unchanged":
743
+ log.debug(line);
744
+ break;
745
+ case "other_agent":
746
+ log.error(line);
747
+ break;
748
+ default:
749
+ log.warn(line);
750
+ }
751
+ }
683
752
  writeStatus() {
684
753
  writeIntegrationStatus(this.options.cfg.home, this.snapshot());
685
754
  }
@@ -973,6 +1042,8 @@ async function runIntegration(opts) {
973
1042
  client: opts.client,
974
1043
  manualPointer: opts.manualPointer,
975
1044
  ...opts.manualPath !== void 0 ? { manualPath: opts.manualPath } : {},
1045
+ ...opts.anchorPath !== void 0 ? { anchorPath: opts.anchorPath } : {},
1046
+ ...opts.anchorLoadNote !== void 0 ? { anchorLoadNote: opts.anchorLoadNote } : {},
976
1047
  profile,
977
1048
  budgetMs,
978
1049
  ...opts.dismissIgnoredInvites !== void 0 ? { dismissIgnoredInvites: opts.dismissIgnoredInvites } : {},