tickmarkr 1.84.0 → 1.86.0

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 (87) hide show
  1. package/README.md +4 -2
  2. package/dist/adapters/catalog-remote.d.ts +64 -0
  3. package/dist/adapters/catalog-remote.js +287 -0
  4. package/dist/adapters/catalog.d.ts +96 -0
  5. package/dist/adapters/catalog.js +176 -0
  6. package/dist/adapters/claude-code.d.ts +1 -0
  7. package/dist/adapters/claude-code.js +59 -1
  8. package/dist/adapters/fake.js +42 -4
  9. package/dist/adapters/model-lints.d.ts +25 -5
  10. package/dist/adapters/model-lints.js +184 -50
  11. package/dist/adapters/model-windows.d.ts +31 -0
  12. package/dist/adapters/model-windows.js +69 -0
  13. package/dist/adapters/prompt.d.ts +5 -1
  14. package/dist/adapters/prompt.js +13 -4
  15. package/dist/adapters/registry.d.ts +25 -26
  16. package/dist/adapters/registry.js +173 -110
  17. package/dist/adapters/types.d.ts +3 -0
  18. package/dist/adapters/types.js +36 -3
  19. package/dist/brand.d.ts +5 -1
  20. package/dist/brand.js +18 -2
  21. package/dist/cli/commands/doctor.d.ts +3 -0
  22. package/dist/cli/commands/doctor.js +43 -21
  23. package/dist/cli/commands/fleet.d.ts +7 -0
  24. package/dist/cli/commands/fleet.js +94 -74
  25. package/dist/cli/commands/init.js +118 -5
  26. package/dist/cli/commands/status.js +202 -46
  27. package/dist/compile/collateral.d.ts +86 -2
  28. package/dist/compile/collateral.js +294 -3
  29. package/dist/compile/gsd.d.ts +2 -1
  30. package/dist/compile/gsd.js +68 -2
  31. package/dist/compile/native.d.ts +14 -0
  32. package/dist/compile/native.js +161 -12
  33. package/dist/config/config.d.ts +82 -5
  34. package/dist/config/config.js +253 -66
  35. package/dist/config/fleet-overlay.d.ts +25 -20
  36. package/dist/config/fleet-overlay.js +195 -77
  37. package/dist/config/fleet-why.d.ts +23 -0
  38. package/dist/config/fleet-why.js +42 -0
  39. package/dist/drivers/herdr.d.ts +21 -3
  40. package/dist/drivers/herdr.js +344 -110
  41. package/dist/gates/acceptance.js +7 -2
  42. package/dist/gates/baseline.d.ts +1 -0
  43. package/dist/gates/baseline.js +91 -13
  44. package/dist/gates/llm.d.ts +0 -1
  45. package/dist/gates/llm.js +5 -30
  46. package/dist/gates/review.d.ts +9 -1
  47. package/dist/gates/review.js +105 -10
  48. package/dist/gates/run-gates.d.ts +9 -0
  49. package/dist/gates/run-gates.js +285 -41
  50. package/dist/gates/verdict-cause.d.ts +4 -0
  51. package/dist/gates/verdict-cause.js +63 -0
  52. package/dist/graph/schema.d.ts +6 -0
  53. package/dist/graph/schema.js +8 -5
  54. package/dist/route/router.d.ts +0 -5
  55. package/dist/route/router.js +16 -20
  56. package/dist/run/consult.d.ts +6 -0
  57. package/dist/run/consult.js +35 -25
  58. package/dist/run/daemon.d.ts +48 -2
  59. package/dist/run/daemon.js +1488 -330
  60. package/dist/run/journal.d.ts +56 -3
  61. package/dist/run/journal.js +358 -4
  62. package/dist/run/stall.d.ts +35 -1
  63. package/dist/run/stall.js +118 -8
  64. package/dist/tui/cockpit/capture.d.ts +12 -0
  65. package/dist/tui/cockpit/capture.js +37 -1
  66. package/dist/tui/cockpit/components.d.ts +2 -0
  67. package/dist/tui/cockpit/components.js +8 -8
  68. package/dist/tui/cockpit/derive.d.ts +29 -2
  69. package/dist/tui/cockpit/derive.js +219 -23
  70. package/dist/tui/cockpit/run-cockpit.js +128 -27
  71. package/dist/tui/cockpit/theme.d.ts +32 -26
  72. package/dist/tui/cockpit/theme.js +11 -5
  73. package/dist/tui/ink/components.d.ts +0 -15
  74. package/dist/tui/ink/components.js +0 -17
  75. package/dist/tui/ink/fleet-app.d.ts +4 -1
  76. package/dist/tui/ink/fleet-app.js +134 -13
  77. package/fixtures/sample.native.md +1 -1
  78. package/package.json +1 -1
  79. package/skills/tickmarkr-overseer/SKILL.md +354 -34
  80. package/skills/tickmarkr-overseer/scripts/watch-artifacts.sh +70 -0
  81. package/skills/tickmarkr-overseer/scripts/watch-panes.sh +1 -1
  82. package/dist/tui/ink/studio-app.d.ts +0 -59
  83. package/dist/tui/ink/studio-app.js +0 -320
  84. package/dist/tui/save.d.ts +0 -38
  85. package/dist/tui/save.js +0 -96
  86. package/dist/tui/staging.d.ts +0 -29
  87. package/dist/tui/staging.js +0 -78
