@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.
- package/README.md +31 -0
- package/package.json +69 -0
- package/src/bin/supervisor.ts +102 -0
- package/src/bin/test-api.ts +30 -0
- package/src/bin/test-preload.ts +308 -0
- package/src/bin/update-helper.ts +32 -0
- package/src/build/bench/CLAUDE.md +106 -0
- package/src/build/bench/SPEC.md +209 -0
- package/src/build/bench/agents.ts +105 -0
- package/src/build/bench/axes.ts +84 -0
- package/src/build/bench/bench.ts +96 -0
- package/src/build/bench/discover.ts +147 -0
- package/src/build/bench/index.ts +7 -0
- package/src/build/bench/log.ts +47 -0
- package/src/build/bench/matrix.ts +23 -0
- package/src/build/bench/preload.ts +440 -0
- package/src/build/bench/prepare.ts +61 -0
- package/src/build/bench/projection.ts +112 -0
- package/src/build/bench/resolve.ts +54 -0
- package/src/build/bench/runner.ts +309 -0
- package/src/build/bench/schema/extract.ts +148 -0
- package/src/build/bench/schema/index.ts +2 -0
- package/src/build/bench/schema/schema.ts +95 -0
- package/src/build/bench/schema/worker.ts +30 -0
- package/src/build/bench/typegen.ts +119 -0
- package/src/build/bench/workspace/files.ts +139 -0
- package/src/build/bench/workspace/handle.ts +133 -0
- package/src/build/bench/workspace/index.ts +11 -0
- package/src/build/bench/workspace/workspace.ts +14 -0
- package/src/build/blueprint/blueprint.ts +398 -0
- package/src/build/blueprint/cognet/abi.ts +207 -0
- package/src/build/blueprint/cognet/bundle-worker.ts +93 -0
- package/src/build/blueprint/cognet/bundle.ts +664 -0
- package/src/build/blueprint/cognet/cognet.ts +249 -0
- package/src/build/blueprint/cognet/index.ts +10 -0
- package/src/build/blueprint/cognet/manifest.ts +38 -0
- package/src/build/blueprint/cognet/resolve.ts +113 -0
- package/src/build/blueprint/collisions.ts +51 -0
- package/src/build/blueprint/index.ts +29 -0
- package/src/build/blueprint/modules/entries.ts +117 -0
- package/src/build/blueprint/modules/index.ts +300 -0
- package/src/build/blueprint/modules/meta.ts +174 -0
- package/src/build/blueprint/scan/boot.ts +34 -0
- package/src/build/blueprint/scan/cognetImports.ts +56 -0
- package/src/build/blueprint/scan/components.ts +45 -0
- package/src/build/blueprint/scan/config.ts +234 -0
- package/src/build/blueprint/scan/configImports.ts +232 -0
- package/src/build/blueprint/scan/declare-worker.ts +61 -0
- package/src/build/blueprint/scan/declare.ts +393 -0
- package/src/build/blueprint/scan/h3-globals.ts +137 -0
- package/src/build/blueprint/scan/knowledge.ts +101 -0
- package/src/build/blueprint/scan/middleware.ts +110 -0
- package/src/build/blueprint/scan/moduleImports.ts +79 -0
- package/src/build/blueprint/scan/plugins.ts +93 -0
- package/src/build/blueprint/scan/promptPackages.ts +45 -0
- package/src/build/blueprint/scan/prompts.ts +164 -0
- package/src/build/blueprint/scan/published.ts +131 -0
- package/src/build/blueprint/scan/resolve.ts +398 -0
- package/src/build/blueprint/scan/routes.ts +109 -0
- package/src/build/blueprint/scan/scripts.ts +119 -0
- package/src/build/blueprint/scan/tool-bundle-worker.ts +69 -0
- package/src/build/blueprint/scan/tools.ts +610 -0
- package/src/build/blueprint/types.ts +28 -0
- package/src/build/extensions/config.ts +261 -0
- package/src/build/extensions/edit.ts +684 -0
- package/src/build/extensions/extensions.ts +731 -0
- package/src/build/extensions/index.ts +10 -0
- package/src/build/extensions/load.ts +350 -0
- package/src/build/extensions/registrations.ts +189 -0
- package/src/build/extensions/store.ts +200 -0
- package/src/build/frame/frame.ts +145 -0
- package/src/build/frame/index.ts +5 -0
- package/src/build/frame/migrate.ts +246 -0
- package/src/build/project/bundle/agent.ts +382 -0
- package/src/build/project/bundle/artifacts.ts +88 -0
- package/src/build/project/bundle/assets.ts +385 -0
- package/src/build/project/bundle/bundle.ts +160 -0
- package/src/build/project/bundle/imports.ts +102 -0
- package/src/build/project/bundle/index.ts +16 -0
- package/src/build/project/bundle/module.ts +130 -0
- package/src/build/project/bundle/source.ts +136 -0
- package/src/build/project/bundle/stage.ts +97 -0
- package/src/build/project/bundle/types.ts +111 -0
- package/src/build/project/cognet.ts +156 -0
- package/src/build/project/create/agent.ts +52 -0
- package/src/build/project/create/bench.ts +81 -0
- package/src/build/project/create/cognet.ts +102 -0
- package/src/build/project/create/extension.ts +63 -0
- package/src/build/project/create/module.ts +43 -0
- package/src/build/project/create/profile.ts +102 -0
- package/src/build/project/create/prompt.ts +68 -0
- package/src/build/project/create/templates.ts +88 -0
- package/src/build/project/deploy.ts +96 -0
- package/src/build/project/index.ts +40 -0
- package/src/build/project/installer.ts +616 -0
- package/src/build/project/kinds.ts +374 -0
- package/src/build/project/links.ts +33 -0
- package/src/build/project/manifest/bunfig.ts +139 -0
- package/src/build/project/manifest/config.ts +246 -0
- package/src/build/project/manifest/env.ts +184 -0
- package/src/build/project/manifest/index.ts +9 -0
- package/src/build/project/manifest/manifest.ts +49 -0
- package/src/build/project/manifest/model.ts +124 -0
- package/src/build/project/manifest/package.ts +386 -0
- package/src/build/project/manifest/text.ts +19 -0
- package/src/build/project/models/fetch.ts +123 -0
- package/src/build/project/models/index.ts +8 -0
- package/src/build/project/models/models.ts +111 -0
- package/src/build/project/models/specifier.ts +106 -0
- package/src/build/project/models/store.ts +202 -0
- package/src/build/project/modules/hash.ts +31 -0
- package/src/build/project/modules/index.ts +5 -0
- package/src/build/project/modules/lock.ts +78 -0
- package/src/build/project/modules/modules.ts +155 -0
- package/src/build/project/prepare.ts +709 -0
- package/src/build/project/project.ts +253 -0
- package/src/build/project/projects.ts +164 -0
- package/src/build/project/propagation.ts +120 -0
- package/src/build/project/publish/verify.ts +312 -0
- package/src/build/project/publish.ts +155 -0
- package/src/build/project/reconcile.ts +93 -0
- package/src/build/project/specifier.ts +42 -0
- package/src/build/project/tree.ts +615 -0
- package/src/build/project/treecache.ts +356 -0
- package/src/build/project/typegen/axon-dts.ts +362 -0
- package/src/build/project/typegen/cognet-dts.ts +91 -0
- package/src/build/project/typegen/components.ts +45 -0
- package/src/build/project/typegen/env.ts +59 -0
- package/src/build/project/typegen/generators.ts +108 -0
- package/src/build/project/typegen/hooks.ts +71 -0
- package/src/build/project/typegen/index.ts +137 -0
- package/src/build/project/typegen/prompt-dts.ts +40 -0
- package/src/build/project/typegen/prompts.ts +36 -0
- package/src/build/project/typegen/registry-dts.ts +109 -0
- package/src/build/project/typegen/scripts.ts +37 -0
- package/src/build/project/typegen/tools.ts +31 -0
- package/src/build/project/typegen/tsconfig.ts +243 -0
- package/src/build/project/typegen/tui-dts.ts +120 -0
- package/src/build/project/typegen/write.ts +40 -0
- package/src/build/project/verify.ts +268 -0
- package/src/build/project/watcher.ts +266 -0
- package/src/build/runtime/agent.ts +550 -0
- package/src/build/runtime/escalations.ts +159 -0
- package/src/build/runtime/index.ts +15 -0
- package/src/build/runtime/instances.ts +604 -0
- package/src/build/runtime/profile.ts +91 -0
- package/src/build/runtime/progress.ts +143 -0
- package/src/build/runtime/requests.ts +167 -0
- package/src/build/runtime/resolve.ts +159 -0
- package/src/build/runtime/runtime.ts +233 -0
- package/src/build/runtime/sessions/index.ts +5 -0
- package/src/build/runtime/sessions/record.ts +145 -0
- package/src/build/runtime/sessions/sessions.ts +240 -0
- package/src/build/runtime/zeno.ts +120 -0
- package/src/index.ts +11 -0
- package/src/link/agent-main.ts +395 -0
- package/src/link/index.ts +70 -0
- package/src/link/services.ts +120 -0
- package/src/platform.ts +293 -0
- package/src/procs/index.ts +15 -0
- package/src/procs/tree.ts +177 -0
- package/src/services/cloud.ts +419 -0
- package/src/services/control/client.ts +126 -0
- package/src/services/control/dispatch.ts +156 -0
- package/src/services/control/index.ts +17 -0
- package/src/services/control/protocol.ts +179 -0
- package/src/services/control/server.ts +241 -0
- package/src/services/deployments.ts +81 -0
- package/src/services/files.ts +329 -0
- package/src/services/index.ts +5 -0
- package/src/services/mic/capture.ts +248 -0
- package/src/services/mic/config.ts +109 -0
- package/src/services/mic/fft.ts +93 -0
- package/src/services/mic/index.ts +139 -0
- package/src/services/mic/visualizer.ts +46 -0
- package/src/services/ollama/catalog.ts +122 -0
- package/src/services/ollama/http.ts +124 -0
- package/src/services/ollama/index.ts +13 -0
- package/src/services/ollama/models.ts +153 -0
- package/src/services/ollama/ollama.ts +89 -0
- package/src/services/ollama/registry.ts +112 -0
- package/src/services/ollama/types.ts +72 -0
- package/src/services/prompts.ts +76 -0
- package/src/services/registry.ts +220 -0
- package/src/services/resources/hardware.ts +125 -0
- package/src/services/resources/index.ts +6 -0
- package/src/services/resources/reservations.ts +162 -0
- package/src/services/resources/resources.ts +156 -0
- package/src/services/running/index.ts +1 -0
- package/src/services/running/running.ts +200 -0
- package/src/services/store/disk.ts +97 -0
- package/src/services/store/index.ts +15 -0
- package/src/services/store/store.ts +729 -0
- package/src/services/store/types.ts +303 -0
- package/src/services/test/child.ts +150 -0
- package/src/services/test/events.ts +102 -0
- package/src/services/test/files.ts +26 -0
- package/src/services/test/frames.ts +39 -0
- package/src/services/test/index.ts +7 -0
- package/src/services/test/runner.ts +122 -0
- package/src/services/test/types.ts +26 -0
- package/src/services/update/contract.ts +77 -0
- package/src/services/update/index.ts +12 -0
- package/src/services/update/installer.ts +139 -0
- package/src/services/update/updates.ts +137 -0
- package/src/utils/fs.ts +148 -0
- package/src/utils/tsast.ts +102 -0
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
import { chmodSync, existsSync, mkdirSync, readdirSync, readFileSync, rmSync, watch, writeFileSync } from "node:fs"
|
|
2
|
+
import type { FSWatcher } from "node:fs"
|
|
3
|
+
import { homedir } from "node:os"
|
|
4
|
+
import { join } from "node:path"
|
|
5
|
+
import type { AxonInstance } from "@arcforge/types"
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Every store root a locally-booted agent might register in.
|
|
9
|
+
*
|
|
10
|
+
* `~/.axon` is the installed CLI's store; `~/.axon-dev` is what a source
|
|
11
|
+
* build uses (see resolvePlatformEnvironment — production is hermetic, so
|
|
12
|
+
* source development gets its own store and the two cannot collide). They
|
|
13
|
+
* hold the same shape and describe the same machine, so an observer reads
|
|
14
|
+
* both: an agent is running whether or not the binary that booted it was
|
|
15
|
+
* the installed one.
|
|
16
|
+
*/
|
|
17
|
+
const ROOTS = [
|
|
18
|
+
join(homedir(), ".axon", "cache", "running"),
|
|
19
|
+
join(homedir(), ".axon-dev", "cache", "running"),
|
|
20
|
+
// The pre-cache/ locations. Read, never written — an agent booted by an
|
|
21
|
+
// older binary is still running on this machine, and an observer that
|
|
22
|
+
// could not see it would report the machine as idle while it worked.
|
|
23
|
+
// Records here drain on their own: every reader probes the pid, so one
|
|
24
|
+
// whose process has gone is already indistinguishable from no record.
|
|
25
|
+
join(homedir(), ".axon", "running"),
|
|
26
|
+
join(homedir(), ".axon-dev", "running"),
|
|
27
|
+
]
|
|
28
|
+
|
|
29
|
+
/** True if a process with this pid exists — sends no signal (kill(pid, 0)), just probes. */
|
|
30
|
+
function isAlive(pid: number): boolean {
|
|
31
|
+
try {
|
|
32
|
+
process.kill(pid, 0)
|
|
33
|
+
return true
|
|
34
|
+
} catch {
|
|
35
|
+
return false
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* A record that fails to parse (a write torn mid-flush) or predates the
|
|
41
|
+
* current shape is treated as absent rather than thrown — the next write
|
|
42
|
+
* supersedes it, and one bad file must never empty a reader's whole view.
|
|
43
|
+
*/
|
|
44
|
+
function read(path: string): AxonInstance | null {
|
|
45
|
+
try {
|
|
46
|
+
const record = JSON.parse(readFileSync(path, "utf-8")) as AxonInstance
|
|
47
|
+
return typeof record.dataRoot === "string" && typeof record.pid === "number" ? record : null
|
|
48
|
+
} catch {
|
|
49
|
+
return null
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
type RunningOpts = {
|
|
54
|
+
/** Where THIS process registers itself. Readers still see every root. */
|
|
55
|
+
root?: string
|
|
56
|
+
/** Coalesce a burst of fs events (several agents booting at once) into one callback. */
|
|
57
|
+
debounceMs?: number
|
|
58
|
+
/** How often to re-check without an fs event — catches a crashed pid, which touches no file. */
|
|
59
|
+
pollMs?: number
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Running — the registry of locally-running Axon processes.
|
|
64
|
+
*
|
|
65
|
+
* One file per live process at `<store>/running/<sessionId>.json`, with the
|
|
66
|
+
* pid as the liveness proof. No daemon, no IPC, no lockfile: any process on
|
|
67
|
+
* the machine can read it, and correctness comes from the OS rather than
|
|
68
|
+
* from cooperation between writers.
|
|
69
|
+
*
|
|
70
|
+
* Self-healing by construction. A dead record is DELETED on read, not
|
|
71
|
+
* skipped, so GC happens on whichever process looks next and a `kill -9`
|
|
72
|
+
* leaves no permanent ghost. That is also why the registry holds no
|
|
73
|
+
* authored state — nothing here can disagree with reality, because
|
|
74
|
+
* everything here is either checkable against the OS or written once at
|
|
75
|
+
* boot.
|
|
76
|
+
*
|
|
77
|
+
* Answers exactly one question: what is running RIGHT NOW. A finished run
|
|
78
|
+
* leaves nothing behind; its session log is the durable trace.
|
|
79
|
+
*/
|
|
80
|
+
export function Running(opts: RunningOpts = {}) {
|
|
81
|
+
const writeRoot = opts.root ?? ROOTS[0]!
|
|
82
|
+
const debounceMs = opts.debounceMs ?? 100
|
|
83
|
+
const pollMs = opts.pollMs ?? 5000
|
|
84
|
+
|
|
85
|
+
let watchers: FSWatcher[] = []
|
|
86
|
+
let poll: ReturnType<typeof setInterval> | null = null
|
|
87
|
+
let debounce: ReturnType<typeof setTimeout> | null = null
|
|
88
|
+
const listeners = new Set<(instances: AxonInstance[]) => void>()
|
|
89
|
+
|
|
90
|
+
function fileOf(root: string, sessionId: string): string {
|
|
91
|
+
return join(root, `${sessionId}.json`)
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function snapshot(): AxonInstance[] {
|
|
95
|
+
// Deduped by session id: one process cannot register twice, but a
|
|
96
|
+
// stale record in one root must never shadow the live one in another.
|
|
97
|
+
const live = new Map<string, AxonInstance>()
|
|
98
|
+
|
|
99
|
+
for (const root of ROOTS) {
|
|
100
|
+
if (!existsSync(root)) continue
|
|
101
|
+
|
|
102
|
+
for (const name of readdirSync(root)) {
|
|
103
|
+
if (!name.endsWith(".json")) continue
|
|
104
|
+
const path = join(root, name)
|
|
105
|
+
const record = read(path)
|
|
106
|
+
if (!record) continue
|
|
107
|
+
|
|
108
|
+
if (isAlive(record.pid)) live.set(record.sessionId, record)
|
|
109
|
+
else rmSync(path, { force: true })
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
return [...live.values()]
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
function notify(): void {
|
|
117
|
+
if (debounce) clearTimeout(debounce)
|
|
118
|
+
debounce = setTimeout(() => {
|
|
119
|
+
debounce = null
|
|
120
|
+
const instances = snapshot()
|
|
121
|
+
for (const listener of listeners) listener(instances)
|
|
122
|
+
}, debounceMs)
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
return {
|
|
126
|
+
/** Every root read by list()/watch(). Exposed for diagnostics, not for callers to walk. */
|
|
127
|
+
roots: ROOTS,
|
|
128
|
+
|
|
129
|
+
/** Register this process. Called once, immediately after the runtime is up. */
|
|
130
|
+
start(instance: AxonInstance): void {
|
|
131
|
+
// 0700/0600: a record may carry the instance's control-channel
|
|
132
|
+
// token, which is the only thing standing between another local
|
|
133
|
+
// account and a socket that drives this agent. The mode is set
|
|
134
|
+
// on the directory AND the file because `recursive: true` does
|
|
135
|
+
// not re-chmod a directory that already exists from an earlier
|
|
136
|
+
// version.
|
|
137
|
+
mkdirSync(writeRoot, { recursive: true, mode: 0o700 })
|
|
138
|
+
chmodSync(writeRoot, 0o700)
|
|
139
|
+
writeFileSync(fileOf(writeRoot, instance.sessionId), JSON.stringify(instance, null, 2), { mode: 0o600 })
|
|
140
|
+
},
|
|
141
|
+
|
|
142
|
+
/** Deregister. Called first thing on shutdown — a reader must never see "alive" for a session mid-teardown. */
|
|
143
|
+
stop(sessionId: string): void {
|
|
144
|
+
for (const root of ROOTS) rmSync(fileOf(root, sessionId), { force: true })
|
|
145
|
+
},
|
|
146
|
+
|
|
147
|
+
/** Every currently-live instance, pid-checked fresh. Dead records are GC'd as a side effect. */
|
|
148
|
+
list(): AxonInstance[] {
|
|
149
|
+
return snapshot()
|
|
150
|
+
},
|
|
151
|
+
|
|
152
|
+
/** One instance by session id, or null when it is not running. */
|
|
153
|
+
get(sessionId: string): AxonInstance | null {
|
|
154
|
+
return snapshot().find(instance => instance.sessionId === sessionId) ?? null
|
|
155
|
+
},
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* Subscribe to the live list. Called once immediately with the
|
|
159
|
+
* current snapshot, then on every add/remove/crash.
|
|
160
|
+
*
|
|
161
|
+
* Two triggers, because one is not enough: fs.watch fires instantly
|
|
162
|
+
* when a record appears or is deleted, and a slow poll catches a
|
|
163
|
+
* killed process — which touches no file and so fires no fs event
|
|
164
|
+
* at all. Returns an unsubscribe function.
|
|
165
|
+
*/
|
|
166
|
+
watch(listener: (instances: AxonInstance[]) => void): () => void {
|
|
167
|
+
if (!watchers.length) {
|
|
168
|
+
for (const root of ROOTS) {
|
|
169
|
+
mkdirSync(root, { recursive: true }) // fs.watch throws on a missing directory
|
|
170
|
+
watchers.push(watch(root, () => notify()))
|
|
171
|
+
}
|
|
172
|
+
poll = setInterval(() => notify(), pollMs)
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
listeners.add(listener)
|
|
176
|
+
listener(snapshot())
|
|
177
|
+
|
|
178
|
+
return () => {
|
|
179
|
+
listeners.delete(listener)
|
|
180
|
+
if (listeners.size === 0) stopWatching()
|
|
181
|
+
}
|
|
182
|
+
},
|
|
183
|
+
|
|
184
|
+
dispose(): void {
|
|
185
|
+
stopWatching()
|
|
186
|
+
listeners.clear()
|
|
187
|
+
},
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
function stopWatching(): void {
|
|
191
|
+
for (const fsWatcher of watchers) fsWatcher.close()
|
|
192
|
+
watchers = []
|
|
193
|
+
if (poll) clearInterval(poll)
|
|
194
|
+
poll = null
|
|
195
|
+
if (debounce) clearTimeout(debounce)
|
|
196
|
+
debounce = null
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
export type RunningT = ReturnType<typeof Running>
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { existsSync, mkdirSync, readdirSync, readFileSync, renameSync, rmSync, writeFileSync, appendFileSync } from "node:fs"
|
|
2
|
+
import { dirname, join } from "node:path"
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Disk — the store's fs leaf. The ONLY code in the store that touches the
|
|
6
|
+
* filesystem. Three primitives: json files, text files, jsonl logs.
|
|
7
|
+
*
|
|
8
|
+
* Absence is a valid state — get() returns null for missing files. Writes
|
|
9
|
+
* are atomic (tmp + rename) so a crash never leaves a half-written record.
|
|
10
|
+
*/
|
|
11
|
+
export function Disk(opts: { root: string }) {
|
|
12
|
+
const { root } = opts
|
|
13
|
+
|
|
14
|
+
function abs(rel: string): string {
|
|
15
|
+
return join(root, rel)
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function writeAtomic(path: string, content: string): void {
|
|
19
|
+
mkdirSync(dirname(path), { recursive: true })
|
|
20
|
+
const tmp = path + ".tmp"
|
|
21
|
+
writeFileSync(tmp, content, "utf-8")
|
|
22
|
+
renameSync(tmp, path)
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
return {
|
|
26
|
+
root,
|
|
27
|
+
|
|
28
|
+
json<T>(rel: string) {
|
|
29
|
+
const path = abs(rel)
|
|
30
|
+
return {
|
|
31
|
+
get(): T | null {
|
|
32
|
+
if (!existsSync(path)) return null
|
|
33
|
+
return JSON.parse(readFileSync(path, "utf-8")) as T
|
|
34
|
+
},
|
|
35
|
+
set(value: T): void {
|
|
36
|
+
writeAtomic(path, JSON.stringify(value, null, 2) + "\n")
|
|
37
|
+
},
|
|
38
|
+
/** Read-modify-write. Missing file starts from `initial`. */
|
|
39
|
+
update(initial: T, fn: (current: T) => T): void {
|
|
40
|
+
const current = existsSync(path) ? (JSON.parse(readFileSync(path, "utf-8")) as T) : initial
|
|
41
|
+
writeAtomic(path, JSON.stringify(fn(current), null, 2) + "\n")
|
|
42
|
+
},
|
|
43
|
+
delete(): void {
|
|
44
|
+
rmSync(path, { force: true })
|
|
45
|
+
},
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
|
|
49
|
+
text(rel: string) {
|
|
50
|
+
const path = abs(rel)
|
|
51
|
+
return {
|
|
52
|
+
get(): string | null {
|
|
53
|
+
return existsSync(path) ? readFileSync(path, "utf-8") : null
|
|
54
|
+
},
|
|
55
|
+
set(value: string): void {
|
|
56
|
+
writeAtomic(path, value)
|
|
57
|
+
},
|
|
58
|
+
delete(): void {
|
|
59
|
+
rmSync(path, { force: true })
|
|
60
|
+
},
|
|
61
|
+
}
|
|
62
|
+
},
|
|
63
|
+
|
|
64
|
+
jsonl<T>(rel: string) {
|
|
65
|
+
const path = abs(rel)
|
|
66
|
+
return {
|
|
67
|
+
append(entry: T): void {
|
|
68
|
+
mkdirSync(dirname(path), { recursive: true })
|
|
69
|
+
appendFileSync(path, JSON.stringify(entry) + "\n", "utf-8")
|
|
70
|
+
},
|
|
71
|
+
read(): T[] {
|
|
72
|
+
if (!existsSync(path)) return []
|
|
73
|
+
return readFileSync(path, "utf-8")
|
|
74
|
+
.split("\n")
|
|
75
|
+
.filter(line => line.trim())
|
|
76
|
+
.map(line => JSON.parse(line) as T)
|
|
77
|
+
},
|
|
78
|
+
delete(): void {
|
|
79
|
+
rmSync(path, { force: true })
|
|
80
|
+
},
|
|
81
|
+
}
|
|
82
|
+
},
|
|
83
|
+
|
|
84
|
+
/** Immediate child names of a directory. Missing dir = []. */
|
|
85
|
+
list(rel: string): string[] {
|
|
86
|
+
const path = abs(rel)
|
|
87
|
+
return existsSync(path) ? readdirSync(path) : []
|
|
88
|
+
},
|
|
89
|
+
|
|
90
|
+
/** Remove a subtree. */
|
|
91
|
+
remove(rel: string): void {
|
|
92
|
+
rmSync(abs(rel), { recursive: true, force: true })
|
|
93
|
+
},
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export type DiskT = ReturnType<typeof Disk>
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// store — the one interface to ~/.axon. Store() is the module's single entry point.
|
|
2
|
+
|
|
3
|
+
export { Store, storeRoot, type StoreT, type ProfileT } from "./store"
|
|
4
|
+
export type {
|
|
5
|
+
ActiveProfile,
|
|
6
|
+
AppIntent,
|
|
7
|
+
AppState,
|
|
8
|
+
AgentManifest,
|
|
9
|
+
EnvTarget,
|
|
10
|
+
HistoryEntry,
|
|
11
|
+
ProfileRecord,
|
|
12
|
+
ProfileSettings,
|
|
13
|
+
UpdateRecord,
|
|
14
|
+
VerbosityProfile,
|
|
15
|
+
} from "./types"
|