@agentchatme/agent-core 0.7.1 → 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.
package/dist/index.js CHANGED
@@ -1,10 +1,13 @@
1
1
  import {
2
2
  AGENT_LOCK_DIR_ENV,
3
+ ANCHOR_END,
4
+ ANCHOR_START,
3
5
  COULD_NOT_PROCESS_FILE,
4
6
  DAEMON_LOCK_FILE,
5
7
  DEFAULT_API_BASE,
6
8
  FAILED_CYCLE_OUTCOMES,
7
9
  HEARTBEAT_FILE,
10
+ IDENTITY_ANCHOR_ATTEMPTS,
8
11
  INTEGRATION_STATUS_FILE,
9
12
  INTEGRATION_STATUS_STALE_MS,
10
13
  LEASE_RENEW_MS,
@@ -32,6 +35,7 @@ import {
32
35
  alwaysOnOptedOut,
33
36
  alwaysOnState,
34
37
  alwaysOnWanted,
38
+ anchorIsCurrentAt,
35
39
  beat,
36
40
  bootedAt,
37
41
  checkManual,
@@ -45,6 +49,7 @@ import {
45
49
  couldNotProcessPath,
46
50
  credentialsPath,
47
51
  describeCouldNotProcessCounts,
52
+ describeIdentityBlock,
48
53
  describeManualSync,
49
54
  describePausedConversations,
50
55
  envApiKey,
@@ -53,9 +58,12 @@ import {
53
58
  failedCyclesInARow,
54
59
  fetchIdentityLine,
55
60
  fetchServedTexts,
61
+ followIdentityAnchor,
56
62
  formatIntegrationStatus,
57
63
  fromKitResult,
64
+ hasAnchorAt,
58
65
  holderLive,
66
+ identityBlockState,
59
67
  identityLineOf,
60
68
  idle,
61
69
  integrationStatusAge,
@@ -63,6 +71,7 @@ import {
63
71
  integrationStatusPath,
64
72
  integrationStatusStaleFor,
65
73
  isRunnerFactory,
74
+ isSetupOfferBody,
66
75
  leaseHolder,
67
76
  loadTexts,
68
77
  manualFrontMatter,
@@ -76,25 +85,38 @@ import {
76
85
  parseLease,
77
86
  pendingPath,
78
87
  pidAlive,
88
+ placeAnchorAt,
79
89
  readAlwaysOnInstalledVersion,
90
+ readAnchorHandleAt,
91
+ readAnchorHandleFrom,
80
92
  readCachedTexts,
81
93
  readCredentials,
82
94
  readIntegrationStatus,
83
95
  readManualVersion,
84
96
  readPending,
97
+ removeAnchorAt,
98
+ renderAnchorBlock,
99
+ renderDeclinedBlock,
100
+ renderUnregisteredBlock,
85
101
  repeatedFailedRuns,
86
102
  resetLeaseObservations,
87
103
  resolveIdentity,
104
+ resolveManualPointer,
88
105
  runtimeCheckFailingNow,
106
+ servedManualUrl,
89
107
  standbyMarkerPath,
90
108
  standbyWaiting,
91
109
  statePath,
110
+ stripAnchorBlock,
92
111
  syncManual,
93
112
  textsCachePath,
113
+ upsertAnchorBlock,
114
+ writeAnchor,
94
115
  writeCredentials,
95
116
  writeIntegrationStatus,
117
+ writeOfferAt,
96
118
  writePending
97
- } from "./chunk-AQTRC7G4.js";
119
+ } from "./chunk-FPAOQGMV.js";
98
120
  import {
99
121
  HOSTED_MCP_PATH,
100
122
  PROBE_KILL_WAIT_MS,
@@ -102,7 +124,7 @@ import {
102
124
  hostedMcpUrl,
103
125
  probeHostedMcp,
104
126
  runProbe
105
- } from "./chunk-4PCDVXAR.js";
127
+ } from "./chunk-7TTV2CQX.js";
106
128
  import {
107
129
  DEFAULT_RUN_BUDGET_MS,
108
130
  DEFAULT_RUN_PROFILE,
@@ -179,201 +201,6 @@ function clearOfferDeclined(home) {
179
201
  writeState(home, state);
180
202
  }
181
203
 
182
- // src/anchor/block.ts
183
- import * as fs from "fs";
184
- import * as path from "path";
185
- import { integration as kit } from "agentchatme";
186
- var ANCHOR_START = kit.anchor.START_MARKER;
187
- var ANCHOR_END = kit.anchor.END_MARKER;
188
- var MARKER_LINES = /* @__PURE__ */ new Set([
189
- kit.anchor.START_MARKER,
190
- kit.anchor.END_MARKER,
191
- kit.anchor.LEGACY_START_MARKER,
192
- kit.anchor.LEGACY_END_MARKER
193
- ]);
194
- function renderAnchorBlock(identityLine, handle) {
195
- if (typeof identityLine !== "string" || identityLine.trim().length === 0) throw new Error("renderAnchorBlock: the identity line is empty");
196
- if (typeof handle !== "string" || kit.anchor.normalizeHandle(handle).length === 0) throw new Error("renderAnchorBlock: the handle is empty");
197
- if (identityLine.split(/\r?\n/).some((line) => MARKER_LINES.has(line.trim()))) {
198
- throw new Error("renderAnchorBlock: the identity line holds an AgentChat marker line");
199
- }
200
- return kit.anchor.render({ identity_line: identityLine, identity_line_template: "" }, handle);
201
- }
202
- function writeAnchor(filePath, block, expectHandle) {
203
- if (expectHandle !== void 0) {
204
- const bare = kit.anchor.normalizeHandle(expectHandle);
205
- const claimed = kit.anchor.find(block)?.handle ?? null;
206
- if (claimed !== bare) {
207
- throw new Error(`writeAnchor: the block for ${filePath} does not name @${bare} \u2014 nothing was written`);
208
- }
209
- }
210
- const existing = readInstructionFile(filePath) ?? { bom: "", text: "" };
211
- const next = untilStable(existing.text, (text) => kit.anchor.replace(text, block));
212
- if (next !== existing.text) writeInstructionFile(filePath, existing.bom + next);
213
- if (expectHandle !== void 0 && readInstructionFile(filePath)?.text !== next) {
214
- throw new Error(`writeAnchor: ${filePath} did not read back as written \u2014 remove the agentchat block manually and re-run`);
215
- }
216
- return "written";
217
- }
218
- function untilStable(text, step) {
219
- let current = text;
220
- for (let i = 0; i < 8; i++) {
221
- const next = step(current);
222
- if (next === current) return current;
223
- current = next;
224
- }
225
- return current;
226
- }
227
- function removeAnchorAt(filePath) {
228
- const existing = readInstructionFile(filePath);
229
- if (existing === null) return "noop";
230
- const next = untilStable(existing.text, (text) => kit.anchor.remove(text));
231
- if (next === existing.text) return "noop";
232
- writeInstructionFile(filePath, existing.bom + next);
233
- return "removed";
234
- }
235
- function hasAnchorAt(filePath) {
236
- const file = readInstructionFile(filePath);
237
- return file !== null && kit.anchor.find(file.text) !== null;
238
- }
239
- function anchorIsCurrentAt(filePath, identityLine, handle) {
240
- const file = readInstructionFile(filePath);
241
- if (file === null) return false;
242
- let expected;
243
- try {
244
- expected = renderAnchorBlock(identityLine, handle);
245
- } catch {
246
- return false;
247
- }
248
- if (kit.anchor.find(file.text) === null) return false;
249
- return kit.anchor.replace(file.text, expected) === file.text;
250
- }
251
- function readAnchorHandleAt(filePath, template) {
252
- const file = readInstructionFile(filePath);
253
- return file === null ? null : readAnchorHandleFrom(file.text, template);
254
- }
255
- function readAnchorHandleFrom(text, template) {
256
- return kit.anchor.find(text.replace(/^\uFEFF/, ""), { template })?.handle ?? null;
257
- }
258
- function upsertAnchorBlock(existing, block) {
259
- return kit.anchor.replace(existing, block);
260
- }
261
- function stripAnchorBlock(existing) {
262
- return kit.anchor.remove(existing);
263
- }
264
- var UTF8 = new TextDecoder("utf-8", { fatal: true, ignoreBOM: true });
265
- function readInstructionFile(filePath) {
266
- let bytes;
267
- try {
268
- bytes = fs.readFileSync(filePath);
269
- } catch (err) {
270
- if (err.code === "ENOENT") return null;
271
- throw err;
272
- }
273
- let decoded;
274
- try {
275
- decoded = UTF8.decode(bytes);
276
- } catch {
277
- throw new Error(`${filePath} is not UTF-8 text; the AgentChat block is not read or written there (save the file as UTF-8 and run the command again)`);
278
- }
279
- return decoded.startsWith("\uFEFF") ? { bom: "\uFEFF", text: decoded.slice(1) } : { bom: "", text: decoded };
280
- }
281
- function resolveWriteTarget(filePath) {
282
- let current = filePath;
283
- for (let hops = 0; hops < 40; hops++) {
284
- let stat;
285
- try {
286
- stat = fs.lstatSync(current);
287
- } catch (err) {
288
- if (err.code === "ENOENT") return current;
289
- throw err;
290
- }
291
- if (!stat.isSymbolicLink()) return current;
292
- const link = fs.readlinkSync(current);
293
- const joined = path.isAbsolute(link) ? link : `${fs.realpathSync.native(path.dirname(current))}${path.sep}${link}`;
294
- current = path.join(fs.realpathSync.native(path.dirname(joined)), path.basename(joined));
295
- }
296
- throw Object.assign(new Error(`${filePath}: too many symbolic links`), { code: "ELOOP" });
297
- }
298
- var IN_PLACE_FALLBACK_CODES = /* @__PURE__ */ new Set(["EACCES", "EPERM", "EROFS", "EBUSY", "EXDEV"]);
299
- function stillWritable(file) {
300
- try {
301
- fs.accessSync(file, fs.constants.W_OK);
302
- return true;
303
- } catch {
304
- return false;
305
- }
306
- }
307
- function writeInstructionFile(filePath, data) {
308
- const target = resolveWriteTarget(filePath);
309
- let existing = null;
310
- try {
311
- existing = fs.statSync(target);
312
- } catch (err) {
313
- if (err.code !== "ENOENT") throw err;
314
- }
315
- if (existing !== null) {
316
- if (!existing.isFile()) throw new Error(`${filePath} is not a regular file`);
317
- fs.accessSync(target, fs.constants.W_OK);
318
- } else {
319
- fs.mkdirSync(path.dirname(target), { recursive: true });
320
- }
321
- try {
322
- atomicWriteFile(target, data, existing === null ? void 0 : existing.mode & 4095);
323
- } catch (err) {
324
- const code = err.code;
325
- if (existing !== null && code !== void 0 && IN_PLACE_FALLBACK_CODES.has(code) && stillWritable(target)) {
326
- fs.writeFileSync(target, data, "utf-8");
327
- return;
328
- }
329
- throw err;
330
- }
331
- if (existing !== null && typeof process.getuid === "function" && process.getuid() === 0 && (existing.uid !== 0 || existing.gid !== 0)) {
332
- try {
333
- fs.chownSync(target, existing.uid, existing.gid);
334
- } catch {
335
- }
336
- }
337
- }
338
-
339
- // src/anchor/offer.ts
340
- function renderUnregisteredBlock(copy) {
341
- const { invoke, label } = copy;
342
- return [
343
- ANCHOR_START,
344
- "## AgentChat is installed \u2014 this agent has no account yet",
345
- "",
346
- `[AgentChat](https://agentchat.me) gives you, the ${label} agent, a persistent \`@handle\` other AI agents can DM. AgentChat is installed for this ${label} agent, but it does not have an AgentChat account yet.`,
347
- "",
348
- "**Offer this ONCE, early, and only if it fits the conversation.** Never interrupt work in progress for it, and never raise it twice in one session.",
349
- "",
350
- `FIRST ask exactly: "Do you already have an AgentChat account for this ${label} agent, or should I create a new one?"`,
351
- "",
352
- "**Run the commands yourself, and ask the user one question per turn.** Each command prints AgentChat\u2019s answer, then the command to run next. Relay the answer to the user as it is; ask them for what the next command needs (a value it leaves as `<\u2026>`, such as the code AgentChat emailed them); if it says to wait, wait; then run it. When a command prints no command to run next, stop and tell the user what it said.",
353
- "",
354
- `- **New account:** ask for their email, then for the @handle they want (offer a suggestion if they like). Run: \`${invoke} register --email <email> --handle <handle>\`. Never submit a handle the user has not chosen or accepted.`,
355
- `- **Existing account, with its API key:** ask the user to run \`${invoke} login\` in their own terminal and paste the key when it asks. Never ask them to paste the key into this conversation, and never put a key in a command you run: a command line is visible to every user of the machine.`,
356
- `- **Existing account, key lost:** recovery replaces the old API key, so anything still using it stops working; say so and ask before going on. Ask for the email the account uses, then which @handle it is. Run: \`${invoke} recover --handle <handle> --email <email>\``,
357
- "- **When it is done:** tell the user the @handle and where the API key is stored, exactly as the command printed them.",
358
- "- Never reuse another active coding agent\u2019s account; each reachable agent needs its own.",
359
- "",
360
- `**If they decline or say "later", run \`${invoke} register --not-now\` immediately.** That records the answer and removes this prompt \u2014 otherwise you will re-read it and ask again every session.`,
361
- ANCHOR_END
362
- ].join("\n");
363
- }
364
- function renderDeclinedBlock(copy) {
365
- const { invoke, label } = copy;
366
- return [
367
- ANCHOR_START,
368
- "## AgentChat",
369
- "",
370
- `AgentChat is installed for this ${label} agent, but no handle is configured and the user has said not for now. **Do not offer to set it up.** Mention it only if they ask about AgentChat or about messaging other agents.`,
371
- "",
372
- `If they ask to set it up later: ${invoke} register --email <email> --handle <handle>`,
373
- ANCHOR_END
374
- ].join("\n");
375
- }
376
-
377
204
  // src/integration/run-context.ts
378
205
  var RUN_CONTEXT_ENV = {
379
206
  wakeKind: "AGENTCHAT_WAKE_KIND",
@@ -396,7 +223,7 @@ function runContextEnv(env, request) {
396
223
 
397
224
  // src/identity/commands.ts
398
225
  import * as readline from "readline";
399
- import { AgentChatClient, integration as kit2 } from "agentchatme";
226
+ import { AgentChatClient, integration as kit } from "agentchatme";
400
227
 
401
228
  // src/identity/host-profile.ts
402
229
  function anchorLabelOf(profile) {
@@ -538,7 +365,10 @@ function createIdentityCommands(profile) {
538
365
  ` ${label}: identity line not written \u2014 GET /v1/texts could not be reached and nothing is cached; run \`${invocation()} doctor --fix\` once online`
539
366
  ];
540
367
  }
541
- writeAnchor(file, profile.renderAnchor(identityLine, handle), handle);
368
+ const placed = placeAnchorAt(file, { handle, identityLine, template: null, mode: "setup", fix: `${invocation()} doctor --fix` });
369
+ if (placed.outcome === "hand_edited" || placed.outcome === "several_blocks") return [` ${label}: WARNING \u2014 ${placed.detail}`];
370
+ if (placed.outcome === "failed") return [` ${label}: FAILED \u2014 ${placed.detail}`];
371
+ if (placed.outcome === "replaced_other") return [` ${label}: ${placed.detail}`];
542
372
  return [` ${label}: @${handle} \u2192 ${file}`];
543
373
  } catch (err) {
544
374
  return [` ${label}: FAILED \u2014 ${String(err)}`];
@@ -619,7 +449,7 @@ function createIdentityCommands(profile) {
619
449
  const held = before !== null && before.kind === kind && before.email === input.email ? before : null;
620
450
  let result;
621
451
  try {
622
- result = kind === "register" ? await kit2.account.start(
452
+ result = kind === "register" ? await kit.account.start(
623
453
  "register",
624
454
  {
625
455
  email: input.email,
@@ -628,7 +458,7 @@ function createIdentityCommands(profile) {
628
458
  ...input.description !== void 0 ? { description: input.description } : {}
629
459
  },
630
460
  accountOptions(apiBase)
631
- ) : await kit2.account.start(
461
+ ) : await kit.account.start(
632
462
  "recover",
633
463
  { email: input.email, ...input.handle !== void 0 ? { handle: input.handle } : {} },
634
464
  accountOptions(apiBase)
@@ -674,7 +504,7 @@ ${runLine(startCommand(kind, input))} again.`);
674
504
  const base = pending.api_base ?? apiBase;
675
505
  let result;
676
506
  try {
677
- result = await kit2.account.submitCode(pending.flow, code, accountOptions(base));
507
+ result = await kit.account.submitCode(pending.flow, code, accountOptions(base));
678
508
  } catch (err) {
679
509
  console.error(`Could not reach AgentChat: ${errorText(err)}
680
510
  ${runLine(codeCommand(kind, pending.flow, code))} again.`);
@@ -698,7 +528,7 @@ ${runLine(codeCommand(kind, pending.flow, code))} again.`);
698
528
  async function converse(kind, input, apiBase) {
699
529
  let outcome;
700
530
  try {
701
- outcome = await kit2.account.run({
531
+ outcome = await kit.account.run({
702
532
  kind,
703
533
  input,
704
534
  ...accountOptions(apiBase),
@@ -777,7 +607,7 @@ login does not adopt an exported key in place of the one this home holds; nothin
777
607
  }
778
608
  let check;
779
609
  try {
780
- check = await kit2.account.checkKey(apiKey, accountOptions(apiBase));
610
+ check = await kit.account.checkKey(apiKey, accountOptions(apiBase));
781
611
  } catch (err) {
782
612
  console.error(`Login failed: ${errorText(err)}
783
613
  The key was not saved.`);
@@ -831,15 +661,37 @@ The key was not saved.`);
831
661
  }
832
662
  return startSignup("recover", { email, ...handle !== void 0 ? { handle } : {} }, apiBase);
833
663
  }
834
- function anchorView(file, identityLine, handle) {
835
- if (file === null) return { present: null, current: null, error: null };
664
+ function loadNoteFor(handle, texts) {
836
665
  try {
837
- const present = hasAnchorAt(file);
838
- const current = identityLine === null || handle === null ? null : anchorIsCurrentAt(file, identityLine, handle);
839
- return { present, current, error: null };
840
- } catch (err) {
841
- return { present: null, current: null, error: errorText(err) };
666
+ return profile.anchorLoadNote?.(handle, { identityLine: texts.identityLine, template: texts.identityLineTemplate }) ?? null;
667
+ } catch {
668
+ return null;
669
+ }
670
+ }
671
+ function anchorView(file, texts, handle) {
672
+ if (file === null) return { present: null, current: null, error: null, state: null };
673
+ if (handle === null) {
674
+ try {
675
+ return { present: hasAnchorAt(file), current: null, error: null, state: null };
676
+ } catch (err) {
677
+ return { present: null, current: null, error: errorText(err), state: null };
678
+ }
842
679
  }
680
+ const state = identityBlockState(file, { handle, identityLine: texts.identityLine, template: texts.identityLineTemplate, loadNote: loadNoteFor(handle, texts) });
681
+ if (state.state === "unreadable") return { present: null, current: null, error: state.what.replace(/^cannot read [^:]*: /, ""), state };
682
+ return {
683
+ present: state.state !== "missing",
684
+ current: texts.identityLine === null ? null : state.state === "current",
685
+ error: null,
686
+ state
687
+ };
688
+ }
689
+ function anchorWords(file, view) {
690
+ if (view.error !== null) return `unreadable \u2014 ${view.error} (${file})`;
691
+ const state = view.state;
692
+ if (state === null) return `${view.present ? "present" : "missing"} (${file})`;
693
+ if (state.verdict === "PASS") return `current (${file})${state.loadNote !== null ? `; ${state.loadNote.note}` : ""}`;
694
+ return describeIdentityBlock(state, `${invocation()} doctor --fix`);
843
695
  }
844
696
  async function runStatus(opts) {
845
697
  const home = profile.home();
@@ -883,7 +735,7 @@ The key was not saved.`);
883
735
  const refused = status === 401 || status === 403;
884
736
  const detail = describeApiError(err);
885
737
  if (opts.json) {
886
- const offline = anchorView(anchorFile, null, null);
738
+ const offline = anchorView(anchorFile, NO_TEXTS, null);
887
739
  console.log(
888
740
  JSON.stringify({
889
741
  configured: true,
@@ -902,23 +754,24 @@ The key was not saved.`);
902
754
  console.error(
903
755
  refused ? `AgentChat refused this agent's key (${detail}). Sign in with a current key: \`${invocation()} login\`; lost it? \`${recoverUsage(invocation())}\`.` : `Could not reach AgentChat: ${detail}`
904
756
  );
757
+ const cached = readCachedTexts(home, profile.client.runtime);
758
+ const context = cached === null ? NO_TEXTS : contextOf(cached.texts);
905
759
  console.log(
906
760
  [
907
761
  `${identity.handle !== null ? `@${identity.handle}` : "This agent"} \u2014 ${refused ? `key refused (HTTP ${status})` : "AgentChat unreachable"} (${LABEL})`,
908
762
  `Key source: ${identity.source} (${identity.source === "file" ? credentialsPath(home) : "AGENTCHAT_API_KEY"})`,
909
763
  `API: ${identity.apiBase}`,
764
+ ...anchorFile === null ? [] : [`Identity line: ${anchorWords(anchorFile, anchorView(anchorFile, context, identity.handle))}`],
910
765
  ...formatIntegrationStatus(integration)
911
766
  ].join("\n")
912
767
  );
913
- const cached = readCachedTexts(home, profile.client.runtime);
914
- await printExtraStatus(cached === null ? NO_TEXTS : contextOf(cached.texts));
768
+ await printExtraStatus(context);
915
769
  }
916
770
  return 1;
917
771
  }
918
772
  const tray = await traySummary(client).catch(() => null);
919
773
  const texts = await served(identity.apiKey, identity.apiBase);
920
- const identityLine = texts.identityLine;
921
- const anchor = anchorView(anchorFile, identityLine, me.handle);
774
+ const anchor = anchorView(anchorFile, texts, me.handle);
922
775
  if (opts.json) {
923
776
  console.log(
924
777
  JSON.stringify({
@@ -935,6 +788,10 @@ The key was not saved.`);
935
788
  anchor_current: anchor.current,
936
789
  /** Why the instruction file could not be read, or null. */
937
790
  anchor_error: anchor.error,
791
+ /** The block as the daemon reads it (`identityBlockState`: current, stale, missing, setup_offer, hand_edited, other_agent, several_blocks, unreadable), or null. */
792
+ anchor_state: anchor.state?.state ?? null,
793
+ /** Why the runtime does not load the instruction file now, or null. */
794
+ anchor_not_loaded: anchor.state?.notLoaded ?? null,
938
795
  integration
939
796
  })
940
797
  );
@@ -947,7 +804,7 @@ The key was not saved.`);
947
804
  `Key source: ${identity.source} (${identity.source === "file" ? credentialsPath(home) : "AGENTCHAT_API_KEY"})`,
948
805
  `API: ${identity.apiBase}`,
949
806
  ...anchorFile === null ? [] : [
950
- `Identity line: ${anchor.error !== null ? `unreadable \u2014 ${anchor.error}` : anchor.present ? anchor.current === null ? "present (served texts unavailable \u2014 not checked)" : anchor.current ? "current" : "present (older text \u2014 `doctor --fix` refreshes it)" : "missing"} (${anchorFile})`
807
+ `Identity line: ${anchorWords(anchorFile, anchor)}`
951
808
  ],
952
809
  ...formatIntegrationStatus(integration)
953
810
  ].join("\n")
@@ -968,9 +825,18 @@ The key was not saved.`);
968
825
  }
969
826
  if (anchorFile !== null) {
970
827
  try {
971
- if (removeAnchorAt(anchorFile) === "removed") {
828
+ const cached = readCachedTexts(home, profile.client.runtime);
829
+ const removed = removeAnchorAt(anchorFile, {
830
+ handle: identity?.handle ?? null,
831
+ identityLine: cached?.texts.identity_line ?? null,
832
+ template: cached?.texts.identity_line_template ?? null
833
+ });
834
+ if (removed.action === "removed") {
972
835
  any = true;
973
836
  reports.push(` ${anchorLabelOf(profile)} identity line removed`);
837
+ } else if (removed.action === "kept") {
838
+ any = true;
839
+ reports.push(` ${removed.detail}`);
974
840
  }
975
841
  } catch (err) {
976
842
  any = true;
@@ -999,41 +865,25 @@ The key was not saved.`);
999
865
  return 0;
1000
866
  }
1001
867
  function readIdentityLine(anchorFile, handle, texts) {
1002
- const claimed = readAnchorHandleAt(anchorFile, texts.identityLineTemplate);
1003
- const current = texts.identityLine === null ? null : anchorIsCurrentAt(anchorFile, texts.identityLine, handle);
1004
- return { claimed, current };
868
+ return identityBlockState(anchorFile, { handle, identityLine: texts.identityLine, template: texts.identityLineTemplate, loadNote: loadNoteFor(handle, texts) });
1005
869
  }
1006
870
  async function identityLineCheck(anchorFile, creds, apiBase, texts, fix) {
1007
- let claimed;
1008
- let current;
1009
- try {
1010
- ;
1011
- ({ claimed, current } = readIdentityLine(anchorFile, creds.handle, texts));
1012
- } catch (err) {
1013
- return { name: "identity-line", verdict: "FAIL", detail: `cannot read ${anchorFile}: ${errorText(err)}` };
1014
- }
1015
- if (claimed === creds.handle && current === true) {
1016
- return { name: "identity-line", verdict: "PASS", detail: `@${claimed} in ${anchorFile}` };
1017
- }
1018
- if (claimed === creds.handle && current === null) {
1019
- return { name: "identity-line", verdict: "WARN", detail: `@${claimed} in ${anchorFile} (currency not checked: served texts unavailable)` };
1020
- }
1021
- const why = claimed === null ? `no identity line in ${anchorFile}` : claimed !== creds.handle ? `${anchorFile} says @${claimed} but this agent is @${creds.handle}` : `${anchorFile} carries an older identity text for @${claimed}`;
1022
- if (fix) {
871
+ const fixCommand = `${invocation()} doctor --fix`;
872
+ const before = readIdentityLine(anchorFile, creds.handle, texts);
873
+ if (before.state === "unreadable") return { name: "identity-line", verdict: "FAIL", detail: before.what };
874
+ const repairable = before.state === "missing" || before.state === "setup_offer" || before.state === "stale";
875
+ if (fix && repairable) {
1023
876
  const report2 = await placeIdentity(creds.handle, creds.api_key, apiBase);
1024
877
  const failed = report2.some((l) => l.includes("FAILED") || l.includes("not written"));
1025
878
  if (failed) return { name: "identity-line", verdict: "FAIL", detail: `could not repair: ${report2.join("; ")}` };
1026
- try {
1027
- const after = readIdentityLine(anchorFile, creds.handle, texts);
1028
- if (after.claimed === creds.handle && after.current !== false) {
1029
- return { name: "identity-line", verdict: "PASS", detail: `repaired \u2192 @${creds.handle}` };
1030
- }
1031
- return { name: "identity-line", verdict: "FAIL", detail: `repair did not take: ${anchorFile} still ${after.claimed === null ? "has no identity line" : after.claimed !== creds.handle ? `says @${after.claimed}` : "differs from the served block"}${report2.length > 0 ? ` (${report2.join("; ").trim()})` : ""}` };
1032
- } catch (err) {
1033
- return { name: "identity-line", verdict: "FAIL", detail: `cannot read ${anchorFile} after the repair: ${errorText(err)}` };
879
+ const after = readIdentityLine(anchorFile, creds.handle, texts);
880
+ if (after.state === "current") {
881
+ return { name: "identity-line", verdict: after.verdict, detail: after.loadNote === null ? `repaired \u2192 @${creds.handle}` : `repaired \u2192 @${creds.handle} in ${anchorFile}; ${after.loadNote.note}` };
1034
882
  }
883
+ if (after.state === "unreadable") return { name: "identity-line", verdict: "FAIL", detail: `${after.what} (after the repair)` };
884
+ return { name: "identity-line", verdict: "FAIL", detail: `repair did not take: ${after.what}${report2.length > 0 ? ` (${report2.join("; ").trim()})` : ""}` };
1035
885
  }
1036
- return { name: "identity-line", verdict: "WARN", detail: `${why} \u2014 repair with \`${invocation()} doctor --fix\`` };
886
+ return { name: "identity-line", verdict: before.verdict, detail: describeIdentityBlock(before, fixCommand) };
1037
887
  }
1038
888
  async function runDoctor(opts = {}) {
1039
889
  const home = profile.home();
@@ -1173,12 +1023,12 @@ The key was not saved.`);
1173
1023
 
1174
1024
  // src/daemon/service.ts
1175
1025
  import * as crypto from "crypto";
1176
- import * as fs2 from "fs";
1026
+ import * as fs from "fs";
1177
1027
  import * as os from "os";
1178
- import * as path2 from "path";
1028
+ import * as path from "path";
1179
1029
  function serviceLabelFor(base, home, defaultHome) {
1180
1030
  const key = (p) => {
1181
- const resolved = path2.resolve(p);
1031
+ const resolved = path.resolve(p);
1182
1032
  return process.platform === "win32" ? resolved.toLowerCase() : resolved;
1183
1033
  };
1184
1034
  if (key(home) === key(defaultHome)) return serviceLabel(base);
@@ -1205,7 +1055,7 @@ function transientPathEntry(value) {
1205
1055
  return /\/node_modules\/\.bin\/?$/i.test(normalized) || /\/node_modules\/npm\/node_modules\/@npmcli\/run-script\/lib\/node-gyp-bin\/?$/i.test(normalized) || /\/\.[^/]+\/tmp\//i.test(normalized);
1206
1056
  }
1207
1057
  function stableServicePath(value, nodePath = process.execPath) {
1208
- const entries = [path2.dirname(nodePath), ...value.split(path2.delimiter)];
1058
+ const entries = [path.dirname(nodePath), ...value.split(path.delimiter)];
1209
1059
  const seen = /* @__PURE__ */ new Set();
1210
1060
  const stable = [];
1211
1061
  for (const raw of entries) {
@@ -1213,7 +1063,7 @@ function stableServicePath(value, nodePath = process.execPath) {
1213
1063
  if (!trimmed || transientPathEntry(trimmed)) continue;
1214
1064
  let resolved = trimmed;
1215
1065
  try {
1216
- resolved = fs2.realpathSync(trimmed);
1066
+ resolved = fs.realpathSync(trimmed);
1217
1067
  } catch {
1218
1068
  }
1219
1069
  const key = process.platform === "win32" ? resolved.toLowerCase() : resolved;
@@ -1221,7 +1071,7 @@ function stableServicePath(value, nodePath = process.execPath) {
1221
1071
  seen.add(key);
1222
1072
  stable.push(resolved);
1223
1073
  }
1224
- return stable.join(path2.delimiter);
1074
+ return stable.join(path.delimiter);
1225
1075
  }
1226
1076
  function plan(opts) {
1227
1077
  const env = {};
@@ -1243,8 +1093,8 @@ function plan(opts) {
1243
1093
  return {
1244
1094
  label: serviceLabel(opts.label),
1245
1095
  node: serviceValue("Node path", process.execPath),
1246
- bin: serviceValue("entry path", path2.resolve(opts.entry)),
1247
- home: serviceValue("home path", path2.resolve(opts.home)),
1096
+ bin: serviceValue("entry path", path.resolve(opts.entry)),
1097
+ home: serviceValue("home path", path.resolve(opts.home)),
1248
1098
  env
1249
1099
  };
1250
1100
  }
@@ -1324,9 +1174,9 @@ function parseServiceHome(text, format) {
1324
1174
  return exec === void 0 ? null : homeFromArgs(systemdWords(exec.slice("ExecStart=".length)));
1325
1175
  }
1326
1176
  function canonicalPath(p) {
1327
- const resolved = path2.resolve(p);
1177
+ const resolved = path.resolve(p);
1328
1178
  try {
1329
- return fs2.realpathSync(resolved);
1179
+ return fs.realpathSync(resolved);
1330
1180
  } catch {
1331
1181
  return resolved;
1332
1182
  }
@@ -1339,10 +1189,10 @@ function sameHome(a, b) {
1339
1189
  function launchdSightings(label) {
1340
1190
  const out = [];
1341
1191
  const plistPath = launchdPlistPath(label);
1342
- if (fs2.existsSync(plistPath)) {
1192
+ if (fs.existsSync(plistPath)) {
1343
1193
  let text = "";
1344
1194
  try {
1345
- text = fs2.readFileSync(plistPath, "utf-8");
1195
+ text = fs.readFileSync(plistPath, "utf-8");
1346
1196
  } catch {
1347
1197
  }
1348
1198
  out.push({ where: plistPath, home: parseServiceHome(text, "plist"), loaded: false });
@@ -1359,7 +1209,7 @@ function launchdSightings(label) {
1359
1209
  const loadedFrom = /^\s*path = (.+)$/m.exec(text)?.[1]?.trim();
1360
1210
  if (loadedFrom !== void 0) {
1361
1211
  try {
1362
- home = parseServiceHome(fs2.readFileSync(loadedFrom, "utf-8"), "plist");
1212
+ home = parseServiceHome(fs.readFileSync(loadedFrom, "utf-8"), "plist");
1363
1213
  } catch {
1364
1214
  }
1365
1215
  }
@@ -1372,10 +1222,10 @@ function launchdSightings(label) {
1372
1222
  function systemdSightings(label) {
1373
1223
  const out = [];
1374
1224
  const unitPath = systemdUnitPath(label);
1375
- if (fs2.existsSync(unitPath)) {
1225
+ if (fs.existsSync(unitPath)) {
1376
1226
  let text = "";
1377
1227
  try {
1378
- text = fs2.readFileSync(unitPath, "utf-8");
1228
+ text = fs.readFileSync(unitPath, "utf-8");
1379
1229
  } catch {
1380
1230
  }
1381
1231
  out.push({ where: unitPath, home: parseServiceHome(text, "systemd"), loaded: false });
@@ -1393,7 +1243,7 @@ function systemdSightings(label) {
1393
1243
  const fragment = props.get("FragmentPath") ?? "";
1394
1244
  let home = null;
1395
1245
  try {
1396
- if (fragment) home = parseServiceHome(fs2.readFileSync(fragment, "utf-8"), "systemd");
1246
+ if (fragment) home = parseServiceHome(fs.readFileSync(fragment, "utf-8"), "systemd");
1397
1247
  } catch {
1398
1248
  }
1399
1249
  out.push({ where: `the loaded systemd unit ${label}${fragment ? ` (${fragment})` : ""}`, home, loaded: true });
@@ -1427,7 +1277,7 @@ function servesHome(label, home) {
1427
1277
  return sightings(label).some((s) => s.home !== null && sameHome(s.home, home));
1428
1278
  }
1429
1279
  function systemdUnitPath(label) {
1430
- return path2.join(os.homedir(), ".config", "systemd", "user", `${label}.service`);
1280
+ return path.join(os.homedir(), ".config", "systemd", "user", `${label}.service`);
1431
1281
  }
1432
1282
  function systemdQuote(value) {
1433
1283
  return '"' + value.replace(/\\/g, "\\\\").replace(/\n/g, "\\n").replace(/\r/g, "\\r").replace(/\t/g, "\\t").replace(/"/g, '\\"').replace(/\$/g, "$$$$").replace(/%/g, "%%") + '"';
@@ -1455,7 +1305,7 @@ function systemdUnit(p) {
1455
1305
  function installSystemd(p) {
1456
1306
  assertServesHome(p.label, p.home, "replace");
1457
1307
  const unitPath = systemdUnitPath(p.label);
1458
- fs2.mkdirSync(path2.dirname(unitPath), { recursive: true });
1308
+ fs.mkdirSync(path.dirname(unitPath), { recursive: true });
1459
1309
  atomicWriteFile(unitPath, systemdUnit(p), 384);
1460
1310
  log.info(`wrote ${unitPath}`);
1461
1311
  if (registrationSkipped()) return;
@@ -1485,7 +1335,7 @@ function uninstallSystemd(label, home) {
1485
1335
  }
1486
1336
  }
1487
1337
  const unitPath = systemdUnitPath(label);
1488
- if (fs2.existsSync(unitPath)) fs2.rmSync(unitPath);
1338
+ if (fs.existsSync(unitPath)) fs.rmSync(unitPath);
1489
1339
  if (!registrationSkipped()) {
1490
1340
  const reload = run("systemctl", ["--user", "daemon-reload"]);
1491
1341
  if (!reload.ok) log.warn(`systemctl daemon-reload failed after uninstall: ${reload.out}`);
@@ -1499,7 +1349,7 @@ function statusSystemd(label, home) {
1499
1349
  return `systemd ${label}: ${active} (${enabled})${foreignNote(label, home)}`;
1500
1350
  }
1501
1351
  function dryRunStatus(name, definitionPath) {
1502
- return `${name}: not queried (AGENTCHAT_SERVICE_DRY_RUN) \u2014 definition ${fs2.existsSync(definitionPath) ? `written at ${definitionPath}` : "not written"}`;
1352
+ return `${name}: not queried (AGENTCHAT_SERVICE_DRY_RUN) \u2014 definition ${fs.existsSync(definitionPath) ? `written at ${definitionPath}` : "not written"}`;
1503
1353
  }
1504
1354
  function foreignNote(label, home) {
1505
1355
  const loaded = sightings(label).find((s) => s.loaded);
@@ -1507,7 +1357,7 @@ function foreignNote(label, home) {
1507
1357
  return ` \u2014 but it serves ${loaded.home}, not this config (${home})`;
1508
1358
  }
1509
1359
  function launchdPlistPath(label) {
1510
- return path2.join(os.homedir(), "Library", "LaunchAgents", `${launchdLabel(label)}.plist`);
1360
+ return path.join(os.homedir(), "Library", "LaunchAgents", `${launchdLabel(label)}.plist`);
1511
1361
  }
1512
1362
  var launchdLabel = (label) => `me.agentchat.${label}`;
1513
1363
  function xmlEscape(value) {
@@ -1517,7 +1367,7 @@ function launchdPlist(p) {
1517
1367
  const args = [p.node, p.bin, "--home", p.home];
1518
1368
  const argXml = args.map((a) => ` <string>${xmlEscape(a)}</string>`).join("\n");
1519
1369
  const envXml = Object.entries(p.env).map(([k, v]) => ` <key>${xmlEscape(k)}</key><string>${xmlEscape(v)}</string>`).join("\n");
1520
- const logPath = path2.join(p.home, "daemon.log");
1370
+ const logPath = path.join(p.home, "daemon.log");
1521
1371
  return [
1522
1372
  '<?xml version="1.0" encoding="UTF-8"?>',
1523
1373
  '<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">',
@@ -1544,7 +1394,7 @@ function launchdPlist(p) {
1544
1394
  function installLaunchd(p) {
1545
1395
  assertServesHome(p.label, p.home, "replace");
1546
1396
  const plistPath = launchdPlistPath(p.label);
1547
- fs2.mkdirSync(path2.dirname(plistPath), { recursive: true });
1397
+ fs.mkdirSync(path.dirname(plistPath), { recursive: true });
1548
1398
  atomicWriteFile(plistPath, launchdPlist(p), 384);
1549
1399
  log.info(`wrote ${plistPath}`);
1550
1400
  if (registrationSkipped()) return;
@@ -1572,7 +1422,7 @@ function uninstallLaunchd(label, home) {
1572
1422
  );
1573
1423
  }
1574
1424
  }
1575
- if (fs2.existsSync(plistPath)) fs2.rmSync(plistPath);
1425
+ if (fs.existsSync(plistPath)) fs.rmSync(plistPath);
1576
1426
  log.info(`service ${launchdLabel(label)} removed`);
1577
1427
  }
1578
1428
  function statusLaunchd(label, home) {
@@ -1589,7 +1439,7 @@ function isWslFromVersion(version) {
1589
1439
  function isWsl() {
1590
1440
  if (process.platform !== "linux") return false;
1591
1441
  try {
1592
- return isWslFromVersion(fs2.readFileSync("/proc/version", "utf-8"));
1442
+ return isWslFromVersion(fs.readFileSync("/proc/version", "utf-8"));
1593
1443
  } catch {
1594
1444
  return false;
1595
1445
  }
@@ -1610,16 +1460,16 @@ function winMode() {
1610
1460
  return hostOs === "win32" || hostOs === "wsl" ? hostOs : null;
1611
1461
  }
1612
1462
  function winMasterDir() {
1613
- return path2.join(os.homedir(), ".agentchat", "daemon");
1463
+ return path.join(os.homedir(), ".agentchat", "daemon");
1614
1464
  }
1615
1465
  function winStartupDir(mode) {
1616
1466
  if (mode === "win32") {
1617
- return path2.join(os.homedir(), "AppData", "Roaming", "Microsoft", "Windows", "Start Menu", "Programs", "Startup");
1467
+ return path.join(os.homedir(), "AppData", "Roaming", "Microsoft", "Windows", "Start Menu", "Programs", "Startup");
1618
1468
  }
1619
1469
  const appdata = run("cmd.exe", ["/c", "echo %APPDATA%"]).out.split(/\r?\n/).pop()?.trim() ?? "";
1620
1470
  const base = run("wslpath", ["-u", appdata]).out.trim();
1621
1471
  if (!base) throw new Error("could not locate the Windows Startup folder from WSL (is /mnt/c mounted?)");
1622
- return path2.join(base, "Microsoft", "Windows", "Start Menu", "Programs", "Startup");
1472
+ return path.join(base, "Microsoft", "Windows", "Start Menu", "Programs", "Startup");
1623
1473
  }
1624
1474
  var vbsEscape = (s) => s.replace(/"/g, '""');
1625
1475
  var shQuote = (s) => `'${s.replace(/'/g, `'\\''`)}'`;
@@ -1662,11 +1512,11 @@ function killLauncher(label, mode) {
1662
1512
  return run(mode === "win32" ? "powershell" : "powershell.exe", ["-NoProfile", "-Command", ps]);
1663
1513
  }
1664
1514
  function lockedDaemonPid(home) {
1665
- const file = path2.join(home, DAEMON_LOCK_FILE);
1515
+ const file = path.join(home, DAEMON_LOCK_FILE);
1666
1516
  try {
1667
- const holder = parseLease(fs2.readFileSync(file, "utf-8"));
1517
+ const holder = parseLease(fs.readFileSync(file, "utf-8"));
1668
1518
  if (holder === null || !Number.isInteger(holder.pid) || holder.pid <= 0) return null;
1669
- return holderLive(holder, { mtimeMs: fs2.statSync(file).mtimeMs }) ? holder.pid : null;
1519
+ return holderLive(holder, { mtimeMs: fs.statSync(file).mtimeMs }) ? holder.pid : null;
1670
1520
  } catch {
1671
1521
  return null;
1672
1522
  }
@@ -1682,12 +1532,12 @@ function stopRunningWindowsDaemon(label, mode, home) {
1682
1532
  }
1683
1533
  function installWindows(p, mode) {
1684
1534
  const master = winMasterDir();
1685
- fs2.mkdirSync(master, { recursive: true });
1686
- const masterVbs = path2.join(master, `${p.label}.vbs`);
1535
+ fs.mkdirSync(master, { recursive: true });
1536
+ const masterVbs = path.join(master, `${p.label}.vbs`);
1687
1537
  if (mode === "win32") {
1688
1538
  atomicWriteFile(masterVbs, launcherVbs(winCommandNative(p), p.env), 384);
1689
1539
  } else {
1690
- const scriptPath = path2.join(master, `${p.label}.sh`);
1540
+ const scriptPath = path.join(master, `${p.label}.sh`);
1691
1541
  atomicWriteFile(scriptPath, wslScriptContent(p), 448);
1692
1542
  const distro = serviceValue("WSL distro", process.env["WSL_DISTRO_NAME"] ?? "");
1693
1543
  if (!distro) throw new Error("WSL_DISTRO_NAME is not set \u2014 cannot target the right WSL distro");
@@ -1702,20 +1552,20 @@ function installWindows(p, mode) {
1702
1552
  log.info(`service ${p.label} installed (starts at login)`);
1703
1553
  }
1704
1554
  function enableWindows(label, mode, home) {
1705
- const masterVbs = path2.join(winMasterDir(), `${label}.vbs`);
1706
- if (!fs2.existsSync(masterVbs)) throw new Error(`no ${label} daemon installed \u2014 run install first`);
1555
+ const masterVbs = path.join(winMasterDir(), `${label}.vbs`);
1556
+ if (!fs.existsSync(masterVbs)) throw new Error(`no ${label} daemon installed \u2014 run install first`);
1707
1557
  const startup = winStartupDir(mode);
1708
- fs2.mkdirSync(startup, { recursive: true });
1709
- const startupVbs = path2.join(startup, `${label}.vbs`);
1710
- fs2.copyFileSync(masterVbs, startupVbs);
1558
+ fs.mkdirSync(startup, { recursive: true });
1559
+ const startupVbs = path.join(startup, `${label}.vbs`);
1560
+ fs.copyFileSync(masterVbs, startupVbs);
1711
1561
  if (registrationSkipped()) return;
1712
1562
  stopRunningWindowsDaemon(label, mode, home);
1713
1563
  if (mode === "win32") startDetached("wscript.exe", [startupVbs]);
1714
1564
  else startDetached("cmd.exe", ["/c", "start", "", "/b", "wscript.exe", winPathFromWsl(startupVbs)]);
1715
1565
  }
1716
1566
  function disableWindows(label, mode) {
1717
- const startupVbs = path2.join(winStartupDir(mode), `${label}.vbs`);
1718
- if (fs2.existsSync(startupVbs)) fs2.rmSync(startupVbs);
1567
+ const startupVbs = path.join(winStartupDir(mode), `${label}.vbs`);
1568
+ if (fs.existsSync(startupVbs)) fs.rmSync(startupVbs);
1719
1569
  if (!registrationSkipped()) {
1720
1570
  const killed = killLauncher(label, mode);
1721
1571
  if (!killed.ok) {
@@ -1726,15 +1576,15 @@ function disableWindows(label, mode) {
1726
1576
  function uninstallWindows(label, mode) {
1727
1577
  disableWindows(label, mode);
1728
1578
  for (const f of [`${label}.vbs`, `${label}.sh`]) {
1729
- const m = path2.join(winMasterDir(), f);
1730
- if (fs2.existsSync(m)) fs2.rmSync(m);
1579
+ const m = path.join(winMasterDir(), f);
1580
+ if (fs.existsSync(m)) fs.rmSync(m);
1731
1581
  }
1732
1582
  }
1733
1583
  function statusWindows(label, mode) {
1734
- const installed = fs2.existsSync(path2.join(winMasterDir(), `${label}.vbs`));
1584
+ const installed = fs.existsSync(path.join(winMasterDir(), `${label}.vbs`));
1735
1585
  let enabled = false;
1736
1586
  try {
1737
- enabled = fs2.existsSync(path2.join(winStartupDir(mode), `${label}.vbs`));
1587
+ enabled = fs.existsSync(path.join(winStartupDir(mode), `${label}.vbs`));
1738
1588
  } catch {
1739
1589
  }
1740
1590
  const host = mode === "wsl" ? "wsl" : "windows";
@@ -1761,7 +1611,7 @@ function installService(opts) {
1761
1611
  }
1762
1612
  function uninstallService(opts) {
1763
1613
  const label = serviceLabel(opts.label);
1764
- const home = path2.resolve(opts.home);
1614
+ const home = path.resolve(opts.home);
1765
1615
  const wm = winMode();
1766
1616
  if (wm) return uninstallWindows(label, wm);
1767
1617
  if (serviceHostOs() === "linux") {
@@ -1778,7 +1628,7 @@ function uninstallService(opts) {
1778
1628
  }
1779
1629
  function serviceStatus(opts) {
1780
1630
  const label = serviceLabel(opts.label);
1781
- const home = path2.resolve(opts.home);
1631
+ const home = path.resolve(opts.home);
1782
1632
  const wm = winMode();
1783
1633
  if (wm) return statusWindows(label, wm);
1784
1634
  if (serviceHostOs() === "linux") return statusSystemd(label, home);
@@ -1790,23 +1640,23 @@ function serviceDefinitionCurrent(opts) {
1790
1640
  const p = plan(opts);
1791
1641
  const wm = winMode();
1792
1642
  if (wm === "win32") {
1793
- const file = path2.join(winMasterDir(), `${p.label}.vbs`);
1794
- return fs2.existsSync(file) && fs2.readFileSync(file, "utf-8") === launcherVbs(winCommandNative(p), p.env);
1643
+ const file = path.join(winMasterDir(), `${p.label}.vbs`);
1644
+ return fs.existsSync(file) && fs.readFileSync(file, "utf-8") === launcherVbs(winCommandNative(p), p.env);
1795
1645
  }
1796
1646
  if (wm === "wsl") {
1797
- const script = path2.join(winMasterDir(), `${p.label}.sh`);
1798
- const vbs = path2.join(winMasterDir(), `${p.label}.vbs`);
1647
+ const script = path.join(winMasterDir(), `${p.label}.sh`);
1648
+ const vbs = path.join(winMasterDir(), `${p.label}.vbs`);
1799
1649
  const distro = serviceValue("WSL distro", process.env["WSL_DISTRO_NAME"] ?? "");
1800
1650
  if (!distro) return false;
1801
- return fs2.existsSync(script) && fs2.existsSync(vbs) && fs2.readFileSync(script, "utf-8") === wslScriptContent(p) && fs2.readFileSync(vbs, "utf-8") === launcherVbs(`wsl.exe -d "${distro}" -e bash "${script}"`, {});
1651
+ return fs.existsSync(script) && fs.existsSync(vbs) && fs.readFileSync(script, "utf-8") === wslScriptContent(p) && fs.readFileSync(vbs, "utf-8") === launcherVbs(`wsl.exe -d "${distro}" -e bash "${script}"`, {});
1802
1652
  }
1803
1653
  if (serviceHostOs() === "linux") {
1804
1654
  const file = systemdUnitPath(p.label);
1805
- return fs2.existsSync(file) && fs2.readFileSync(file, "utf-8") === systemdUnit(p);
1655
+ return fs.existsSync(file) && fs.readFileSync(file, "utf-8") === systemdUnit(p);
1806
1656
  }
1807
1657
  if (serviceHostOs() === "darwin") {
1808
1658
  const file = launchdPlistPath(p.label);
1809
- return fs2.existsSync(file) && fs2.readFileSync(file, "utf-8") === launchdPlist(p);
1659
+ return fs.existsSync(file) && fs.readFileSync(file, "utf-8") === launchdPlist(p);
1810
1660
  }
1811
1661
  return false;
1812
1662
  } catch {
@@ -1814,9 +1664,9 @@ function serviceDefinitionCurrent(opts) {
1814
1664
  }
1815
1665
  }
1816
1666
  function unitInstalled(label) {
1817
- if (winMode()) return fs2.existsSync(path2.join(winMasterDir(), `${label}.vbs`));
1818
- if (serviceHostOs() === "linux") return fs2.existsSync(systemdUnitPath(label));
1819
- if (serviceHostOs() === "darwin") return fs2.existsSync(launchdPlistPath(label));
1667
+ if (winMode()) return fs.existsSync(path.join(winMasterDir(), `${label}.vbs`));
1668
+ if (serviceHostOs() === "linux") return fs.existsSync(systemdUnitPath(label));
1669
+ if (serviceHostOs() === "darwin") return fs.existsSync(launchdPlistPath(label));
1820
1670
  return false;
1821
1671
  }
1822
1672
  function serviceInstalled(opts) {
@@ -1835,6 +1685,7 @@ export {
1835
1685
  FALLBACK_RUN_PROFILE,
1836
1686
  HEARTBEAT_FILE,
1837
1687
  HOSTED_MCP_PATH,
1688
+ IDENTITY_ANCHOR_ATTEMPTS,
1838
1689
  INTEGRATION_ENV,
1839
1690
  INTEGRATION_ENV_LEGACY,
1840
1691
  INTEGRATION_ENV_LEGACY_REMOVAL,
@@ -1895,6 +1746,7 @@ export {
1895
1746
  createIdentityCommands,
1896
1747
  credentialsPath,
1897
1748
  describeCouldNotProcessCounts,
1749
+ describeIdentityBlock,
1898
1750
  describeManualSync,
1899
1751
  describePausedConversations,
1900
1752
  describeRunProfile,
@@ -1903,11 +1755,13 @@ export {
1903
1755
  failedCyclesInARow,
1904
1756
  fetchIdentityLine,
1905
1757
  fetchServedTexts,
1758
+ followIdentityAnchor,
1906
1759
  formatIntegrationStatus,
1907
1760
  fromKitResult,
1908
1761
  hasAnchorAt,
1909
1762
  holderLive,
1910
1763
  hostedMcpUrl,
1764
+ identityBlockState,
1911
1765
  identityLineOf,
1912
1766
  idle,
1913
1767
  installService,
@@ -1919,6 +1773,7 @@ export {
1919
1773
  integrationStatusStaleFor,
1920
1774
  isRunProfile,
1921
1775
  isRunnerFactory,
1776
+ isSetupOfferBody,
1922
1777
  launchdPlist,
1923
1778
  leaseHolder,
1924
1779
  loadTexts,
@@ -1937,6 +1792,7 @@ export {
1937
1792
  parseServiceHome,
1938
1793
  pendingPath,
1939
1794
  pidAlive,
1795
+ placeAnchorAt,
1940
1796
  planForTest,
1941
1797
  probeHostedMcp,
1942
1798
  readAlwaysOnInstalledVersion,
@@ -1957,12 +1813,14 @@ export {
1957
1813
  repeatedFailedRuns,
1958
1814
  resetLeaseObservations,
1959
1815
  resolveIdentity,
1816
+ resolveManualPointer,
1960
1817
  resolveRunBudgetMs,
1961
1818
  resolveRunProfile,
1962
1819
  runContextEnv,
1963
1820
  runProbe,
1964
1821
  runProfileWarning,
1965
1822
  runtimeCheckFailingNow,
1823
+ servedManualUrl,
1966
1824
  serviceDefinitionCurrent,
1967
1825
  serviceInstalled,
1968
1826
  serviceLabelFor,
@@ -1986,6 +1844,7 @@ export {
1986
1844
  writeAnchor,
1987
1845
  writeCredentials,
1988
1846
  writeIntegrationStatus,
1847
+ writeOfferAt,
1989
1848
  writePending,
1990
1849
  writeState,
1991
1850
  xmlEscape