@chibitek/chibi 0.1.205 → 0.1.207

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.
Files changed (103) hide show
  1. package/dist/assets/{TerminalPanel-D1wGUjRa.js → TerminalPanel-Cqjxle8G.js} +1 -1
  2. package/dist/assets/{abnfDiagram-O67JEVCF-DbeVBipN.js → abnfDiagram-O67JEVCF-XB80WX43.js} +1 -1
  3. package/dist/assets/{arc-D1akvHh4.js → arc-BERcgYDi.js} +1 -1
  4. package/dist/assets/{architectureDiagram-NJMV4G6O-DMqZ2Zb2.js → architectureDiagram-NJMV4G6O-Dnc9s6SQ.js} +1 -1
  5. package/dist/assets/{blockDiagram-BEXU5L5S-C2zhO-SN.js → blockDiagram-BEXU5L5S-Cxc21eYL.js} +1 -1
  6. package/dist/assets/{c4Diagram-YGBWAQC7-BvoSvm-3.js → c4Diagram-YGBWAQC7-CW-3gUcf.js} +1 -1
  7. package/dist/assets/channel-DaeKCO76.js +1 -0
  8. package/dist/assets/{chunk-2Q5K7J3B-CnbuWhvy.js → chunk-2Q5K7J3B-Bs484eiW.js} +1 -1
  9. package/dist/assets/{chunk-3FUC2YCW-DahSA7ym.js → chunk-3FUC2YCW-qhnBgRDy.js} +2 -2
  10. package/dist/assets/{chunk-5VM5RSS4-4DVZPQ68.js → chunk-5VM5RSS4-CsCqAEkH.js} +1 -1
  11. package/dist/assets/{chunk-GTNCS2PH-F_r0v8yd.js → chunk-GTNCS2PH-ChBgFjPw.js} +1 -1
  12. package/dist/assets/{chunk-GWA4HPMP-DRP-mB8u.js → chunk-GWA4HPMP-Df5-WClq.js} +1 -1
  13. package/dist/assets/{chunk-JWPE2WC7-CudGEr4i.js → chunk-JWPE2WC7-BdMXRJhO.js} +1 -1
  14. package/dist/assets/{chunk-NETBCI7D-54zUjRUj.js → chunk-NETBCI7D-rmAqJ9nY.js} +1 -1
  15. package/dist/assets/{chunk-WEXAMYUT-Cf3WOSP2.js → chunk-WEXAMYUT-DYmTw4lw.js} +1 -1
  16. package/dist/assets/{chunk-XXDRQBXY-Cx685pqX.js → chunk-XXDRQBXY-C4o5SHm0.js} +1 -1
  17. package/dist/assets/{classDiagram-v2-NBCMYWYE-CJzSmUjW.js → classDiagram-v2-NBCMYWYE-Bm-ZzDk5.js} +1 -1
  18. package/dist/assets/{cose-bilkent-JH36ORCC-B7BGVTVs.js → cose-bilkent-JH36ORCC-CFMRSfMu.js} +1 -1
  19. package/dist/assets/{cynefin-OW5HDTMX-BWmECHiA.js → cynefin-OW5HDTMX-BDedZ5yW.js} +1 -1
  20. package/dist/assets/{cynefinDiagram-VND7K2PF-DHXO0SU2.js → cynefinDiagram-VND7K2PF-i7KARSqF.js} +1 -1
  21. package/dist/assets/{dagre-6A5THRUB-C3D5zoFM.js → dagre-6A5THRUB-CwWpV0i_.js} +1 -1
  22. package/dist/assets/{diagram-22UHCM2B-BGORY_N5.js → diagram-22UHCM2B-CWIMT3-K.js} +1 -1
  23. package/dist/assets/{diagram-3UASUU5V-Cwn-Zojz.js → diagram-3UASUU5V-C7HGc_ap.js} +1 -1
  24. package/dist/assets/{diagram-ATOU4E4O-BbzoyPGD.js → diagram-ATOU4E4O-BeLM7ihN.js} +1 -1
  25. package/dist/assets/{diagram-CDSNMT55-DNWK_SlS.js → diagram-CDSNMT55-CN1rVM-W.js} +1 -1
  26. package/dist/assets/{diagram-MLGK6HIB-BmmP-hmh.js → diagram-MLGK6HIB-CuLcsx4e.js} +1 -1
  27. package/dist/assets/{diagram-MPIPVDR6-xqxM2yWT.js → diagram-MPIPVDR6-Bie61r-h.js} +1 -1
  28. package/dist/assets/{ebnfDiagram-ZINNZB2B-B0GaVIQn.js → ebnfDiagram-ZINNZB2B-ChMg86y3.js} +1 -1
  29. package/dist/assets/{elk-276RUBZZ-BTkrwlOJ.js → elk-276RUBZZ-DG9xXwoW.js} +1 -1
  30. package/dist/assets/{erDiagram-OPXOYQCR-Dw8FpKKd.js → erDiagram-OPXOYQCR-C9bl-nWK.js} +1 -1
  31. package/dist/assets/{flowDiagram-KWPJA3E3-DcWQfIK9.js → flowDiagram-KWPJA3E3-DvdWxFI8.js} +1 -1
  32. package/dist/assets/{ganttDiagram-FUAMR5RP-CIAZE9bZ.js → ganttDiagram-FUAMR5RP-DDCNSEYc.js} +1 -1
  33. package/dist/assets/{gitGraphDiagram-X574FWY7-D1aB6PDc.js → gitGraphDiagram-X574FWY7-PFvmOSMd.js} +1 -1
  34. package/dist/assets/{index-DfkFSy12.js → index-Ci2mINhA.js} +160 -160
  35. package/dist/assets/{index-C8GkjyYq.js → index-DnniNB7N.js} +1 -1
  36. package/dist/assets/{infoDiagram-VRGFBTTK-CUPJD6fR.js → infoDiagram-VRGFBTTK-HEZh-PnK.js} +1 -1
  37. package/dist/assets/{ishikawaDiagram-OU5B5YK6-Qt4T-A1k.js → ishikawaDiagram-OU5B5YK6-P3mmCGAU.js} +1 -1
  38. package/dist/assets/{journeyDiagram-ZHPQQLJL-Br8kwdWE.js → journeyDiagram-ZHPQQLJL-dKG4AQu2.js} +1 -1
  39. package/dist/assets/{kanban-definition-PNTS6WVX-B7BRfQOT.js → kanban-definition-PNTS6WVX-BeIHeQTt.js} +1 -1
  40. package/dist/assets/{linear-snu1EH2X.js → linear-DnEqDr6r.js} +1 -1
  41. package/dist/assets/{mermaid.core-ImU9bwtO.js → mermaid.core-D7hz6n4u.js} +5 -5
  42. package/dist/assets/{mindmap-definition-NLK3R4M7-xKUVLPlR.js → mindmap-definition-NLK3R4M7-BxJ8p-DN.js} +1 -1
  43. package/dist/assets/{pegDiagram-GJSIUBJH-B9BidmhC.js → pegDiagram-GJSIUBJH-CkQT2dHJ.js} +1 -1
  44. package/dist/assets/{pieDiagram-5QR66LMP-Ch8Kv8t8.js → pieDiagram-5QR66LMP-DmVVhYaY.js} +1 -1
  45. package/dist/assets/{quadrantDiagram-O4NWA36T-Dunnqt7g.js → quadrantDiagram-O4NWA36T-DsOz-qCY.js} +1 -1
  46. package/dist/assets/{railroadDiagram-XR7U4H2S-DnOaSZzz.js → railroadDiagram-XR7U4H2S-CeYfvaki.js} +1 -1
  47. package/dist/assets/{requirementDiagram-PLB6GJNP-D0BmDdKg.js → requirementDiagram-PLB6GJNP-BCtM-2uN.js} +1 -1
  48. package/dist/assets/{sankeyDiagram-IPEJSGJF-CWtfZ9Pz.js → sankeyDiagram-IPEJSGJF-Cu8ki35x.js} +1 -1
  49. package/dist/assets/{sequenceDiagram-PO4LG4MO-DlMxxz_s.js → sequenceDiagram-PO4LG4MO-DKbS5Gcs.js} +1 -1
  50. package/dist/assets/{sizeCapture-INFHLROL-CBK9A--M.js → sizeCapture-INFHLROL-Ceut6PrE.js} +1 -1
  51. package/dist/assets/{stateDiagram-v2-GCMORJYK-C7yP85Rg.js → stateDiagram-v2-GCMORJYK-Bl5uMY2f.js} +1 -1
  52. package/dist/assets/{swimlanes-2SLR337P-CPWaiwCv.js → swimlanes-2SLR337P-CoMPbJ2k.js} +1 -1
  53. package/dist/assets/swimlanesDiagram-TC7HE7FX-DLJq0mAR.js +8 -0
  54. package/dist/assets/{timeline-definition-EJHVYXUP-C1i2k1l3.js → timeline-definition-EJHVYXUP-D0xkKp46.js} +1 -1
  55. package/dist/assets/{usecaseDiagram-POWQR4AR-DZMn9spA.js → usecaseDiagram-POWQR4AR-BCCL6QIf.js} +1 -1
  56. package/dist/assets/{vennDiagram-UO4OBE2U-CQTd7MTx.js → vennDiagram-UO4OBE2U-B7g3jK72.js} +1 -1
  57. package/dist/assets/{wardleyDiagram-VNRHLVJA-zuVyHyHg.js → wardleyDiagram-VNRHLVJA-DFhnqQKP.js} +1 -1
  58. package/dist/assets/{xychartDiagram-PMCCYNJV-D6HRPUA0.js → xychartDiagram-PMCCYNJV-mIXMscRS.js} +1 -1
  59. package/dist/index.html +1 -1
  60. package/dist-server/accounts-proxy.js +12 -2
  61. package/dist-server/browser-proxy.js +15 -2
  62. package/dist-server/companion/src/routes.js +10 -0
  63. package/dist-server/container-mcp.js +81 -81
  64. package/dist-server/drivers/agents-proxy.js +81 -81
  65. package/dist-server/drivers/phone-proxy.js +13 -4
  66. package/dist-server/index.js +1031 -890
  67. package/dist-server/openmausbot.js +581 -569
  68. package/dist-server/pair-cli.js +581 -569
  69. package/dist-server/server/accounts-proxy.js +17 -2
  70. package/dist-server/server/agents-token-file.js +10 -7
  71. package/dist-server/server/bot-package.js +3 -2
  72. package/dist-server/server/browser-proxy.js +18 -2
  73. package/dist-server/server/connection-cap-failover.js +3 -1
  74. package/dist-server/server/drivers/phone-proxy.js +18 -4
  75. package/dist-server/server/engine-failover.js +5 -0
  76. package/dist-server/server/engine-failure.js +3 -3
  77. package/dist-server/server/engine-rest.js +1 -0
  78. package/dist-server/server/harness/bus.js +7 -2
  79. package/dist-server/server/harness-import/adapters.js +13 -1
  80. package/dist-server/server/harness-import/apply.js +21 -41
  81. package/dist-server/server/harness-import/cli-skills.js +124 -0
  82. package/dist-server/server/harness-import/convert.js +2 -2
  83. package/dist-server/server/harness-import/grokbot.js +36 -0
  84. package/dist-server/server/harness-import/hermes.js +3 -2
  85. package/dist-server/server/index.js +13 -13
  86. package/dist-server/server/model-evidence-context.js +7 -0
  87. package/dist-server/server/model-evidence.js +6 -1
  88. package/dist-server/server/system-prompt.js +1 -1
  89. package/dist-server/shared/model-evidence.js +13 -0
  90. package/dist-server/vps-container-mcp.js +81 -81
  91. package/package.json +1 -1
  92. package/skills/reverse-engineer-anything/LICENSE-rea-agents.txt +21 -0
  93. package/skills/reverse-engineer-anything/SKILL.md +356 -0
  94. package/skills/reverse-engineer-anything/VENDORED.md +46 -0
  95. package/skills/reverse-engineer-anything/manifest.json +21 -0
  96. package/skills/reverse-engineer-anything/references/android-applications.md +36 -0
  97. package/skills/reverse-engineer-anything/references/connection-and-recovery.md +127 -0
  98. package/skills/reverse-engineer-anything/references/evidence-workflows.md +71 -0
  99. package/skills/reverse-engineer-anything/references/javascript-applications.md +218 -0
  100. package/skills/reverse-engineer-anything/references/native-and-artifacts.md +297 -0
  101. package/skills/reverse-engineer-anything/references/runtime-observation.md +78 -0
  102. package/dist/assets/channel-Ber8y2Xi.js +0 -1
  103. package/dist/assets/swimlanesDiagram-TC7HE7FX-BxCTRDZa.js +0 -8
