@awebai/oats 0.44.1 → 0.46.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.
@@ -0,0 +1,147 @@
1
+ # Explicit native harness trust
2
+
3
+ Run this command on the host where Claude or Codex runs, while other native
4
+ configuration editors are quiescent:
5
+
6
+ ```sh
7
+ oats harness trust --dir /absolute/deployment --harness all --plan
8
+ oats harness trust --dir /absolute/deployment --harness all
9
+ ```
10
+
11
+ `--plan` reads only. The bare command applies a fresh plan; there is no `--apply`.
12
+ The default harness is `all`, in Claude-then-Codex order. `claude` or `codex`
13
+ selects one. The deployment is resolved from the existing local command context,
14
+ including when invoked from an instance home, then canonicalized with the native
15
+ filesystem lookup. The result, native key, audit and reader verification use that
16
+ on-disk spelling, including on case-insensitive APFS. No remote
17
+ adapter, arbitrary file selector, parent-root substitution or harness launch is
18
+ performed. A native executable need not be installed to edit the qualified format.
19
+
20
+ The command writes only the canonical deployment root's native trust leaf:
21
+
22
+ - Claude: `projects[root].hasTrustDialogAccepted = true` in
23
+ `$CLAUDE_CONFIG_DIR/.claude.json`, or `~/.claude.json`.
24
+ - Codex: `projects[root].trust_level = "trusted"` in
25
+ `$CODEX_HOME/config.toml`, or `~/.codex/config.toml`.
26
+
27
+ Nonempty override directories must be absolute. Directory aliases are resolved;
28
+ symlink/nonregular/hardlinked leaves, foreign ownership and ACLs refuse. On Linux, GNU ls's single `.` security-context marker is accepted;
29
+ the context must be readable, match the same-directory candidate before replacement,
30
+ and remain unchanged at verification. A differing directory-default context refuses
31
+ before rename; OATS does not relabel files. This comparison narrows metadata races,
32
+ not the documented uncooperative-writer race. Tests simulate these SELinux probes;
33
+ they are not a live SELinux-host qualification.
34
+
35
+ On macOS, any extended-attribute (`@`) or ACL (`+`) marker deliberately refuses,
36
+ including `com.apple.provenance`. This v1 writer does not copy or remove those
37
+ attributes. Inspect the selected file; a refusal never authorizes stripping its
38
+ metadata automatically. Existing file permissions are preserved.
39
+ New config directories use 0700 and files 0600. The plan shows the effective file,
40
+ semantic key, current/desired trust scalar, byte digests and override provenance;
41
+ it never returns other config values or credentials.
42
+
43
+ This explicit act is the exception to read-only launch trust checks. Spawning,
44
+ scaffolding, starting and retiring do not write native trust or create consent
45
+ records. Existing Codex root-trust/yolo per-invocation overrides are unchanged.
46
+ This command does not enable development-channel prompt consent, change permission
47
+ mode, authenticate, install a plugin, or establish model/channel readiness.
48
+
49
+ ## Qualified scope and formats
50
+
51
+ Claude 2.1.289 darwin-arm64 was qualified against pinned native source and a
52
+ private no-Git deployment. One native root acceptance preceded two fresh child
53
+ launches. Root trust was true before each; neither child had accepted trust;
54
+ both reached ordinary UI. Native child bookkeeping later contained false.
55
+ Both bypass-mode controls in a separate disposable deployment still asked trust.
56
+ Native source independently walks trusted ancestors outside repository boundaries.
57
+ The recorded recipe and source exclude channel argv as a grant of trust. There
58
+ was no contemporaneous per-process environment snapshot; the same-runner root
59
+ trust question and absence of child recipe/capability bypass settings support
60
+ this bounded evidence. This is not qualification of other versions, nested Git
61
+ layouts or account/channel readiness.
62
+
63
+ Codex 0.160.1 native source independently declares a project `trust_level` and
64
+ writes `trusted`/`untrusted` under the project path. See the pinned
65
+ [native writer](https://github.com/openai/codex/blob/rust-v0.160.1/codex-rs/core/src/config/mod.rs)
66
+ and [configuration type](https://github.com/openai/codex/blob/rust-v0.160.1/codex-rs/config/src/config_toml.rs).
67
+ OATS's existing root-consent-to-exact-home invocation override remains separate
68
+ from native ancestor inheritance; Claude evidence is not Codex evidence.
69
+
70
+ JSON parsing rejects duplicate keys and wrong shapes. Only the required missing
71
+ object suffix or existing boolean token changes; unrelated large numbers, keys,
72
+ spacing and newlines remain byte-identical. False becomes true; an existing true
73
+ is a byte/mtime-preserving no-op.
74
+
75
+ The dependency-free TOML editor supports ordinary single-line assignments,
76
+ quoted/bare/dotted keys, explicit project tables, dotted trust keys and the
77
+ reader's inline project form containing only `trust_level`. It validates scalar,
78
+ single-line array and inline-table structure, duplicate/conflicting definitions,
79
+ and signed 64-bit integers. Multiline values, array-of-table headers, dates,
80
+ nondecimal numbers and unsupported representations refuse even if another TOML
81
+ parser accepts them. Root-level inline `projects` and inline project entries with
82
+ additional fields refuse rather than write a shape the existing readiness reader
83
+ does not consume. Comments, whitespace and line endings outside edit spans stay
84
+ unchanged. Untrusted becomes trusted; other trust values/types refuse. Both
85
+ editors validate the candidate and compare semantic trees with only the intended
86
+ leaf changed. Unsupported native format changes require refreshed qualification.
87
+
88
+ A Claude root entry cannot cover a home behind an intervening Git boundary.
89
+ Readiness may still warn after an unchanged root apply. Inspect that boundary;
90
+ do not automatically write a second root or answer a trust dialog.
91
+
92
+ ## Durability, audit and recovery
93
+
94
+ All selected configs are preflighted before any native write. Cooperating OATS
95
+ writers acquire exclusive destination locks in canonical-path order plus an audit
96
+ lock. Existing locks refuse promptly. The human/JSON error message names the exact
97
+ lock path so an operator can inspect an interrupted apply; OATS never steals or
98
+ deletes another invocation's lock, even when it appears stale. Identity and
99
+ raw-byte digests are rechecked after locking and immediately before replacement.
100
+ Candidate files are exclusively created beside the destination, fsynced, atomically
101
+ renamed and verified through the existing trust reader. Native writers do not
102
+ honor OATS locks: final checks detect observed drift but cannot guarantee exclusion
103
+ against an uncooperative writer racing the rename. No native process is stopped.
104
+
105
+ The deployment-private `.agents/harness-trust.jsonl` is independent of instance
106
+ lifetime, alongside other private kernel events. Its new directory/file modes are
107
+ 0700/0600. A checked, durable intent precedes each changed file; a checked outcome
108
+ follows it. An unchanged apply records an outcome without touching config bytes
109
+ or mtime. Plan creates no audit, directory, lock or temporary file. Invalid or
110
+ truncated existing JSONL refuses until operator inspection.
111
+
112
+ `all` is not a transaction. Failure stops later work, retains earlier changes and
113
+ reports unattempted entries. Trust may already have been consumed, so no rollback
114
+ is simulated. Inspect the native files and audit before rerunning; a correct
115
+ existing entry converges as a no-op. `E_HARNESS_TRUST_INCOMPLETE` has closed reasons
116
+ `locked|changed|audit|write|verify` and a conservative `mayHaveChanged` flag.
117
+ An audit failure before a write prevents it; failure after a possible replacement
118
+ reports incomplete and preserves intent evidence. The command never claims that
119
+ failure means native trust was undone.
120
+
121
+ ### Native qualification references
122
+
123
+ Claude source qualification used executable SHA256
124
+ `03d66745e3bb69ec727d66023696f3820bc0a00a8a5ba725eb6706d0c67cbe69`.
125
+ Its native exact/ancestor lookup is in byte range 182226330–182227750;
126
+ the startup trust decision is 197759244–197759315. The lookup has no
127
+ permission-mode or channel-argument input. Environment gates remain a separate
128
+ limit: `CLAUDE_CODE_SANDBOXED`, `IS_DEMO`, `CLAUBBIT` and the native `Le(false)`
129
+ gate can bypass the question. The disposable observation did not record a
130
+ contemporaneous child-process environment snapshot. No proprietary source is
131
+ included here.
132
+
133
+ Codex qualification is source-derived from `rust-v0.160.1`, independently of the
134
+ Claude observation. `set_project_trust_level_inner` (core config lines 2343–2410)
135
+ writes the exact project key and trust scalar; `ProjectConfig` (config type
136
+ lines 603–615) consumes the enum. The
137
+ [loader](https://github.com/openai/codex/blob/rust-v0.160.1/codex-rs/config/src/loader/mod.rs)
138
+ uses exact normalized project lookup keys (lines 1030–1082), preferring canonical
139
+ path spelling (1370–1398). This qualifies the native representation; OATS retains
140
+ its separately tested invocation override instead of claiming universal native
141
+ ancestor inheritance. The source files' SHA256 digests are:
142
+
143
+ | Upstream path | SHA256 |
144
+ | --- | --- |
145
+ | `codex-rs/core/src/config/mod.rs` | `854f5a6b184714740500b8d3eae2bb04cb88172efccf11d38a74f2f6189c0341` |
146
+ | `codex-rs/config/src/config_toml.rs` | `453b5ed4d49cf3768ce47e1f2fe1987c92d694bba9b52373dcf10f15901ab9d1` |
147
+ | `codex-rs/config/src/loader/mod.rs` | `2ec85a665f827dd7080f8e562c960e49158b0d8a11b1022cc0a93eed05986d0c` |
@@ -53,7 +53,8 @@ published to npm. Its developer docs are in
53
53
  | `capability-show.mjs` | `oats capabilities show`: one catalog row's inject and skill files, read at its commit |
54
54
  | `materialize.mjs` | copying modules into a home and composing it |
55
55
  | `core.mjs` | spawn, retire, sessions, hooks, launch recipes, instance metadata |
56
- | `instruction-composition.mjs` | the generated `AGENTS.md` |
56
+ | `instruction-composition.mjs` | the generated `AGENTS.md`; `renderInstructionParts` is the span-reporting renderer (`renderInstructionText` is its text) |
57
+ | `soul-composition.mjs` | the instructions a spawn of a soul would write, composed without a spawn (kernel half + materialize into a scratch home): the one path behind `doctor --soul` and `inspect --soul --instructions` |
57
58
  | `teams.mjs`, `teams-verbs.mjs` | the team model and the `oats teams` verbs |
58
59
  | `schedule.mjs`, `schedule-host.mjs`, `triggers.mjs`, `automations.mjs` | schedules, triggers and the host timer |
59
60
  | `schedule-command.mjs`, `schedule-command-child.mjs` | synchronous scheduler adapter and asynchronous child supervisor: bounded output, TERM/KILL escalation and observed exit; no changes to synchronous tick/lock callbacks |
@@ -67,7 +68,9 @@ published to npm. Its developer docs are in
67
68
  | `servers.mjs` | routing commands to a registered server |
68
69
  | `launch-prompt-policy.mjs` | strict host-local exact-home aweb development-channel consent, canonical directory validation and config provenance |
69
70
  | `launch-prompts.mjs`, `launch-prompt-transport.mjs` | bounded launch-only controller and visible-screen transport; private process authority, injectable clock/transport, durable checked receipts and the fixture-gated exact aweb development-channel signature |
70
- | `harness-trust.mjs` | reading (never writing) Claude's and Codex's folder trust for a launch |
71
+ | `harness-trust.mjs` | read-only native trust coverage and operator remedy for launches |
72
+ | `harness-trust-write.mjs` | explicit operator plan/apply, cooperating locks, durable deployment audit and no-rollback outcomes |
73
+ | `harness-trust-json.mjs`, `harness-trust-toml.mjs` | bounded native parsers and byte-preserving edits of one trust leaf |
71
74
 
72
75
  The schedule registry stores explicit concurrency caps, leaving the schedule
73
76
  cap absent for its effective default of five. `readRegistry()` is a pure,
@@ -0,0 +1,56 @@
1
+ # OATS 0.45.0
2
+
3
+ ## Added
4
+
5
+ - **`oats souls` rows say what each soul composes.** Each row of
6
+ `oats souls --json` carries `capabilities`: the capabilities its
7
+ resolution composes, keyed like `oats capabilities` rows (`name`, `kind`,
8
+ `repoKey` or `package`), each with `from` (`soul` or `workspace`). A soul
9
+ that does not resolve has `null`. The Desktop uses it to say which souls
10
+ use a capability, including ones no live instance carries. Feature
11
+ `souls-capabilities`; `soulsApi` is unchanged. See
12
+ [`oats capabilities` and `oats souls`](../desktop-cli-api.md#oats-capabilities---dir---json--capabilitiesapi-1--oats-souls---dir---json--soulsapi-1).
13
+
14
+ ## Changed
15
+
16
+ - **The Desktop accepts OATS CLIs `>=0.25.8 <0.46.0`**, so it runs against
17
+ 0.45. Upgrade the Desktop and the CLI together: a 0.44 Desktop refuses a 0.45
18
+ CLI as outside its band. Without `souls-capabilities` (an older CLI), *Used by*
19
+ keeps its earlier, live-instance behaviour.
20
+ - **Desktop: Capabilities says which souls use each capability, without the
21
+ Source column.**
22
+ - **Used by.** With `souls-capabilities`, *Used by* lists the souls whose
23
+ composition includes the capability, matched by name and source (its
24
+ repository or package). Before, it listed only souls with a live instance
25
+ that recorded it, so a capability souls declare read "Not used" until one
26
+ ran. A soul that does not resolve is not counted, and a workspace default
27
+ still reads "Every soul". The capability page lists one row per soul, with
28
+ that soul's live instances carrying it (0 when none runs). A package
29
+ soul's instances are found by its `<package>--<soul>` agent name. With an
30
+ older OATS, *Used by* stays instance-derived, as before.
31
+ - **No Source column.** Each group's heading names where its capabilities
32
+ come from, so the column repeated it. The row's accessible name still
33
+ says "from <source>", and the capability page keeps its *Comes from*
34
+ card.
35
+ - **Packages grouped by package.** The Packages section is headed per
36
+ package, like the other two sections are per repository:
37
+ "package · v<version> · N capabilities".
38
+
39
+ - **Desktop: the Claude Code harness badge shows the Claude spark.** It
40
+ replaces the four-pointed sparkle from 0.44.1. The mark is Anthropic's spark,
41
+ geometry unmodified, in ivory on the same terracotta tile, and it holds 4.5:1
42
+ in White, Solarized and Dark. Pi and Codex are unchanged, and the badge keeps
43
+ its accessible name ("Harness: Claude"). Source and terms are in
44
+ `packages/desktop/renderer/harness-marks/README.md`.
45
+
46
+ ## Fixed
47
+
48
+ - **An operator soul may empty its knowledge and tasks slots.** Operator
49
+ coverage (readiness and doctor) excluded a soul that composes `oats.setup`
50
+ when it emptied any slot the workspace fills, so a setup soul with
51
+ `knowledge: none` or `tasks: none` left permanent warnings: its teams
52
+ uncovered, and `operator-soul-missing` naming it ("not usable here: …
53
+ slot-none") when it was the only one. Only `messaging: none` now excludes
54
+ it, so an operator stays reachable. The items' shape and codes are
55
+ unchanged. See
56
+ [Operator coverage items](../desktop-cli-api.md#operator-coverage-items).
@@ -0,0 +1,71 @@
1
+ # OATS 0.46.0
2
+
3
+ ## Added
4
+
5
+ - **`oats inspect --soul <soul> --instructions` shows the instructions a new
6
+ instance would get.** `souls[0].composedInstructions` is the AGENTS.md a
7
+ spawn of that soul here would write: the soul's own text, then the
8
+ instance-boundary and work-mode blocks and each capability's inject,
9
+ produced by spawn's own composition, with nothing written to the
10
+ deployment. The soul's text and each block are given as ranges into the
11
+ text, named like an instance's `instructions.sources`, so the Desktop can
12
+ show which part comes from where. Without `--instructions` nothing extra is
13
+ composed; with `--home` it is refused. Feature `soul-composed-instructions`.
14
+ `oats doctor --soul` uses the same composition, and its capability markers
15
+ now name the inject home-relative instead of a deleted temporary path.
16
+ Routed with `--server <id>`, a host whose probe does not advertise
17
+ `soul-composed-instructions` is refused with `E_REMOTE_INCOMPATIBLE`, and
18
+ nothing is sent.
19
+
20
+ ## Fixed
21
+
22
+ - **Interim subscription completion extension:** the qualified Claude 2.1.289
23
+ darwin-arm64 110x35 empty Opus 5.5 / auto / medium frames additionally accept
24
+ exactly Claude Max, Pro, Team and Enterprise billing labels. These variants
25
+ are source-derived synthetic frames, not captured subscription sessions.
26
+ The exact Enter-authorizing prompt, explicit home consent and all launch
27
+ guards are unchanged. Completion closes input authority and proves no
28
+ account/channel readiness. This is **not the #754 onboarding fix**: #754
29
+ remains open for task-filled and bypass-permissions completion recognition.
30
+ Other unqualified frames still retain a blocked result after a submitted
31
+ answer; there is no automatic retry.
32
+
33
+ - **`oats doctor --soul` lists every inject block of a capability that
34
+ declares several.** Its `instructionBlocks` kept only the first block of
35
+ such a capability, though its composed text had them all; it now lists
36
+ each one, as a spawn records them.
37
+
38
+ ## Changed
39
+
40
+ - **The Desktop accepts OATS CLIs `>=0.25.8 <0.47.0`.** Its kernel band
41
+ admits 0.46; the soul composed-instructions feature is not read by the
42
+ Desktop yet, so no new gate is needed.
43
+
44
+ - **oats.framework 1.7.0: oats.setup 2.4.0 and oats.core 2.4.2.** Instruction
45
+ text only; no kernel, schema or provider contract changes.
46
+ - **oats.setup 2.4.0: team setup instructions are executable from one
47
+ authorized intake.** The onboarding and teams skills carry one
48
+ authorized intake through team configuration, operator composition
49
+ checks and first-task verification; they link the provider-owned
50
+ identity and delivery procedures, distinguish unsupported paths, and keep
51
+ project operator advice independent of central knowledge identities. An
52
+ instruction change, not a new team or provider primitive
53
+ ([#709](https://github.com/awebai/oats/issues/709), #721). The setup
54
+ inject and `oats-automations` keep configuration repairs proportional to
55
+ the requested outcome (#689, #692) and describe schedule and trigger
56
+ descriptions, retained-attempt reconciliation and supervisor cleanup as
57
+ the kernel now does them (#684, #591, #592, #593).
58
+ - **oats.core 2.4.2:** `oats-operate` covers the extra work trees a
59
+ work-mode briefing allows and their retirement (#678), and what
60
+ `oats session input` does and does not prove (#595).
61
+
62
+ - Add explicit host-local `oats harness trust --plan` and bare apply for one
63
+ canonical deployment-root Claude/Codex trust entry. Edits preserve unrelated
64
+ native bytes and record a durable `.agents/harness-trust.jsonl` audit. Partial
65
+ failures are retained with `E_HARNESS_TRUST_INCOMPLETE`; no rollback is claimed.
66
+ Spawn/start/retire do not write native trust. Claude ancestor qualification is
67
+ bounded to2.1.289 darwin-arm64/no-Git paths; Codex format qualification is separate.
68
+ Nested Git boundaries and unsupported native formats still refuse or warn.
69
+ Native canonicalization preserves on-disk root casing on APFS; result keys,
70
+ audit and reader verification agree. Lock refusals name the exact blocking
71
+ lock in human/JSON errors without stealing or deleting it.
package/docs/servers.md CHANGED
@@ -216,7 +216,7 @@ sent as text or on stdin, never as paths.
216
216
  | `okf harvest --instance <name>` | the saved home | `harvest` |
217
217
  | `schedule ...` | registered workspace | `schedule` |
218
218
  | `launch-config list\|set\|remove\|preview` | `--dir`, the instance's home, or the registered workspace | `launch-config` |
219
- | `inspect`, `operation run` | `--dir`, the instance's home, or the registered workspace | `operations` |
219
+ | `inspect`, `operation run` | `--dir`, the instance's home, or the registered workspace | `operations`; `inspect --instructions` also `soul-composed-instructions` |
220
220
  | `readiness` | the instance's home, `--dir`, or the registered workspace | `readiness` (`readinessApi: 2`) |
221
221
  | `instance events` | the instance's home | `instance-events-2` (`eventsApi: 2`) |
222
222
  | `instance git`, `instance diff` | the instance's home; the Git runs there | `instance-git` (`instanceGitApi: 1`) |
@@ -105,7 +105,10 @@ souls) is ordinary capability content: **`oats.core`** (package
105
105
  knowledge an onboarding expert needs. Neither is kernel magic; the kernel still
106
106
  composes its own instance-boundary and work-mode briefings, and the "You run
107
107
  on OATS" briefing is `oats.core`'s inject: a soul without `oats.core` gets no
108
- OATS operating instructions, and `oats doctor --soul` says so.
108
+ OATS operating instructions, and `oats doctor --soul` says so. Its capability
109
+ markers' `src=` is home-relative (`.oats/modules/<cap>/<inject>`), composed by
110
+ the same path as `oats inspect --soul --instructions`; kernel markers keep the
111
+ installed package's path.
109
112
 
110
113
  ## Instance anatomy
111
114
 
@@ -210,18 +213,18 @@ instructions and pins model/provider settings; it excludes nothing.
210
213
  Claude Code and Codex ask before they work in a folder they have not seen, and
211
214
  every instance home is new. A launch stopped at that prompt waits for a human,
212
215
  so the operator trusts the **deployment directory** (where `oats-local.yaml`
213
- is) once per harness. OATS only reads the harnesses' configuration; it never
214
- writes it.
216
+ is) once per harness. Launches only read native configuration. The explicit
217
+ `oats harness trust --dir D --harness all --plan` previews the entry; the same
218
+ command without `--plan` applies it with a deployment audit. See
219
+ [native trust](harness-trust.md) for safe operation and partial-failure recovery.
215
220
 
216
221
  - **Claude Code** looks for an accepted entry for its folder or an ancestor, up
217
- to a git root. Instance homes are not inside a git repository, so one entry
218
- for the deployment covers every home under it. To add it, run `claude` in the
219
- deployment once and accept the prompt. That records
222
+ to a Git root. An intervening repository can prevent deployment-root inheritance;
223
+ the command does not automatically trust another root. The native field is
220
224
  `projects["<deployment>"].hasTrustDialogAccepted` in `~/.claude.json`
221
225
  (`$CLAUDE_CONFIG_DIR/.claude.json` when that is set).
222
226
  - **Codex** applies only an exact entry: a trusted parent does not cover the
223
- folders below it. To give the operator's consent, run `codex` in the
224
- deployment once and choose "Trust and continue". That records
227
+ folders below it. The explicit deployment-root command records
225
228
  `[projects."<deployment>"] trust_level = "trusted"` in
226
229
  `~/.codex/config.toml` (`$CODEX_HOME/config.toml`). With that entry, or one
227
230
  for an ancestor of the deployment, each codex launch trusts its own new home
@@ -0,0 +1,81 @@
1
+ /** Lossless JSON span edits for the one native Claude trust leaf. The parser
2
+ * rejects duplicate keys and never converts unrelated numeric tokens to Number. */
3
+ const bad = () => { throw new Error('unsupported or invalid native JSON configuration'); };
4
+ export function jsonDocument(text) {
5
+ let i = 0;
6
+ const space = () => { while (/\s/.test(text[i] ?? '') && i < text.length) { if (!' \r\n\t'.includes(text[i])) bad(); i++; } };
7
+ const string = () => {
8
+ const start = i++;
9
+ while (i < text.length) {
10
+ if (text[i] === '\\') { i += 2; continue; }
11
+ if (text[i++] === '"') { try { return { start, end: i, value: JSON.parse(text.slice(start, i)) }; } catch { bad(); } }
12
+ }
13
+ bad();
14
+ };
15
+ const value = (depth = 0) => {
16
+ if (depth > 128) bad();
17
+ space(); const start = i;
18
+ if (text[i] === '{') {
19
+ i++; space(); const fields = new Map();
20
+ if (text[i] !== '}') for (;;) {
21
+ if (text[i] !== '"') bad();
22
+ const key = string(); if (fields.has(key.value)) bad();
23
+ space(); if (text[i++] !== ':') bad();
24
+ fields.set(key.value, value(depth + 1)); space();
25
+ if (text[i] !== ',') break;
26
+ i++; space();
27
+ }
28
+ if (text[i++] !== '}') bad();
29
+ return { kind: 'object', start, end: i, fields };
30
+ }
31
+ if (text[i] === '[') {
32
+ i++; space(); const items = [];
33
+ if (text[i] !== ']') for (;;) {
34
+ items.push(value(depth + 1)); space();
35
+ if (text[i] !== ',') break;
36
+ i++; space();
37
+ }
38
+ if (text[i++] !== ']') bad();
39
+ return { kind: 'array', start, end: i, items };
40
+ }
41
+ if (text[i] === '"') return { kind: 'string', ...string() };
42
+ const match = /^(?:true|false|null|-?(?:0|[1-9][0-9]*)(?:\.[0-9]+)?(?:[eE][+-]?[0-9]+)?)/.exec(text.slice(i));
43
+ if (!match) bad();
44
+ i += match[0].length;
45
+ return { kind: 'scalar', start, end: i, token: match[0] };
46
+ };
47
+ const node = value(); space(); if (i !== text.length) bad(); return node;
48
+ }
49
+ const fingerprint = (n) => n.kind === 'object' ? ['object', [...n.fields].map(([k, v]) => [k, fingerprint(v)])]
50
+ : n.kind === 'array' ? ['array', n.items.map(fingerprint)] : [n.kind, n.value ?? n.token];
51
+ /** Return the exact candidate bytes; no configuration I/O or host defaults. */
52
+ export function editClaudeTrust(text, root) {
53
+ const document = jsonDocument(text);
54
+ const path = ['projects', root, 'hasTrustDialogAccepted'];
55
+ let parent = document;
56
+ for (let at = 0; at < path.length; at++) {
57
+ if (parent.kind !== 'object') bad();
58
+ const key = path[at], child = parent.fields.get(key);
59
+ if (!child) {
60
+ let inserted = true;
61
+ for (let n = path.length - 1; n > at; n--) inserted = { [path[n]]: inserted };
62
+ const insertion = `${parent.fields.size ? ',' : ''}${JSON.stringify(key)}:${JSON.stringify(inserted)}`;
63
+ const candidate = text.slice(0, parent.end - 1) + insertion + text.slice(parent.end - 1);
64
+ const after = jsonDocument(candidate);
65
+ // Independently derive the expected tree: only the missing suffix may appear.
66
+ parent.fields.set(key, jsonDocument(JSON.stringify(inserted)));
67
+ if (JSON.stringify(fingerprint(document)) !== JSON.stringify(fingerprint(after))) bad();
68
+ return { text: candidate, current: null };
69
+ }
70
+ if (at === path.length - 1) {
71
+ if (child.kind !== 'scalar' || !['true', 'false'].includes(child.token)) bad();
72
+ if (child.token === 'true') return { text, current: true };
73
+ const candidate = text.slice(0, child.start) + 'true' + text.slice(child.end);
74
+ child.token = 'true';
75
+ if (JSON.stringify(fingerprint(document)) !== JSON.stringify(fingerprint(jsonDocument(candidate)))) bad();
76
+ return { text: candidate, current: false };
77
+ }
78
+ parent = child;
79
+ }
80
+ bad();
81
+ }
@@ -0,0 +1,138 @@
1
+ /** Bounded, lossless native TOML editor. Unknown syntax is refused rather than
2
+ * interpreted by the deliberately permissive readiness reader. No dependencies. */
3
+ const bad = () => { throw new Error('unsupported or invalid native TOML configuration'); };
4
+ const object = (style = 'implicit') => ({ kind: 'object', style, fields: new Map() });
5
+ function scanner(text, offset = 0) {
6
+ let i = 0;
7
+ const space = () => { while (text[i] === ' ' || text[i] === '\t') i++; };
8
+ const quoted = () => {
9
+ const start = i, quote = text[i++];
10
+ if (text.slice(i, i + 2) === quote + quote) bad();
11
+ while (i < text.length) {
12
+ if (quote === '"' && text[i] === '\\') {
13
+ const point = text[i + 1] === 'u' ? Number.parseInt(text.slice(i + 2, i + 6), 16) : -1;
14
+ if (point >= 0xD800 && point <= 0xDFFF) bad();
15
+ i += 2; continue;
16
+ }
17
+ if (text[i++] === quote) {
18
+ const raw = text.slice(start, i);
19
+ let value;
20
+ try { value = quote === '"' ? JSON.parse(raw) : raw.slice(1, -1); } catch { bad(); }
21
+ if (/[\x00-\x08\x0a-\x1f\x7f]/.test(raw.slice(1, -1))) bad();
22
+ // JSON accepts escaped slash and lone surrogates; TOML does not.
23
+ if (quote === '"' && (/\\\//.test(raw) || /[\uD800-\uDFFF]/u.test(value))) bad();
24
+ return { kind: 'string', value, start: offset + start, end: offset + i };
25
+ }
26
+ }
27
+ bad();
28
+ };
29
+ const key = () => {
30
+ space(); const parts = [];
31
+ for (;;) {
32
+ if (text[i] === '"' || text[i] === "'") parts.push(quoted().value);
33
+ else { const m = /^[A-Za-z0-9_-]+/.exec(text.slice(i)); if (!m) bad(); parts.push(m[0]); i += m[0].length; }
34
+ space(); if (text[i] !== '.') break; i++; space();
35
+ }
36
+ return parts;
37
+ };
38
+ const put = (node, path, value) => {
39
+ for (const k of path.slice(0, -1)) {
40
+ if (!node.fields.has(k)) node.fields.set(k, object('dotted'));
41
+ node = node.fields.get(k); if (node.kind !== 'object' || ['inline', 'table'].includes(node.style)) bad();
42
+ }
43
+ const k = path.at(-1); if (node.fields.has(k)) bad(); node.fields.set(k, value);
44
+ };
45
+ const value = (depth = 0) => {
46
+ if (depth > 64) bad(); space(); const start = i;
47
+ if (text[i] === '"' || text[i] === "'") return quoted();
48
+ if (text[i] === '[') {
49
+ i++; space(); const items = [];
50
+ while (text[i] !== ']') {
51
+ items.push(value(depth + 1)); space();
52
+ if (text[i] !== ',') break; i++; space();
53
+ }
54
+ if (text[i++] !== ']') bad();
55
+ return { kind: 'array', items, start: offset + start, end: offset + i };
56
+ }
57
+ if (text[i] === '{') {
58
+ const node = object('inline'); node.start = offset + i++; space();
59
+ if (text[i] !== '}') for (;;) {
60
+ const path = key(); if (text[i++] !== '=') bad(); put(node, path, value(depth + 1)); space();
61
+ if (text[i] !== ',') break; i++; space(); if (text[i] === '}') bad();
62
+ }
63
+ if (text[i++] !== '}') bad(); node.end = offset + i; return node;
64
+ }
65
+ const token = /^[^\s,#\]}]+/.exec(text.slice(i))?.[0];
66
+ if (!token || !/^(?:true|false|[+-]?(?:0|[1-9](?:_?[0-9])*)(?:\.[0-9](?:_?[0-9])*)?(?:[eE][+-]?[0-9](?:_?[0-9])*)?)$/.test(token)) bad();
67
+ // TOML integers are signed 64-bit, unlike JSON's unrestricted numeric syntax.
68
+ if (/^[+-]?[0-9_]+$/.test(token)) { const n = BigInt(token.replaceAll('_', '')); if (n < -(2n ** 63n) || n > 2n ** 63n - 1n) bad(); }
69
+ // Reject integer forms TOML excludes (e.g. -01); preserve all numeric bytes.
70
+ i += token.length; return { kind: 'scalar', token, start: offset + start, end: offset + i };
71
+ };
72
+ return { key, value, space, get at() { return i; }, get char() { return text[i]; }, advance() { i++; }, put };
73
+ }
74
+ export function tomlDocument(text) {
75
+ const root = object(), tables = []; let table = root, offset = 0;
76
+ for (const raw of text.split(/(?<=\n)/)) {
77
+ const line = raw.replace(/\r?\n$/, '');
78
+ if (/[\x00-\x08\x0b-\x1f\x7f]/.test(line)) bad();
79
+ const scan = scanner(line, offset); scan.space();
80
+ if (scan.char !== undefined && scan.char !== '#') {
81
+ if (scan.char === '[') {
82
+ if (tables.length) tables.at(-1).end = offset;
83
+ scan.advance(); const path = scan.key(); if (scan.char !== ']') bad(); scan.advance();
84
+ table = root;
85
+ for (const k of path) {
86
+ if (!table.fields.has(k)) table.fields.set(k, object());
87
+ table = table.fields.get(k); if (table.kind !== 'object' || ['inline', 'dotted'].includes(table.style)) bad();
88
+ }
89
+ if (table.style === 'table') bad(); table.style = 'table'; table.path = path;
90
+ table.bodyStart = offset + raw.length; table.end = text.length; tables.push(table);
91
+ } else {
92
+ const path = scan.key(); if (scan.char !== '=') bad(); scan.advance(); const value = scan.value();
93
+ scan.put(table, path, value);
94
+ }
95
+ scan.space(); if (scan.char !== undefined && scan.char !== '#') bad();
96
+ }
97
+ offset += raw.length;
98
+ }
99
+ return { root, tables };
100
+ }
101
+ const semantic = (n) => n.kind === 'object' ? ['object', [...n.fields].sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0).map(([k, v]) => [k, semantic(v)])]
102
+ : n.kind === 'array' ? ['array', n.items.map(semantic)] : [n.kind, n.value ?? n.token];
103
+ export function editCodexTrust(text, rootPath) {
104
+ const { root, tables } = tomlDocument(text), projects = root.fields.get('projects');
105
+ if (projects && (projects.kind !== 'object' || projects.style === 'inline')) bad();
106
+ const project = projects?.fields.get(rootPath);
107
+ if (project && project.kind !== 'object') bad();
108
+ if (project?.style === 'inline' && [...project.fields.keys()].some(k => k !== 'trust_level')) bad();
109
+ const leaf = project?.fields.get('trust_level');
110
+ if (leaf && (leaf.kind !== 'string' || !['trusted', 'untrusted'].includes(leaf.value))) bad();
111
+ if (leaf?.value === 'trusted') return { text, current: 'trusted' };
112
+ let candidate;
113
+ const nl = text.includes('\r\n') ? '\r\n' : '\n';
114
+ const append = (at, line) => text.slice(0, at) + (at && text[at - 1] !== '\n' ? nl : '') + line + nl + text.slice(at);
115
+ if (leaf) candidate = text.slice(0, leaf.start) + '"trusted"' + text.slice(leaf.end);
116
+ else if (project?.style === 'inline') {
117
+ candidate = text.slice(0, project.end - 1) + (project.fields.size ? ', ' : '') + 'trust_level = "trusted"' + text.slice(project.end - 1);
118
+ } else if (project?.style === 'table') candidate = append(project.end, 'trust_level = "trusted"');
119
+ else if (!project && projects?.style !== 'dotted') candidate = append(text.length, `[projects.${JSON.stringify(rootPath)}]${nl}trust_level = "trusted"`);
120
+ else {
121
+ // Dotted-key tables cannot be reopened as headers. Add another dotted leaf
122
+ // in the nearest explicit enclosing table, or the document's root region.
123
+ const container = projects?.style === 'table' ? projects : null;
124
+ const at = container ? container.end : text.length;
125
+ const line = `${container ? '' : 'projects.'}${JSON.stringify(rootPath)}.trust_level = "trusted"`;
126
+ if (!container && tables.length) {
127
+ // The first header offset is derived from its body, not a bracket in a
128
+ // preceding string/comment.
129
+ const header = text.lastIndexOf('\n', tables[0].bodyStart - 2) + 1;
130
+ candidate = append(header, line);
131
+ } else candidate = append(at, line);
132
+ }
133
+ const expectedProjects = projects ?? object(); if (!projects) root.fields.set('projects', expectedProjects);
134
+ const expectedProject = project ?? object(); if (!project) expectedProjects.fields.set(rootPath, expectedProject);
135
+ expectedProject.fields.set('trust_level', { kind: 'string', value: 'trusted' });
136
+ if (JSON.stringify(semantic(root)) !== JSON.stringify(semantic(tomlDocument(candidate).root))) bad();
137
+ return { text: candidate, current: leaf ? 'untrusted' : null };
138
+ }