@@ -1,320 +0,0 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
2
- import { render, useApp, useInput } from "ink";
3
- import { useEffect, useRef, useState } from "react";
4
- import { allAdapters, doctorAgeMs, readDoctor } from "../../adapters/registry.js";
5
- import { fleetEditableFromConfig, loadConfig } from "../../config/config.js";
6
- import { loadGraph } from "../../graph/graph.js";
7
- import { Journal, readAllTelemetry, RUNS_WINDOW, } from "../../run/journal.js";
8
- import { buildSaveProposal, confirmSave } from "../save.js";
9
- import { FleetStaging } from "../staging.js";
10
- import { DiffConfirmationScreen, StudioScreen, } from "./components.js";
11
- const STATUS = {
12
- "task-dispatch": "running", "task-done": "done", "task-failed": "failed",
13
- "task-human": "human", "task-approved": "pending",
14
- };
15
- const HELP = [
16
- "Key bindings",
17
- "1-5 switch view",
18
- "tab cycle views",
19
- "? show this help",
20
- "esc / q quit",
21
- "u revert staged changes",
22
- "s save staged changes",
23
- ];
24
- function loadFleetData(repoRoot) {
25
- try {
26
- const cfg = loadConfig(repoRoot);
27
- const health = readDoctor(repoRoot);
28
- if (!health)
29
- return undefined;
30
- const editable = fleetEditableFromConfig(cfg);
31
- const adapters = allAdapters().flatMap((adapter) => {
32
- if (!health[adapter.id]?.installed)
33
- return [];
34
- const models = adapter.channels(cfg).map((channel) => ({
35
- model: channel.model,
36
- tier: channel.tier,
37
- channel: channel.channel,
38
- }));
39
- return models.length ? [{ adapter: adapter.id, models }] : [];
40
- });
41
- return {
42
- adapters,
43
- health,
44
- doctorAgeMs: doctorAgeMs(repoRoot),
45
- denyAdapters: editable.denyAdapters,
46
- denyModels: editable.denyModels,
47
- telemetry: readAllTelemetry(repoRoot, RUNS_WINDOW),
48
- };
49
- }
50
- catch {
51
- // Best-effort read surface: line-mode commands remain the diagnostic path when config is unavailable.
52
- return undefined;
53
- }
54
- }
55
- function emptyStaging() {
56
- return new FleetStaging({
57
- denyAdapters: [],
58
- denyModels: [],
59
- tiers: {},
60
- map: {},
61
- floors: {},
62
- });
63
- }
64
- function loadStaging(repoRoot) {
65
- try {
66
- return new FleetStaging(fleetEditableFromConfig(loadConfig(repoRoot)));
67
- }
68
- catch {
69
- return emptyStaging();
70
- }
71
- }
72
- const componentView = (id, label, line) => ({ id, label, render: () => [line] });
73
- const createView = (id, label) => (..._) => componentView(id, label, `${label} view`);
74
- const createFleetView = createView("fleet", "Fleet"), createRoutingView = createView("routing", "Routing"), createPreviewView = createView("preview", "Preview"), createProfileView = createView("profile", "Profile"), createRunsView = createView("runs", "Runs");
75
- function defaultViews(repoRoot, staging) {
76
- return [
77
- createFleetView(loadFleetData(repoRoot), staging),
78
- createRoutingView({ repoRoot, staging }),
79
- createPreviewView({ cwd: repoRoot }),
80
- createProfileView({ repoRoot }),
81
- createRunsView(undefined, { repoRoot }),
82
- ];
83
- }
84
- const emptyGraph = () => ({ version: 1, spec: { source: "prd", paths: [], hash: "" }, tasks: [] });
85
- function loadRunsData(repoRoot) {
86
- const runId = Journal.latestRunId(repoRoot, { withJournal: true }) ?? undefined;
87
- let graph = emptyGraph();
88
- try {
89
- graph = loadGraph(repoRoot);
90
- }
91
- catch { /* no graph loaded */ }
92
- return { runId, events: runId ? Journal.open(repoRoot, runId).read() : [], graph };
93
- }
94
- export function foldConsultDossier(data, taskId) {
95
- let prompt = 0;
96
- const verdicts = data.events.flatMap((event) => {
97
- if (event.taskId !== taskId || event.event !== "consult-verdict")
98
- return [];
99
- const action = event.data.action;
100
- if (!["retry", "reroute", "decompose", "human"].includes(action))
101
- return [];
102
- return [{
103
- action,
104
- reason: typeof event.data.reason === "string" ? event.data.reason : undefined,
105
- prompt: data.prompts?.[taskId]?.[prompt++],
106
- }];
107
- });
108
- return { taskId, verdicts };
109
- }
110
- export function buildRunsCockpitTasks(data, nowMs) {
111
- return data.graph.tasks.map((task) => {
112
- const events = data.events.filter((event) => event.taskId === task.id);
113
- const state = [...events].reverse().find((event) => STATUS[event.event]);
114
- const status = STATUS[state?.event ?? ""] ?? task.status;
115
- const phaseStart = [...events].reverse().find((event) => event.event === "phase-start");
116
- const start = phaseStart ?? (state?.event === "task-dispatch" ? state : undefined);
117
- const phase = typeof phaseStart?.data.phase === "string" ? phaseStart.data.phase : undefined;
118
- const running = status === "running" && start !== undefined;
119
- const elapsedMs = running ? Math.max(0, nowMs - Date.parse(start.ts)) : 0;
120
- return {
121
- id: task.id, status,
122
- ...(running ? { phase: phase ?? "worker",
123
- elapsed: `${Math.floor(elapsedMs / 1000)}s` } : {}),
124
- consultCount: foldConsultDossier(data, task.id).verdicts.length,
125
- };
126
- });
127
- }
128
- function dossierLines(data) {
129
- if (!data)
130
- return ["d opens consult dossier"];
131
- if (!data.verdicts.length)
132
- return [`no consult verdicts recorded for ${data.taskId}`];
133
- return [`Consult dossier — ${data.taskId}`, "d back", ...data.verdicts.flatMap((verdict, index) => [
134
- `❯ ${index + 1}. ${verdict.action}${verdict.reason ? ` — ${verdict.reason}` : ""}`,
135
- ` prompt ${index + 1}`,
136
- ...(verdict.prompt ?? "(prompt unavailable)").split("\n")
137
- .map((line) => ` ${line.replace(/^#{1,6}\s+/, "")}`),
138
- ])];
139
- }
140
- function runsLines(runId, tasks, cursor) {
141
- if (!runId)
142
- return ["Runs cockpit", "no run loaded"];
143
- return [`Runs cockpit — ${runId}`, "d consult dossier", ...tasks.flatMap((task, index) => [
144
- `${index === cursor ? "❯ " : " "}${task.id} — ${task.status}`,
145
- ` ${task.phase ? `${task.phase} · ${task.elapsed}` : "waiting"}${task.consultCount ? ` · ${task.consultCount} consult verdict` : ""}`,
146
- ])];
147
- }
148
- export function StudioApp({ views: suppliedViews, repoRoot = process.cwd(), globalDir, staging: suppliedStaging, runsData: suppliedRunsData, clock = Date.now, columns = 80, rows = 24, }) {
149
- const { exit } = useApp();
150
- const stagingRef = useRef(undefined);
151
- stagingRef.current ??= suppliedStaging ?? loadStaging(repoRoot);
152
- const staging = stagingRef.current;
153
- const viewsRef = useRef(undefined);
154
- viewsRef.current ??= suppliedViews ?? defaultViews(repoRoot, staging);
155
- const views = viewsRef.current;
156
- const [active, setActive] = useState(0);
157
- const [help, setHelp] = useState(false);
158
- const [saveProposal, setSaveProposal] = useState(null);
159
- const [notice, setNotice] = useState(null);
160
- const [runsData, setRunsData] = useState(() => suppliedRunsData ?? loadRunsData(repoRoot));
161
- const [nowMs, setNowMs] = useState(clock);
162
- const [dossierOpen, setDossierOpen] = useState(false);
163
- const [, repaint] = useState(0);
164
- const nativeRuns = suppliedViews === undefined && views[active]?.id === "runs";
165
- const runTasks = buildRunsCockpitTasks(runsData, nowMs);
166
- const runsCursor = Math.max(0, runTasks.findIndex((task) => task.consultCount > 0));
167
- const selectedRunTask = runTasks[runsCursor];
168
- const dossier = selectedRunTask ? foldConsultDossier(runsData, selectedRunTask.id) : undefined;
169
- useEffect(() => {
170
- if (!nativeRuns)
171
- return;
172
- const timer = setInterval(() => {
173
- setNowMs(clock());
174
- if (!suppliedRunsData)
175
- setRunsData(loadRunsData(repoRoot));
176
- }, 250);
177
- return () => clearInterval(timer);
178
- }, [clock, nativeRuns, repoRoot, suppliedRunsData]);
179
- useInput((input, key) => {
180
- if (key.escape) {
181
- if (help)
182
- setHelp(false);
183
- else if (saveProposal)
184
- setSaveProposal(null);
185
- else
186
- exit();
187
- return;
188
- }
189
- if (key.ctrl && input === "c") {
190
- exit();
191
- return;
192
- }
193
- if (saveProposal) {
194
- if (input === "n") {
195
- setSaveProposal(null);
196
- }
197
- else if (input === "t") {
198
- const target = saveProposal.target === "repo" ? "global" : "repo";
199
- setSaveProposal(buildSaveProposal({
200
- repoRoot,
201
- loaded: staging.loadedState,
202
- staged: staging.current,
203
- target,
204
- globalDir,
205
- }));
206
- }
207
- else if (input === "y") {
208
- const result = confirmSave({
209
- repoRoot,
210
- loaded: staging.loadedState,
211
- staged: staging.current,
212
- target: saveProposal.target,
213
- globalDir,
214
- });
215
- if (result.kind === "written") {
216
- const nextStaging = new FleetStaging(staging.current);
217
- stagingRef.current = nextStaging;
218
- if (!suppliedViews)
219
- viewsRef.current = defaultViews(repoRoot, nextStaging);
220
- setNotice(`wrote ${result.path}`);
221
- }
222
- else if (result.kind === "refused") {
223
- setNotice(`save refused: ${result.reason}`);
224
- }
225
- setSaveProposal(null);
226
- }
227
- return;
228
- }
229
- if (input === "q") {
230
- if (!help)
231
- exit();
232
- return;
233
- }
234
- if (input === "?") {
235
- setHelp(true);
236
- return;
237
- }
238
- if (help)
239
- return;
240
- if (nativeRuns && input === "d" && (dossierOpen || selectedRunTask)) {
241
- setDossierOpen((open) => !open);
242
- return;
243
- }
244
- if (input === "s") {
245
- if (!staging.isDirty) {
246
- setNotice("no staged changes");
247
- }
248
- else {
249
- setNotice(null);
250
- setSaveProposal(buildSaveProposal({
251
- repoRoot,
252
- loaded: staging.loadedState,
253
- staged: staging.current,
254
- target: "repo",
255
- globalDir,
256
- }));
257
- }
258
- return;
259
- }
260
- if (input === "u") {
261
- staging.revert();
262
- setNotice(staging.isDirty ? null : "no staged changes");
263
- repaint((revision) => revision + 1);
264
- return;
265
- }
266
- if (key.tab) {
267
- setActive((index) => (index + 1) % views.length);
268
- setNotice(null);
269
- setDossierOpen(false);
270
- return;
271
- }
272
- if (/^[1-9]$/.test(input)) {
273
- const index = Number(input) - 1;
274
- if (index < views.length) {
275
- setActive(index);
276
- setNotice(null);
277
- setDossierOpen(false);
278
- }
279
- return;
280
- }
281
- const name = key.upArrow ? "up" : key.downArrow ? "down" : null;
282
- if (name) {
283
- views[active]?.key?.(name);
284
- repaint((revision) => revision + 1);
285
- }
286
- });
287
- const view = views[active];
288
- const lines = help
289
- ? HELP
290
- : nativeRuns
291
- ? dossierOpen
292
- ? dossierLines(dossier)
293
- : runsLines(runsData.runId, runTasks, runsCursor)
294
- : [
295
- ...view.render({ cols: columns, rows: Math.max(rows - 2, 1) }),
296
- ...(notice ? [notice] : []),
297
- ];
298
- const count = staging.changeCount;
299
- const status = staging.isDirty
300
- ? `● ${count} staged change${count === 1 ? "" : "s"}`
301
- : "no staged changes";
302
- return (_jsx(StudioScreen, { tabs: views.map((candidate) => candidate.label), active: active, lines: lines, status: status, children: saveProposal
303
- ? (_jsx(DiffConfirmationScreen, { target: saveProposal.target, targetPath: saveProposal.targetPath, diff: saveProposal.diff, liveRun: saveProposal.liveRun }))
304
- : undefined }));
305
- }
306
- export async function runStudioInk({ input, output, views, repoRoot, globalDir, staging, runsData, clock, debug = false, }) {
307
- const app = render(_jsx(StudioApp, { views: views, repoRoot: repoRoot, globalDir: globalDir, staging: staging, runsData: runsData, clock: clock, columns: output.columns, rows: output.rows }), {
308
- stdin: input,
309
- stdout: output,
310
- exitOnCtrlC: false,
311
- patchConsole: false,
312
- debug,
313
- });
314
- try {
315
- await app.waitUntilExit();
316
- }
317
- finally {
318
- app.unmount();
319
- }
320
- }
@@ -1,38 +0,0 @@
1
- import { type FleetEditable } from "../config/config.js";
2
- export type SaveTarget = "repo" | "global";
3
- /** Notice surfaced in the save modal whenever a run lock is live. */
4
- export declare const RELOAD_GUARD_NOTICE = "reload guard: a live run is active; the running daemon will not see these changes until it reloads";
5
- export type SaveProposal = {
6
- target: SaveTarget;
7
- targetPath: string;
8
- before: string;
9
- after: string;
10
- diff: string;
11
- liveRun: boolean;
12
- loadError: string | null;
13
- };
14
- export type SaveResult = {
15
- kind: "written";
16
- path: string;
17
- } | {
18
- kind: "declined";
19
- } | {
20
- kind: "refused";
21
- reason: string;
22
- };
23
- /** Build the diff-confirm payload for the current staging delta and chosen target. */
24
- export declare function buildSaveProposal(opts: {
25
- repoRoot: string;
26
- loaded: FleetEditable;
27
- staged: FleetEditable;
28
- target: SaveTarget;
29
- globalDir?: string;
30
- }): SaveProposal;
31
- /** Confirm and execute the write for the chosen target. */
32
- export declare function confirmSave(opts: {
33
- repoRoot: string;
34
- loaded: FleetEditable;
35
- staged: FleetEditable;
36
- target: SaveTarget;
37
- globalDir?: string;
38
- }): SaveResult;
package/dist/tui/save.js DELETED
@@ -1,96 +0,0 @@
1
- import { randomUUID } from "node:crypto";
2
- import { existsSync, mkdtempSync, mkdirSync, readFileSync, renameSync, rmSync, writeFileSync } from "node:fs";
3
- import { tmpdir } from "node:os";
4
- import { dirname, join } from "node:path";
5
- import { fleetEditableFromConfig, fleetEditableEquals, fleetRepoOverlayFromDelta, globalConfigDir, loadConfigWithMode, readOverlayFile, repoOverlayPath, repoOverlayYaml, unifiedYamlDiff, } from "../config/config.js";
6
- import { isRunLockLive } from "../run/lock.js";
7
- /** Notice surfaced in the save modal whenever a run lock is live. */
8
- export const RELOAD_GUARD_NOTICE = "reload guard: a live run is active; the running daemon will not see these changes until it reloads";
9
- function overlayPath(repoRoot, target, globalDir) {
10
- return target === "repo"
11
- ? repoOverlayPath(repoRoot)
12
- : join(globalDir ?? globalConfigDir(), "config.yaml");
13
- }
14
- function currentOverlayText(path) {
15
- return existsSync(path) ? readFileSync(path, "utf8") : "";
16
- }
17
- function computeAfterBytes(target, loaded, staged, repoRoot, globalDir) {
18
- const path = overlayPath(repoRoot, target, globalDir);
19
- const existing = readOverlayFile(path);
20
- // Reuse the existing fleet serializer and diff renderer rather than inventing a parallel formatter.
21
- const merged = fleetRepoOverlayFromDelta(loaded, staged, existing);
22
- return repoOverlayYaml(merged);
23
- }
24
- function roundTripError(target, repoRoot, after, staged, globalDir) {
25
- try {
26
- let effective;
27
- if (target === "repo") {
28
- effective = loadConfigWithMode(repoRoot, { globalDir, repoOverlayText: after });
29
- }
30
- else {
31
- // Validate a candidate global overlay by loading with it in a scratch globalDir.
32
- const scratch = mkdtempSync(join(tmpdir(), "tickmarkr-global-rt-"));
33
- try {
34
- writeFileSync(join(scratch, "config.yaml"), after);
35
- effective = loadConfigWithMode(repoRoot, { globalDir: scratch });
36
- }
37
- finally {
38
- try {
39
- rmSync(scratch, { recursive: true, force: true });
40
- }
41
- catch { /* best-effort cleanup */ }
42
- }
43
- }
44
- const reparsed = fleetEditableFromConfig(effective.cfg);
45
- if (!fleetEditableEquals(reparsed, staged)) {
46
- return "round-trip mismatch: the written overlay does not re-parse to the staged state";
47
- }
48
- return null;
49
- }
50
- catch (e) {
51
- return e.message;
52
- }
53
- }
54
- /** Build the diff-confirm payload for the current staging delta and chosen target. */
55
- export function buildSaveProposal(opts) {
56
- const path = overlayPath(opts.repoRoot, opts.target, opts.globalDir);
57
- const before = currentOverlayText(path);
58
- const after = computeAfterBytes(opts.target, opts.loaded, opts.staged, opts.repoRoot, opts.globalDir);
59
- const diff = unifiedYamlDiff(before, after, path);
60
- const loadError = roundTripError(opts.target, opts.repoRoot, after, opts.staged, opts.globalDir);
61
- return {
62
- target: opts.target,
63
- targetPath: path,
64
- before,
65
- after,
66
- diff,
67
- liveRun: isRunLockLive(opts.repoRoot),
68
- loadError,
69
- };
70
- }
71
- function atomicWrite(path, bytes) {
72
- const dir = dirname(path);
73
- mkdirSync(dir, { recursive: true });
74
- // The sibling temp keeps rename(2) on one filesystem: readers see old or new bytes, never a partial overlay.
75
- const tmp = join(dir, `.tickmarkr-save-${randomUUID()}.tmp`);
76
- try {
77
- writeFileSync(tmp, bytes);
78
- renameSync(tmp, path);
79
- }
80
- catch (e) {
81
- rmSync(tmp, { force: true }); // a failed rename must not leave a partial candidate behind
82
- throw e;
83
- }
84
- }
85
- /** Confirm and execute the write for the chosen target. */
86
- export function confirmSave(opts) {
87
- const proposal = buildSaveProposal(opts);
88
- if (proposal.loadError) {
89
- return { kind: "refused", reason: proposal.loadError };
90
- }
91
- if (proposal.before === proposal.after) {
92
- return { kind: "declined" };
93
- }
94
- atomicWrite(proposal.targetPath, proposal.after);
95
- return { kind: "written", path: proposal.targetPath };
96
- }
@@ -1,29 +0,0 @@
1
- import { type FleetEditable } from "../config/config.js";
2
- /** One in-memory edit to the buffered fleet state. */
3
- export type FleetEdit = (buffer: FleetEditable) => void;
4
- /**
5
- * Staged-changes buffer for the Fleet Studio write path.
6
- *
7
- * - The loaded state is captured at construction and never mutated.
8
- * - Edits apply to an in-memory buffer only.
9
- * - `revert()` discards the buffer and restores the loaded state.
10
- * - The delta is computed through the existing `fleetEditableEquals` comparison.
11
- * - No code path in this module writes to disk.
12
- */
13
- export declare class FleetStaging {
14
- private readonly loaded;
15
- private buffer;
16
- constructor(loaded: FleetEditable);
17
- /** Read-only snapshot of the originally loaded state. */
18
- get loadedState(): FleetEditable;
19
- /** Current buffered (possibly edited) state. */
20
- get current(): FleetEditable;
21
- /** Apply an edit to the buffer. Never touches disk. */
22
- apply(edit: FleetEdit): void;
23
- /** Discard all buffered edits and restore the loaded state. */
24
- revert(): void;
25
- /** True when the buffer differs from the loaded state. */
26
- get isDirty(): boolean;
27
- /** Number of distinct staged changes vs the loaded state. */
28
- get changeCount(): number;
29
- }
@@ -1,78 +0,0 @@
1
- import { fleetEditableEquals } from "../config/config.js";
2
- /**
3
- * Staged-changes buffer for the Fleet Studio write path.
4
- *
5
- * - The loaded state is captured at construction and never mutated.
6
- * - Edits apply to an in-memory buffer only.
7
- * - `revert()` discards the buffer and restores the loaded state.
8
- * - The delta is computed through the existing `fleetEditableEquals` comparison.
9
- * - No code path in this module writes to disk.
10
- */
11
- export class FleetStaging {
12
- loaded;
13
- buffer;
14
- constructor(loaded) {
15
- this.loaded = structuredClone(loaded);
16
- this.buffer = structuredClone(loaded);
17
- }
18
- /** Read-only snapshot of the originally loaded state. */
19
- get loadedState() {
20
- return structuredClone(this.loaded);
21
- }
22
- /** Current buffered (possibly edited) state. */
23
- get current() {
24
- return structuredClone(this.buffer);
25
- }
26
- /** Apply an edit to the buffer. Never touches disk. */
27
- apply(edit) {
28
- edit(this.buffer);
29
- }
30
- /** Discard all buffered edits and restore the loaded state. */
31
- revert() {
32
- this.buffer = structuredClone(this.loaded);
33
- }
34
- /** True when the buffer differs from the loaded state. */
35
- get isDirty() {
36
- return !fleetEditableEquals(this.loaded, this.buffer);
37
- }
38
- /** Number of distinct staged changes vs the loaded state. */
39
- get changeCount() {
40
- return fleetEditableDeltaCount(this.loaded, this.buffer);
41
- }
42
- }
43
- /** Count changed leaves using the same equality semantics as `fleetEditableEquals`. */
44
- function fleetEditableDeltaCount(initial, edited) {
45
- let count = 0;
46
- if (JSON.stringify(initial.denyAdapters) !== JSON.stringify(edited.denyAdapters)) {
47
- count += 1;
48
- }
49
- if (JSON.stringify(initial.denyModels) !== JSON.stringify(edited.denyModels)) {
50
- count += 1;
51
- }
52
- const mapKeys = new Set([...Object.keys(initial.map), ...Object.keys(edited.map)]);
53
- for (const shape of mapKeys) {
54
- if (JSON.stringify(initial.map[shape]) !== JSON.stringify(edited.map[shape])) {
55
- count += 1;
56
- }
57
- }
58
- const floorKeys = new Set([...Object.keys(initial.floors), ...Object.keys(edited.floors)]);
59
- for (const shape of floorKeys) {
60
- if (initial.floors[shape] !== edited.floors[shape]) {
61
- count += 1;
62
- }
63
- }
64
- const adapterKeys = new Set([...Object.keys(initial.tiers), ...Object.keys(edited.tiers)]);
65
- for (const adapter of adapterKeys) {
66
- const modelKeys = new Set([
67
- ...Object.keys(initial.tiers[adapter] ?? {}),
68
- ...Object.keys(edited.tiers[adapter] ?? {}),
69
- ]);
70
- for (const model of modelKeys) {
71
- if (JSON.stringify(initial.tiers[adapter]?.[model]) !==
72
- JSON.stringify(edited.tiers[adapter]?.[model])) {
73
- count += 1;
74
- }
75
- }
76
- }
77
- return count;
78
- }