@goah/cli 0.13.0 → 0.13.2

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 (236) hide show
  1. package/dist/LICENSE +201 -0
  2. package/dist/THIRD-PARTY-NOTICES.md +2319 -0
  3. package/dist/anthropic-messages-WBFOHES5.js +7214 -0
  4. package/dist/azure-openai-responses-NZFH3PO6.js +253 -0
  5. package/dist/chunk-25XSBFX6.js +639 -0
  6. package/dist/chunk-2QBQZGXF.js +110 -0
  7. package/dist/chunk-2ZP2NBW3.js +345 -0
  8. package/dist/chunk-4KA63VNZ.js +2 -0
  9. package/dist/chunk-4M6TXTT5.js +86 -0
  10. package/dist/chunk-4US7ZHT3.js +20 -0
  11. package/dist/chunk-6M3OOCKO.js +11809 -0
  12. package/dist/chunk-7AXAFDPG.js +17 -0
  13. package/dist/chunk-7E7V6OIU.js +920 -0
  14. package/dist/chunk-BXA47DTF.js +548 -0
  15. package/dist/chunk-D2DVAH37.js +25 -0
  16. package/dist/chunk-FSBUS2BI.js +26 -0
  17. package/dist/chunk-GKDRAHLI.js +4787 -0
  18. package/dist/chunk-H462EFJP.js +89 -0
  19. package/dist/chunk-IIJQ3DW4.js +35 -0
  20. package/dist/chunk-JQD5EWJY.js +34 -0
  21. package/dist/chunk-K26BVR6O.js +61 -0
  22. package/dist/chunk-KAO7WIXG.js +31 -0
  23. package/dist/chunk-KJ4HJCTK.js +1178 -0
  24. package/dist/chunk-LBKI23CC.js +9810 -0
  25. package/dist/chunk-LKBKZEHT.js +41 -0
  26. package/dist/chunk-MD7TLTXZ.js +18 -0
  27. package/dist/chunk-MPXK7QBL.js +868 -0
  28. package/dist/chunk-NRLGWZJC.js +11 -0
  29. package/dist/chunk-QBD6EJ2Z.js +1746 -0
  30. package/dist/chunk-R6I3VKME.js +132 -0
  31. package/dist/chunk-TJON22J4.js +87 -0
  32. package/dist/chunk-ULY36ME4.js +33097 -0
  33. package/dist/chunk-XALZLRYK.js +9221 -0
  34. package/dist/chunk-XPQKM3L7.js +57 -0
  35. package/dist/chunk-YH6YJ2IB.js +1773 -0
  36. package/dist/cli.d.ts +0 -2
  37. package/dist/cli.js +13716 -580
  38. package/dist/console/assets/{index-Rtc_B7cs.js → index-B1vGMXKr.js} +11 -11
  39. package/dist/console/assets/{index-Rtc_B7cs.js.map → index-B1vGMXKr.js.map} +1 -1
  40. package/dist/console/index.html +1 -1
  41. package/dist/dist-65MDQA4Q.js +1126 -0
  42. package/dist/dist-KNR2XL6J.js +39 -0
  43. package/dist/execution.d.ts +557 -2
  44. package/dist/execution.js +37 -2
  45. package/dist/faux-runner-worker.js +128 -0
  46. package/dist/google-generative-ai-YMHXZSFE.js +422 -0
  47. package/dist/google-vertex-X6DB3ZQ6.js +471 -0
  48. package/dist/index.d.ts +853 -25
  49. package/dist/index.js +84 -385
  50. package/dist/kernel.d.ts +39 -2
  51. package/dist/kernel.js +21 -2
  52. package/dist/mistral-conversations-TY3MMD6G.js +718 -0
  53. package/dist/multipart-parser-F6M4NJZU.js +373 -0
  54. package/dist/openai-codex-responses-BRDUMLN5.js +1374 -0
  55. package/dist/openai-completions-CX634XN3.js +1139 -0
  56. package/dist/openai-responses-HMCXJIHT.js +300 -0
  57. package/dist/openrouter-images-KTWET2H2.js +148 -0
  58. package/dist/pi-messages-XL5OEC4K.js +307 -0
  59. package/dist/pi-worker.js +671 -0
  60. package/dist/runner-pi.d.ts +342 -2
  61. package/dist/runner-pi.js +46 -2
  62. package/dist/runner-registry-GD4BYCQC.js +22 -0
  63. package/dist/sqlite.d.ts +446 -2
  64. package/dist/sqlite.js +15 -2
  65. package/dist/src-F2KBSV4T.js +1398 -0
  66. package/dist/supervisor.d.ts +625 -2
  67. package/dist/supervisor.js +39 -2
  68. package/dist/testkit.d.ts +564 -2
  69. package/dist/testkit.js +127 -2
  70. package/dist/transcript.d.ts +84 -2
  71. package/dist/transcript.js +25 -2
  72. package/dist/verification-worker.js +72 -0
  73. package/package.json +2 -26
  74. package/dist/cli.d.ts.map +0 -1
  75. package/dist/cli.js.map +0 -1
  76. package/dist/control.d.ts +0 -106
  77. package/dist/control.d.ts.map +0 -1
  78. package/dist/control.js +0 -242
  79. package/dist/control.js.map +0 -1
  80. package/dist/execution.d.ts.map +0 -1
  81. package/dist/execution.js.map +0 -1
  82. package/dist/index.d.ts.map +0 -1
  83. package/dist/index.js.map +0 -1
  84. package/dist/kernel.d.ts.map +0 -1
  85. package/dist/kernel.js.map +0 -1
  86. package/dist/live-config.d.ts +0 -10
  87. package/dist/live-config.d.ts.map +0 -1
  88. package/dist/live-config.js +0 -44
  89. package/dist/live-config.js.map +0 -1
  90. package/dist/prompt-queue.d.ts +0 -13
  91. package/dist/prompt-queue.d.ts.map +0 -1
  92. package/dist/prompt-queue.js +0 -35
  93. package/dist/prompt-queue.js.map +0 -1
  94. package/dist/runner-pi.d.ts.map +0 -1
  95. package/dist/runner-pi.js.map +0 -1
  96. package/dist/runner-registry.d.ts +0 -8
  97. package/dist/runner-registry.d.ts.map +0 -1
  98. package/dist/runner-registry.js +0 -12
  99. package/dist/runner-registry.js.map +0 -1
  100. package/dist/searchable-select.d.ts +0 -24
  101. package/dist/searchable-select.d.ts.map +0 -1
  102. package/dist/searchable-select.js +0 -61
  103. package/dist/searchable-select.js.map +0 -1
  104. package/dist/secret-input.d.ts +0 -8
  105. package/dist/secret-input.d.ts.map +0 -1
  106. package/dist/secret-input.js +0 -14
  107. package/dist/secret-input.js.map +0 -1
  108. package/dist/setup-wizard.d.ts +0 -22
  109. package/dist/setup-wizard.d.ts.map +0 -1
  110. package/dist/setup-wizard.js +0 -154
  111. package/dist/setup-wizard.js.map +0 -1
  112. package/dist/sqlite.d.ts.map +0 -1
  113. package/dist/sqlite.js.map +0 -1
  114. package/dist/supervisor.d.ts.map +0 -1
  115. package/dist/supervisor.js.map +0 -1
  116. package/dist/testkit.d.ts.map +0 -1
  117. package/dist/testkit.js.map +0 -1
  118. package/dist/thread-inspect.d.ts +0 -47
  119. package/dist/thread-inspect.d.ts.map +0 -1
  120. package/dist/thread-inspect.js +0 -78
  121. package/dist/thread-inspect.js.map +0 -1
  122. package/dist/transcript.d.ts.map +0 -1
  123. package/dist/transcript.js.map +0 -1
  124. package/dist/tui-theme.d.ts +0 -17
  125. package/dist/tui-theme.d.ts.map +0 -1
  126. package/dist/tui-theme.js +0 -19
  127. package/dist/tui-theme.js.map +0 -1
  128. package/dist/tui.d.ts +0 -24
  129. package/dist/tui.d.ts.map +0 -1
  130. package/dist/tui.js +0 -784
  131. package/dist/tui.js.map +0 -1
  132. package/dist/update.d.ts +0 -16
  133. package/dist/update.d.ts.map +0 -1
  134. package/dist/update.js +0 -67
  135. package/dist/update.js.map +0 -1
  136. package/dist/web-console.d.ts +0 -33
  137. package/dist/web-console.d.ts.map +0 -1
  138. package/dist/web-console.js +0 -242
  139. package/dist/web-console.js.map +0 -1
  140. package/dist/welcome.d.ts +0 -30
  141. package/dist/welcome.d.ts.map +0 -1
  142. package/dist/welcome.js +0 -69
  143. package/dist/welcome.js.map +0 -1
  144. package/node_modules/goah-ledger-contract/dist/execution.d.ts +0 -544
  145. package/node_modules/goah-ledger-contract/dist/execution.d.ts.map +0 -1
  146. package/node_modules/goah-ledger-contract/dist/execution.js +0 -52
  147. package/node_modules/goah-ledger-contract/dist/execution.js.map +0 -1
  148. package/node_modules/goah-ledger-contract/dist/index.d.ts +0 -4
  149. package/node_modules/goah-ledger-contract/dist/index.d.ts.map +0 -1
  150. package/node_modules/goah-ledger-contract/dist/index.js +0 -4
  151. package/node_modules/goah-ledger-contract/dist/index.js.map +0 -1
  152. package/node_modules/goah-ledger-contract/dist/kernel.d.ts +0 -37
  153. package/node_modules/goah-ledger-contract/dist/kernel.d.ts.map +0 -1
  154. package/node_modules/goah-ledger-contract/dist/kernel.js +0 -8
  155. package/node_modules/goah-ledger-contract/dist/kernel.js.map +0 -1
  156. package/node_modules/goah-ledger-contract/dist/transcript.d.ts +0 -63
  157. package/node_modules/goah-ledger-contract/dist/transcript.d.ts.map +0 -1
  158. package/node_modules/goah-ledger-contract/dist/transcript.js +0 -115
  159. package/node_modules/goah-ledger-contract/dist/transcript.js.map +0 -1
  160. package/node_modules/goah-ledger-contract/package.json +0 -28
  161. package/node_modules/goah-ledger-sqlite/dist/index.d.ts +0 -86
  162. package/node_modules/goah-ledger-sqlite/dist/index.d.ts.map +0 -1
  163. package/node_modules/goah-ledger-sqlite/dist/index.js +0 -1254
  164. package/node_modules/goah-ledger-sqlite/dist/index.js.map +0 -1
  165. package/node_modules/goah-ledger-sqlite/package.json +0 -26
  166. package/node_modules/goah-runner-pi/dist/configurator.d.ts +0 -20
  167. package/node_modules/goah-runner-pi/dist/configurator.d.ts.map +0 -1
  168. package/node_modules/goah-runner-pi/dist/configurator.js +0 -423
  169. package/node_modules/goah-runner-pi/dist/configurator.js.map +0 -1
  170. package/node_modules/goah-runner-pi/dist/credential-store.d.ts +0 -14
  171. package/node_modules/goah-runner-pi/dist/credential-store.d.ts.map +0 -1
  172. package/node_modules/goah-runner-pi/dist/credential-store.js +0 -163
  173. package/node_modules/goah-runner-pi/dist/credential-store.js.map +0 -1
  174. package/node_modules/goah-runner-pi/dist/env-spec.d.ts +0 -17
  175. package/node_modules/goah-runner-pi/dist/env-spec.d.ts.map +0 -1
  176. package/node_modules/goah-runner-pi/dist/env-spec.js +0 -95
  177. package/node_modules/goah-runner-pi/dist/env-spec.js.map +0 -1
  178. package/node_modules/goah-runner-pi/dist/index.d.ts +0 -76
  179. package/node_modules/goah-runner-pi/dist/index.d.ts.map +0 -1
  180. package/node_modules/goah-runner-pi/dist/index.js +0 -326
  181. package/node_modules/goah-runner-pi/dist/index.js.map +0 -1
  182. package/node_modules/goah-runner-pi/dist/model-provider.d.ts +0 -30
  183. package/node_modules/goah-runner-pi/dist/model-provider.d.ts.map +0 -1
  184. package/node_modules/goah-runner-pi/dist/model-provider.js +0 -96
  185. package/node_modules/goah-runner-pi/dist/model-provider.js.map +0 -1
  186. package/node_modules/goah-runner-pi/dist/pi-worker.d.ts +0 -31
  187. package/node_modules/goah-runner-pi/dist/pi-worker.d.ts.map +0 -1
  188. package/node_modules/goah-runner-pi/dist/pi-worker.js +0 -579
  189. package/node_modules/goah-runner-pi/dist/pi-worker.js.map +0 -1
  190. package/node_modules/goah-runner-pi/dist/steering-no-ack.test-fixture.d.ts +0 -2
  191. package/node_modules/goah-runner-pi/dist/steering-no-ack.test-fixture.d.ts.map +0 -1
  192. package/node_modules/goah-runner-pi/dist/steering-no-ack.test-fixture.js +0 -3
  193. package/node_modules/goah-runner-pi/dist/steering-no-ack.test-fixture.js.map +0 -1
  194. package/node_modules/goah-runner-pi/dist/steering-reject.test-fixture.d.ts +0 -2
  195. package/node_modules/goah-runner-pi/dist/steering-reject.test-fixture.d.ts.map +0 -1
  196. package/node_modules/goah-runner-pi/dist/steering-reject.test-fixture.js +0 -5
  197. package/node_modules/goah-runner-pi/dist/steering-reject.test-fixture.js.map +0 -1
  198. package/node_modules/goah-runner-pi/dist/steering-worker.test-fixture.d.ts +0 -2
  199. package/node_modules/goah-runner-pi/dist/steering-worker.test-fixture.d.ts.map +0 -1
  200. package/node_modules/goah-runner-pi/dist/steering-worker.test-fixture.js +0 -5
  201. package/node_modules/goah-runner-pi/dist/steering-worker.test-fixture.js.map +0 -1
  202. package/node_modules/goah-runner-pi/dist/test-helpers.d.ts +0 -4
  203. package/node_modules/goah-runner-pi/dist/test-helpers.d.ts.map +0 -1
  204. package/node_modules/goah-runner-pi/dist/test-helpers.js +0 -13
  205. package/node_modules/goah-runner-pi/dist/test-helpers.js.map +0 -1
  206. package/node_modules/goah-runner-pi/dist/verification-worker.d.ts +0 -2
  207. package/node_modules/goah-runner-pi/dist/verification-worker.d.ts.map +0 -1
  208. package/node_modules/goah-runner-pi/dist/verification-worker.js +0 -46
  209. package/node_modules/goah-runner-pi/dist/verification-worker.js.map +0 -1
  210. package/node_modules/goah-runner-pi/package.json +0 -28
  211. package/node_modules/goah-supervisor/dist/context-view.d.ts +0 -30
  212. package/node_modules/goah-supervisor/dist/context-view.d.ts.map +0 -1
  213. package/node_modules/goah-supervisor/dist/context-view.js +0 -58
  214. package/node_modules/goah-supervisor/dist/context-view.js.map +0 -1
  215. package/node_modules/goah-supervisor/dist/index.d.ts +0 -96
  216. package/node_modules/goah-supervisor/dist/index.d.ts.map +0 -1
  217. package/node_modules/goah-supervisor/dist/index.js +0 -1075
  218. package/node_modules/goah-supervisor/dist/index.js.map +0 -1
  219. package/node_modules/goah-supervisor/dist/roles.d.ts +0 -4
  220. package/node_modules/goah-supervisor/dist/roles.d.ts.map +0 -1
  221. package/node_modules/goah-supervisor/dist/roles.js +0 -29
  222. package/node_modules/goah-supervisor/dist/roles.js.map +0 -1
  223. package/node_modules/goah-supervisor/dist/verification.d.ts +0 -61
  224. package/node_modules/goah-supervisor/dist/verification.d.ts.map +0 -1
  225. package/node_modules/goah-supervisor/dist/verification.js +0 -135
  226. package/node_modules/goah-supervisor/dist/verification.js.map +0 -1
  227. package/node_modules/goah-supervisor/package.json +0 -26
  228. package/node_modules/goah-testkit/dist/faux-runner-worker.d.ts +0 -2
  229. package/node_modules/goah-testkit/dist/faux-runner-worker.d.ts.map +0 -1
  230. package/node_modules/goah-testkit/dist/faux-runner-worker.js +0 -82
  231. package/node_modules/goah-testkit/dist/faux-runner-worker.js.map +0 -1
  232. package/node_modules/goah-testkit/dist/index.d.ts +0 -49
  233. package/node_modules/goah-testkit/dist/index.d.ts.map +0 -1
  234. package/node_modules/goah-testkit/dist/index.js +0 -96
  235. package/node_modules/goah-testkit/dist/index.js.map +0 -1
  236. package/node_modules/goah-testkit/package.json +0 -29