@@ -5,9 +5,24 @@
5
5
  // the harness decides, per call, which accounts this bot may use.
6
6
  //
7
7
  // stdout is the MCP transport. Never log there.
8
+ import { readFileSync } from "node:fs";
8
9
  import readline from "node:readline";
9
10
  const HARNESS = process.env.OMB_HARNESS_URL ?? "http://127.0.0.1:8799";
10
- const TOKEN = process.env.OMB_ACCOUNTS_TOKEN ?? "";
11
+ const TOKEN_FILE = process.env.OMB_ACCOUNTS_TOKEN_FILE ?? "";
12
+ const SPAWN_TOKEN = process.env.OMB_ACCOUNTS_TOKEN ?? "";
13
+ // Read per call: the harness rewrites the file each turn, and a pooled engine
14
+ // keeps this process across turns, so the spawn-time token is revoked by turn
15
+ // two and every call would answer "this turn's tool access has expired".
16
+ const token = () => {
17
+ if (!TOKEN_FILE)
18
+ return SPAWN_TOKEN;
19
+ try {
20
+ return readFileSync(TOKEN_FILE, "utf8").trim() || SPAWN_TOKEN;
21
+ }
22
+ catch {
23
+ return SPAWN_TOKEN;
24
+ }
25
+ };
11
26
  const TIMEOUT_MS = 3 * 60_000;
