@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,266 @@
|
|
|
1
|
+
import { watch } from "node:fs"
|
|
2
|
+
import type { FSWatcher } from "node:fs"
|
|
3
|
+
|
|
4
|
+
export type DuringOptions = {
|
|
5
|
+
/**
|
|
6
|
+
* The caller reloads on its own once `during()` returns, so changes made
|
|
7
|
+
* inside it must not also be delivered as a notification.
|
|
8
|
+
*
|
|
9
|
+
* ── The tradeoff this accepts ───────────────────────────────────────────
|
|
10
|
+
*
|
|
11
|
+
* A suspension holds ONE pending path, and it cannot tell the caller's own
|
|
12
|
+
* writes apart from a user's edit that happened to land in the same
|
|
13
|
+
* window. So this discards both: a file the user saved during a `bun
|
|
14
|
+
* install` is not picked up until they touch something again.
|
|
15
|
+
*
|
|
16
|
+
* That is the right trade for the callers that set it. An install is
|
|
17
|
+
* seconds long and rewrites the project underneath the user; an edit
|
|
18
|
+
* landing inside that window is rare, and the alternative — a guaranteed
|
|
19
|
+
* duplicate full rescan on every single install — is constant. Callers
|
|
20
|
+
* that do NOT reload themselves must leave this unset, where a held
|
|
21
|
+
* change is always delivered.
|
|
22
|
+
*/
|
|
23
|
+
selfReloads?: boolean
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export type WatcherOpts = {
|
|
27
|
+
root: string
|
|
28
|
+
/** Directory names pruned from the watch entirely (e.g. node_modules, .git). */
|
|
29
|
+
ignore?: string[]
|
|
30
|
+
/** Path prefixes (relative to root) pruned from the watch entirely (e.g. data/sessions). */
|
|
31
|
+
ignorePaths?: string[]
|
|
32
|
+
/**
|
|
33
|
+
* Prunes by BASENAME, at any depth — for transient files whose name is the
|
|
34
|
+
* only thing identifying them, wherever they appear. A prefix list cannot
|
|
35
|
+
* express that: the config loader's reload copies sit beside whichever file
|
|
36
|
+
* they shadow, so their directory is not known in advance.
|
|
37
|
+
*/
|
|
38
|
+
ignoreFiles?: (name: string) => boolean
|
|
39
|
+
/** Coalesce a burst of fs events (editor saves touch multiple files) into one callback. */
|
|
40
|
+
debounceMs?: number
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const DEFAULT_IGNORE = ["node_modules", ".git", ".agent", ".module", "dist"]
|
|
44
|
+
|
|
45
|
+
// The agent's own runtime output, at its PRE-MIGRATION location. Every
|
|
46
|
+
// commit appends to a JSONL file under these paths, so without excluding
|
|
47
|
+
// them a live request self-triggers a reload mid-run: the write lands
|
|
48
|
+
// mid-request, the debounced reload fires, and the in-flight run gets killed
|
|
49
|
+
// out from under itself.
|
|
50
|
+
//
|
|
51
|
+
// data/sensory is the sensory ring, and it is far worse than sessions ever
|
|
52
|
+
// was: a 31Hz microphone writes every 32ms, which is a reload every 32ms
|
|
53
|
+
// forever. An agent with a mic reloaded ~1700 times in a couple of minutes
|
|
54
|
+
// — fast enough that it never finished booting before the next one started.
|
|
55
|
+
//
|
|
56
|
+
// Runtime output now lands in `.agent/data`, which DEFAULT_IGNORE already
|
|
57
|
+
// prunes wholesale — the frame is generated output and none of it should
|
|
58
|
+
// ever trigger a reload. That is the real fix for this class of bug: a
|
|
59
|
+
// reload loop is now impossible by construction rather than by remembering
|
|
60
|
+
// to list each new retention tier here.
|
|
61
|
+
//
|
|
62
|
+
// These entries remain for agents that have not been re-prepared yet, whose
|
|
63
|
+
// output is still at the old path. They cost two string comparisons and are
|
|
64
|
+
// safe to delete once no such agent can plausibly exist. Note only the
|
|
65
|
+
// runtime-output paths are named, never all of data/ — knowledge files are
|
|
66
|
+
// real project content a user still wants reloads for.
|
|
67
|
+
const DEFAULT_IGNORE_PATHS = ["data/sessions", "data/sensory"]
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Watcher — raw filesystem change notifications for one project root.
|
|
71
|
+
* Knows nothing about blueprints, Axon, or what a "reload" means — that
|
|
72
|
+
* interpretation belongs to whoever consumes the events (Agent, in dev).
|
|
73
|
+
*/
|
|
74
|
+
export function Watcher(opts: WatcherOpts) {
|
|
75
|
+
const ignore = new Set(opts.ignore ?? DEFAULT_IGNORE)
|
|
76
|
+
const ignorePaths = opts.ignorePaths ?? DEFAULT_IGNORE_PATHS
|
|
77
|
+
const ignoreFiles = opts.ignoreFiles
|
|
78
|
+
const debounceMs = opts.debounceMs ?? 100
|
|
79
|
+
|
|
80
|
+
let fsWatcher: FSWatcher | null = null
|
|
81
|
+
let timer: ReturnType<typeof setTimeout> | null = null
|
|
82
|
+
const listeners = new Set<(path: string) => void>()
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Nesting depth of suspend() calls, and the one change seen while
|
|
86
|
+
* suspended (if any).
|
|
87
|
+
*
|
|
88
|
+
* A counter rather than a boolean so overlapping suspensions can't have
|
|
89
|
+
* the inner one resume the outer's window. `pending` holds a path rather
|
|
90
|
+
* than a flag because resume() must still deliver a notification: a user
|
|
91
|
+
* editing a file DURING an install is a real change, and dropping it
|
|
92
|
+
* would leave the agent stale until they touched something else.
|
|
93
|
+
*/
|
|
94
|
+
let suspended = 0
|
|
95
|
+
let pending: string | null = null
|
|
96
|
+
/** The path a currently-armed debounce timer will deliver, if any. */
|
|
97
|
+
let scheduled: string | null = null
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Schedule the debounced notification. The single place the timer is set,
|
|
101
|
+
* so a resume and a normal fs event share one window rather than racing
|
|
102
|
+
* each other into two callbacks.
|
|
103
|
+
*/
|
|
104
|
+
function notify(path: string): void {
|
|
105
|
+
if (timer) clearTimeout(timer)
|
|
106
|
+
scheduled = path
|
|
107
|
+
timer = setTimeout(() => {
|
|
108
|
+
timer = null
|
|
109
|
+
scheduled = null
|
|
110
|
+
for (const listener of listeners) listener(path)
|
|
111
|
+
}, debounceMs)
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Whether this watcher would drop a change to `filename`.
|
|
116
|
+
*
|
|
117
|
+
* Public because it is the one part of the watch decision that cannot be
|
|
118
|
+
* exercised through start()/onChange(): a Windows-separator path never
|
|
119
|
+
* arrives from fs.watch() on the host running the tests, and the whole
|
|
120
|
+
* point of normalizing is that it behaves identically when it does.
|
|
121
|
+
*/
|
|
122
|
+
function ignores(filename: string): boolean {
|
|
123
|
+
const path = normalizePath(filename)
|
|
124
|
+
if (path.split("/").some(segment => ignore.has(segment))) return true
|
|
125
|
+
if (ignoreFiles?.(path.split("/").at(-1) ?? "")) return true
|
|
126
|
+
return ignorePaths.some(prefix => path === prefix || path.startsWith(`${prefix}/`))
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
return {
|
|
130
|
+
ignores: ignores,
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Start watching. Idempotent — a second call is a no-op while
|
|
134
|
+
* already running.
|
|
135
|
+
*
|
|
136
|
+
* Recursive inotify watches (Linux) aren't fully attached the
|
|
137
|
+
* instant fs.watch() returns — a change landing immediately after
|
|
138
|
+
* can be silently dropped while the kernel finishes registering
|
|
139
|
+
* watches on the existing subtree. Awaiting start() guarantees the
|
|
140
|
+
* watch is actually live before the caller proceeds.
|
|
141
|
+
*/
|
|
142
|
+
async start(): Promise<void> {
|
|
143
|
+
if (fsWatcher) return
|
|
144
|
+
fsWatcher = watch(opts.root, { recursive: true }, (_event, filename) => {
|
|
145
|
+
if (!filename) return
|
|
146
|
+
if (ignores(filename)) return
|
|
147
|
+
const path = normalizePath(filename)
|
|
148
|
+
|
|
149
|
+
// Held, not dropped — resume() delivers it. The debounce timer
|
|
150
|
+
// is deliberately not started: a suspension can outlast it by
|
|
151
|
+
// far (a `bun install` is seconds), and firing mid-way is the
|
|
152
|
+
// whole thing suspension exists to prevent.
|
|
153
|
+
if (suspended > 0) {
|
|
154
|
+
pending = path
|
|
155
|
+
return
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
notify(path)
|
|
159
|
+
})
|
|
160
|
+
await Bun.sleep(75)
|
|
161
|
+
},
|
|
162
|
+
|
|
163
|
+
/** Stop watching. Idempotent. */
|
|
164
|
+
stop(): void {
|
|
165
|
+
fsWatcher?.close()
|
|
166
|
+
fsWatcher = null
|
|
167
|
+
if (timer) clearTimeout(timer)
|
|
168
|
+
timer = null
|
|
169
|
+
},
|
|
170
|
+
|
|
171
|
+
/** Subscribe to (debounced) change notifications. Returns an unsubscribe function. */
|
|
172
|
+
onChange(listener: (path: string) => void): () => void {
|
|
173
|
+
listeners.add(listener)
|
|
174
|
+
return () => listeners.delete(listener)
|
|
175
|
+
},
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* Run `fn` without notifying listeners of changes IT causes.
|
|
179
|
+
*
|
|
180
|
+
* For a caller that is deliberately rewriting the project and will
|
|
181
|
+
* account for the result itself — an install writes package.json,
|
|
182
|
+
* bunfig.toml and axon.config.ts, then rebuilds node_modules. Left to
|
|
183
|
+
* the watcher, the manifest writes fire a reload ~100ms later, which
|
|
184
|
+
* rescans while `bun install` still has the tree torn down, and the
|
|
185
|
+
* cognet build correctly reports a runtime that is genuinely absent
|
|
186
|
+
* for that instant. The install then succeeds — leaving two error
|
|
187
|
+
* cards for an operation that worked.
|
|
188
|
+
*
|
|
189
|
+
* Suspension is not silencing: a change that arrives during `fn` is
|
|
190
|
+
* held and delivered on resume, so a user edit mid-install is not
|
|
191
|
+
* lost. What it removes is the watcher inferring a reload from writes
|
|
192
|
+
* whose author already knows what they mean.
|
|
193
|
+
*
|
|
194
|
+
* Restores on throw — an install that fails must not leave the
|
|
195
|
+
* watcher deaf for the rest of the session.
|
|
196
|
+
*/
|
|
197
|
+
async during<T>(fn: () => Promise<T>, options: DuringOptions = {}): Promise<T> {
|
|
198
|
+
// A debounce window already open when suspension starts would fire
|
|
199
|
+
// INSIDE fn() — exactly the mid-install reload this prevents. Fold
|
|
200
|
+
// it into the suspension instead of letting it land: the change is
|
|
201
|
+
// still real, so it is held and delivered on resume like any other.
|
|
202
|
+
if (suspended === 0 && timer) {
|
|
203
|
+
clearTimeout(timer)
|
|
204
|
+
timer = null
|
|
205
|
+
pending = scheduled
|
|
206
|
+
scheduled = null
|
|
207
|
+
}
|
|
208
|
+
suspended++
|
|
209
|
+
try {
|
|
210
|
+
return await fn()
|
|
211
|
+
} finally {
|
|
212
|
+
suspended--
|
|
213
|
+
|
|
214
|
+
// The caller reloads for itself, so the writes it just made
|
|
215
|
+
// must not ALSO arrive as a change notification.
|
|
216
|
+
//
|
|
217
|
+
// fs.watch cannot say who wrote a file, so attribution is
|
|
218
|
+
// impossible to infer here — it has to be declared by the one
|
|
219
|
+
// party that knows: the caller that both made the writes and
|
|
220
|
+
// will act on them. An install rewrote package.json,
|
|
221
|
+
// bunfig.toml, axon.config.ts and all of node_modules, then
|
|
222
|
+
// reloads once itself; delivering the held change on top of
|
|
223
|
+
// that ran the entire scan a second time for the same event.
|
|
224
|
+
//
|
|
225
|
+
// The cost of this being wrong is asymmetric, which is why it
|
|
226
|
+
// is opt-in rather than the default: a missed notification
|
|
227
|
+
// leaves the agent silently stale until the user touches
|
|
228
|
+
// something else, while a spurious one is only wasted work.
|
|
229
|
+
// Callers that do not reload themselves keep the safe
|
|
230
|
+
// behaviour without having to know this option exists.
|
|
231
|
+
//
|
|
232
|
+
// Only the OUTERMOST suspension may discard, and only if it
|
|
233
|
+
// is the one that asked to. An inner `during(..., selfReloads)`
|
|
234
|
+
// nested inside a plain outer one would otherwise throw away a
|
|
235
|
+
// change the outer caller is still relying on being told
|
|
236
|
+
// about — the inner reload covers its own writes, not
|
|
237
|
+
// everything the outer span went on to do afterwards.
|
|
238
|
+
if (suspended === 0 && options.selfReloads) pending = null
|
|
239
|
+
|
|
240
|
+
if (suspended === 0 && pending !== null) {
|
|
241
|
+
const path = pending
|
|
242
|
+
pending = null
|
|
243
|
+
// Scheduled through the same debounce every other event
|
|
244
|
+
// uses, deliberately: fs notifications are asynchronous, so
|
|
245
|
+
// the tail of a burst written inside fn() keeps arriving
|
|
246
|
+
// for a few ms AFTER resume. Those land on the normal path
|
|
247
|
+
// and restart this timer, folding themselves into this one
|
|
248
|
+
// notification instead of producing a second — which is
|
|
249
|
+
// what an install's three manifest writes did.
|
|
250
|
+
notify(path)
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
},
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
export type WatcherT = ReturnType<typeof Watcher>
|
|
258
|
+
|
|
259
|
+
/**
|
|
260
|
+
* `fs.watch()` reports project-relative paths using the host separator. Keep
|
|
261
|
+
* watcher contracts POSIX-shaped so ignore prefixes behave identically on
|
|
262
|
+
* Windows (`data\\sessions\\…`) and Unix (`data/sessions/…`).
|
|
263
|
+
*/
|
|
264
|
+
function normalizePath(filename: string): string {
|
|
265
|
+
return filename.replaceAll("\\", "/")
|
|
266
|
+
}
|