@awebai/oats 0.61.0 → 0.63.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 (90) hide show
  1. package/README.md +1 -1
  2. package/bin/oats.mjs +27 -12
  3. package/docs/capabilities.md +1 -1
  4. package/docs/desktop-cli-api.md +30 -2
  5. package/docs/execution-targets.md +89 -4
  6. package/docs/implementation.md +2 -1
  7. package/docs/named-test-runs.md +382 -0
  8. package/docs/official-catalog.md +1 -1
  9. package/docs/packages.md +5 -5
  10. package/docs/release-lane.md +13 -0
  11. package/docs/release-notes/v0.62.0.md +223 -0
  12. package/docs/release-notes/v0.63.0.md +135 -0
  13. package/docs/souls-and-instances.md +6 -1
  14. package/docs/upgrading.md +135 -11
  15. package/docs/workspaces.md +1 -1
  16. package/lib/core.mjs +73 -23
  17. package/lib/doctor-capture.mjs +35 -0
  18. package/lib/session-viewer.mjs +86 -7
  19. package/lib/tree-copy.mjs +188 -7
  20. package/package-catalog.json +1 -1
  21. package/package.json +1 -1
  22. package/packages/client/cli-locator.mjs +2 -2
  23. package/packages/record/README.md +87 -13
  24. package/packages/record/bin/capture-hook.mjs +8 -0
  25. package/packages/record/bin/capture.mjs +200 -139
  26. package/packages/record/bin/recall.mjs +8 -3
  27. package/packages/record/bin/setup.mjs +116 -225
  28. package/packages/record/bin/turn-record.mjs +2 -2
  29. package/packages/record/docs/capture-service.md +1527 -28
  30. package/packages/record/docs/capture-status.schema.json +429 -12
  31. package/packages/record/lib/capture-admission.mjs +82 -0
  32. package/packages/record/lib/capture-aw-unit.mjs +137 -0
  33. package/packages/record/lib/capture-aw.mjs +31 -12
  34. package/packages/record/lib/capture-budget.mjs +31 -0
  35. package/packages/record/lib/capture-cc.mjs +39 -6
  36. package/packages/record/lib/capture-cleanup-queue.mjs +135 -0
  37. package/packages/record/lib/capture-cleanup-work.mjs +77 -0
  38. package/packages/record/lib/capture-command-operation.mjs +37 -0
  39. package/packages/record/lib/capture-command-output.mjs +62 -0
  40. package/packages/record/lib/capture-command-worker.mjs +6 -0
  41. package/packages/record/lib/capture-command.mjs +65 -0
  42. package/packages/record/lib/capture-completion.mjs +152 -0
  43. package/packages/record/lib/capture-context.mjs +50 -0
  44. package/packages/record/lib/capture-default-roots.mjs +30 -0
  45. package/packages/record/lib/capture-discovery.mjs +114 -0
  46. package/packages/record/lib/capture-failures.mjs +45 -0
  47. package/packages/record/lib/capture-health-doctor.mjs +13 -0
  48. package/packages/record/lib/capture-health-installation.mjs +117 -0
  49. package/packages/record/lib/capture-health.mjs +116 -0
  50. package/packages/record/lib/capture-hook-ownership.mjs +58 -0
  51. package/packages/record/lib/capture-hook-runner.mjs +17 -0
  52. package/packages/record/lib/capture-hook.mjs +26 -0
  53. package/packages/record/lib/capture-index-inventory.mjs +205 -0
  54. package/packages/record/lib/capture-index-outcomes.mjs +113 -0
  55. package/packages/record/lib/capture-index-reset.mjs +110 -0
  56. package/packages/record/lib/capture-index-work.mjs +77 -0
  57. package/packages/record/lib/capture-issue-preparation.mjs +73 -0
  58. package/packages/record/lib/capture-issues.mjs +15 -2
  59. package/packages/record/lib/capture-lock.mjs +137 -17
  60. package/packages/record/lib/capture-native-unit.mjs +322 -0
  61. package/packages/record/lib/capture-pass.mjs +116 -0
  62. package/packages/record/lib/capture-recovery-snapshot.mjs +182 -0
  63. package/packages/record/lib/capture-retained-scratch.mjs +213 -0
  64. package/packages/record/lib/capture-retry.mjs +102 -0
  65. package/packages/record/lib/capture-run.mjs +125 -0
  66. package/packages/record/lib/capture-scratch.mjs +12 -3
  67. package/packages/record/lib/capture-service-definition.mjs +104 -0
  68. package/packages/record/lib/capture-service-install.mjs +362 -0
  69. package/packages/record/lib/capture-service-ownership.mjs +137 -0
  70. package/packages/record/lib/capture-service-runner.mjs +18 -0
  71. package/packages/record/lib/capture-small-snapshot.mjs +85 -0
  72. package/packages/record/lib/capture-source-discovery.mjs +319 -0
  73. package/packages/record/lib/capture-source-queue.mjs +199 -0
  74. package/packages/record/lib/capture-source-work.mjs +85 -0
  75. package/packages/record/lib/capture-state.mjs +16 -71
  76. package/packages/record/lib/capture-status.mjs +171 -0
  77. package/packages/record/lib/capture-supervisor.mjs +136 -0
  78. package/packages/record/lib/capture-watch.mjs +32 -0
  79. package/packages/record/lib/capture-work-session.mjs +241 -0
  80. package/packages/record/lib/capture-worker.mjs +74 -0
  81. package/packages/record/lib/derived-state.mjs +58 -17
  82. package/packages/record/lib/file-lines.mjs +22 -6
  83. package/packages/record/lib/formats.mjs +4 -3
  84. package/packages/record/lib/index-capture.mjs +97 -0
  85. package/packages/record/lib/index-db.mjs +121 -66
  86. package/packages/record/lib/index-reset.mjs +19 -0
  87. package/packages/record/lib/store.mjs +46 -14
  88. package/packages/record/lib/transcript-prefix.mjs +125 -0
  89. package/skills/oats-getting-started/SKILL.md +1 -1
  90. package/docs/macos-test-runs.md +0 -246