12
27
  const MAX_RESPONSE_BYTES = 1024 * 1024;
13
28
  const send = (message) => process.stdout.write(`${JSON.stringify(message)}\n`);
@@ -17,7 +32,7 @@ const textResult = (text, isError = false) => ({ content: [{ type: "text", text
17
32
  async function harness(path, init = {}) {
18
33
  const response = await fetch(`${HARNESS}${path}`, {
19
34
  ...init,
20
- headers: { "content-type": "application/json", authorization: `Bearer ${TOKEN}` },
35
+ headers: { "content-type": "application/json", authorization: `Bearer ${token()}` },
21
36
  signal: AbortSignal.timeout(TIMEOUT_MS),
22
37
  });
23
38
  const text = await response.text();
@@ -1,22 +1,25 @@
1
- // The agents proxy's current bearer, on disk. The harness rewrites it every
1
+ // A spawned proxy's current bearer, on disk. The harness rewrites it every
2
2
  // turn; the proxy reads it per call. An ACP engine keeps the proxy process it
3
3
  // connected at session/new for the whole pooled session (Hermes skips
4
4
  // already-connected MCP names on session/load), so a token carried only in
5
- // the spawn environment is revoked by turn two and every peer tool call
6
- // answers INTERNAL_CAPABILITY_EXPIRED until the session idles out. Same
5
+ // the spawn environment is revoked by turn two and every tool call through
6
+ // that proxy answers INTERNAL_CAPABILITY_EXPIRED until the session idles out.
7
+ // Applies to every turn-scoped proxy (agents, accounts, phone, browser). Same
7
8
  // pattern as the Claude driver's hook tokens; never exported in a backup.
8
9
  import { createHash } from "node:crypto";
9
10
  import { mkdirSync } from "node:fs";
10
11
  import { join } from "node:path";
11
12
  import { writeFileAtomic } from "./atomic.js";
12
13
  import { DATA_DIR } from "./config.js";
13
- export function agentsTokenFile(botId, threadId, dataDir = DATA_DIR) {
14
+ // "agents" keeps its historical bare name so a pooled agents proxy spawned by
15
+ // an older harness build still finds its file after an update.
16
+ export function agentsTokenFile(botId, threadId, dataDir = DATA_DIR, kind = "agents") {
14
17
  const digest = createHash("sha256").update(`${botId}\0${threadId}`).digest("hex").slice(0, 24);
15
- return join(dataDir, "agents-tokens", `${digest}.token`);
18
+ return join(dataDir, "agents-tokens", kind === "agents" ? `${digest}.token` : `${digest}.${kind}.token`);
16
19
  }
17
20
  /** Writes this turn's token (0600) and returns the path the proxy reads. */
18
- export function writeAgentsTokenFile(botId, threadId, token, dataDir = DATA_DIR) {
19
- const path = agentsTokenFile(botId, threadId, dataDir);
21
+ export function writeAgentsTokenFile(botId, threadId, token, dataDir = DATA_DIR, kind = "agents") {
22
+ const path = agentsTokenFile(botId, threadId, dataDir, kind);
20
23
  mkdirSync(join(dataDir, "agents-tokens"), { recursive: true, mode: 0o700 });
21
24
  writeFileAtomic(path, token, { mode: 0o600 });
22
25
  return path;
@@ -148,7 +148,8 @@ const packageSchema = z.object({
148
148
  }),
149
149
  playbooks: z.array(key).max(40).optional(),
150
150
  skills: z.array(skillName).max(BOT_PACKAGE_MAX_SKILLS).optional(),
151
- })).min(1).max(200),
151
+ // Empty for a harness import that brought skills alone (command-line tools).
152
+ })).max(200),
152
153
  chiefOfStaff: key.optional(),
153
154
  rooms: z.array(z.object({
154
155
  key,
@@ -367,7 +368,7 @@ export function renderBotPackageMarkdown(document) {
367
368
  const connections = pkg.requirements.apps.length
368
369
  ? pkg.requirements.apps.map((app) => `- **${app.label}${app.optional ? " (optional)" : ""}:** ${app.reason}`).join("\n")
369
370
  : "- No connected apps are required.";
370
- const markdown = `---\n${frontmatter}\n---\n\n# ${pkg.name}\n\n${pkg.tagline}\n\n> **Give this file to your Chief of Staff.** It is the complete team blueprint. Any agent system can run it; Atomic can also install it directly.\n\n## Activation\n\nYou are the Chief of Staff for this blueprint. Read the whole document before acting. Confirm the user's goal and any missing inputs, then create or delegate to the specialist roles below. Preserve their names, ownership, boundaries, shared-room rules, and playbooks. If your platform cannot literally spawn agents, perform the roles one at a time and keep their outputs clearly separated.\n\nNever request pasted passwords or secret keys. Use the platform's normal connection flow. Do not send messages, publish content, spend money, delete data, or enable a schedule without the user's explicit approval. All routines start paused.\n\n## Mission\n\n${pkg.summary}\n\n## Outcomes\n\n${list(pkg.outcomes)}\n\n## Connections\n\n${connections}\n\n## Team\n\n${agents}\n\n## Chief of Staff\n\nThe Chief of Staff role is \`${pkg.chiefOfStaff ?? pkg.agents[0].key}\`. This role owns delegation, synthesis, conflict resolution, and the final answer to the user.\n${rooms ? `\n## Shared rooms\n\n${rooms}\n` : ""}${routines ? `\n## Suggested routines\n\n${routines}\n` : ""}${playbooks ? `\n## Playbooks\n\n${playbooks}\n` : ""}${examples ? `\n## Example job\n\n${examples}\n` : ""}\n## Completion rule\n\nReturn one clear result to the user, distinguish evidence from inference, cite source links when the work uses external material, and state what still needs human approval or a connected app.\n`;
371
+ const markdown = `---\n${frontmatter}\n---\n\n# ${pkg.name}\n\n${pkg.tagline}\n\n> **Give this file to your Chief of Staff.** It is the complete team blueprint. Any agent system can run it; Atomic can also install it directly.\n\n## Activation\n\nYou are the Chief of Staff for this blueprint. Read the whole document before acting. Confirm the user's goal and any missing inputs, then create or delegate to the specialist roles below. Preserve their names, ownership, boundaries, shared-room rules, and playbooks. If your platform cannot literally spawn agents, perform the roles one at a time and keep their outputs clearly separated.\n\nNever request pasted passwords or secret keys. Use the platform's normal connection flow. Do not send messages, publish content, spend money, delete data, or enable a schedule without the user's explicit approval. All routines start paused.\n\n## Mission\n\n${pkg.summary}\n\n## Outcomes\n\n${list(pkg.outcomes)}\n\n## Connections\n\n${connections}\n\n## Team\n\n${agents}\n\n## Chief of Staff\n\nThe Chief of Staff role is \`${pkg.chiefOfStaff ?? pkg.agents[0]?.key ?? "chibi"}\`. This role owns delegation, synthesis, conflict resolution, and the final answer to the user.\n${rooms ? `\n## Shared rooms\n\n${rooms}\n` : ""}${routines ? `\n## Suggested routines\n\n${routines}\n` : ""}${playbooks ? `\n## Playbooks\n\n${playbooks}\n` : ""}${examples ? `\n## Example job\n\n${examples}\n` : ""}\n## Completion rule\n\nReturn one clear result to the user, distinguish evidence from inference, cite source links when the work uses external material, and state what still needs human approval or a connected app.\n`;
371
372
  if (Buffer.byteLength(markdown) > BOT_PACKAGE_MARKDOWN_MAX_BYTES)
372
373
  throw new Error("The bot playbook is too large");
373
374
  return markdown;
@@ -1,5 +1,6 @@
1
1
  // Per-turn MCP entry point. Only a scoped browser capability crosses into the
2
2
  // agent process; engine commands, session names, and credentials stay in OMB.
3
+ import { readFileSync } from "node:fs";
3
4
  import { pathToFileURL } from "node:url";
4
5
  const MAX_INPUT_BYTES = 1_048_576;
5
6
  const MAX_OUTPUT_BYTES = 16_777_216;
@@ -75,7 +76,22 @@ export async function browserProxyRequest(frame, connection) {
75
76
  }
76
77
  }
77
78
  function run() {
78
- const connection = { url: process.env.OMB_HARNESS_URL ?? "", token: process.env.OMB_BROWSER_TOKEN ?? "" };
79
+ const url = process.env.OMB_HARNESS_URL ?? "";
80
+ const spawnToken = process.env.OMB_BROWSER_TOKEN ?? "";
81
+ const tokenFile = process.env.OMB_BROWSER_TOKEN_FILE ?? "";
82
+ // Read per call: the harness rewrites the file each turn, and a pooled
83
+ // engine keeps this process across turns, so the spawn-time token is
84
+ // revoked by turn two.
85
+ const connection = () => {
86
+ let token = spawnToken;
87
+ if (tokenFile) {
88
+ try {
89
+ token = readFileSync(tokenFile, "utf8").trim() || spawnToken;
90
+ }
91
+ catch { /* fall back */ }
92
+ }
93
+ return { url, token };
94
+ };
79
95
  let input = Buffer.alloc(0);
80
96
  let pending = 0;
81
97
  const output = (message) => {
@@ -118,7 +134,7 @@ function run() {
118
134
  continue;
119
135
  }
120
136
  pending++;
121
- void browserProxyRequest(frame, connection).then(output).finally(() => { pending--; });
137
+ void browserProxyRequest(frame, connection()).then(output).finally(() => { pending--; });
122
138
  }
123
139
  if (input.length > MAX_INPUT_BYTES) {
124
140
  process.stdin.destroy();
@@ -134,7 +134,9 @@ export function finalizeConnectionCapPick(input) {
134
134
  return { line: transientThrottleStopLine(input.currentLabel), category: "failover_exhausted" };
135
135
  }
136
136
  const { choice } = input;
137
- if (!choice && input.failureKind === "provider_error")
137
+ // An engine's own error text passes through only while the turn may still
138
+ // move; at the cap the person gets the plain stopped line, not raw text.
139
+ if (!choice && input.failureKind === "provider_error" && input.triedCount < MAX_ENGINES_PER_TURN)
138
140
  return { passthrough: true };
139
141
  if (!choice) {
140
142
  if (input.pausedUntil !== undefined && input.skipped.some((skip) => skip.reason === "paused")) {
@@ -1,7 +1,7 @@
1
1
  // First-party Android phone MCP server. It deliberately accepts physical USB
2
2
  // devices only: no emulators, wireless debugging, network ADB, or Tailscale.
3
3
  import { spawn } from "node:child_process";
4
- import { accessSync, constants, existsSync } from "node:fs";
4
+ import { accessSync, constants, existsSync, readFileSync } from "node:fs";
5
5
  import { createInterface } from "node:readline";
6
6
  import { delimiter, join } from "node:path";
7
7
  import { homedir } from "node:os";
@@ -252,18 +252,32 @@ const textResult = (text, isError = false) => ({ content: [{ type: "text", text
252
252
  // is idempotent; a blocked caller can retry once the holding turn settles.
253
253
  export function createPhoneClaim(env = process.env, fetchImpl = fetch) {
254
254
  const url = env.OMB_HARNESS_URL?.trim();
255
- const token = env.OMB_PHONE_TOKEN?.trim();
256
- if (!url || !token) {
255
+ const spawnToken = env.OMB_PHONE_TOKEN?.trim() ?? "";
256
+ const tokenFile = env.OMB_PHONE_TOKEN_FILE?.trim() ?? "";
257
+ if (!url || (!spawnToken && !tokenFile)) {
257
258
  // Spawned outside the harness (development, direct debugging): no
258
259
  // exclusivity to enforce, exactly the behavior this proxy always had.
259
260
  return async () => ({ ok: true });
260
261
  }
262
+ // Read per call: the harness rewrites the file each turn, and a pooled
263
+ // engine keeps this process across turns, so the spawn-time token is
264
+ // revoked by turn two.
265
+ const token = () => {
266
+ if (!tokenFile)
267
+ return spawnToken;
268
+ try {
269
+ return readFileSync(tokenFile, "utf8").trim() || spawnToken;
270
+ }
271
+ catch {
272
+ return spawnToken;
273
+ }
274
+ };
261
275
  return async () => {
262
276
  try {
263
277
  const response = await fetchImpl(new URL("/api/internal/phone/claim", url), {
264
278
  method: "POST",
265
279
  redirect: "error",
266
- headers: { authorization: `Bearer ${token}`, "content-type": "application/json" },
280
+ headers: { authorization: `Bearer ${token()}`, "content-type": "application/json" },
267
281
  body: "{}",
268
282
  signal: AbortSignal.timeout(10_000),
269
283
  });
@@ -51,6 +51,11 @@ export function triesSpent(tried, needsPerson) {
51
51
  const all = [...tried];
52
52
  return all.length >= MAX_ENGINES_WALKED || all.filter((instanceId) => !needsPerson(instanceId)).length >= MAX_ENGINES_PER_TURN;
53
53
  }
54
+ /** The `needsPerson` of triesSpent widened: an engine that failed before
55
+ * accepting the prompt (session, gateway: `setup` on its rest, or on this
56
+ * turn's own failure) did not run the turn either, so it is not a try. */
57
+ export const uncountedTry = (turn, resting, needsPerson) => (instanceId) => needsPerson(instanceId) ||
58
+ (instanceId === turn.instanceId && turn.failure?.setup === true) || resting.some((entry) => entry.instanceId === instanceId && entry.setup === true);
54
59
  const accountOf = (engine) => engine.snapshot.account?.email ?? engine.snapshot.account?.organization;
55
60
  /** Another instance of the same engine on the same account (or on none): it
56
61
  * sends a model down the route a failure just broke (two OpenCode instances
@@ -49,7 +49,7 @@ const USAGE_LIMITED = [
49
49
  // Codex: "You've hit your usage limit. Upgrade to Pro ... or try again in 2 days 4 hours";
50
50
  // Cursor: "You've hit your usage limit for this month".
51
51
  /\busage limit\b/i,
52
- /\bhit your (?:\w+ )?limit\b/i,
52
+ /\bhit your (?:[\w-]+ )?limit\b/i, // \"hit your 5-hour limit · resets 3:50am\" (Claude Code, 2026-11-22)
53
53
  /\b(?:5-hour|five-hour|hourly|weekly|daily|monthly|session|opus|sonnet) (?:usage )?limit (?:reached|exceeded|hit)\b/i,
54
54
  /\blimit reached\b[^.]*\breset/i,
55
55
  // OpenAI API: "You exceeded your current quota, please check your plan and billing details." (insufficient_quota);
@@ -60,7 +60,7 @@ const USAGE_LIMITED = [
60
60
  /\bplan limit\b|\blimit (?:of|for) your (?:plan|subscription)\b/i,
61
61
  // Anthropic API: "Your credit balance is too low to access the Anthropic API."
62
62
  // xAI: "Your team ... has either used all available credits or reached its monthly spending limit."
63
- /\bcredit balance (?:is )?too low\b|\binsufficient (?:\w+ )?(?:credits?|balance|funds)\b|\b(?:out|run out) of credits\b/i,
63
+ /\bcredit balance (?:is )?too low\b|\binsufficient (?:\w+ )?(?:credits?|balance|funds)\b|\b(?:out|run out) of (?:usage )?credits\b/i,
64
64
  /\bused all (?:available |of your )?credits\b|\bno credits? (?:left|remaining)\b|\bspending limit\b/i,
65
65
  /\bexhausted your (?:\w+ )?quota\b/i,
66
66
  /\bquota\b[^.]{0,60}\b(?:exceeded|exhausted|reached|used up)\b|\b(?:exceeded|exhausted|reached)\b[^.]{0,40}\bquota\b/i,
@@ -121,7 +121,7 @@ const AUTH_FAILED = [
121
121
  // the message and the turn was stopped." Drivers tag it structurally
122
122
  // (runtime.error failure "stalled"); this reads the text form too.
123
123
  const STALLED = [
124
- /\bwent fully silent\b[^.]{0,80}\bturn was stopped\b/i,
124
+ /\bwent fully silent\b[^.]{0,80}\bturn was stopped\b|\bGateway inaccessible\b/i, // the second: Hermes `acp` could not reach or start its gateway service, so it is not responding (2026-11-22)
125
125
  ];
126
126
  // OpenCode's ACP answer when its provider's API returned a bare 400: the
127
127
  // JSON-RPC internal error with the provider's status text and nothing else,
@@ -181,6 +181,7 @@ export class EngineRestStore {
181
181
  instanceId, ...(scope ? { scope } : {}), ...(account ? { account } : {}), reason, since: active?.since ?? now,
182
182
  until: restUntil, count,
183
183
  ...(reason === "auth_failed" ? { needsSignIn: true } : {}),
184
+ ...(detail.setup ? { setup: true } : {}),
184
185
  ...(keyExpired ? { keyExpired: true } : {}),
185
186
  ...(reason === "auth_failed" && detail.reportedSignedIn !== undefined ? { reportedSignedIn: detail.reportedSignedIn } : {}),
186
187
  ...(reason === "auth_failed" && active?.sawSignedOut ? { sawSignedOut: true } : {}),
@@ -16,6 +16,9 @@ export class EventBus {
16
16
  gate = null;
17
17
  unsubscribes = new Map();
18
18
  pendingLogWarnings = new Map();
19
+ /** Events already in the canonical log: a held event released later by the
20
+ * gate is the same object, logged once. */
21
+ recorded = new WeakSet();
19
22
  appendLog;
20
23
  constructor(appendLog = appendFileSync) {
21
24
  this.appendLog = appendLog;
@@ -44,12 +47,14 @@ export class EventBus {
44
47
  this.record(event);
45
48
  const deliveries = this.gate ? this.gate(event) : [event];
46
49
  for (const delivery of deliveries) {
47
- if (delivery !== event)
48
- this.record(delivery);
50
+ this.record(delivery);
49
51
  this.deliver(delivery);
50
52
  }
51
53
  }
52
54
  record(event) {
55
+ if (this.recorded.has(event))
56
+ return;
57
+ this.recorded.add(event);
53
58
  const pendingWarning = this.pendingLogWarnings.get(event.threadId);
54
59
  const persistedEvents = pendingWarning ? [pendingWarning, redactSecrets(event)] : [redactSecrets(event)];
55
60
  try {
@@ -3,6 +3,7 @@
3
3
  // (model.ts), and says where its conversations are. Conversion, preview and
4
4
  // apply are shared.
5
5
  import { appRules, checkBackupFolder } from "./apply.js";
6
+ import { checkCliSkillsFolder, CLI_SKILLS_HISTORY, CLI_SKILLS_KIND, CLI_SKILLS_LABEL, detectCliSkills, readCliSkills } from "./cli-skills.js";
6
7
  import { convertHarness } from "./convert.js";
7
8
  import { readGrokBackup } from "./grokbot.js";
8
9
  import { checkHermesFolder, detectHermes, hermesRules, readHermesHome } from "./hermes.js";
@@ -26,7 +27,18 @@ export const HERMES_ADAPTER = {
26
27
  rules: hermesRules,
27
28
  history: HERMES_HISTORY,
28
29
  };
29
- export const HARNESS_ADAPTERS = [HERMES_ADAPTER, GROKBOT_ADAPTER];
30
+ /** Skills from Claude Code, Codex, Gemini CLI and Grok CLI on this computer.
31
+ * They land on Chibi, who routes work to the bot that holds a skill. */
32
+ export const CLI_SKILLS_ADAPTER = {
33
+ id: CLI_SKILLS_KIND,
34
+ label: CLI_SKILLS_LABEL,
35
+ detect: () => detectCliSkills().map((found) => ({ root: found.root, bots: 0, skills: found.skills })),
36
+ checkFolder: checkCliSkillsFolder,
37
+ read: (root) => readCliSkills(root),
38
+ rules: hermesRules,
39
+ history: CLI_SKILLS_HISTORY,
40
+ };
41
+ export const HARNESS_ADAPTERS = [HERMES_ADAPTER, GROKBOT_ADAPTER, CLI_SKILLS_ADAPTER];
30
42
  export const harnessAdapter = (id) => HARNESS_ADAPTERS.find((adapter) => adapter.id === id);
31
43
  /** The in-app conversion: credentials as references, disabled jobs and
32
44
  * skipped items offered unticked. */
@@ -3,9 +3,6 @@
3
3
  // rest of the app uses. The client only ever names package keys; the server
4
4
  // re-reads the backup for both steps, so no persona text or credential
5
5
  // crosses the wire, and every credential arrives as an `${ENV}` reference.
6
- import { existsSync, statSync } from "node:fs";
7
- import { homedir } from "node:os";
8
- import { basename, dirname, isAbsolute, join, resolve } from "node:path";
9
6
  import { packageAgentAsMember } from "../bot-package.js";
10
7
  import { parseSkillMd, SKILL_FILE_MAX_BYTES } from "../skills.js";
11
8
  import { maskedMcpTarget, mcpTargetKey } from "../mcp-import-detect.js";
@@ -28,41 +25,20 @@ export const importIdentity = (result) => ({
28
25
  label: result.report.source.label ?? GROKBOT_IDENTITY.label,
29
26
  packageId: result.pkg.package.id,
30
27
  });
28
+ /** A source with no bots (skills from command-line tools) puts its skills on
29
+ * Chibi, the Primary Bot, who routes work to the bot that holds a skill. */
30
+ export function skillsOnlyHome(report, bots) {
31
+ return report.bots.length ? undefined : bots.find((bot) => bot.builtin === "chibi");
32
+ }
33
+ /** `grokbot:workflows/<slug>`, `hermes:skills/<slug>`, `cli-skills:.claude/skills/<slug>`:
34
+ * where an installed skill came from. */
35
+ export const skillProvenance = (identity, skill) => identity.kind === "grokbot" ? `grokbot:workflows/${skill.slug}`
36
+ : identity.kind === "cli-skills" ? `cli-skills:${skill.sourcePath}`
37
+ : `${identity.kind}:skills/${skill.slug}`;
31
38
  /** `grokbot:<uuid>`, `hermes:<profile>`: the source bot an Atomic bot came from. */
32
39
  export const sourceRefFor = (identity, sourceId) => `${identity.kind}:${sourceId}`;
33
- /** Where a typed or picked path points, as a Grok Bot backup root. Choosing
34
- * the `agent-data` folder itself is accepted and means its parent. */
35
- export function checkBackupFolder(input) {
36
- if (typeof input !== "string" || !input.trim()) {
37
- return { ok: false, code: "path_required", error: "Choose the folder that holds your Grok Bot backup." };
38
- }
39
- if (input.length > 4096 || input.includes("\0"))
40
- return { ok: false, code: "not_found", error: "That folder does not exist." };
41
- let path = input.trim();
42
- if (path === "~" || path.startsWith("~/"))
43
- path = join(homedir(), path.slice(1));
44
- if (!isAbsolute(path)) {
45
- return { ok: false, code: "not_absolute", error: "Enter the full path to the backup folder, for example /Users/you/Downloads/grokbot-backup." };
46
- }
47
- path = resolve(path);
48
- if (!existsSync(path))
49
- return { ok: false, code: "not_found", error: "That folder does not exist." };
50
- if (!statSync(path).isDirectory())
51
- return { ok: false, code: "not_folder", error: "That path is a file. Choose the backup folder instead." };
52
- const isBackup = (root) => {
53
- const agents = join(root, "agent-data", "agents");
54
- return existsSync(agents) && statSync(agents).isDirectory();
55
- };
56
- if (isBackup(path))
57
- return { ok: true, root: path };
58
- if (basename(path) === "agent-data" && isBackup(dirname(path)))
59
- return { ok: true, root: dirname(path) };
60
- return {
61
- ok: false,
62
- code: "not_grokbot",
63
- error: "This folder is not a Grok Bot backup. Choose the folder that contains agent-data.",
64
- };
65
- }
40
+ // ── the backup folder ──────────────────────────────────────────────────
41
+ export { checkBackupFolder } from "./grokbot.js";
66
42
  /** The conversion the in-app import uses: credentials as references, disabled
67
43
  * automations included (offered unticked), and plain schedules in the zone
68
44
  * Grok Bot ran them in (Eastern), whatever this computer's zone is. */
@@ -257,14 +233,15 @@ export function buildPreview(result, root, deps, candidates = []) {
257
233
  apps: (botApps.get(bot.key) ?? []).map((app) => ({ slug: app.slug, label: app.label, status: app.status })),
258
234
  notes: (bot.notes ?? []).map(safe),
259
235
  }));
236
+ const skillHome = skillsOnlyHome(report, botsNow);
260
237
  const skills = report.skills.map((skill) => {
261
- const targets = skill.ownerKeys.map((key) => botIdByKey.get(key)).filter((id) => Boolean(id));
238
+ const targets = skillHome ? [skillHome.id] : skill.ownerKeys.map((key) => botIdByKey.get(key)).filter((id) => Boolean(id));
262
239
  return {
263
240
  slug: skill.slug,
264
241
  offered: skill.offered ?? null,
265
242
  description: safe(descriptionOf(result, skill.slug)),
266
- owners: skill.ownerKeys.map((key) => safe(botName.get(key) ?? key)),
267
- alreadyImported: skill.ownerKeys.length > 0 && targets.length === skill.ownerKeys.length &&
243
+ owners: skillHome ? [safe(skillHome.name)] : skill.ownerKeys.map((key) => safe(botName.get(key) ?? key)),
244
+ alreadyImported: targets.length > 0 && (skillHome || targets.length === skill.ownerKeys.length) &&
268
245
  targets.every((id) => deps.listSkills(id).some((installed) => installed.name === skill.slug)),
269
246
  secrets: refCount(result, "skill", skill.slug),
270
247
  };
@@ -720,9 +697,12 @@ export async function applyImport(result, selection, deps) {
720
697
  out.needsAttention.playbookTriggers.push(safe(`${name} (${target.name}): ${trigger}`));
721
698
  }
722
699
  // Skills install switched off, the way every imported skill does.
700
+ const skillHome = skillsOnlyHome(report, botsNow);
723
701
  for (const slug of selection.skills) {
724
702
  const skill = reportSkill.get(slug);
725
- const owners = skill.ownerKeys.map((key) => targets.get(key)).filter((target) => Boolean(target));
703
+ const owners = skillHome
704
+ ? [{ id: skillHome.id, name: skillHome.name, created: false }]
705
+ : skill.ownerKeys.map((key) => targets.get(key)).filter((target) => Boolean(target));
726
706
  if (!owners.length) {
727
707
  out.skipped.push({ kind: "skill", name: slug, reason: "None of the bots that use it were selected" });
728
708
  continue;
@@ -741,7 +721,7 @@ export async function applyImport(result, selection, deps) {
741
721
  out.alreadyImported.skills++;
742
722
  continue;
743
723
  }
744
- const installed = deps.installSkill(owner.id, identity.kind === "grokbot" ? `grokbot:workflows/${slug}` : `${identity.kind}:skills/${slug}`, [{ path: "SKILL.md", content }]);
724
+ const installed = deps.installSkill(owner.id, skillProvenance(identity, skill), [{ path: "SKILL.md", content }]);
745
725
  if ("error" in installed) {
746
726
  out.skipped.push({ kind: "skill", name: slug, reason: `Could not be added to ${owner.name}: ${installed.error}` });
747
727
  continue;
@@ -0,0 +1,124 @@
1
+ // Skills from the command-line tools on this computer: Claude Code
2
+ // (~/.claude/skills), Codex (~/.codex/skills and the shared ~/.agents/skills),
3
+ // Gemini CLI (~/.gemini/skills) and Grok CLI (~/.grok/skills). Read-only: the
4
+ // source folders are never changed. Atomic keeps one copy of each skill, so
5
+ // the same skill found in several tools is offered once; the copies are
6
+ // listed unticked as exact copies.
7
+ import { existsSync, statSync } from "node:fs";
8
+ import { homedir } from "node:os";
9
+ import { isAbsolute, join, resolve } from "node:path";
10
+ import { fingerprint, readSkillFolder } from "./hermes.js";
11
+ import { createSourceReader } from "./source-reader.js";
12
+ export const CLI_SKILLS_KIND = "cli-skills";
13
+ export const CLI_SKILLS_LABEL = "Command-line tools";
14
+ /** Where each tool keeps its skills, relative to the home folder. Order is
15
+ * precedence: when the same skill name differs between tools, the first wins. */
16
+ export const CLI_SKILL_HOMES = [
17
+ { tool: "Claude Code", dir: ".claude/skills" },
18
+ { tool: "Codex", dir: ".codex/skills" },
19
+ { tool: "Codex", dir: ".agents/skills" },
20
+ { tool: "Gemini CLI", dir: ".gemini/skills" },
21
+ { tool: "Grok CLI", dir: ".grok/skills" },
22
+ ];
23
+ // ponytail: $CODEX_HOME / $GROK_HOME / $CLAUDE_CONFIG_DIR overrides are not followed; type the folder instead.
24
+ const SLUG = "[A-Za-z0-9][A-Za-z0-9._-]*";
25
+ const HOME_DIRS = CLI_SKILL_HOMES.map((home) => home.dir.replace(/\./g, "\\.")).join("|");
26
+ /** `<skills dir>/<slug>` in a home folder, or `<slug>` in a plain skills folder. */
27
+ const SKILL = `(?:(?:${HOME_DIRS})/)?${SLUG}`;
28
+ export const CLI_SKILLS_ALLOWLIST = {
29
+ files: [
30
+ new RegExp(`^${SKILL}/SKILL\\.md$`),
31
+ new RegExp(`^${SKILL}/(?:references|scripts)/${SLUG}$`),
32
+ ],
33
+ dirs: [
34
+ /^$/,
35
+ new RegExp(`^(?:${HOME_DIRS})$`),
36
+ new RegExp(`^${SKILL}$`),
37
+ new RegExp(`^${SKILL}/(?:references|scripts)$`),
38
+ ],
39
+ };
40
+ const isSlug = (name) => new RegExp(`^${SLUG}$`).test(name);
41
+ /** Skill folders under `base` ("" for the root itself). */
42
+ function skillDirs(reader, base) {
43
+ const out = [];
44
+ for (const entry of reader.list(base, "dir")) {
45
+ const dir = base ? `${base}/${entry}` : entry;
46
+ if (isSlug(entry) && reader.exists(`${dir}/SKILL.md`))
47
+ out.push(dir);
48
+ }
49
+ return out;
50
+ }
51
+ /** The tool skill folders present in `root`, or `[""]` when `root` is itself a folder of skills. */
52
+ function layout(reader) {
53
+ // The reader's exists() is for files; a tool folder counts when it lists.
54
+ const homes = CLI_SKILL_HOMES.map((home) => home.dir).filter((dir) => reader.list(dir, "dir").length);
55
+ if (homes.length)
56
+ return homes;
57
+ return skillDirs(reader, "").length ? [""] : [];
58
+ }
59
+ export function readCliSkills(root, fs) {
60
+ const reader = createSourceReader(root, CLI_SKILLS_ALLOWLIST, fs);
61
+ const found = new Map();
62
+ const skills = [];
63
+ for (const base of layout(reader)) {
64
+ for (const dir of skillDirs(reader, base)) {
65
+ const files = readSkillFolder(reader, dir);
66
+ if (!files)
67
+ continue;
68
+ const slug = dir.slice(dir.lastIndexOf("/") + 1);
69
+ const print = fingerprint(files);
70
+ const first = found.get(slug);
71
+ // Same name, same content elsewhere: offered as an exact copy by the
72
+ // shared dedupe. Same name, different content: the first tool wins.
73
+ const name = !first ? slug : first.print === print ? `${slug}-copy-${skills.length}` : "";
74
+ if (!name)
75
+ continue;
76
+ if (!first)
77
+ found.set(slug, { dir, print });
78
+ skills.push({ slug: name, sourcePath: dir, files });
79
+ }
80
+ }
81
+ return { kind: CLI_SKILLS_KIND, label: CLI_SKILLS_LABEL, root: reader.root, bots: [], routines: [], rooms: [], vendorSkills: [], skills };
82
+ }
83
+ export function checkCliSkillsFolder(input) {
84
+ if (typeof input !== "string" || !input.trim()) {
85
+ return { ok: false, code: "path_required", error: "Choose your home folder, or a folder of skills." };
86
+ }
87
+ if (input.length > 4096 || input.includes("\0"))
88
+ return { ok: false, code: "not_found", error: "That folder does not exist." };
89
+ let path = input.trim();
90
+ if (path === "~" || path.startsWith("~/"))
91
+ path = join(homedir(), path.slice(1));
92
+ if (!isAbsolute(path))
93
+ return { ok: false, code: "not_absolute", error: "Enter the full path, for example /Users/you." };
94
+ path = resolve(path);
95
+ if (!existsSync(path))
96
+ return { ok: false, code: "not_found", error: "That folder does not exist." };
97
+ if (!statSync(path).isDirectory())
98
+ return { ok: false, code: "not_folder", error: "That path is a file. Choose a folder instead." };
99
+ try {
100
+ if (layout(createSourceReader(path, CLI_SKILLS_ALLOWLIST)).length)
101
+ return { ok: true, root: path };
102
+ }
103
+ catch {
104
+ // Unreadable: reported below.
105
+ }
106
+ return { ok: false, code: "not_skills", error: "No skills here. Choose your home folder (it holds .claude/skills, .codex/skills, .agents/skills, .gemini/skills or .grok/skills) or a folder whose subfolders each have a SKILL.md." };
107
+ }
108
+ export function detectCliSkills(home = homedir(), fs) {
109
+ try {
110
+ const count = readCliSkills(home, fs).skills.length;
111
+ return count ? [{ root: home, skills: count }] : [];
112
+ }
113
+ catch {
114
+ return [];
115
+ }
116
+ }
117
+ /** Skills have no conversations. */
118
+ export const CLI_SKILLS_HISTORY = {
119
+ project: "",
120
+ receiptPrefix: "cli-skills:",
121
+ available: () => false,
122
+ plan: () => ({ plan: null, unreadable: false }),
123
+ reader: (root, fs) => createSourceReader(root, { files: [], dirs: [] }, fs),
124
+ };
@@ -623,7 +623,7 @@ export function convertHarness(source, options = {}) {
623
623
  ...(offeredSkill.has(skill.slug) ? { offered: offeredSkill.get(skill.slug) } : {}),
624
624
  });
625
625
  }
626
- if (converted.length > packageSkills.length) {
626
+ if (source.bots.length && converted.length > packageSkills.length) {
627
627
  report.limits.push(`Team files carry at most ${rules.maxEmbeddedSkills} skills; ${converted.length - packageSkills.length} converted skill(s) are only in skills/ and must be installed per bot.`);
628
628
  }
629
629
  // ── rooms and vendor skills ─────────────────────────────────────────
@@ -704,7 +704,7 @@ export function convertHarness(source, options = {}) {
704
704
  flags: spec.refs.length ? ["secrets-referenced"] : [],
705
705
  });
706
706
  }
707
- if (!agents.length)
707
+ if (source.bots.length && !agents.length)
708
708
  throw new Error("Nothing to convert: every bot was dropped or held back");
709
709
  if (!orchestratorKey)
710
710
  report.limits.push("No Chief of Staff could be set: the orchestrator bot was not converted.");
@@ -2,6 +2,9 @@
2
2
  // neutral harness model. It never lists an agent folder, so it never learns
3
3
  // the names of the stores that sit beside profile.json. It lists only the
4
4
  // memory/ folder, whose markdown notes are the bot's own memory.
5
+ import { existsSync, statSync } from "node:fs";
6
+ import { homedir } from "node:os";
7
+ import { basename, dirname, isAbsolute, join, resolve } from "node:path";
5
8
  import { parse as parseYaml } from "yaml";
6
9
  import { DEFAULT_RULES } from "./rules.js";
7
10
  import { createSourceReader, MAX_MEMORY_FILE_BYTES } from "./source-reader.js";
@@ -262,3 +265,36 @@ export function skillFrontmatter(content) {
262
265
  body: match[2] ?? "",
263
266
  };
264
267
  }
268
+ /** Where a typed or picked path points, as a Grok Bot backup root. Choosing
269
+ * the `agent-data` folder itself is accepted and means its parent. */
270
+ export function checkBackupFolder(input) {
271
+ if (typeof input !== "string" || !input.trim()) {
272
+ return { ok: false, code: "path_required", error: "Choose the folder that holds your Grok Bot backup." };
273
+ }
274
+ if (input.length > 4096 || input.includes("\0"))
275
+ return { ok: false, code: "not_found", error: "That folder does not exist." };
276
+ let path = input.trim();
277
+ if (path === "~" || path.startsWith("~/"))
278
+ path = join(homedir(), path.slice(1));
279
+ if (!isAbsolute(path)) {
280
+ return { ok: false, code: "not_absolute", error: "Enter the full path to the backup folder, for example /Users/you/Downloads/grokbot-backup." };
281
+ }
282
+ path = resolve(path);
283
+ if (!existsSync(path))
284
+ return { ok: false, code: "not_found", error: "That folder does not exist." };
285
+ if (!statSync(path).isDirectory())
286
+ return { ok: false, code: "not_folder", error: "That path is a file. Choose the backup folder instead." };
287
+ const isBackup = (root) => {
288
+ const agents = join(root, "agent-data", "agents");
289
+ return existsSync(agents) && statSync(agents).isDirectory();
290
+ };
291
+ if (isBackup(path))
292
+ return { ok: true, root: path };
293
+ if (basename(path) === "agent-data" && isBackup(dirname(path)))
294
+ return { ok: true, root: dirname(path) };
295
+ return {
296
+ ok: false,
297
+ code: "not_grokbot",
298
+ error: "This folder is not a Grok Bot backup. Choose the folder that contains agent-data.",
299
+ };
300
+ }
@@ -322,7 +322,8 @@ function readRoutines(reader, profile, config) {
322
322
  };
323
323
  });
324
324
  }
325
- function readSkillFolder(reader, dir) {
325
+ /** SKILL.md plus the text files under references/ and scripts/. Shared with the CLI skills adapter. */
326
+ export function readSkillFolder(reader, dir) {
326
327
  const main = reader.readText(`${dir}/SKILL.md`);
327
328
  if (main === null)
328
329
  return null;
@@ -369,7 +370,7 @@ function bundledSkills(reader, profile) {
369
370
  const text = reader.readText(`${profile.base}skills/.bundled_manifest`) ?? "";
370
371
  return new Set(text.split(/\r?\n/).map((line) => line.split(":")[0].trim()).filter(Boolean));
371
372
  }
372
- const fingerprint = (files) => createHash("sha256").update(files.map((file) => `${file.file}\0${file.content.replace(/\r\n/g, "\n").trim()}`).join("\0\0")).digest("hex");
373
+ export const fingerprint = (files) => createHash("sha256").update(files.map((file) => `${file.file}\0${file.content.replace(/\r\n/g, "\n").trim()}`).join("\0\0")).digest("hex");
373
374
  /** One skill per slug and content across profiles. The version most profiles
374
375
  * share keeps the slug; a profile's own edit becomes `<slug>-<profile>`. */
375
376
  function mergeSkills(found) {