@arcforge/platform 2.0.166

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 (207) hide show
  1. package/README.md +31 -0
  2. package/package.json +69 -0
  3. package/src/bin/supervisor.ts +102 -0
  4. package/src/bin/test-api.ts +30 -0
  5. package/src/bin/test-preload.ts +308 -0
  6. package/src/bin/update-helper.ts +32 -0
  7. package/src/build/bench/CLAUDE.md +106 -0
  8. package/src/build/bench/SPEC.md +209 -0
  9. package/src/build/bench/agents.ts +105 -0
  10. package/src/build/bench/axes.ts +84 -0
  11. package/src/build/bench/bench.ts +96 -0
  12. package/src/build/bench/discover.ts +147 -0
  13. package/src/build/bench/index.ts +7 -0
  14. package/src/build/bench/log.ts +47 -0
  15. package/src/build/bench/matrix.ts +23 -0
  16. package/src/build/bench/preload.ts +440 -0
  17. package/src/build/bench/prepare.ts +61 -0
  18. package/src/build/bench/projection.ts +112 -0
  19. package/src/build/bench/resolve.ts +54 -0
  20. package/src/build/bench/runner.ts +309 -0
  21. package/src/build/bench/schema/extract.ts +148 -0
  22. package/src/build/bench/schema/index.ts +2 -0
  23. package/src/build/bench/schema/schema.ts +95 -0
  24. package/src/build/bench/schema/worker.ts +30 -0
  25. package/src/build/bench/typegen.ts +119 -0
  26. package/src/build/bench/workspace/files.ts +139 -0
  27. package/src/build/bench/workspace/handle.ts +133 -0
  28. package/src/build/bench/workspace/index.ts +11 -0
  29. package/src/build/bench/workspace/workspace.ts +14 -0
  30. package/src/build/blueprint/blueprint.ts +398 -0
  31. package/src/build/blueprint/cognet/abi.ts +207 -0
  32. package/src/build/blueprint/cognet/bundle-worker.ts +93 -0
  33. package/src/build/blueprint/cognet/bundle.ts +664 -0
  34. package/src/build/blueprint/cognet/cognet.ts +249 -0
  35. package/src/build/blueprint/cognet/index.ts +10 -0
  36. package/src/build/blueprint/cognet/manifest.ts +38 -0
  37. package/src/build/blueprint/cognet/resolve.ts +113 -0
  38. package/src/build/blueprint/collisions.ts +51 -0
  39. package/src/build/blueprint/index.ts +29 -0
  40. package/src/build/blueprint/modules/entries.ts +117 -0
  41. package/src/build/blueprint/modules/index.ts +300 -0
  42. package/src/build/blueprint/modules/meta.ts +174 -0
  43. package/src/build/blueprint/scan/boot.ts +34 -0
  44. package/src/build/blueprint/scan/cognetImports.ts +56 -0
  45. package/src/build/blueprint/scan/components.ts +45 -0
  46. package/src/build/blueprint/scan/config.ts +234 -0
  47. package/src/build/blueprint/scan/configImports.ts +232 -0
  48. package/src/build/blueprint/scan/declare-worker.ts +61 -0
  49. package/src/build/blueprint/scan/declare.ts +393 -0
  50. package/src/build/blueprint/scan/h3-globals.ts +137 -0
  51. package/src/build/blueprint/scan/knowledge.ts +101 -0
  52. package/src/build/blueprint/scan/middleware.ts +110 -0
  53. package/src/build/blueprint/scan/moduleImports.ts +79 -0
  54. package/src/build/blueprint/scan/plugins.ts +93 -0
  55. package/src/build/blueprint/scan/promptPackages.ts +45 -0
  56. package/src/build/blueprint/scan/prompts.ts +164 -0
  57. package/src/build/blueprint/scan/published.ts +131 -0
  58. package/src/build/blueprint/scan/resolve.ts +398 -0
  59. package/src/build/blueprint/scan/routes.ts +109 -0
  60. package/src/build/blueprint/scan/scripts.ts +119 -0
  61. package/src/build/blueprint/scan/tool-bundle-worker.ts +69 -0
  62. package/src/build/blueprint/scan/tools.ts +610 -0
  63. package/src/build/blueprint/types.ts +28 -0
  64. package/src/build/extensions/config.ts +261 -0
  65. package/src/build/extensions/edit.ts +684 -0
  66. package/src/build/extensions/extensions.ts +731 -0
  67. package/src/build/extensions/index.ts +10 -0
  68. package/src/build/extensions/load.ts +350 -0
  69. package/src/build/extensions/registrations.ts +189 -0
  70. package/src/build/extensions/store.ts +200 -0
  71. package/src/build/frame/frame.ts +145 -0
  72. package/src/build/frame/index.ts +5 -0
  73. package/src/build/frame/migrate.ts +246 -0
  74. package/src/build/project/bundle/agent.ts +382 -0
  75. package/src/build/project/bundle/artifacts.ts +88 -0
  76. package/src/build/project/bundle/assets.ts +385 -0
  77. package/src/build/project/bundle/bundle.ts +160 -0
  78. package/src/build/project/bundle/imports.ts +102 -0
  79. package/src/build/project/bundle/index.ts +16 -0
  80. package/src/build/project/bundle/module.ts +130 -0
  81. package/src/build/project/bundle/source.ts +136 -0
  82. package/src/build/project/bundle/stage.ts +97 -0
  83. package/src/build/project/bundle/types.ts +111 -0
  84. package/src/build/project/cognet.ts +156 -0
  85. package/src/build/project/create/agent.ts +52 -0
  86. package/src/build/project/create/bench.ts +81 -0
  87. package/src/build/project/create/cognet.ts +102 -0
  88. package/src/build/project/create/extension.ts +63 -0
  89. package/src/build/project/create/module.ts +43 -0
  90. package/src/build/project/create/profile.ts +102 -0
  91. package/src/build/project/create/prompt.ts +68 -0
  92. package/src/build/project/create/templates.ts +88 -0
  93. package/src/build/project/deploy.ts +96 -0
  94. package/src/build/project/index.ts +40 -0
  95. package/src/build/project/installer.ts +616 -0
  96. package/src/build/project/kinds.ts +374 -0
  97. package/src/build/project/links.ts +33 -0
  98. package/src/build/project/manifest/bunfig.ts +139 -0
  99. package/src/build/project/manifest/config.ts +246 -0
  100. package/src/build/project/manifest/env.ts +184 -0
  101. package/src/build/project/manifest/index.ts +9 -0
  102. package/src/build/project/manifest/manifest.ts +49 -0
  103. package/src/build/project/manifest/model.ts +124 -0
  104. package/src/build/project/manifest/package.ts +386 -0
  105. package/src/build/project/manifest/text.ts +19 -0
  106. package/src/build/project/models/fetch.ts +123 -0
  107. package/src/build/project/models/index.ts +8 -0
  108. package/src/build/project/models/models.ts +111 -0
  109. package/src/build/project/models/specifier.ts +106 -0
  110. package/src/build/project/models/store.ts +202 -0
  111. package/src/build/project/modules/hash.ts +31 -0
  112. package/src/build/project/modules/index.ts +5 -0
  113. package/src/build/project/modules/lock.ts +78 -0
  114. package/src/build/project/modules/modules.ts +155 -0
  115. package/src/build/project/prepare.ts +709 -0
  116. package/src/build/project/project.ts +253 -0
  117. package/src/build/project/projects.ts +164 -0
  118. package/src/build/project/propagation.ts +120 -0
  119. package/src/build/project/publish/verify.ts +312 -0
  120. package/src/build/project/publish.ts +155 -0
  121. package/src/build/project/reconcile.ts +93 -0
  122. package/src/build/project/specifier.ts +42 -0
  123. package/src/build/project/tree.ts +615 -0
  124. package/src/build/project/treecache.ts +356 -0
  125. package/src/build/project/typegen/axon-dts.ts +362 -0
  126. package/src/build/project/typegen/cognet-dts.ts +91 -0
  127. package/src/build/project/typegen/components.ts +45 -0
  128. package/src/build/project/typegen/env.ts +59 -0
  129. package/src/build/project/typegen/generators.ts +108 -0
  130. package/src/build/project/typegen/hooks.ts +71 -0
  131. package/src/build/project/typegen/index.ts +137 -0
  132. package/src/build/project/typegen/prompt-dts.ts +40 -0
  133. package/src/build/project/typegen/prompts.ts +36 -0
  134. package/src/build/project/typegen/registry-dts.ts +109 -0
  135. package/src/build/project/typegen/scripts.ts +37 -0
  136. package/src/build/project/typegen/tools.ts +31 -0
  137. package/src/build/project/typegen/tsconfig.ts +243 -0
  138. package/src/build/project/typegen/tui-dts.ts +120 -0
  139. package/src/build/project/typegen/write.ts +40 -0
  140. package/src/build/project/verify.ts +268 -0
  141. package/src/build/project/watcher.ts +266 -0
  142. package/src/build/runtime/agent.ts +550 -0
  143. package/src/build/runtime/escalations.ts +159 -0
  144. package/src/build/runtime/index.ts +15 -0
  145. package/src/build/runtime/instances.ts +604 -0
  146. package/src/build/runtime/profile.ts +91 -0
  147. package/src/build/runtime/progress.ts +143 -0
  148. package/src/build/runtime/requests.ts +167 -0
  149. package/src/build/runtime/resolve.ts +159 -0
  150. package/src/build/runtime/runtime.ts +233 -0
  151. package/src/build/runtime/sessions/index.ts +5 -0
  152. package/src/build/runtime/sessions/record.ts +145 -0
  153. package/src/build/runtime/sessions/sessions.ts +240 -0
  154. package/src/build/runtime/zeno.ts +120 -0
  155. package/src/index.ts +11 -0
  156. package/src/link/agent-main.ts +395 -0
  157. package/src/link/index.ts +70 -0
  158. package/src/link/services.ts +120 -0
  159. package/src/platform.ts +293 -0
  160. package/src/procs/index.ts +15 -0
  161. package/src/procs/tree.ts +177 -0
  162. package/src/services/cloud.ts +419 -0
  163. package/src/services/control/client.ts +126 -0
  164. package/src/services/control/dispatch.ts +156 -0
  165. package/src/services/control/index.ts +17 -0
  166. package/src/services/control/protocol.ts +179 -0
  167. package/src/services/control/server.ts +241 -0
  168. package/src/services/deployments.ts +81 -0
  169. package/src/services/files.ts +329 -0
  170. package/src/services/index.ts +5 -0
  171. package/src/services/mic/capture.ts +248 -0
  172. package/src/services/mic/config.ts +109 -0
  173. package/src/services/mic/fft.ts +93 -0
  174. package/src/services/mic/index.ts +139 -0
  175. package/src/services/mic/visualizer.ts +46 -0
  176. package/src/services/ollama/catalog.ts +122 -0
  177. package/src/services/ollama/http.ts +124 -0
  178. package/src/services/ollama/index.ts +13 -0
  179. package/src/services/ollama/models.ts +153 -0
  180. package/src/services/ollama/ollama.ts +89 -0
  181. package/src/services/ollama/registry.ts +112 -0
  182. package/src/services/ollama/types.ts +72 -0
  183. package/src/services/prompts.ts +76 -0
  184. package/src/services/registry.ts +220 -0
  185. package/src/services/resources/hardware.ts +125 -0
  186. package/src/services/resources/index.ts +6 -0
  187. package/src/services/resources/reservations.ts +162 -0
  188. package/src/services/resources/resources.ts +156 -0
  189. package/src/services/running/index.ts +1 -0
  190. package/src/services/running/running.ts +200 -0
  191. package/src/services/store/disk.ts +97 -0
  192. package/src/services/store/index.ts +15 -0
  193. package/src/services/store/store.ts +729 -0
  194. package/src/services/store/types.ts +303 -0
  195. package/src/services/test/child.ts +150 -0
  196. package/src/services/test/events.ts +102 -0
  197. package/src/services/test/files.ts +26 -0
  198. package/src/services/test/frames.ts +39 -0
  199. package/src/services/test/index.ts +7 -0
  200. package/src/services/test/runner.ts +122 -0
  201. package/src/services/test/types.ts +26 -0
  202. package/src/services/update/contract.ts +77 -0
  203. package/src/services/update/index.ts +12 -0
  204. package/src/services/update/installer.ts +139 -0
  205. package/src/services/update/updates.ts +137 -0
  206. package/src/utils/fs.ts +148 -0
  207. package/src/utils/tsast.ts +102 -0