@@ -0,0 +1,362 @@
1
+ // Setup's two-phase service migration. Preflight is read-only across every
2
+ // target; apply rechecks identities, backs up replacements, then mutates only
3
+ // the named label/units. Manager failure is partial apply, not atomic rollback.
4
+ import fs from "node:fs";
5
+ import { spawnSync } from "node:child_process";
6
+ import { randomUUID } from "node:crypto";
7
+ import { basename, dirname, isAbsolute, join } from "node:path";
8
+ import { CAPTURE_POLICY } from "./capture-budget.mjs";
9
+ import { capturePendingActivationName, captureServiceDefinition, captureServiceLabel, captureServiceUnit, captureServiceTimer } from "./capture-service-definition.mjs";
10
+ import { captureServiceOwnership, captureServiceArgvOwnership } from "./capture-service-ownership.mjs";
11
+
12
+ export const serviceShellWord = value => /^[A-Za-z0-9_./:@%+,-]+$/.test(value) ? value : `'${value.replace(/'/g, `'\\''`)}'`;
13
+ const identity = stat => [stat.dev, stat.ino, stat.mode, stat.size, stat.mtimeMs, stat.ctimeMs].join(":");
14
+ function parents(path) {
15
+ const records = [];
16
+ for (let directory = dirname(path); ; directory = dirname(directory)) {
17
+ let stat;
18
+ try { stat = fs.lstatSync(directory); }
19
+ catch (error) { if (error.code !== "ENOENT") throw error; }
20
+ if (stat) {
21
+ let target = null;
22
+ if (stat.isSymbolicLink()) {
23
+ try { target = fs.statSync(directory); }
24
+ catch (error) { if (error.code !== "ENOENT") throw error; }
25
+ }
26
+ // Even a dangling ancestor link has an identity to retain. Its missing
27
+ // target must not turn a later retargeting into ordinary directory creation.
28
+ records.push([directory, `${stat.dev}:${stat.ino}:${stat.mode}`, stat.isSymbolicLink() ? fs.readlinkSync(directory) : null,
29
+ target ? `${target.dev}:${target.ino}:${target.mode}` : null]);
30
+ } else records.push([directory, null, null, null]);
31
+ if (dirname(directory) === directory) return records;
32
+ }
33
+ }
34
+
35
+ export function captureSetupSnapshot(path) {
36
+ const ancestry = parents(path);
37
+ let stat;
38
+ try { stat = fs.lstatSync(path); }
39
+ catch (error) { if (error.code === "ENOENT") return { path, kind: "absent", parents: ancestry }; throw error; }
40
+ const before = identity(stat);
41
+ let bytes, link;
42
+ if (stat.isSymbolicLink()) link = fs.readlinkSync(path);
43
+ else {
44
+ if (!stat.isFile() || stat.size > 1024 * 1024) throw new Error(`refusing nonregular or oversized setup target ${path}`);
45
+ const fd = fs.openSync(path, fs.constants.O_RDONLY | fs.constants.O_NOFOLLOW);
46
+ try {
47
+ if (identity(fs.fstatSync(fd)) !== before) throw new Error(`setup target changed while opening ${path}`);
48
+ bytes = fs.readFileSync(fd);
49
+ if (identity(fs.fstatSync(fd)) !== before) throw new Error(`setup target changed while reading ${path}`);
50
+ } finally { fs.closeSync(fd); }
51
+ }
52
+ if (identity(fs.lstatSync(path)) !== before) throw new Error(`setup target changed while reading ${path}`);
53
+ return { path, kind: link === undefined ? "file" : "link", identity: before, bytes, link, parents: ancestry };
54
+ }
55
+
56
+ function recheckParents(snapshot, current, createdParents = new Map()) {
57
+ if (snapshot.parents.some(record => {
58
+ const expected = record[1] === null ? createdParents.get(record[0]) ?? record : record;
59
+ return !current.parents.some(now => JSON.stringify(now) === JSON.stringify(expected));
60
+ }))
61
+ throw new Error(`setup target parent changed since preflight: ${snapshot.path}; re-run setup`);
62
+ }
63
+ export function recheckCaptureSetup(snapshot, createdParents = new Map()) {
64
+ recheckParents(snapshot, { parents: parents(snapshot.path) }, createdParents);
65
+ const current = captureSetupSnapshot(snapshot.path);
66
+ recheckParents(snapshot, current, createdParents);
67
+ if (current.kind !== snapshot.kind || current.identity !== snapshot.identity || current.link !== snapshot.link ||
68
+ (snapshot.bytes && !snapshot.bytes.equals(current.bytes))) throw new Error(`setup target changed since preflight: ${snapshot.path}; re-run setup`);
69
+ }
70
+
71
+ export function writeCaptureSetup(snapshot, contents, createdParents = new Map()) {
72
+ recheckCaptureSetup(snapshot, createdParents);
73
+ // A missing ancestor is evidence, not permission to follow whatever appears
74
+ // there later. Create one level at a time, refusing EEXIST, and share only
75
+ // this apply's observed non-link directory identities with subsequent writes.
76
+ for (const record of [...snapshot.parents].reverse()) {
77
+ if (record[1] !== null || createdParents.has(record[0])) continue;
78
+ recheckCaptureSetup(snapshot, createdParents);
79
+ fs.mkdirSync(record[0]);
80
+ const stat = fs.lstatSync(record[0]);
81
+ if (!stat.isDirectory() || stat.isSymbolicLink()) throw new Error(`setup created parent changed: ${record[0]}; re-run setup`);
82
+ createdParents.set(record[0], [record[0], `${stat.dev}:${stat.ino}:${stat.mode}`, null, null]);
83
+ }
84
+ recheckCaptureSetup(snapshot, createdParents);
85
+ const temporary = `${snapshot.path}.tmp-${randomUUID()}`;
86
+ let temporaryIdentity;
87
+ try {
88
+ fs.writeFileSync(temporary, contents, { flag: "wx", mode: 0o600 });
89
+ temporaryIdentity = identity(fs.lstatSync(temporary));
90
+ recheckCaptureSetup(snapshot, createdParents);
91
+ fs.renameSync(temporary, snapshot.path);
92
+ } finally {
93
+ // A refused ancestor replacement also revokes cleanup through that path.
94
+ // Leave the original scratch file rather than unlink an unrelated target.
95
+ let safe = false;
96
+ try {
97
+ recheckParents(snapshot, { parents: parents(snapshot.path) }, createdParents);
98
+ safe = temporaryIdentity !== undefined && identity(fs.lstatSync(temporary)) === temporaryIdentity;
99
+ } catch { /* absent scratch or changed ancestry: no pathname cleanup */ }
100
+ if (safe) fs.unlinkSync(temporary);
101
+ }
102
+ }
103
+
104
+ const detail = result => [result.error?.message, result.signal && `signal ${result.signal}`, result.stderr?.trim(),
105
+ result.status !== null && result.status !== undefined && `exit ${result.status}`].filter(Boolean).join("; ") || "no exit status returned";
106
+ const manager = (command, argv) => spawnSync(command, argv, { encoding: "utf8", timeout: 10000, maxBuffer: 1024 * 1024 });
107
+ function call(run, command, argv) {
108
+ const result = run(command, argv);
109
+ if (result.error || result.signal || result.status === null || result.status === undefined)
110
+ throw new Error(`${command} ${argv.map(serviceShellWord).join(" ")} failed (${detail(result)}); check manager availability/access and re-run setup`);
111
+ return result;
112
+ }
113
+ function requireOk(run, command, argv) {
114
+ const result = call(run, command, argv);
115
+ if (result.status !== 0) throw new Error(`${command} ${argv.map(serviceShellWord).join(" ")} failed (${detail(result)}); re-run setup to recover the named service`);
116
+ return result.stdout ?? "";
117
+ }
118
+
119
+ function linuxState(run, unit) {
120
+ const output = requireOk(run, "systemctl", ["--user", "show", unit, "--no-pager", "--all",
121
+ "--property=LoadState,UnitFileState,ActiveState,SubState,FragmentPath,DropInPaths,NeedDaemonReload"]);
122
+ const fields = {};
123
+ for (const line of output.trim().split("\n")) {
124
+ const item = /^([A-Za-z]+)=(.*)$/.exec(line);
125
+ if (!item || Object.hasOwn(fields, item[1])) throw new Error(`indeterminate systemctl state for ${unit}`);
126
+ fields[item[1]] = item[2];
127
+ }
128
+ const keys = ["LoadState", "UnitFileState", "ActiveState", "SubState", "FragmentPath", "DropInPaths", "NeedDaemonReload"];
129
+ if (Object.keys(fields).length !== keys.length || keys.some(key => !Object.hasOwn(fields, key)) ||
130
+ !["loaded", "not-found", "masked"].includes(fields.LoadState) ||
131
+ !["", "enabled", "enabled-runtime", "disabled", "static", "masked", "masked-runtime"].includes(fields.UnitFileState) ||
132
+ !["active", "inactive", "failed", "activating", "deactivating"].includes(fields.ActiveState) || !["yes", "no"].includes(fields.NeedDaemonReload))
133
+ throw new Error(`indeterminate systemctl state for ${unit}`);
134
+ if (fields.DropInPaths) throw new Error(`unsupported manager drop-ins for ${unit}; inspect ${fields.DropInPaths}, or use --no-service`);
135
+ if (fields.LoadState === "not-found" && (fields.FragmentPath || fields.UnitFileState || fields.ActiveState !== "inactive"))
136
+ throw new Error(`inconsistent absent systemctl state for ${unit}`);
137
+ if (fields.LoadState === "loaded" && (!isAbsolute(fields.FragmentPath) || !fields.UnitFileState))
138
+ throw new Error(`indeterminate loaded systemctl identity for ${unit}`);
139
+ return fields;
140
+ }
141
+
142
+ function darwinState(run, domain, target) {
143
+ const disabledText = requireOk(run, "launchctl", ["print-disabled", domain]);
144
+ // Only the one disabled-services block, closed by a brace on its own line, is
145
+ // the override DB. Other blocks (login item associations, for one) carry other
146
+ // syntax and no disable state. launchd has printed both value spellings.
147
+ const blocks = [...disabledText.matchAll(/^[ \t]*disabled services = \{(?:[ \t]*\n([^]*?)^)?[ \t]*\}[ \t]*$/gm)];
148
+ if (blocks.length !== 1) throw new Error("indeterminate launchctl disabled state");
149
+ const disabled = new Map();
150
+ for (const line of (blocks[0][1] ?? "").split("\n").map(value => value.trim()).filter(Boolean)) {
151
+ const item = /^("(?:[^"\\]|\\.)*") => (true|false|disabled|enabled)\s*;?$/.exec(line);
152
+ if (!item) throw new Error("indeterminate launchctl disabled entry");
153
+ const label = JSON.parse(item[1]);
154
+ if (disabled.has(label)) throw new Error("duplicate launchctl disabled entry");
155
+ disabled.set(label, item[2] === "true" || item[2] === "disabled");
156
+ }
157
+ const result = call(run, "launchctl", ["print", target]);
158
+ if (result.status === 113 && /Could not find (?:specified )?service/.test(result.stderr ?? ""))
159
+ return { disabled: disabled.get(captureServiceLabel) === true, registered: false };
160
+ if (result.status !== 0) throw new Error(`launchctl print failed (${detail(result)}); cannot determine registration`);
161
+ const path = /^\s*path = (.+)$/m.exec(result.stdout ?? "")?.[1];
162
+ const block = /^\s*arguments = \{\n([^]*?)^\s*\}/m.exec(result.stdout ?? "");
163
+ if (!path || !block) throw new Error("indeterminate launchctl registered identity");
164
+ const argv = block[1].split("\n").map(line => line.trim()).filter(Boolean);
165
+ const interval = /^\s*run interval = (\d+) seconds\s*$/m.exec(result.stdout ?? "")?.[1];
166
+ return { disabled: disabled.get(captureServiceLabel) === true, registered: true, path, argv, interval: interval ? Number(interval) : null };
167
+ }
168
+
169
+ function inspect(plan) {
170
+ return plan.platform === "darwin" ? darwinState(plan.run, plan.domain, plan.target) :
171
+ { service: linuxState(plan.run, captureServiceUnit), timer: linuxState(plan.run, captureServiceTimer) };
172
+ }
173
+ function stateIdentity(state, platform) {
174
+ if (platform === "darwin") return JSON.stringify(state);
175
+ // A normal pass may finish during setup. Its activity is not ownership or
176
+ // enablement, so don't mistake that transition for operator replacement.
177
+ return JSON.stringify(Object.values(state).map(({ LoadState, UnitFileState, FragmentPath, DropInPaths, NeedDaemonReload }) =>
178
+ ({ LoadState, UnitFileState, FragmentPath, DropInPaths, NeedDaemonReload })));
179
+ }
180
+ // The recovery is the command the person runs (setupCommand: `oats setup` or
181
+ // `turn-record setup`), so a rerun selects its node the same way this run did.
182
+ function refuse(plan, code, found, replaceable = true) {
183
+ const recovery = `${plan.setupCommand} --owner ${serviceShellWord(plan.request.owner)} --root ${serviceShellWord(plan.request.root)}${plan.noHooks ? " --no-hooks" : ""}`;
184
+ const replacement = replaceable ? `replace only the named capture service with ${recovery} --replace-service` :
185
+ `--replace-service replaces only the named capture plist; remove that registration yourself, then re-run ${recovery}`;
186
+ throw Object.assign(new Error(`${code}: ${found}; ${replacement}, or keep it with ${recovery} --no-service`), { code });
187
+ }
188
+
189
+ export function preflightCaptureService({ platform, node, request, setupCommand, dry = false, replace = false,
190
+ noHooks = false, uid = process.getuid?.(), run = manager, log = console.log, intervalSeconds = CAPTURE_POLICY.intervalSeconds }) {
191
+ // intervalSeconds is the definition module's internal seam for guarded
192
+ // real-manager tests; ownership and verification expect what was rendered.
193
+ const definition = captureServiceDefinition({ platform, node, request, intervalSeconds }), schedule = { intervalSeconds };
194
+ // All targets are read before a refusal or mutation; no existsSync fallback
195
+ // may turn EACCES, a dangling link, or an unreadable target into absence.
196
+ const files = definition.files.map(file => {
197
+ const snapshot = captureSetupSnapshot(file.path), kind = file.path.endsWith(".plist") ? "plist" : file.path.endsWith(".timer") ? "timer" : "service";
198
+ const ownership = snapshot.kind === "absent" ? "absent" : platform === "linux" && snapshot.kind === "link" && snapshot.link === "/dev/null" ? "masked" : snapshot.kind === "file" &&
199
+ Buffer.from(snapshot.bytes.toString("utf8")).equals(snapshot.bytes) ? captureServiceOwnership(snapshot.bytes.toString("utf8"), kind, schedule) : "foreign";
200
+ return { ...file, snapshot, ownership, changed: snapshot.kind !== "file" || !snapshot.bytes.equals(Buffer.from(file.contents)) };
201
+ });
202
+ const plan = { platform, node, request: JSON.parse(definition.argv[2]), setupCommand, dry, replace, noHooks, run, log, files, intervalSeconds,
203
+ argv: definition.argv, domain: `gui/${uid}`, target: `gui/${uid}/${captureServiceLabel}` };
204
+ if (platform === "darwin" && !Number.isSafeInteger(uid)) throw new Error("cannot determine launchd user domain");
205
+ plan.state = dry ? null : inspect(plan);
206
+ // The marker counts only beside setup's own marked definitions; with no
207
+ // unit, or one without setup's mark, it is stale and authorizes nothing.
208
+ const markerPath = join(plan.request.root, capturePendingActivationName), marker = captureSetupSnapshot(markerPath);
209
+ if (!["absent", "file"].includes(marker.kind)) throw new Error(`cannot safely read the pending-activation marker ${markerPath}`);
210
+ plan.marker = marker;
211
+ plan.pending = marker.kind === "absent" ? null :
212
+ { path: markerPath, snapshot: marker, stale: !files.every(file => file.ownership === "periodic") };
213
+ // A label registered from any other plist is not a named file: booting it
214
+ // out would not remove that file, which can load it again, and the file is
215
+ // never setup's to unlink. Explicit replacement does not reach it.
216
+ if (platform === "darwin" && plan.state?.registered && plan.state.path !== files[0].path)
217
+ refuse(plan, "E_CAPTURE_SERVICE_FOREIGN", `launchd registration ${captureServiceLabel} is loaded from ${JSON.stringify(plan.state.path)}, not from the named capture plist ${JSON.stringify(files[0].path)}`, false);
218
+ const foreign = files.filter(file => file.ownership === "foreign");
219
+ if (platform === "darwin" && plan.state?.registered && captureServiceArgvOwnership(plan.state.argv) === "foreign") foreign.push({ path: plan.target });
220
+ if (platform === "linux" && plan.state) for (const [i, state] of Object.values(plan.state).entries()) {
221
+ if (state.FragmentPath && state.FragmentPath !== files[i].path && state.LoadState !== "masked") foreign.push({ path: state.FragmentPath });
222
+ }
223
+ if (foreign.length && !replace) refuse(plan, "E_CAPTURE_SERVICE_FOREIGN", `unrecognized definition/registration at ${foreign.map(file => JSON.stringify(file.path)).join(", ")}`);
224
+ // Report what was observed, not a cause: a disabled unit file state alone
225
+ // does not tell an operator's disable from an incomplete earlier activation.
226
+ const disabled = [];
227
+ if (platform === "darwin") {
228
+ if (plan.state?.disabled) disabled.push(`launchctl print-disabled ${plan.domain} lists ${captureServiceLabel} as disabled (named plist ${files[0].snapshot.kind === "absent" ? "absent" : "present"}, label ${plan.state.registered ? "registered" : "not registered"})`);
229
+ } else {
230
+ for (const file of files) if (file.ownership === "masked") disabled.push(`${JSON.stringify(file.path)} links to /dev/null`);
231
+ // A loaded, unmasked disabled unit beside setup's live marker is setup's
232
+ // own unverified activation (a failed enable), not an operator's choice.
233
+ const ownPending = plan.pending && !plan.pending.stale;
234
+ if (plan.state) for (const [i, state] of Object.values(plan.state).entries()) if (state.LoadState === "masked" || state.UnitFileState.startsWith("masked") ||
235
+ (state.UnitFileState === "disabled" && (files[i].snapshot.kind !== "absent" || state.LoadState !== "not-found") && !(ownPending && state.LoadState === "loaded")))
236
+ disabled.push(`${[captureServiceUnit, captureServiceTimer][i]} LoadState=${state.LoadState} UnitFileState=${state.UnitFileState}`);
237
+ }
238
+ if (disabled.length && !replace) refuse(plan, "E_CAPTURE_SERVICE_DISABLED", `named capture service is not enabled: observed ${disabled.join(", ")}; setup enables it only when asked`);
239
+ plan.disabled = disabled.length > 0;
240
+ plan.changed = files.some(file => file.changed) || (platform === "darwin" && plan.state?.registered &&
241
+ (JSON.stringify(plan.state.argv) !== JSON.stringify(plan.argv) || plan.state.interval !== plan.intervalSeconds)) ||
242
+ (platform === "linux" && plan.state && (Object.values(plan.state).some(state => state.NeedDaemonReload === "yes") ||
243
+ ["enabled", "enabled-runtime"].includes(plan.state.service.UnitFileState)));
244
+ return plan;
245
+ }
246
+
247
+ // Apply has no atomic rollback. A failure names, on the thrown error's
248
+ // `applied`, every change made before it, as each was logged.
249
+ export function applyCaptureService(plan, createdParents = new Map()) {
250
+ const applied = [];
251
+ try { return applyCaptureServiceSteps(plan, createdParents, applied); }
252
+ catch (error) { if (applied.length) error.applied = [...applied]; throw error; }
253
+ }
254
+
255
+ function applyCaptureServiceSteps(plan, createdParents, applied) {
256
+ const { files, run, log } = plan;
257
+ const changed = text => { applied.push(text); log(`service: ${text}`); };
258
+ if (plan.dry) {
259
+ for (const file of files) log(`service: would ${file.snapshot.kind === "absent" ? "install" : file.changed ? "update" : "keep"} ${file.path}`);
260
+ if (plan.pending) log(`service: pending-activation marker ${plan.pending.path} is ${plan.pending.stale ? "stale; would remove it" : "present; would retry activation"}`);
261
+ log("service: manager registration/disabled state unexamined (--dry-run); no manager invoked");
262
+ return;
263
+ }
264
+ const recheck = () => files.forEach(file => recheckCaptureSetup(file.snapshot, createdParents));
265
+ recheck();
266
+ const current = inspect(plan);
267
+ if (stateIdentity(current, plan.platform) !== stateIdentity(plan.state, plan.platform)) throw new Error("capture manager identity/enablement changed since preflight; re-run setup");
268
+ const markerPath = join(plan.request.root, capturePendingActivationName);
269
+ // The marker is written like every other setup target: against what
270
+ // preflight saw, never through a link or a replaced file.
271
+ let markerSnapshot = plan.marker;
272
+ if (plan.pending?.stale) {
273
+ recheckCaptureSetup(plan.pending.snapshot, createdParents); fs.rmSync(markerPath);
274
+ markerSnapshot = captureSetupSnapshot(markerPath);
275
+ changed(`removed stale pending-activation marker ${markerPath} (no setup-marked capture definition); it authorizes nothing`);
276
+ }
277
+ // Written before the first manager change or definition write, removed only
278
+ // after activation is verified: a failure in between leaves it for a rerun.
279
+ let marked = false;
280
+ const mark = () => {
281
+ if (marked) return;
282
+ writeCaptureSetup(markerSnapshot, JSON.stringify({ platform: plan.platform, startedAt: new Date().toISOString() }) + "\n", createdParents);
283
+ marked = true;
284
+ changed(`pending-activation marker written: ${markerPath}`);
285
+ };
286
+ const replaced = files.filter(file => file.changed && file.snapshot.kind !== "absent");
287
+ if (replaced.length) {
288
+ // Replacing definitions is activation work: the marker comes first, and its
289
+ // write creates a missing root as a recorded parent the backups then use.
290
+ mark();
291
+ const directory = join(plan.request.root, "service-backups", `${new Date().toISOString().replace(/:/g, "-")}-${randomUUID()}`);
292
+ fs.mkdirSync(dirname(directory), { recursive: true }); fs.mkdirSync(directory);
293
+ changed(`replacement backups at ${directory}`);
294
+ for (const file of replaced) {
295
+ recheck(); const path = join(directory, basename(file.path));
296
+ if (file.snapshot.kind === "link") fs.symlinkSync(file.snapshot.link, path);
297
+ else fs.writeFileSync(path, file.snapshot.bytes, { flag: "wx", mode: 0o600 });
298
+ }
299
+ }
300
+ recheck();
301
+ const command = (name, args) => {
302
+ mark(); requireOk(run, name, args);
303
+ changed(`manager action completed: ${name} ${args.map(serviceShellWord).join(" ")}`);
304
+ };
305
+ const writeDefinition = file => {
306
+ mark(); writeCaptureSetup(file.snapshot, file.contents, createdParents);
307
+ changed(`definition written: ${file.path}`);
308
+ };
309
+ if (plan.platform === "darwin") {
310
+ if (plan.changed && current.registered) command("launchctl", ["bootout", plan.target]);
311
+ for (const file of files) if (file.changed) writeDefinition(file);
312
+ recheckParents(files[0].snapshot, { parents: parents(files[0].path) }, createdParents);
313
+ fs.mkdirSync(join(plan.request.plan.home, "Library", "Logs"), { recursive: true });
314
+ if (plan.disabled) command("launchctl", ["enable", plan.target]);
315
+ if (plan.changed || !current.registered) command("launchctl", ["bootstrap", plan.domain, files[0].path]);
316
+ const after = inspect(plan);
317
+ if (after.disabled || !after.registered || after.path !== files[0].path || after.interval !== plan.intervalSeconds || JSON.stringify(after.argv) !== JSON.stringify(plan.argv))
318
+ throw new Error("capture launchd registration verification failed; inspect the named job and re-run setup");
319
+ } else {
320
+ // Stop the timer first so it cannot launch the old service between writes.
321
+ // An unchanged enabled timer never receives stop/restart, preserving its pass.
322
+ if (plan.changed || plan.disabled) {
323
+ if (current.timer.LoadState !== "not-found") command("systemctl", ["--user", "stop", captureServiceTimer]);
324
+ if (current.service.LoadState !== "not-found") command("systemctl", ["--user", "stop", captureServiceUnit]);
325
+ if (["enabled", "enabled-runtime"].includes(current.service.UnitFileState)) command("systemctl",
326
+ ["--user", ...(current.service.UnitFileState === "enabled-runtime" ? ["--runtime"] : []), "disable", captureServiceUnit]);
327
+ if (plan.disabled) for (const [unit, state] of [[captureServiceUnit, current.service], [captureServiceTimer, current.timer]]) {
328
+ if (state.LoadState === "masked" || state.UnitFileState.startsWith("masked")) command("systemctl",
329
+ ["--user", ...(state.UnitFileState === "masked-runtime" ? ["--runtime"] : []), "unmask", unit]);
330
+ }
331
+ }
332
+ // unmask may remove the exact named /dev/null links. Reconcile only that
333
+ // expected removal; any other replacement still refuses the file write.
334
+ for (const file of files) {
335
+ if (plan.disabled && file.snapshot.kind === "link" && file.snapshot.link === "/dev/null") {
336
+ const now = captureSetupSnapshot(file.path);
337
+ recheckParents(file.snapshot, now, createdParents);
338
+ if (now.kind === "absent") file.snapshot = now;
339
+ }
340
+ if (file.changed) writeDefinition(file);
341
+ }
342
+ if (plan.changed || plan.disabled || current.service.LoadState !== "loaded" || current.timer.LoadState !== "loaded") command("systemctl", ["--user", "daemon-reload"]);
343
+ if (plan.changed || plan.disabled || current.timer.UnitFileState !== "enabled" || current.timer.ActiveState !== "active")
344
+ command("systemctl", ["--user", "enable", "--now", captureServiceTimer]);
345
+ const after = inspect(plan);
346
+ if (after.service.LoadState !== "loaded" || after.timer.LoadState !== "loaded" ||
347
+ after.service.FragmentPath !== files[0].path || after.timer.FragmentPath !== files[1].path ||
348
+ after.timer.UnitFileState !== "enabled" || after.timer.ActiveState !== "active" ||
349
+ after.service.UnitFileState !== "static" || after.service.NeedDaemonReload !== "no" || after.timer.NeedDaemonReload !== "no")
350
+ throw new Error("capture timer/service verification failed; inspect the named units and re-run setup");
351
+ }
352
+ for (const file of files) {
353
+ const final = captureSetupSnapshot(file.path);
354
+ recheckParents(file.snapshot, final, createdParents);
355
+ if (final.kind !== "file" || !final.bytes.equals(Buffer.from(file.contents))) throw new Error(`capture definition changed during activation: ${file.path}; re-run setup`);
356
+ }
357
+ if (marked || plan.pending && !plan.pending.stale) {
358
+ fs.rmSync(markerPath, { force: true });
359
+ log(`service: activation verified; pending-activation marker removed: ${markerPath}`);
360
+ }
361
+ log(`service: periodic capture scheduled (every 15 minutes)${plan.changed ? "" : "; definitions already installed"}`);
362
+ }
@@ -0,0 +1,137 @@
1
+ // Deliberately small readers for the templates this package has actually
2
+ // written. Unsupported directives, expansions, markers or XML are foreign,
3
+ // never permission inferred from a filename or a mention of capture.
4
+ import { basename, isAbsolute, join } from "node:path";
5
+ import { captureServiceIntervalText, captureServiceLabel, captureServiceUnit, captureServiceRequest } from "./capture-service-definition.mjs";
6
+ import { CAPTURE_POLICY } from "./capture-budget.mjs";
7
+
8
+ const owner = value => /^[A-Za-z0-9._-]+$/.test(value);
9
+ const node = value => typeof value === "string" && isAbsolute(value) && ["node", "nodejs"].includes(basename(value));
10
+ const exactKeys = (value, keys) => Object.keys(value).sort().join("|") === [...keys].sort().join("|");
11
+ function legacy(argv) {
12
+ return argv?.length === 5 && node(argv[0]) && isAbsolute(argv[1]) && argv[1].endsWith("/bin/capture.mjs") &&
13
+ argv[2] === "--watch" && argv[3] === "--owner" && owner(argv[4]);
14
+ }
15
+ function periodic(argv) {
16
+ if (argv?.length !== 3 || typeof argv[0] !== "string" || !isAbsolute(argv[0]) || !isAbsolute(argv[1]) || !argv[1].endsWith("/lib/capture-service-runner.mjs")) return null;
17
+ const value = JSON.parse(argv[2]);
18
+ const request = captureServiceRequest(value);
19
+ return JSON.stringify(value) === JSON.stringify(request) ? request : null;
20
+ }
21
+
22
+ export function captureServiceArgvOwnership(argv) {
23
+ try { return legacy(argv) ? "legacy" : periodic(argv) ? "periodic" : "foreign"; }
24
+ catch { return "foreign"; }
25
+ }
26
+
27
+ export function serviceSystemdArgs(line) {
28
+ const words = []; let i = 0;
29
+ while (i < line.length) {
30
+ while (/[ \t]/.test(line[i] ?? "")) i++;
31
+ if (i === line.length) break;
32
+ let word = "";
33
+ if (line[i] === '"') {
34
+ i++;
35
+ while (line[i] !== '"') {
36
+ if (i >= line.length) throw new Error("unterminated systemd word");
37
+ if (line[i] === "\\") { i++; if (!['"', "\\"].includes(line[i])) throw new Error("unsupported systemd escape"); }
38
+ word += line[i++];
39
+ }
40
+ i++;
41
+ if (i < line.length && !/[ \t]/.test(line[i])) throw new Error("joined systemd word");
42
+ } else {
43
+ while (i < line.length && !/[ \t]/.test(line[i])) word += line[i++];
44
+ if (!/^[A-Za-z0-9_./:@+,-]+$/.test(word)) throw new Error("unsupported bare systemd word");
45
+ }
46
+ if (/%/.test(word.replace(/%%/g, ""))) throw new Error("systemd specifier");
47
+ if (words.length) {
48
+ if (/\$/.test(word.replace(/\$\$/g, ""))) throw new Error("systemd environment expansion");
49
+ word = word.replace(/\$\$/g, "$");
50
+ }
51
+ words.push(word.replace(/%%/g, "%"));
52
+ }
53
+ return words;
54
+ }
55
+
56
+ function ini(text) {
57
+ const values = {}; let section = null;
58
+ for (const raw of text.split(/\r?\n/)) {
59
+ const line = raw.trim();
60
+ if (!line || /^[#;]/.test(line)) continue;
61
+ const heading = /^\[([A-Za-z]+)\]$/.exec(line);
62
+ if (heading) { section = heading[1]; continue; }
63
+ const item = /^([A-Za-z]+)=(.*)$/.exec(line);
64
+ if (!section || !item || line.endsWith("\\")) throw new Error("unsupported unit directive");
65
+ const key = `${section}.${item[1]}`;
66
+ if (Object.hasOwn(values, key)) throw new Error("duplicate unit directive");
67
+ values[key] = item[2];
68
+ }
69
+ return values;
70
+ }
71
+
72
+ function xmlText(raw) {
73
+ if (/[<>]/.test(raw) || /&(?!amp;|lt;|gt;|quot;|apos;|#13;)/.test(raw)) throw new Error("unsupported XML text");
74
+ return raw.replace(/&#13;/g, "\r").replace(/&lt;/g, "<").replace(/&gt;/g, ">").replace(/&quot;/g, '"')
75
+ .replace(/&apos;/g, "'").replace(/&amp;/g, "&");
76
+ }
77
+ function plist(text) {
78
+ if (/[\u0000-\u0008\u000b\u000c\u000e-\u001f\ufffe\uffff]/u.test(text)) throw new Error("invalid XML character");
79
+ for (const comment of text.matchAll(/<!--([^]*?)-->/g)) if (comment[1].includes("--")) throw new Error("invalid XML comment");
80
+ let rest = text.replace(/\r\n?/g, "\n").trim();
81
+ rest = rest.replace(/^<\?xml version="1\.0" encoding="UTF-8"\?>\s*/, "")
82
+ .replace(/^<!DOCTYPE plist PUBLIC "-\/\/Apple\/\/DTD PLIST 1\.0\/\/EN" "http:\/\/www\.apple\.com\/DTDs\/PropertyList-1\.0\.dtd">\s*/, "")
83
+ .replace(/<!--[^]*?-->/g, "").trim();
84
+ const body = /^<plist version="1\.0">\s*<dict>([^]*)<\/dict>\s*<\/plist>$/.exec(rest);
85
+ if (!body) throw new Error("unsupported plist");
86
+ rest = body[1]; const values = {};
87
+ while (rest.trim()) {
88
+ const key = /^\s*<key>([^<]*)<\/key>\s*/.exec(rest);
89
+ if (!key || Object.hasOwn(values, key[1])) throw new Error("invalid plist key");
90
+ rest = rest.slice(key[0].length);
91
+ const scalar = /^(?:<string>([^]*?)<\/string>|<integer>(\d+)<\/integer>|<(true|false)\s*\/>)/.exec(rest);
92
+ if (scalar) {
93
+ values[key[1]] = scalar[1] !== undefined ? xmlText(scalar[1]) : scalar[2] !== undefined ? Number(scalar[2]) : scalar[3] === "true";
94
+ rest = rest.slice(scalar[0].length); continue;
95
+ }
96
+ const array = /^<array>([^]*?)<\/array>/.exec(rest);
97
+ if (!array) throw new Error("unsupported plist value");
98
+ let members = array[1]; const args = [];
99
+ while (members.trim()) {
100
+ const item = /^\s*<string>([^]*?)<\/string>/.exec(members);
101
+ if (!item) throw new Error("unsupported plist array");
102
+ args.push(xmlText(item[1])); members = members.slice(item[0].length);
103
+ }
104
+ values[key[1]] = args; rest = rest.slice(array[0].length);
105
+ }
106
+ return values;
107
+ }
108
+
109
+ // intervalSeconds: the definition module's internal test seam, default the policy.
110
+ export function captureServiceOwnership(text, kind, { intervalSeconds = CAPTURE_POLICY.intervalSeconds } = {}) {
111
+ try {
112
+ const markers = text.match(/oats-turn-record-service:[^\s<>]*/g) ?? [];
113
+ if (markers.length > 1 || (markers.length && markers[0] !== "oats-turn-record-service:1")) return "foreign";
114
+ const marked = markers.length === 1;
115
+ if (marked && !(kind === "plist" ? /<!-- oats-turn-record-service:1 -->/ : /^# oats-turn-record-service:1\s*$/m).test(text)) return "foreign";
116
+ if (kind === "plist") {
117
+ const p = plist(text);
118
+ const common = ["Label", "ProgramArguments", "RunAtLoad", "StandardOutPath", "StandardErrorPath"];
119
+ if (p.Label !== captureServiceLabel || p.RunAtLoad !== true || typeof p.StandardOutPath !== "string" ||
120
+ p.StandardOutPath !== p.StandardErrorPath || !isAbsolute(p.StandardOutPath)) return "foreign";
121
+ if (!marked && exactKeys(p, [...common, "KeepAlive", "ThrottleInterval"]) && p.KeepAlive === true && p.ThrottleInterval === 60 && legacy(p.ProgramArguments)) return "legacy";
122
+ const request = marked && exactKeys(p, [...common, "StartInterval"]) && p.StartInterval === intervalSeconds && periodic(p.ProgramArguments);
123
+ return request && p.StandardOutPath === join(request.plan.home, "Library", "Logs", "turn-record-capture.log") ? "periodic" : "foreign";
124
+ }
125
+ const p = ini(text);
126
+ if (kind === "timer") return marked && exactKeys(p, ["Unit.Description", "Timer.OnBootSec", "Timer.OnUnitActiveSec", "Timer.Unit", "Install.WantedBy"]) &&
127
+ p["Unit.Description"] === "turn-record periodic capture" && p["Timer.OnBootSec"] === "1min" && p["Timer.OnUnitActiveSec"] === captureServiceIntervalText(intervalSeconds) &&
128
+ p["Timer.Unit"] === captureServiceUnit && p["Install.WantedBy"] === "timers.target" ? "periodic" : "foreign";
129
+ const argv = serviceSystemdArgs(p["Service.ExecStart"] ?? "");
130
+ if (!marked && exactKeys(p, ["Unit.Description", "Service.ExecStart", "Service.Restart", "Service.RestartSec", "Install.WantedBy"]) &&
131
+ p["Unit.Description"] === "turn-record capture watcher" && p["Service.Restart"] === "always" && p["Service.RestartSec"] === "60" &&
132
+ p["Install.WantedBy"] === "default.target" && legacy(argv)) return "legacy";
133
+ return marked && exactKeys(p, ["Unit.Description", "Service.Type", "Service.ExecStart", "Service.MemoryMax", "Service.RuntimeMaxSec"]) &&
134
+ p["Unit.Description"] === "turn-record bounded capture pass" && p["Service.Type"] === "exec" && p["Service.MemoryMax"] === "2G" &&
135
+ p["Service.RuntimeMaxSec"] === "300" && periodic(argv) ? "periodic" : "foreign";
136
+ } catch { return "foreign"; }
137
+ }
@@ -0,0 +1,18 @@
1
+ // Fixed, finite installed-service supervisor entry. It neither schedules the
2
+ // next pass nor installs/inspects a manager; the root lock owns child lifetime.
3
+ import { captureServiceRequest } from "./capture-service-definition.mjs";
4
+ import { captureCommandPass } from "./capture-command-output.mjs";
5
+ import { IgnoreError, loadIgnore } from "./ignore.mjs";
6
+
7
+ try {
8
+ if (process.argv.length !== 3) throw new Error("invalid private capture service arguments");
9
+ const request = captureServiceRequest(JSON.parse(process.argv[2]));
10
+ // Match foreground setup/manual privacy ordering. No source discovery runs
11
+ // here: the registered worker resolves the explicit plan after admission.
12
+ loadIgnore(request.root);
13
+ await captureCommandPass(request.root, { owner: request.owner, plan: request.plan,
14
+ trigger: "service", indexEnabled: true, retrySetAside: false }, { entry: "service-runner" });
15
+ } catch (error) {
16
+ console.error(error instanceof IgnoreError ? error.message : `capture service failed: ${error.message}`);
17
+ process.exitCode = 1;
18
+ }
@@ -0,0 +1,85 @@
1
+ // A disposable command snapshot, eligible by TOTAL fixed end, never suffix
2
+ // length. Reopening a later worker's source is not proof: it must finish a new
3
+ // chunked copy/hash and match the full digest+size before reusing comparison.
4
+ import { createHash } from "node:crypto";
5
+ import { closeSync, fstatSync, openSync, writeSync } from "node:fs";
6
+ import { join } from "node:path";
7
+ import { createCaptureScratch } from "./capture-scratch.mjs";
8
+ import { fileVersion, sameVersion, statVersion } from "./derived-state.mjs";
9
+ import { assertProtectedDescriptor, sourceChunks } from "./session-snapshot.mjs";
10
+ import { fileChunks } from "./file-lines.mjs";
11
+
12
+ export const SMALL_SNAPSHOT_BYTES = 8388608;
13
+
14
+ export function smallCommandSnapshot(root, fd, path, size, { capturedPi, stopped = () => false, work } = {}) {
15
+ if (!Number.isSafeInteger(size) || size < 0 || size > SMALL_SNAPSHOT_BYTES) {
16
+ throw new Error("small command snapshot exceeds its total fixed-end eligibility");
17
+ }
18
+ const observe = () => {
19
+ assertProtectedDescriptor(fd, path, capturedPi);
20
+ const stat = fstatSync(fd, { bigint: true });
21
+ if (!stat.isFile()) throw new Error("small snapshot source is not a regular file");
22
+ const version = statVersion(stat);
23
+ if (!sameVersion(version, fileVersion(path))) throw new Error("small snapshot descriptor differs from its named source");
24
+ return version;
25
+ };
26
+ const before = observe();
27
+ let observed = before;
28
+ if (before.size < size) throw new Error("small snapshot source shrank before staging");
29
+ if (stopped()) return { complete: false };
30
+ const scratch = createCaptureScratch(root, "snapshot");
31
+ let stagedFd, keep = false;
32
+ try {
33
+ stagedFd = openSync(join(scratch.path, "snapshot"), "wx+", 0o600);
34
+ const hash = createHash("sha256");
35
+ let copied = 0;
36
+ const iterator = sourceChunks(fd, 0, size, path, capturedPi);
37
+ try {
38
+ while (copied < size) {
39
+ if (stopped()) return { complete: false };
40
+ const next = iterator.next();
41
+ if (next.done) throw new Error("small snapshot short read");
42
+ const bytes = next.value;
43
+ if (work) work.sourceBytes = (work.sourceBytes ?? 0) + bytes.length;
44
+ // Bytes are copied, never joined into lines: a captured record of any
45
+ // size stages; the raw-record limit belongs to capture beyond the prefix.
46
+ hash.update(bytes);
47
+ for (let written = 0; written < bytes.length;) {
48
+ const count = writeSync(stagedFd, bytes, written, bytes.length - written, copied + written);
49
+ if (!count) throw new Error("small snapshot short write");
50
+ written += count;
51
+ }
52
+ copied += bytes.length;
53
+ if (work) work.stagedWriteBytes = (work.stagedWriteBytes ?? 0) + bytes.length;
54
+ }
55
+ } finally { iterator.return(); }
56
+ const digest = hash.digest("hex"), payload = statVersion(fstatSync(stagedFd, { bigint: true }));
57
+ const verify = () => {
58
+ if (!sameVersion(payload, statVersion(fstatSync(stagedFd, { bigint: true })))) throw new Error("small snapshot payload changed");
59
+ const after = observe();
60
+ if (sameVersion(observed, after)) return;
61
+ if (after.dev !== observed.dev || after.ino !== observed.ino || after.size <= observed.size) throw new Error("small snapshot source changed");
62
+ // Growth while copying/verifying requires a complete fixed-end digest,
63
+ // not the ordinary incremental cursor's bounded boundary witness.
64
+ const check = createHash("sha256");
65
+ for (const bytes of sourceChunks(fd, 0, size, path, capturedPi)) {
66
+ if (work) work.sourceVerificationBytes = (work.sourceVerificationBytes ?? 0) + bytes.length;
67
+ check.update(bytes);
68
+ }
69
+ if (check.digest("hex") !== digest || !sameVersion(after, observe())) throw new Error("small snapshot source changed during verification");
70
+ observed = after;
71
+ };
72
+ verify(); keep = true; let closed = false;
73
+ return { complete: true, small: true, snapshot: { id: `sha256:${digest}:${size}`, size,
74
+ *chunks(from = 0, end = size) {
75
+ if (!Number.isSafeInteger(from) || from < 0 || !Number.isSafeInteger(end) || end < from || end > size) throw new Error("invalid small snapshot range");
76
+ verify(); let read = 0;
77
+ for (const bytes of fileChunks(stagedFd, { start: from, end, size: 65536 })) { read += bytes.length; yield bytes; }
78
+ if (read !== end - from) throw new Error("small snapshot payload short read");
79
+ verify();
80
+ } }, verify,
81
+ close() { if (!closed) { closed = true; try { closeSync(stagedFd); } finally { scratch.close(); } } } };
82
+ } finally {
83
+ if (!keep) { try { if (stagedFd !== undefined) closeSync(stagedFd); } finally { scratch.close(); } }
84
+ }
85
+ }