package/dist/index.js CHANGED
@@ -1,385 +1,84 @@
1
- import { accessSync, chmodSync, constants, existsSync, mkdirSync, openSync, closeSync, readFileSync, renameSync, rmSync, statSync, writeFileSync } from "node:fs";
2
- import { createHash, randomUUID } from "node:crypto";
3
- import { homedir } from "node:os";
4
- import { dirname, isAbsolute, join, resolve } from "node:path";
5
- import { DatabaseSync } from "node:sqlite";
6
- import { CONTRACT_VERSION } from "goah-ledger-contract";
7
- import { SQLITE_SCHEMA_VERSION, SqliteLedger } from "goah-ledger-sqlite";
8
- import { createPiModel, piWorkerPath, ProcessRunner, resolveEnvSpec } from "goah-runner-pi";
9
- import { RunnerRouter, Supervisor } from "goah-supervisor";
10
- import { runnerPlugin } from "./runner-registry.js";
11
- const configRoots = new WeakMap();
12
- export function loadConfig(path = "goah.config.json") {
13
- recoverProfileTransaction();
14
- const absolute = resolve(path);
15
- const config = JSON.parse(readFileSync(absolute, "utf8"));
16
- if (config.version !== 1 && config.version !== 2)
17
- throw new Error(`unsupported goah config version: ${String(config.version)}`);
18
- const base = dirname(absolute);
19
- const root = config.workspace ? absolutePath(base, config.workspace) : base;
20
- delete config.workspace;
21
- delete config.limits;
22
- delete config.heartbeatPolicies;
23
- delete config.progressPolicies;
24
- configRoots.set(config, root);
25
- config.stateDir = absolutePath(base, config.stateDir);
26
- if (config.runner) {
27
- config.runner.command = resolveCommand(config.runner.command);
28
- config.runner.args = config.runner.args.map((arg) => arg === "$GOAH_PI_WORKER" ? piWorkerPath() : arg);
29
- }
30
- if (!config.runnerProfiles?.length && config.runner?.env?.GOAH_PI_PROVIDER && config.runner.env.GOAH_PI_MODEL) {
31
- const env = config.runner.env;
32
- const provider = env.GOAH_PI_PROVIDER;
33
- const model = env.GOAH_PI_MODEL;
34
- const keyRef = Object.entries(env).find(([key, value]) => key.endsWith("API_KEY") && value.startsWith("env:"));
35
- config.runnerProfiles = [{ id: "default", runner: "pi", config: { provider, model, ...(keyRef ? { apiKeyEnv: keyRef[1].slice(4) } : {}), ...(env.GOAH_PI_BASE_URL ? { baseUrl: env.GOAH_PI_BASE_URL } : {}) } }];
36
- if (config.profiles)
37
- config.profiles = config.profiles.map((profile) => ({ ...profile, runnerProfile: profile.runnerProfile ?? "default" }));
38
- }
39
- return config;
40
- }
41
- export function createRuntime(config) {
42
- mkdirSync(config.stateDir, { recursive: true });
43
- const ledger = new SqliteLedger(join(config.stateDir, "ledger.sqlite"));
44
- const runner = config.runnerProfiles?.length
45
- ? new RunnerRouter(new Map(config.runnerProfiles.map((profile) => [profile.id, runnerPlugin(profile.runner).create(profile.config, configRoot(config))])))
46
- : legacyRunner(config);
47
- const supervisor = new Supervisor(ledger, runner, new class {
48
- now() { return new Date(); }
49
- }(), {
50
- ...(config.profiles ? { profiles: config.profiles } : {}),
51
- ...(config.runnerProfiles ? { runnerProfiles: config.runnerProfiles } : {}),
52
- ...(config.retryPolicy ? { retryPolicy: config.retryPolicy } : {}),
53
- });
54
- return { ledger, supervisor };
55
- }
56
- export function defaultConfig(directory, options = {}) {
57
- const provider = options.provider ?? "faux";
58
- const model = options.model ?? defaultModel(provider);
59
- const runnerProfile = { id: "default", runner: "pi", config: { provider, model, thinking: "medium", ...(options.apiKeyEnv ? { apiKeyEnv: options.apiKeyEnv } : {}), ...(options.baseUrl ? { baseUrl: options.baseUrl } : {}), ...(options.contextWindowTokens ? { contextWindowTokens: options.contextWindowTokens } : {}), ...(options.maxOutputTokensPerTurn ? { maxOutputTokens: options.maxOutputTokensPerTurn } : {}) } };
60
- return {
61
- version: 2,
62
- stateDir: defaultStateDir(directory),
63
- runnerProfiles: [runnerProfile],
64
- profiles: [{ agent: "ceo", role: "ceo", runnerProfile: "default" }, { agent: options.agent ?? "worker", role: "child", runnerProfile: "default" }],
65
- };
66
- }
67
- export class SupervisorLock {
68
- path;
69
- #owned = false;
70
- constructor(stateDir) { this.path = join(stateDir, "supervisor.lock"); }
71
- acquire() {
72
- mkdirSync(dirname(this.path), { recursive: true });
73
- if (existsSync(this.path)) {
74
- const pid = Number(readFileSync(this.path, "utf8"));
75
- if (Number.isInteger(pid) && alive(pid))
76
- throw new Error(`supervisor already running with pid ${pid}`);
77
- rmSync(this.path);
78
- }
79
- const fd = openSync(this.path, "wx");
80
- writeFileSync(fd, String(process.pid));
81
- closeSync(fd);
82
- this.#owned = true;
83
- }
84
- release() { if (this.#owned) {
85
- rmSync(this.path, { force: true });
86
- this.#owned = false;
87
- } }
88
- }
89
- export function writeDefaultConfig(path = "goah.config.json", options = {}, overwrite = false) {
90
- const absolute = resolve(path);
91
- if (existsSync(absolute) && !overwrite)
92
- throw new Error(`${absolute} already exists`);
93
- writeFileSync(absolute, `${JSON.stringify(defaultConfig(dirname(absolute), options), null, 2)}\n`);
94
- }
95
- export function profilePath() { return join(process.env.GOAH_STATE_HOME ?? join(homedir(), ".goah"), "profile.json"); }
96
- export function readDefaultRunnerProfile() {
97
- recoverProfileTransaction();
98
- try {
99
- const raw = JSON.parse(readFileSync(profilePath(), "utf8"));
100
- if (typeof raw.id === "string" && typeof raw.runner === "string" && raw.config && typeof raw.config === "object")
101
- return raw;
102
- if (typeof raw.provider === "string" && typeof raw.model === "string") {
103
- const { provider, model, apiKeyEnv, baseUrl, contextWindowTokens, maxOutputTokensPerTurn } = raw;
104
- return { id: "default", runner: "pi", config: { provider, model, ...(typeof apiKeyEnv === "string" ? { apiKeyEnv } : {}), ...(typeof baseUrl === "string" ? { baseUrl } : {}), ...(typeof contextWindowTokens === "number" ? { contextWindowTokens } : {}), ...(typeof maxOutputTokensPerTurn === "number" ? { maxOutputTokens: maxOutputTokensPerTurn } : {}) } };
105
- }
106
- return null;
107
- }
108
- catch {
109
- return null;
110
- }
111
- }
112
- export function writeDefaultRunnerProfile(profile) {
113
- withProfileLock(() => { recoverProfileTransactionUnlocked(); writeDefaultRunnerProfileUnlocked(profile); });
114
- }
115
- function writeDefaultRunnerProfileUnlocked(profile) {
116
- mkdirSync(dirname(profilePath()), { recursive: true });
117
- const temporary = `${profilePath()}.${process.pid}.tmp`;
118
- writeFileSync(temporary, `${JSON.stringify(profile, null, 2)}\n`, { mode: 0o600 });
119
- renameSync(temporary, profilePath());
120
- chmodSync(profilePath(), 0o600);
121
- }
122
- export function updateWorkspaceRunnerProfile(path, profile) {
123
- withProfileLock(() => { recoverProfileTransactionUnlocked(); updateWorkspaceRunnerProfileUnlocked(path, profile); });
124
- }
125
- function updateWorkspaceRunnerProfileUnlocked(path, profile) {
126
- const absolute = resolve(path);
127
- const current = existsSync(absolute) ? JSON.parse(readFileSync(absolute, "utf8")) : defaultConfig(dirname(absolute));
128
- current.runnerProfiles = [...(current.runnerProfiles ?? []).filter((item) => item.id !== profile.id), profile];
129
- current.profiles = (current.profiles ?? [{ agent: "ceo", role: "ceo" }, { agent: "worker", role: "child" }]).map((agent) => ({ ...agent, runnerProfile: agent.runnerProfile ?? profile.id }));
130
- const temporary = `${absolute}.${process.pid}.tmp`;
131
- writeFileSync(temporary, `${JSON.stringify(current, null, 2)}\n`);
132
- renameSync(temporary, absolute);
133
- }
134
- /** Persist default + workspace profile with a crash-recoverable rollback journal. */
135
- export function persistRunnerProfile(profile, workspacePath) {
136
- withProfileLock(() => {
137
- recoverProfileTransactionUnlocked();
138
- const targets = [profilePath(), ...(workspacePath ? [resolve(workspacePath)] : [])];
139
- const before = targets.map((path) => ({ path, content: existsSync(path) ? readFileSync(path) : null }));
140
- writeProfileTransaction(before);
141
- try {
142
- writeDefaultRunnerProfileUnlocked(profile);
143
- if (workspacePath)
144
- updateWorkspaceRunnerProfileUnlocked(workspacePath, profile);
145
- rmSync(profileTransactionPath(), { force: true });
146
- }
147
- catch (error) {
148
- restoreProfileSnapshots(before);
149
- rmSync(profileTransactionPath(), { force: true });
150
- throw error;
151
- }
152
- });
153
- }
154
- function withProfileLock(operation) {
155
- const lock = `${profilePath()}.lock`;
156
- const ownerPath = join(lock, "owner.json");
157
- const token = randomUUID();
158
- mkdirSync(dirname(lock), { recursive: true });
159
- acquireProfileLock(lock, ownerPath, token);
160
- try {
161
- return operation();
162
- }
163
- finally {
164
- if (readProfileLockOwner(ownerPath)?.token === token)
165
- rmSync(lock, { recursive: true, force: true });
166
- }
167
- }
168
- function acquireProfileLock(lock, ownerPath, token) {
169
- while (true) {
170
- try {
171
- mkdirSync(lock);
172
- try {
173
- writeFileSync(ownerPath, JSON.stringify({ pid: process.pid, token }), { mode: 0o600 });
174
- }
175
- catch (error) {
176
- rmSync(lock, { recursive: true, force: true });
177
- throw error;
178
- }
179
- return;
180
- }
181
- catch (error) {
182
- if (error.code !== "EEXIST")
183
- throw error;
184
- }
185
- const owner = readProfileLockOwner(ownerPath);
186
- let oldUnownedLock = false;
187
- try {
188
- oldUnownedLock = !owner && Date.now() - statSync(lock).mtimeMs > 5_000;
189
- }
190
- catch (error) {
191
- if (error.code === "ENOENT")
192
- continue;
193
- throw error;
194
- }
195
- if (owner && processIsAlive(owner.pid) || !owner && !oldUnownedLock)
196
- throw new Error("Another Goah process is updating Runner Profiles; try again.");
197
- const stale = `${lock}.stale.${token}`;
198
- try {
199
- renameSync(lock, stale);
200
- rmSync(stale, { recursive: true, force: true });
201
- }
202
- catch (error) {
203
- if (error.code !== "ENOENT")
204
- throw error;
205
- }
206
- }
207
- }
208
- function profileTransactionPath() { return join(dirname(profilePath()), "profile-transaction.json"); }
209
- function writeProfileTransaction(snapshots) {
210
- const path = profileTransactionPath();
211
- const temporary = `${path}.${process.pid}.tmp`;
212
- mkdirSync(dirname(path), { recursive: true });
213
- writeFileSync(temporary, `${JSON.stringify({ version: 1, snapshots: snapshots.map((snapshot) => ({ path: snapshot.path, content: snapshot.content?.toString("base64") ?? null })) })}\n`, { mode: 0o600 });
214
- renameSync(temporary, path);
215
- chmodSync(path, 0o600);
216
- }
217
- function restoreProfileSnapshots(snapshots) {
218
- for (const snapshot of snapshots) {
219
- if (snapshot.content === null)
220
- rmSync(snapshot.path, { force: true });
221
- else {
222
- mkdirSync(dirname(snapshot.path), { recursive: true });
223
- const temporary = `${snapshot.path}.${process.pid}.rollback.tmp`;
224
- writeFileSync(temporary, snapshot.content, snapshot.path === profilePath() ? { mode: 0o600 } : undefined);
225
- renameSync(temporary, snapshot.path);
226
- if (snapshot.path === profilePath())
227
- chmodSync(snapshot.path, 0o600);
228
- }
229
- }
230
- }
231
- function recoverProfileTransaction() { if (existsSync(profileTransactionPath()))
232
- withProfileLock(recoverProfileTransactionUnlocked); }
233
- function recoverProfileTransactionUnlocked() {
234
- const path = profileTransactionPath();
235
- if (!existsSync(path))
236
- return;
237
- const value = JSON.parse(readFileSync(path, "utf8"));
238
- if (value.version !== 1 || !Array.isArray(value.snapshots))
239
- throw new Error("Goah Runner Profile transaction journal is invalid");
240
- const snapshots = value.snapshots.map((snapshot) => {
241
- if (typeof snapshot.path !== "string" || snapshot.content !== null && typeof snapshot.content !== "string")
242
- throw new Error("Goah Runner Profile transaction journal is invalid");
243
- return { path: snapshot.path, content: snapshot.content === null ? null : Buffer.from(snapshot.content, "base64") };
244
- });
245
- restoreProfileSnapshots(snapshots);
246
- rmSync(path, { force: true });
247
- }
248
- function readProfileLockOwner(path) {
249
- try {
250
- const value = JSON.parse(readFileSync(path, "utf8"));
251
- return Number.isInteger(value.pid) && Number(value.pid) > 0 && typeof value.token === "string" ? value : null;
252
- }
253
- catch (error) {
254
- if (error.code === "ENOENT" || error instanceof SyntaxError)
255
- return null;
256
- throw error;
257
- }
258
- }
259
- function processIsAlive(pid) { try {
260
- process.kill(pid, 0);
261
- return true;
262
- }
263
- catch (error) {
264
- return error.code === "EPERM";
265
- } }
266
- export function diagnoseConfig(config) {
267
- const checks = [];
268
- const check = (name, fn) => {
269
- try {
270
- checks.push({ name, ok: true, detail: fn() });
271
- }
272
- catch (error) {
273
- checks.push({ name, ok: false, detail: error instanceof Error ? error.message : String(error) });
274
- }
275
- };
276
- check("node", () => {
277
- if (Number(process.versions.node.split(".")[0]) < 24)
278
- throw new Error(`Node ${process.versions.node} is unsupported; require >=24`);
279
- return process.versions.node;
280
- });
281
- check("root", () => {
282
- const root = configRoot(config);
283
- accessSync(root, constants.R_OK | constants.W_OK);
284
- return `${root} (runner-owned local execution)`;
285
- });
286
- check("state", () => {
287
- const existing = nearestExisting(config.stateDir);
288
- accessSync(existing, constants.W_OK);
289
- const database = join(config.stateDir, "ledger.sqlite");
290
- if (!existsSync(database))
291
- return `${config.stateDir} (will create)`;
292
- const db = new DatabaseSync(database, { readOnly: true });
293
- try {
294
- const version = db.prepare("PRAGMA user_version").get().user_version;
295
- if (version > SQLITE_SCHEMA_VERSION)
296
- throw new Error(`ledger schema ${version} is newer than supported schema ${SQLITE_SCHEMA_VERSION}`);
297
- if (version > 0 && version < SQLITE_SCHEMA_VERSION)
298
- throw new Error(`ledger schema ${version} predates runtime schema ${SQLITE_SCHEMA_VERSION}; recreate this development workspace`);
299
- return `${database} (schema ${version})`;
300
- }
301
- finally {
302
- db.close();
303
- }
304
- });
305
- check("runner", () => {
306
- if (config.runnerProfiles?.length) {
307
- for (const profile of config.runnerProfiles)
308
- runnerPlugin(profile.runner);
309
- return config.runnerProfiles.map((profile) => `${profile.id}:${profile.runner}`).join(", ");
310
- }
311
- if (!config.runner)
312
- throw new Error("no runner is configured");
313
- accessSync(config.runner.command, constants.X_OK);
314
- const workerArg = config.runner.args[0];
315
- if (workerArg && isAbsolute(workerArg))
316
- accessSync(workerArg, constants.R_OK);
317
- const env = resolveEnvSpec(config.runner.env, { root: configRoot(config) });
318
- const provider = requiredEnv(env, "GOAH_PI_PROVIDER");
319
- const modelId = requiredEnv(env, "GOAH_PI_MODEL");
320
- const model = createPiModel(provider, modelId, env).model;
321
- return `${provider}/${modelId} context=${model.contextWindow} output=${model.maxTokens}; auth is checked when the wake starts`;
322
- });
323
- return { ok: checks.every((item) => item.ok || item.severity === "warning"), checks };
324
- }
325
- export function statusSnapshot(ledger) {
326
- const events = ledger.events();
327
- const wakes = ledger.wakes().map((wake) => {
328
- const turn = wake.turnId ? ledger.turn(wake.turnId) : null;
329
- const turnEvents = turn ? ledger.readStream(`turn:${turn.id}`) : [];
330
- const tokensUsed = turnEvents.reduce((total, event) => total + assistantTokens(event.data), 0);
331
- return { ...wake, tokensUsed, abnormalReason: turn?.status === "failed" ? field(turn.error, "message") : null };
332
- });
333
- const goals = ledger.goals();
334
- const handoffs = events.filter((event) => event.type === "handoff.recorded").slice(-20).map((event) => ({ seq: event.seq, ts: event.ts, agent: event.actor, streamId: event.streamId, handoff: event.data }));
335
- const modelCapabilitiesByAgent = Object.fromEntries(ledger.threads().flatMap((thread) => { const turnIds = new Set(ledger.turns(thread.id).map((turn) => turn.id)); const capability = [...events].reverse().find((event) => event.type === "transcript.started" && event.streamId.startsWith("turn:") && turnIds.has(event.streamId.slice("turn:".length)))?.data; return capability ? [[thread.agent, capability]] : []; }));
336
- const modelCapabilities = modelCapabilitiesByAgent.ceo ?? [...events].reverse().find((event) => event.type === "transcript.started")?.data ?? null;
337
- return { seq: events.at(-1)?.seq ?? 0, threads: ledger.threads(), turns: ledger.turns().map((turn) => ({ ...turn, leaseToken: null })), goals, wakes, wakeTriggers: wakes.flatMap((wake) => ledger.wakeTriggers(wake.id)), schedules: ledger.schedules(), modelCapabilities, modelCapabilitiesByAgent, recentHandoffs: handoffs };
338
- }
339
- function defaultModel(provider) {
340
- if (provider === "faux")
341
- return "faux-goah";
342
- throw new Error(`--model is required for ${provider}; interactive setup discovers models through the selected Runner.`);
343
- }
344
- function legacyRunner(config) {
345
- if (!config.runner)
346
- throw new Error("no runner profiles are configured");
347
- const { env, ...spec } = config.runner;
348
- return new ProcessRunner({ ...spec, envSpec: env, cwd: configRoot(config) });
349
- }
350
- function requiredEnv(env, name) { const value = env[name]; if (!value)
351
- throw new Error(`${name} is missing`); return value; }
352
- function nearestExisting(path) { let current = resolve(path); while (!existsSync(current)) {
353
- const parent = dirname(current);
354
- if (parent === current)
355
- break;
356
- current = parent;
357
- } return current; }
358
- function defaultStateDir(directory) {
359
- const id = createHash("sha256").update(resolve(directory)).digest("hex").slice(0, 16);
360
- return join(process.env.GOAH_STATE_HOME ?? join(homedir(), ".goah", "state"), id);
361
- }
362
- function field(value, key) { return typeof value === "object" && value !== null && !Array.isArray(value) ? value[key] : undefined; }
363
- function assistantTokens(value) {
364
- const message = field(value, "message");
365
- if (field(message, "role") !== "assistant")
366
- return 0;
367
- const usage = field(message, "usage");
368
- const total = field(usage, "totalTokens");
369
- return typeof total === "number" ? total : 0;
370
- }
371
- function resolveCommand(command) { return command === "$NODE" ? process.execPath : command; }
372
- function absolutePath(base, value) { return isAbsolute(value) ? value : resolve(base, value); }
373
- function alive(pid) { try {
374
- process.kill(pid, 0);
375
- return true;
376
- }
377
- catch {
378
- return false;
379
- } }
380
- export function configRoot(config) { return configRoots.get(config) ?? process.cwd(); }
381
- export { exportThread, listThreads, redactValue, replayThread, showThread, showTurnContext, streamEvents } from "./thread-inspect.js";
382
- export { controlAvailable, controlEndpoint, requestControl, runControlServer, streamControl } from "./control.js";
383
- export { consoleMetadataPath, consoleSnapshot, organizationTrajectory, readConsoleMetadata, runWebConsole } from "./web-console.js";
384
- export { CONTRACT_VERSION };
385
- //# sourceMappingURL=index.js.map
1
+ import { createRequire as __goahCreateRequire } from "node:module";
2
+ const require = __goahCreateRequire(import.meta.url);
3
+ import {
4
+ SupervisorLock,
5
+ configRoot,
6
+ consoleMetadataPath,
7
+ consoleSnapshot,
8
+ controlAvailable,
9
+ controlEndpoint,
10
+ createRuntime,
11
+ defaultConfig,
12
+ diagnoseConfig,
13
+ exportThread,
14
+ listThreads,
15
+ loadConfig,
16
+ organizationTrajectory,
17
+ persistRunnerProfile,
18
+ profilePath,
19
+ readConsoleMetadata,
20
+ readDefaultRunnerProfile,
21
+ redactValue,
22
+ replayThread,
23
+ requestControl,
24
+ runControlServer,
25
+ runWebConsole,
26
+ showThread,
27
+ showTurnContext,
28
+ statusSnapshot,
29
+ streamControl,
30
+ streamEvents,
31
+ updateWorkspaceRunnerProfile,
32
+ writeDefaultConfig,
33
+ writeDefaultRunnerProfile
34
+ } from "./chunk-KJ4HJCTK.js";
35
+ import "./chunk-D2DVAH37.js";
36
+ import "./chunk-YH6YJ2IB.js";
37
+ import "./chunk-QBD6EJ2Z.js";
38
+ import "./chunk-7E7V6OIU.js";
39
+ import "./chunk-6M3OOCKO.js";
40
+ import "./chunk-K26BVR6O.js";
41
+ import "./chunk-IIJQ3DW4.js";
42
+ import "./chunk-2ZP2NBW3.js";
43
+ import "./chunk-MPXK7QBL.js";
44
+ import "./chunk-2QBQZGXF.js";
45
+ import "./chunk-4KA63VNZ.js";
46
+ import {
47
+ CONTRACT_VERSION
48
+ } from "./chunk-KAO7WIXG.js";
49
+ import "./chunk-R6I3VKME.js";
50
+ import "./chunk-TJON22J4.js";
51
+ import "./chunk-XPQKM3L7.js";
52
+ export {
53
+ CONTRACT_VERSION,
54
+ SupervisorLock,
55
+ configRoot,
56
+ consoleMetadataPath,
57
+ consoleSnapshot,
58
+ controlAvailable,
59
+ controlEndpoint,
60
+ createRuntime,
61
+ defaultConfig,
62
+ diagnoseConfig,
63
+ exportThread,
64
+ listThreads,
65
+ loadConfig,
66
+ organizationTrajectory,
67
+ persistRunnerProfile,
68
+ profilePath,
69
+ readConsoleMetadata,
70
+ readDefaultRunnerProfile,
71
+ redactValue,
72
+ replayThread,
73
+ requestControl,
74
+ runControlServer,
75
+ runWebConsole,
76
+ showThread,
77
+ showTurnContext,
78
+ statusSnapshot,
79
+ streamControl,
80
+ streamEvents,
81
+ updateWorkspaceRunnerProfile,
82
+ writeDefaultConfig,
83
+ writeDefaultRunnerProfile
84
+ };
package/dist/kernel.d.ts CHANGED
@@ -1,2 +1,39 @@
1
- export * from "goah-ledger-contract/kernel";
2
- //# sourceMappingURL=kernel.d.ts.map
1
+ declare const CONTRACT_VERSION: "0.13.0";
2
+ declare const CONTRACT_STABILITY: "experimental";
3
+ type JsonPrimitive = string | number | boolean | null;
4
+ type JsonValue = JsonPrimitive | JsonValue[] | {
5
+ [key: string]: JsonValue;
6
+ };
7
+ /** One append request. Sequence numbers are assigned by the ledger. */
8
+ interface EventInput {
9
+ streamId: string;
10
+ ts: string;
11
+ actor: string;
12
+ type: string;
13
+ data: JsonValue;
14
+ /** An unfamiliar reader may skip this event without changing replay semantics. */
15
+ ignorable?: true;
16
+ }
17
+ /** One immutable fact in the global ledger and in one logical stream. */
18
+ interface EventRecord extends EventInput {
19
+ seq: number;
20
+ streamSeq: number;
21
+ }
22
+ interface EventStore {
23
+ appendEvent(input: EventInput): EventRecord;
24
+ appendEvents(inputs: EventInput[]): EventRecord[];
25
+ readStream(streamId: string, fromStreamSeq?: number): EventRecord[];
26
+ eventsSince(seq: number, types?: string[]): EventRecord[];
27
+ events(): EventRecord[];
28
+ }
29
+ interface Clock {
30
+ now(): Date;
31
+ }
32
+ declare function wakeStream(wakeId: string): string;
33
+ declare function controlStream(actor?: string): string;
34
+ declare function goalStream(goalId: string): string;
35
+ declare function workRecordStream(goalId: string): string;
36
+ declare function memoryStream(agent: string): string;
37
+
38
+ export { CONTRACT_STABILITY, CONTRACT_VERSION, controlStream, goalStream, memoryStream, wakeStream, workRecordStream };
39
+ export type { Clock, EventInput, EventRecord, EventStore, JsonPrimitive, JsonValue };
package/dist/kernel.js CHANGED
@@ -1,2 +1,21 @@
1
- export * from "goah-ledger-contract/kernel";
2
- //# sourceMappingURL=kernel.js.map
1
+ import { createRequire as __goahCreateRequire } from "node:module";
2
+ const require = __goahCreateRequire(import.meta.url);
3
+ import {
4
+ CONTRACT_STABILITY,
5
+ CONTRACT_VERSION,
6
+ controlStream,
7
+ goalStream,
8
+ memoryStream,
9
+ wakeStream,
10
+ workRecordStream
11
+ } from "./chunk-KAO7WIXG.js";
12
+ import "./chunk-XPQKM3L7.js";
13
+ export {
14
+ CONTRACT_STABILITY,
15
+ CONTRACT_VERSION,
16
+ controlStream,
17
+ goalStream,
18
+ memoryStream,
19
+ wakeStream,
20
+ workRecordStream
21
+ };