@@ -0,0 +1,71 @@
1
+ import { existsSync, readFileSync } from "node:fs"
2
+ import type { AxonModule } from "@arcforge/types"
3
+ import { writeDts } from "./write"
4
+
5
+ /**
6
+ * .agent/hooks.d.ts — AxonModuleEvents augmentation. Makes
7
+ * `axon.hooks.hook("discord:message.received", ({ content }) => ...)` fully
8
+ * typed in userland: the event name autocompletes and the payload is inferred,
9
+ * with no imports and no generics.
10
+ *
11
+ * The mechanism (chosen over asking authors to export a named emit type):
12
+ * import each module's config by its resolved path and merge the payload types
13
+ * recovered via `typeof Module.emits` into the open AxonModuleEvents interface.
14
+ * `defineModule` is generic over `emits`, so those payloads survive as their
15
+ * declared shapes — the inline `{} as { ... }` IS the single source of truth,
16
+ * no duplicated exported type to drift.
17
+ *
18
+ * Only modules that actually declare `emits` are imported, so an agent's type
19
+ * graph pulls in a module config only when that module has events to type.
20
+ */
21
+ export function generateHookTypes(root: string, modules: AxonModule[]): number {
22
+ const withEmits = modules.filter(m => m.configPath && hasEmits(m.configPath))
23
+ if (withEmits.length === 0) return 0
24
+
25
+ const lines: string[] = [
26
+ "// .agent/hooks.d.ts — generated by axon prepare, do not edit",
27
+ "// Re-run `axon prepare` after installing or changing modules.",
28
+ "//",
29
+ "// Merges each installed module's `emits` payloads into AxonModuleEvents,",
30
+ "// so axon.hooks.hook(<event>, handler) is typed from the module's own",
31
+ "// declaration — no imports, no generics in your plugin.",
32
+ "",
33
+ ]
34
+
35
+ // One `import type` per module, aliased so two modules can't collide, plus
36
+ // a payload alias that unwraps the optional `emits` to a concrete map.
37
+ withEmits.forEach((module, i) => {
38
+ lines.push(`import type __M${i} from ${JSON.stringify(module.configPath)}`)
39
+ })
40
+ lines.push("")
41
+ withEmits.forEach((_, i) => {
42
+ // `__M${i}` is a VALUE (the default export) — recover its emits type
43
+ // via `typeof`. NonNullable unwraps the optional `emits?: E`.
44
+ lines.push(`type __E${i} = NonNullable<(typeof __M${i})["emits"]>`)
45
+ })
46
+
47
+ // Merge every module's emit map into the open interface via `extends`.
48
+ // An interface extending object types is exactly declaration merging.
49
+ lines.push(
50
+ "",
51
+ 'declare module "@arcforge/types" {',
52
+ ` interface AxonModuleEvents extends ${withEmits.map((_, i) => `__E${i}`).join(", ")} {}`,
53
+ "}",
54
+ "",
55
+ "export {}",
56
+ "",
57
+ )
58
+
59
+ writeDts(root, "hooks.d.ts", lines.join("\n"))
60
+ return withEmits.length
61
+ }
62
+
63
+ /** Cheap text check for an `emits` block in a module.config.ts — avoids importing modules that have no events. */
64
+ function hasEmits(configPath: string): boolean {
65
+ if (!existsSync(configPath)) return false
66
+ try {
67
+ return /(^|\s)emits\s*:/.test(readFileSync(configPath, "utf-8"))
68
+ } catch {
69
+ return false
70
+ }
71
+ }
@@ -0,0 +1,137 @@
1
+ import type { AxonPartialBlueprint } from "@arcforge/types"
2
+ import { err } from "@arcforge/err"
3
+ import { Generators } from "./generators"
4
+ import type { BuiltinRegistry } from "./registry-dts"
5
+ import { Tools } from "../../blueprint/scan/tools"
6
+ import { KINDS, type ProjectKind } from "../kinds"
7
+
8
+ export type TypegenResult = {
9
+ toolGlobals: number
10
+ prompts: number
11
+ scripts: number
12
+ components: number
13
+ env: number
14
+ }
15
+
16
+ /** Nothing generated beyond the shared frame. What every non-agent kind returns. */
17
+ const EMPTY: TypegenResult = { toolGlobals: 0, prompts: 0, scripts: 0, components: 0, env: 0 }
18
+
19
+ type TypegenOpts = {
20
+ root: string
21
+ kind: ProjectKind
22
+ /**
23
+ * Roots to scan for registrations, in LOAD ORDER — the profile first, then
24
+ * each extension as profile.config.ts lists them.
25
+ *
26
+ * Optional because a caller that knows nothing about extensions (a bare
27
+ * `axon prepare` on a profile directory) still gets that profile's own
28
+ * names. Order decides which description survives a duplicate, matching
29
+ * the loader's first-wins rule.
30
+ */
31
+ sources?: readonly string[]
32
+ /**
33
+ * Axon's own catalogue of component and line names.
34
+ *
35
+ * Passed IN rather than imported: the catalogue lives in the TUI, where the
36
+ * composables it reads live, and the platform must not depend on the app it
37
+ * serves. The names are data — the platform only writes them down.
38
+ */
39
+ builtins?: BuiltinRegistry
40
+ }
41
+
42
+ /**
43
+ * Typegen — the generated type declarations of one project. The policy
44
+ * layer: decides what "write everything" means per kind, delegating each
45
+ * file to Generators (the mechanism — also exposed as `generate` for
46
+ * targeted regeneration in watch mode).
47
+ *
48
+ * Agents: driven by a loaded blueprint (the surfaces ARE the types) —
49
+ * axon.d.ts, tool-globals, prompts, scripts, components, env, tsconfig,
50
+ * all into .agent/.
51
+ *
52
+ * Modules: the static frame plus their own tool declarations —
53
+ * axon.d.ts, tsconfig, and tool-globals.d.ts into .module/. Those
54
+ * declarations are the module's published surface: publish() sends them as
55
+ * the version manifest, and the registry renders them as "what this module
56
+ * gives your agent".
57
+ *
58
+ * Cognets: the ambient authoring frame — cognet-globals.d.ts (loop, kernel,
59
+ * phase, system, defineCognet) + tsconfig into .cognet/types/. An agent with
60
+ * an INLINE cognet gets the same declarations written into its own frame,
61
+ * under a second tsconfig scope — see tsconfig.ts.
62
+ */
63
+ export function Typegen(opts: TypegenOpts) {
64
+ const { kind, root } = opts
65
+ const generate = Generators(opts)
66
+
67
+ return {
68
+ /** Per-domain generators — regenerate one file when one domain changed. */
69
+ generate,
70
+
71
+ /** Write all declarations. Agents require the blueprint — no blueprint, no types. */
72
+ async write(blueprint?: AxonPartialBlueprint): Promise<TypegenResult> {
73
+ if (!KINDS[kind].frame) return EMPTY
74
+
75
+ // Every framed kind gets the same two files. What differs is only
76
+ // what is generated ON TOP of them.
77
+ generate.axon()
78
+ generate.tsconfig()
79
+
80
+ // A prompt package's whole authoring surface is definePrompt(),
81
+ // which generate.axon() just declared. It has no tools, scripts,
82
+ // or blueprint to generate anything else from.
83
+ if (kind === "prompt") return EMPTY
84
+
85
+ /**
86
+ * The two TUI kinds get the ambient contract plus a REGISTRY of
87
+ * what they actually declare.
88
+ *
89
+ * The contract alone types the verbs; this types their arguments —
90
+ * so `lines.set(["me:statuz"])` is a red squiggle while you type it
91
+ * rather than a fault reported after boot, and `me:` completes to
92
+ * whatever you registered in the same file.
93
+ *
94
+ * Scanned from source rather than asked of the runtime, because
95
+ * these types have to exist BEFORE a terminal boots — that is the
96
+ * whole point of them.
97
+ */
98
+ if (kind === "profile" || kind === "extension") {
99
+ generate.registry(opts.sources ?? [root], opts.builtins)
100
+ return EMPTY
101
+ }
102
+
103
+ // A module has no blueprint of its own — it is not an agent — but
104
+ // it does have src/tools, and those declarations ARE its public
105
+ // surface: what the registry shows a user, and what publish sends
106
+ // as the version manifest. Scanning them here is what makes that
107
+ // surface exist at all; without it every published module carried
108
+ // a null manifest and rendered as "no tool declarations".
109
+ if (kind === "module") {
110
+ const tools = await Tools(root)
111
+ return { ...EMPTY, toolGlobals: generate.tools(tools.entries) }
112
+ }
113
+
114
+ // A bench's declarations come from its own config (axes,
115
+ // measurements), which BenchTypegen owns and the bench branch of
116
+ // prepare() drives. The shared frame above is all this writes, so
117
+ // the two never race to author the same files.
118
+ if (kind === "bench" || kind === "cognet") return EMPTY
119
+
120
+ if (!blueprint) {
121
+ throw err("TYPEGEN_NO_BLUEPRINT")
122
+ }
123
+
124
+ generate.hooks(blueprint.modules ?? [])
125
+
126
+ return {
127
+ toolGlobals: generate.tools(blueprint.tools ?? []),
128
+ prompts: generate.prompts(blueprint.prompts ?? []),
129
+ scripts: generate.scripts(blueprint.scripts ?? []),
130
+ components: await generate.components(blueprint.modules ?? []),
131
+ env: generate.env(),
132
+ }
133
+ },
134
+ }
135
+ }
136
+
137
+ export type TypegenT = ReturnType<typeof Typegen>
@@ -0,0 +1,40 @@
1
+ import { join } from "node:path"
2
+ import { writeFileSync } from "node:fs"
3
+ import { Frame } from "../../frame"
4
+
5
+ /**
6
+ * globals.d.ts for prompt packages — the ambient surface of
7
+ * `prompt.config.ts`, which is the only code a prompt package has.
8
+ *
9
+ * `PromptConfig` is inlined rather than imported from @arcforge/types. A
10
+ * prompt package is text: it declares no dependencies and installs no
11
+ * node_modules, so there is nothing on disk for an import to resolve
12
+ * through. Duplicating one type is the price of a package that typechecks
13
+ * with an empty directory beside it — and the type is part of the published
14
+ * registry contract, so it changes about as often as the config file format
15
+ * itself. It must stay in step with @arcforge/types/src/prompts.ts.
16
+ */
17
+ export const PROMPT_DTS = `// Generated by axon prepare — do not edit.
18
+ // Ambient globals for prompt.config.ts. Implemented by the CLI that reads it.
19
+
20
+ declare global {
21
+ /**
22
+ * A prompt package's marker. Empty: identity (name, version, description)
23
+ * lives in package.json, which is what the registry reads.
24
+ */
25
+ type PromptConfig = Record<string, never>
26
+
27
+ /** identity declaration — prompt.config.ts only */
28
+ function definePrompt(config: PromptConfig): { _kind: "prompt", config: PromptConfig }
29
+ }
30
+
31
+ export {}
32
+ `
33
+
34
+ export function generatePromptDts(promptPath: string): void {
35
+ writeFileSync(
36
+ join(Frame({ root: promptPath, kind: "prompt" }).ensure("types"), "globals.d.ts"),
37
+ PROMPT_DTS,
38
+ "utf-8",
39
+ )
40
+ }
@@ -0,0 +1,36 @@
1
+ import type { AxonPrompt } from "@arcforge/types"
2
+ import { writeDts } from "./write"
3
+
4
+ function propsType(props: NonNullable<AxonPrompt["props"]>): string {
5
+ if (props.length === 0) return "Record<string, never>"
6
+ return `{ ${props.map(p => `${p.name}${p.required ? "" : "?"}: ${p.type}`).join("; ")} }`
7
+ }
8
+
9
+ /**
10
+ * .agent/prompts.d.ts — AxonPromptMap augmentation. Makes
11
+ * axon.prompt(name, props) fully typed: autocomplete on names,
12
+ * validation on props.
13
+ */
14
+ export function generatePromptTypes(root: string, prompts: AxonPrompt[]): number {
15
+ if (prompts.length === 0) return 0
16
+
17
+ const lines: string[] = [
18
+ "// .agent/prompts.d.ts — generated by axon prepare, do not edit",
19
+ "// Re-run `axon prepare` after adding or modifying prompts.",
20
+ "",
21
+ 'import "@arcforge/types"',
22
+ 'declare module "@arcforge/types" {',
23
+ " interface AxonPromptMap {",
24
+ ]
25
+
26
+ for (const prompt of prompts) {
27
+ const type = prompt.props && prompt.props.length > 0 ? propsType(prompt.props) : "Record<string, never>"
28
+ if (prompt.description) lines.push(` /** ${prompt.description} */`)
29
+ lines.push(` "${prompt.name}": ${type}`)
30
+ }
31
+
32
+ lines.push(" }", "}", "", "export {}", "")
33
+
34
+ writeDts(root, "prompts.d.ts", lines.join("\n"))
35
+ return prompts.length
36
+ }
@@ -0,0 +1,109 @@
1
+ import { join } from "node:path"
2
+ import { writeFileSync } from "node:fs"
3
+ import { Frame, type ProjectKind } from "../../frame"
4
+ import { emptyRegistrations, mergeRegistrations, scanSource, type Registration, type Registrations } from "../../extensions/registrations"
5
+
6
+ /**
7
+ * `.axon/types/registry.d.ts` — what a config actually registered, as types.
8
+ *
9
+ * ── What this buys ──────────────────────────────────────────────────────────
10
+ *
11
+ * `lines.set(["me:statuz"])` was a runtime fault reported after boot. It is now
12
+ * a red squiggle while you type it, and `me:` completes to whatever you
13
+ * declared in that same file. The same holds for palettes and commands, which
14
+ * were string-addressed with no completion at all.
15
+ *
16
+ * ── Built-ins and your own are the SAME tier ────────────────────────────────
17
+ *
18
+ * Both land in one registry through declaration merging, so nothing about a
19
+ * built-in is more discoverable than something you wrote four lines up. That
20
+ * has been the rule everywhere else in this API — a built-in is a registration
21
+ * the terminal happened to make — and generating types is where it would have
22
+ * been easiest to quietly break.
23
+ *
24
+ * ── Regenerated, never appended ─────────────────────────────────────────────
25
+ *
26
+ * The file is written whole on every run. A name you delete has to stop
27
+ * completing, and a merge step would keep it forever.
28
+ */
29
+
30
+ /** Axon's own catalogue — the names the TUI registers at boot. */
31
+ export type BuiltinRegistry = {
32
+ components: readonly string[]
33
+ lines: readonly string[]
34
+ }
35
+
36
+ function entries(registrations: readonly Registration[], indent = " "): string[] {
37
+ const out: string[] = []
38
+ for (const entry of registrations) {
39
+ if (entry.description) {
40
+ const summary = entry.description.split("\n")[0]!.trim()
41
+ if (summary) out.push(`${indent}/** ${summary.replace(/\*\//g, "*\\/")} */`)
42
+ }
43
+ out.push(`${indent}${JSON.stringify(entry.name)}: true`)
44
+ }
45
+ return out
46
+ }
47
+
48
+ function block(name: string, registrations: readonly Registration[]): string[] {
49
+ // An empty interface still emits: reopening it with nothing is harmless and
50
+ // keeps the generated file's shape stable, which makes a diff between two
51
+ // runs readable.
52
+ return [` interface ${name} {`, ...entries(registrations), " }"]
53
+ }
54
+
55
+ /**
56
+ * Write the registry declarations for one profile or extension.
57
+ *
58
+ * `sources` are the roots to scan, in LOAD ORDER — the profile first, then each
59
+ * extension as `profile.config.ts` lists them. Order decides which description
60
+ * survives a duplicate name, matching the loader's own first-wins rule.
61
+ */
62
+ export function generateRegistryDts(
63
+ root: string,
64
+ kind: ProjectKind,
65
+ sources: readonly string[],
66
+ builtins: BuiltinRegistry = { components: [], lines: [] },
67
+ ): void {
68
+ const scanned = sources.map(scanSource)
69
+
70
+ // Built-ins go FIRST so their documentation wins a collision with a config
71
+ // that shadowed the name — the shadow is a mistake worth leaving legible.
72
+ const builtinRegistrations: Registrations = {
73
+ ...emptyRegistrations(),
74
+ components: builtins.components.map(name => ({ name })),
75
+ lines: builtins.lines.map(name => ({ name })),
76
+ }
77
+
78
+ const all = mergeRegistrations([builtinRegistrations, ...scanned])
79
+
80
+ /**
81
+ * `declare global`, NOT `declare module "@arcforge/types"`.
82
+ *
83
+ * The contract is INLINED into globals.d.ts inside a `declare global`
84
+ * block — a profile has no node_modules for a module augmentation to
85
+ * resolve through, which is the same constraint that keeps tui.ts
86
+ * import-free. So the registries are global interfaces, and reopening them
87
+ * has to happen in the same scope or the two declarations never meet: the
88
+ * file typechecks, the union stays empty, and nothing completes.
89
+ */
90
+ const lines = [
91
+ "// Generated by axon prepare — do not edit.",
92
+ "// What this profile and its extensions register, as completable names.",
93
+ "//",
94
+ "// Reopens the registry interfaces declared in globals.d.ts. Both live in",
95
+ "// `declare global` because a profile has no node_modules to augment through.",
96
+ "",
97
+ "declare global {",
98
+ ...block("AxonComponentRegistry", all.components),
99
+ ...block("AxonLineRegistry", all.lines),
100
+ ...block("AxonPaletteRegistry", all.palettes),
101
+ ...block("AxonCommandRegistry", all.commands),
102
+ "}",
103
+ "",
104
+ "export {}",
105
+ "",
106
+ ]
107
+
108
+ writeFileSync(join(Frame({ root, kind }).ensure("types"), "registry.d.ts"), lines.join("\n"), "utf-8")
109
+ }
@@ -0,0 +1,37 @@
1
+ import type { AxonScript } from "@arcforge/types"
2
+ import { writeDts } from "./write"
3
+
4
+ function argsType(args: NonNullable<AxonScript["args"]>): string {
5
+ if (args.length === 0) return "Record<string, never>"
6
+ return `{ ${args.map(a => `${a.name}${a.required ? "" : "?"}: ${a.type}`).join("; ")} }`
7
+ }
8
+
9
+ /**
10
+ * .agent/scripts.d.ts — AxonScriptMap augmentation. Makes
11
+ * axon.scripts.request(name, args) fully typed.
12
+ */
13
+ export function generateScriptTypes(root: string, scripts: AxonScript[]): number {
14
+ if (scripts.length === 0) return 0
15
+
16
+ const lines: string[] = [
17
+ "// .agent/scripts.d.ts — generated by axon prepare, do not edit",
18
+ "// Re-run `axon prepare` after adding or modifying scripts.",
19
+ "",
20
+ 'import "@arcforge/types"',
21
+ 'declare module "@arcforge/types" {',
22
+ " interface AxonScriptMap {",
23
+ ]
24
+
25
+ for (const script of scripts) {
26
+ const type = script.args && script.args.length > 0 ? argsType(script.args) : "Record<string, never>"
27
+ if (script.args && script.args.length > 0) {
28
+ lines.push(` /** Args: ${script.args.map(a => `${a.name}${a.required ? "" : "?"}: ${a.type}`).join(", ")} */`)
29
+ }
30
+ lines.push(` "${script.name}": { args: ${type}; return: unknown }`)
31
+ }
32
+
33
+ lines.push(" }", "}", "", "export {}", "")
34
+
35
+ writeDts(root, "scripts.d.ts", lines.join("\n"))
36
+ return scripts.length
37
+ }
@@ -0,0 +1,31 @@
1
+ import type { AxonTool } from "@arcforge/types"
2
+ import { isLoadable, scopeMemberCount, scopeToDts, toScopeModule } from "@arcforge/core"
3
+ import { writeDts, type TypegenKind } from "./write"
4
+
5
+ /**
6
+ * .agent/tool-globals.d.ts — the agent's executable scope as ambient
7
+ * TypeScript, so tool calls in the author's own src/tools, src/scripts,
8
+ * hooks, and routes typecheck against exactly what the capsule provides.
9
+ *
10
+ * This file does not decide anything. Membership comes from isLoadable()
11
+ * and the rendering from scopeToDts(), both in @arcforge/core — the same pair
12
+ * that produces the <scope> block the model receives. The two surfaces
13
+ * are one list by construction, not by convention.
14
+ *
15
+ * That matters because this file used to build its own list, and drifted:
16
+ * it rendered every scanned tool including the agent's npm dependencies,
17
+ * whose .d.ts exports had been introspected and hoisted in as callable
18
+ * globals. The capsule filtered them out, so the file described a scope
19
+ * the model never had. An npm dependency is importable by the agent's
20
+ * source; it is not a tool. To make one a tool, re-export it from
21
+ * src/tools/.
22
+ */
23
+ export function generateToolGlobals(root: string, tools: AxonTool[], kind: TypegenKind = "agent"): number {
24
+ const scope = { modules: tools.filter(isLoadable).map(toScopeModule) }
25
+
26
+ const count = scopeMemberCount(scope)
27
+ if (count === 0) return 0
28
+
29
+ writeDts(root, "tool-globals.d.ts", scopeToDts(scope), kind)
30
+ return count
31
+ }