@quolu/lattice 0.64.0 → 0.64.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +147 -147
- package/README.ja.md +378 -378
- package/README.md +303 -303
- package/bin/lattice-mcp.mjs +0 -0
- package/bin/lattice-scripted-adapter.mjs +0 -0
- package/bin/lattice-scripted-worker.mjs +0 -0
- package/bin/lattice-work-order-adapter.mjs +0 -0
- package/bin/lattice.mjs +0 -0
- package/docs/bridge-setup.md +248 -248
- package/docs/schemas/lattice.executor_packet.v1.schema.json +57 -57
- package/docs/schemas/lattice.executor_receipt.v1.schema.json +66 -66
- package/docs/schemas/lattice.phase_todo_revision.v3.schema.json +360 -360
- package/docs/schemas/lattice.plan_create_input.v1.schema.json +56 -56
- package/docs/schemas/lattice.plan_create_input.v2.schema.json +72 -72
- package/docs/schemas/lattice.plan_create_input.v3.schema.json +81 -81
- package/docs/schemas/lattice.plan_create_input.v4.schema.json +357 -357
- package/docs/schemas/lattice.plan_scope_review.v1.schema.json +55 -55
- package/docs/schemas/lattice.run_request.v1.schema.json +238 -238
- package/docs/schemas/lattice.runtime_adapter_capabilities.v2.schema.json +55 -55
- package/docs/schemas/lattice.runtime_adapter_registration_input.v1.schema.json +78 -78
- package/docs/schemas/lattice.runtime_adapter_registration_input.v2.schema.json +86 -86
- package/docs/schemas/lattice.todo_extraction.v2.schema.json +298 -298
- package/docs/schemas/lattice.todo_extraction.v3.schema.json +150 -150
- package/docs/schemas/lattice.todo_extraction.v4.schema.json +161 -161
- package/docs/schemas/lattice.todo_revision.v2.schema.json +260 -260
- package/docs/schemas/lattice.todo_revision_set.v3.schema.json +363 -363
- package/docs/schemas/lattice.todo_structure_binding.v1.schema.json +47 -47
- package/docs/schemas/lattice.todo_structure_realization.v1.schema.json +55 -55
- package/docs/schemas/lattice.todo_structure_set.v1.schema.json +264 -264
- package/package.json +109 -109
- package/sensor/LICENSE +21 -21
- package/sensor/NOTICE +19 -19
- package/sensor/dist/bin/lattice-sensor.js +9 -9
- package/sensor/dist/db/index.js +24 -24
- package/sensor/dist/db/migrations.js +41 -41
- package/sensor/dist/db/queries.js +164 -164
- package/sensor/dist/db/schema.sql +205 -205
- package/sensor/dist/directory.js +5 -5
- package/sensor/dist/extraction/wasm/tree-sitter-c_sharp.wasm +0 -0
- package/sensor/dist/extraction/wasm/tree-sitter-cfml.wasm +0 -0
- package/sensor/dist/extraction/wasm/tree-sitter-cfquery.wasm +0 -0
- package/sensor/dist/extraction/wasm/tree-sitter-cfscript.wasm +0 -0
- package/sensor/dist/extraction/wasm/tree-sitter-cobol.wasm +0 -0
- package/sensor/dist/extraction/wasm/tree-sitter-erlang.wasm +0 -0
- package/sensor/dist/extraction/wasm/tree-sitter-go.wasm +0 -0
- package/sensor/dist/extraction/wasm/tree-sitter-java.wasm +0 -0
- package/sensor/dist/extraction/wasm/tree-sitter-javascript.wasm +0 -0
- package/sensor/dist/extraction/wasm/tree-sitter-nix.wasm +0 -0
- package/sensor/dist/extraction/wasm/tree-sitter-pascal.wasm +0 -0
- package/sensor/dist/extraction/wasm/tree-sitter-python.wasm +0 -0
- package/sensor/dist/extraction/wasm/tree-sitter-tsx.wasm +0 -0
- package/sensor/dist/extraction/wasm/tree-sitter-typescript.wasm +0 -0
- package/sensor/dist/extraction/wasm/tree-sitter-vbnet.wasm +0 -0
- package/sensor/dist/mcp/liveness-watchdog.js +53 -53
- package/sensor/dist/mcp/server-instructions.js +95 -95
- package/sensor/package.json +56 -56
- package/src/cli-help.mjs +2 -0
- package/src/hooks-cli.mjs +0 -1
- package/src/project-cli.mjs +8 -1
- package/src/todo-cli.mjs +20 -2
- package/src/todo-store-worktree-eol.mjs +191 -0
- package/src/todo-store.mjs +35 -17
|
@@ -18,79 +18,79 @@ exports.SERVER_INSTRUCTIONS_NO_ROOT_INDEX = exports.SERVER_INSTRUCTIONS = void 0
|
|
|
18
18
|
* burn tokens. ADR 0049 / 0059 require the eight compatibility tools to remain
|
|
19
19
|
* visible by default; provider identity is Lattice regardless of their names.
|
|
20
20
|
*/
|
|
21
|
-
exports.SERVER_INSTRUCTIONS = `# Lattice sensor — code intelligence over an indexed knowledge graph
|
|
22
|
-
|
|
23
|
-
Provider identity: lattice. The lattice_sensor_* names below are compatibility tool names served by Lattice's own bundled sensor; they do not call or require the independent Lattice sensor product.
|
|
24
|
-
|
|
25
|
-
Lattice sensor is a SQLite knowledge graph of every symbol, edge, and file in
|
|
26
|
-
the workspace — pre-computed structure you would otherwise re-derive by
|
|
27
|
-
reading files (cached intelligence: thousands of parse/trace decisions you
|
|
28
|
-
don't pay to re-reason each run). Reads are sub-millisecond; the index lags
|
|
29
|
-
writes by ~1s through the file watcher. Reach for it BEFORE *and* while
|
|
30
|
-
writing or editing code — not just for questions: one call returns the
|
|
31
|
-
verbatim source PLUS who calls it and what it affects, so you edit with the
|
|
32
|
-
blast radius in view. More accurate context, in far fewer tokens and
|
|
33
|
-
round-trips than reading files yourself.
|
|
34
|
-
|
|
35
|
-
## One tool: lattice_sensor_explore — use it instead of reading files
|
|
36
|
-
|
|
37
|
-
There is a single tool, \`lattice_sensor_explore\`, and it is Read-equivalent. It
|
|
38
|
-
takes either a natural-language question or a bag of symbol/file names and
|
|
39
|
-
returns the **verbatim, line-numbered source** of the relevant symbols
|
|
40
|
-
grouped by file — the same \`<n>\\t<line>\` shape \`Read\` gives you, safe to
|
|
41
|
-
\`Edit\` from — PLUS the call path among them (including dynamic-dispatch hops
|
|
42
|
-
like callbacks, React re-render, and JSX children that grep can't follow) and
|
|
43
|
-
a blast-radius summary of what depends on them.
|
|
44
|
-
|
|
45
|
-
Whether you're answering "how does X work" or implementing a change (fixing a
|
|
46
|
-
bug, adding a feature), call \`lattice_sensor_explore\` before you Read. ONE call
|
|
47
|
-
usually answers the whole question. Lattice sensor IS the pre-built search index —
|
|
48
|
-
so running your own grep + read loop, or delegating the lookup to a separate
|
|
49
|
-
file-reading sub-task/agent, repeats work lattice sensor already did and costs more
|
|
50
|
-
for the same answer. A direct lattice sensor answer is typically one to a few
|
|
51
|
-
calls; a grep/read exploration is dozens.
|
|
52
|
-
|
|
53
|
-
## How to query
|
|
54
|
-
|
|
55
|
-
- **Almost any question — "how does X work", architecture, a bug, "what/where is X", or surveying an area** → \`lattice_sensor_explore\` with a natural-language question or the relevant names. ONE capped call returns the verbatim source grouped by file; most often the ONLY call you need.
|
|
56
|
-
- **"How does X reach/become Y? / the flow / the path from X to Y"** → \`lattice_sensor_explore\`, naming the symbols that span the flow (e.g. \`mutateElement renderScene\`) — it surfaces the call path among them, riding dynamic-dispatch hops, and returns their source.
|
|
57
|
-
- **Reading or editing a file/symbol you can name** → put its name or file path in the \`lattice_sensor_explore\` query — it returns that current line-numbered source (safe to \`Edit\` from) with the call path and blast radius attached, so you don't Read it separately. For an overloaded name it returns every matching definition's body in one call.
|
|
58
|
-
- **Need more?** Call \`lattice_sensor_explore\` again with more specific names — treat the source it returns as already Read.
|
|
59
|
-
|
|
60
|
-
## Anti-patterns
|
|
61
|
-
|
|
62
|
-
- **Trust lattice sensor's results — don't re-verify them with grep.** They come from a full AST parse; re-checking with grep is slower, less accurate, and wastes context.
|
|
63
|
-
- **Don't grep or Read first** to find or understand indexed code — ONE \`lattice_sensor_explore\` returns the relevant symbols' source together in a single round-trip. Reach for raw \`Read\`/\`Grep\` only to confirm a specific detail lattice sensor didn't cover, or for what lattice sensor doesn't index (configs, docs).
|
|
64
|
-
- **Don't reconstruct a flow by hand** — name the endpoints in one \`lattice_sensor_explore\` and it surfaces the path between them, dynamic-dispatch hops included.
|
|
65
|
-
- **After editing, check the staleness banner.** When a tool response starts with "⚠️ Some files referenced below were edited since the last index sync…", the listed files are pending re-index — Read those specific files for accurate content. Every file NOT in that banner is fresh, so still trust lattice sensor. A different, rarer banner — "⚠️ LatticeSensor auto-sync is DISABLED…" — means live watching stopped entirely (the whole index is frozen, not just a few files); until it's resolved, Read files directly to confirm anything that may have changed.
|
|
66
|
-
- **A file flagged "⚠ changed on disk after the last index sync" drifted from its index** (most common on projects queried via \`projectPath\`, which have no live watcher). LatticeSensor never serves a possibly-mis-sliced body from such a file — it either shows the file's full CURRENT source (trust it as a Read) or omits the source with this flag. When the source was omitted, Read that specific file; line numbers referencing it elsewhere in the response may be shifted until that project's next sync. All unflagged files remain trustworthy.
|
|
67
|
-
|
|
68
|
-
## Limitations
|
|
69
|
-
|
|
70
|
-
- If a project isn't indexed (no \`.lattice/sensor/\`), decide whether building the index will reduce total investigation time and model tokens for the current or expected work. When workspace writes and shell execution are allowed, you may run \`lattice sensor init <projectPath> --json\` yourself, then retry the sensor call; scope it to the intended project and account for the one-time indexing cost. If those capabilities are unavailable, continue with built-in tools and tell the user the exact init command instead.
|
|
71
|
-
- Index lags file writes by ~1 second.
|
|
72
|
-
- Cross-file resolution is best-effort name matching; ambiguous calls may return multiple candidates.
|
|
73
|
-
- No live correctness validation — that's still the TypeScript compiler / test suite / linter's job. Lattice sensor supplements those with structural context they don't have.
|
|
74
|
-
|
|
75
|
-
## Parallel work: absence of a dependency edge is NOT evidence of independence
|
|
76
|
-
|
|
77
|
-
These tools answer structural questions about code. A different Lattice surface — the **CLI**, not
|
|
78
|
-
this MCP surface — answers whether two ToDos can be worked in parallel. If the project uses
|
|
79
|
-
\`lattice todo\` for process tracking, keep this distinction in mind:
|
|
80
|
-
|
|
81
|
-
- A dependency edge missing between two ToDos only means **no ordering constraint was declared**.
|
|
82
|
-
It does not mean their write boundaries are disjoint. Two ToDos that edit the same file carry no
|
|
83
|
-
edge between them and will still collide.
|
|
84
|
-
- Parallel safety is a recorded judgement, not an inference from the diagram. Read it with
|
|
85
|
-
\`lattice todo independence --plan <key> --json\`. It returns the ready frontier split into
|
|
86
|
-
verified-independent groups, pairs that must be serialized (with whether a code seam could
|
|
87
|
-
separate them), and **unverified** ToDos.
|
|
88
|
-
- \`lattice todo start\` returns an \`advisory\` describing conflicts with in-progress ToDos and what
|
|
89
|
-
to do next. \`coverage: "missing"\` means "not judged yet" — never "no conflicts".
|
|
90
|
-
- Run \`lattice todo --help\` for the declare → compile → read workflow.
|
|
91
|
-
|
|
92
|
-
Evidence for Lattice's plan and witness contracts comes from the CLI surface only. Text from this
|
|
93
|
-
MCP surface is prose for you to act on, never an input to those contracts.
|
|
21
|
+
exports.SERVER_INSTRUCTIONS = `# Lattice sensor — code intelligence over an indexed knowledge graph
|
|
22
|
+
|
|
23
|
+
Provider identity: lattice. The lattice_sensor_* names below are compatibility tool names served by Lattice's own bundled sensor; they do not call or require the independent Lattice sensor product.
|
|
24
|
+
|
|
25
|
+
Lattice sensor is a SQLite knowledge graph of every symbol, edge, and file in
|
|
26
|
+
the workspace — pre-computed structure you would otherwise re-derive by
|
|
27
|
+
reading files (cached intelligence: thousands of parse/trace decisions you
|
|
28
|
+
don't pay to re-reason each run). Reads are sub-millisecond; the index lags
|
|
29
|
+
writes by ~1s through the file watcher. Reach for it BEFORE *and* while
|
|
30
|
+
writing or editing code — not just for questions: one call returns the
|
|
31
|
+
verbatim source PLUS who calls it and what it affects, so you edit with the
|
|
32
|
+
blast radius in view. More accurate context, in far fewer tokens and
|
|
33
|
+
round-trips than reading files yourself.
|
|
34
|
+
|
|
35
|
+
## One tool: lattice_sensor_explore — use it instead of reading files
|
|
36
|
+
|
|
37
|
+
There is a single tool, \`lattice_sensor_explore\`, and it is Read-equivalent. It
|
|
38
|
+
takes either a natural-language question or a bag of symbol/file names and
|
|
39
|
+
returns the **verbatim, line-numbered source** of the relevant symbols
|
|
40
|
+
grouped by file — the same \`<n>\\t<line>\` shape \`Read\` gives you, safe to
|
|
41
|
+
\`Edit\` from — PLUS the call path among them (including dynamic-dispatch hops
|
|
42
|
+
like callbacks, React re-render, and JSX children that grep can't follow) and
|
|
43
|
+
a blast-radius summary of what depends on them.
|
|
44
|
+
|
|
45
|
+
Whether you're answering "how does X work" or implementing a change (fixing a
|
|
46
|
+
bug, adding a feature), call \`lattice_sensor_explore\` before you Read. ONE call
|
|
47
|
+
usually answers the whole question. Lattice sensor IS the pre-built search index —
|
|
48
|
+
so running your own grep + read loop, or delegating the lookup to a separate
|
|
49
|
+
file-reading sub-task/agent, repeats work lattice sensor already did and costs more
|
|
50
|
+
for the same answer. A direct lattice sensor answer is typically one to a few
|
|
51
|
+
calls; a grep/read exploration is dozens.
|
|
52
|
+
|
|
53
|
+
## How to query
|
|
54
|
+
|
|
55
|
+
- **Almost any question — "how does X work", architecture, a bug, "what/where is X", or surveying an area** → \`lattice_sensor_explore\` with a natural-language question or the relevant names. ONE capped call returns the verbatim source grouped by file; most often the ONLY call you need.
|
|
56
|
+
- **"How does X reach/become Y? / the flow / the path from X to Y"** → \`lattice_sensor_explore\`, naming the symbols that span the flow (e.g. \`mutateElement renderScene\`) — it surfaces the call path among them, riding dynamic-dispatch hops, and returns their source.
|
|
57
|
+
- **Reading or editing a file/symbol you can name** → put its name or file path in the \`lattice_sensor_explore\` query — it returns that current line-numbered source (safe to \`Edit\` from) with the call path and blast radius attached, so you don't Read it separately. For an overloaded name it returns every matching definition's body in one call.
|
|
58
|
+
- **Need more?** Call \`lattice_sensor_explore\` again with more specific names — treat the source it returns as already Read.
|
|
59
|
+
|
|
60
|
+
## Anti-patterns
|
|
61
|
+
|
|
62
|
+
- **Trust lattice sensor's results — don't re-verify them with grep.** They come from a full AST parse; re-checking with grep is slower, less accurate, and wastes context.
|
|
63
|
+
- **Don't grep or Read first** to find or understand indexed code — ONE \`lattice_sensor_explore\` returns the relevant symbols' source together in a single round-trip. Reach for raw \`Read\`/\`Grep\` only to confirm a specific detail lattice sensor didn't cover, or for what lattice sensor doesn't index (configs, docs).
|
|
64
|
+
- **Don't reconstruct a flow by hand** — name the endpoints in one \`lattice_sensor_explore\` and it surfaces the path between them, dynamic-dispatch hops included.
|
|
65
|
+
- **After editing, check the staleness banner.** When a tool response starts with "⚠️ Some files referenced below were edited since the last index sync…", the listed files are pending re-index — Read those specific files for accurate content. Every file NOT in that banner is fresh, so still trust lattice sensor. A different, rarer banner — "⚠️ LatticeSensor auto-sync is DISABLED…" — means live watching stopped entirely (the whole index is frozen, not just a few files); until it's resolved, Read files directly to confirm anything that may have changed.
|
|
66
|
+
- **A file flagged "⚠ changed on disk after the last index sync" drifted from its index** (most common on projects queried via \`projectPath\`, which have no live watcher). LatticeSensor never serves a possibly-mis-sliced body from such a file — it either shows the file's full CURRENT source (trust it as a Read) or omits the source with this flag. When the source was omitted, Read that specific file; line numbers referencing it elsewhere in the response may be shifted until that project's next sync. All unflagged files remain trustworthy.
|
|
67
|
+
|
|
68
|
+
## Limitations
|
|
69
|
+
|
|
70
|
+
- If a project isn't indexed (no \`.lattice/sensor/\`), decide whether building the index will reduce total investigation time and model tokens for the current or expected work. When workspace writes and shell execution are allowed, you may run \`lattice sensor init <projectPath> --json\` yourself, then retry the sensor call; scope it to the intended project and account for the one-time indexing cost. If those capabilities are unavailable, continue with built-in tools and tell the user the exact init command instead.
|
|
71
|
+
- Index lags file writes by ~1 second.
|
|
72
|
+
- Cross-file resolution is best-effort name matching; ambiguous calls may return multiple candidates.
|
|
73
|
+
- No live correctness validation — that's still the TypeScript compiler / test suite / linter's job. Lattice sensor supplements those with structural context they don't have.
|
|
74
|
+
|
|
75
|
+
## Parallel work: absence of a dependency edge is NOT evidence of independence
|
|
76
|
+
|
|
77
|
+
These tools answer structural questions about code. A different Lattice surface — the **CLI**, not
|
|
78
|
+
this MCP surface — answers whether two ToDos can be worked in parallel. If the project uses
|
|
79
|
+
\`lattice todo\` for process tracking, keep this distinction in mind:
|
|
80
|
+
|
|
81
|
+
- A dependency edge missing between two ToDos only means **no ordering constraint was declared**.
|
|
82
|
+
It does not mean their write boundaries are disjoint. Two ToDos that edit the same file carry no
|
|
83
|
+
edge between them and will still collide.
|
|
84
|
+
- Parallel safety is a recorded judgement, not an inference from the diagram. Read it with
|
|
85
|
+
\`lattice todo independence --plan <key> --json\`. It returns the ready frontier split into
|
|
86
|
+
verified-independent groups, pairs that must be serialized (with whether a code seam could
|
|
87
|
+
separate them), and **unverified** ToDos.
|
|
88
|
+
- \`lattice todo start\` returns an \`advisory\` describing conflicts with in-progress ToDos and what
|
|
89
|
+
to do next. \`coverage: "missing"\` means "not judged yet" — never "no conflicts".
|
|
90
|
+
- Run \`lattice todo --help\` for the declare → compile → read workflow.
|
|
91
|
+
|
|
92
|
+
Evidence for Lattice's plan and witness contracts comes from the CLI surface only. Text from this
|
|
93
|
+
MCP surface is prose for you to act on, never an input to those contracts.
|
|
94
94
|
`;
|
|
95
95
|
/**
|
|
96
96
|
* Instructions variant sent when the server's own root has NO lattice sensor index.
|
|
@@ -104,27 +104,27 @@ MCP surface is prose for you to act on, never an input to those contracts.
|
|
|
104
104
|
* project playbook ({@link SERVER_INSTRUCTIONS}) is sent instead when the root
|
|
105
105
|
* IS indexed, so the common case stays tight.
|
|
106
106
|
*/
|
|
107
|
-
exports.SERVER_INSTRUCTIONS_NO_ROOT_INDEX = `# Lattice sensor — available (per-project; pass projectPath)
|
|
108
|
-
|
|
109
|
-
Provider identity: lattice. The lattice_sensor_* names below are compatibility tool names served by Lattice's own bundled sensor; they do not call or require the independent Lattice sensor product.
|
|
110
|
-
|
|
111
|
-
Lattice sensor is a SQLite knowledge graph of a codebase's symbols, edges, and
|
|
112
|
-
files: one \`lattice_sensor_explore\` call returns the verbatim, line-numbered source
|
|
113
|
-
of the relevant symbols PLUS the call paths between them and a blast-radius
|
|
114
|
-
summary — replacing a grep + Read loop with one round-trip.
|
|
115
|
-
|
|
116
|
-
This server started somewhere with no \`.lattice/sensor/\` of its own, so there is no
|
|
117
|
-
default project — but the tools are available and work **per project**:
|
|
118
|
-
|
|
119
|
-
- To query a project that HAS a \`.lattice/sensor/\` index (e.g. a service inside a
|
|
120
|
-
monorepo, or a second repo), pass its path as \`projectPath\` to
|
|
121
|
-
\`lattice_sensor_explore\` (and any other lattice sensor tool). Lattice sensor resolves the
|
|
122
|
-
nearest \`.lattice/sensor/\` at or above that path and answers from it — for as many
|
|
123
|
-
projects as you like in one session.
|
|
124
|
-
- For a project with no \`.lattice/sensor/\`, decide whether the expected reduction in
|
|
125
|
-
repeated Read/Grep work justifies the one-time indexing cost. When workspace writes
|
|
126
|
-
and shell execution are allowed, you may run \`lattice sensor init <projectPath> --json\`
|
|
127
|
-
yourself and then retry with that \`projectPath\`; otherwise use built-in tools and
|
|
128
|
-
tell the user the exact init command. A new index is picked up live, with no restart.
|
|
107
|
+
exports.SERVER_INSTRUCTIONS_NO_ROOT_INDEX = `# Lattice sensor — available (per-project; pass projectPath)
|
|
108
|
+
|
|
109
|
+
Provider identity: lattice. The lattice_sensor_* names below are compatibility tool names served by Lattice's own bundled sensor; they do not call or require the independent Lattice sensor product.
|
|
110
|
+
|
|
111
|
+
Lattice sensor is a SQLite knowledge graph of a codebase's symbols, edges, and
|
|
112
|
+
files: one \`lattice_sensor_explore\` call returns the verbatim, line-numbered source
|
|
113
|
+
of the relevant symbols PLUS the call paths between them and a blast-radius
|
|
114
|
+
summary — replacing a grep + Read loop with one round-trip.
|
|
115
|
+
|
|
116
|
+
This server started somewhere with no \`.lattice/sensor/\` of its own, so there is no
|
|
117
|
+
default project — but the tools are available and work **per project**:
|
|
118
|
+
|
|
119
|
+
- To query a project that HAS a \`.lattice/sensor/\` index (e.g. a service inside a
|
|
120
|
+
monorepo, or a second repo), pass its path as \`projectPath\` to
|
|
121
|
+
\`lattice_sensor_explore\` (and any other lattice sensor tool). Lattice sensor resolves the
|
|
122
|
+
nearest \`.lattice/sensor/\` at or above that path and answers from it — for as many
|
|
123
|
+
projects as you like in one session.
|
|
124
|
+
- For a project with no \`.lattice/sensor/\`, decide whether the expected reduction in
|
|
125
|
+
repeated Read/Grep work justifies the one-time indexing cost. When workspace writes
|
|
126
|
+
and shell execution are allowed, you may run \`lattice sensor init <projectPath> --json\`
|
|
127
|
+
yourself and then retry with that \`projectPath\`; otherwise use built-in tools and
|
|
128
|
+
tell the user the exact init command. A new index is picked up live, with no restart.
|
|
129
129
|
`;
|
|
130
130
|
//# sourceMappingURL=server-instructions.js.map
|
package/sensor/package.json
CHANGED
|
@@ -1,56 +1,56 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@quolu/lattice-sensor",
|
|
3
|
-
"version": "0.7.3-lattice.1",
|
|
4
|
-
"private": true,
|
|
5
|
-
"description": "Lattice-owned local structural sensor.",
|
|
6
|
-
"repository": {
|
|
7
|
-
"type": "git",
|
|
8
|
-
"url": "git+https://github.com/kitepon/Lattice.git"
|
|
9
|
-
},
|
|
10
|
-
"main": "dist/index.js",
|
|
11
|
-
"types": "dist/index.d.ts",
|
|
12
|
-
"files": [
|
|
13
|
-
"dist",
|
|
14
|
-
"README.md"
|
|
15
|
-
],
|
|
16
|
-
"scripts": {
|
|
17
|
-
"build": "npm run clean && tsc && npm run copy-assets",
|
|
18
|
-
"copy-assets": "node -e \"const fs=require('fs');fs.mkdirSync('dist/db',{recursive:true});fs.copyFileSync('src/db/schema.sql','dist/db/schema.sql');fs.mkdirSync('dist/extraction/wasm',{recursive:true});fs.readdirSync('src/extraction/wasm').filter(f=>f.endsWith('.wasm')).forEach(f=>fs.copyFileSync('src/extraction/wasm/'+f,'dist/extraction/wasm/'+f))\"",
|
|
19
|
-
"dev": "tsc --watch",
|
|
20
|
-
"build:kernel": "bash scripts/build-kernel.sh",
|
|
21
|
-
"test": "vitest run --maxWorkers=4 --minWorkers=1",
|
|
22
|
-
"test:watch": "vitest",
|
|
23
|
-
"test:eval": "vitest run __tests__/evaluation/",
|
|
24
|
-
"eval": "npm run build && npx tsx __tests__/evaluation/runner.ts",
|
|
25
|
-
"clean": "node -e \"const fs=require('fs');fs.rmSync('dist',{recursive:true,force:true})\""
|
|
26
|
-
},
|
|
27
|
-
"keywords": [
|
|
28
|
-
"code-intelligence",
|
|
29
|
-
"knowledge-graph",
|
|
30
|
-
"static-analysis"
|
|
31
|
-
],
|
|
32
|
-
"author": "",
|
|
33
|
-
"license": "MIT",
|
|
34
|
-
"dependencies": {
|
|
35
|
-
"@clack/prompts": "^1.3.0",
|
|
36
|
-
"commander": "^14.0.2",
|
|
37
|
-
"fast-string-width": "^3.0.2",
|
|
38
|
-
"fast-wrap-ansi": "^0.2.0",
|
|
39
|
-
"ignore": "^7.0.5",
|
|
40
|
-
"jsonc-parser": "^3.3.1",
|
|
41
|
-
"picomatch": "^4.0.4",
|
|
42
|
-
"sisteransi": "^1.0.5",
|
|
43
|
-
"tree-sitter-wasms": "^0.1.11",
|
|
44
|
-
"web-tree-sitter": "^0.25.3"
|
|
45
|
-
},
|
|
46
|
-
"devDependencies": {
|
|
47
|
-
"@types/better-sqlite3": "^7.6.0",
|
|
48
|
-
"@types/node": "^20.19.30",
|
|
49
|
-
"@types/picomatch": "^4.0.2",
|
|
50
|
-
"typescript": "^5.0.0",
|
|
51
|
-
"vitest": "^2.1.9"
|
|
52
|
-
},
|
|
53
|
-
"engines": {
|
|
54
|
-
"node": ">=20.0.0 <25.0.0 || >=26.0.0"
|
|
55
|
-
}
|
|
56
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@quolu/lattice-sensor",
|
|
3
|
+
"version": "0.7.3-lattice.1",
|
|
4
|
+
"private": true,
|
|
5
|
+
"description": "Lattice-owned local structural sensor.",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/kitepon/Lattice.git"
|
|
9
|
+
},
|
|
10
|
+
"main": "dist/index.js",
|
|
11
|
+
"types": "dist/index.d.ts",
|
|
12
|
+
"files": [
|
|
13
|
+
"dist",
|
|
14
|
+
"README.md"
|
|
15
|
+
],
|
|
16
|
+
"scripts": {
|
|
17
|
+
"build": "npm run clean && tsc && npm run copy-assets",
|
|
18
|
+
"copy-assets": "node -e \"const fs=require('fs');fs.mkdirSync('dist/db',{recursive:true});fs.copyFileSync('src/db/schema.sql','dist/db/schema.sql');fs.mkdirSync('dist/extraction/wasm',{recursive:true});fs.readdirSync('src/extraction/wasm').filter(f=>f.endsWith('.wasm')).forEach(f=>fs.copyFileSync('src/extraction/wasm/'+f,'dist/extraction/wasm/'+f))\"",
|
|
19
|
+
"dev": "tsc --watch",
|
|
20
|
+
"build:kernel": "bash scripts/build-kernel.sh",
|
|
21
|
+
"test": "vitest run --maxWorkers=4 --minWorkers=1",
|
|
22
|
+
"test:watch": "vitest",
|
|
23
|
+
"test:eval": "vitest run __tests__/evaluation/",
|
|
24
|
+
"eval": "npm run build && npx tsx __tests__/evaluation/runner.ts",
|
|
25
|
+
"clean": "node -e \"const fs=require('fs');fs.rmSync('dist',{recursive:true,force:true})\""
|
|
26
|
+
},
|
|
27
|
+
"keywords": [
|
|
28
|
+
"code-intelligence",
|
|
29
|
+
"knowledge-graph",
|
|
30
|
+
"static-analysis"
|
|
31
|
+
],
|
|
32
|
+
"author": "",
|
|
33
|
+
"license": "MIT",
|
|
34
|
+
"dependencies": {
|
|
35
|
+
"@clack/prompts": "^1.3.0",
|
|
36
|
+
"commander": "^14.0.2",
|
|
37
|
+
"fast-string-width": "^3.0.2",
|
|
38
|
+
"fast-wrap-ansi": "^0.2.0",
|
|
39
|
+
"ignore": "^7.0.5",
|
|
40
|
+
"jsonc-parser": "^3.3.1",
|
|
41
|
+
"picomatch": "^4.0.4",
|
|
42
|
+
"sisteransi": "^1.0.5",
|
|
43
|
+
"tree-sitter-wasms": "^0.1.11",
|
|
44
|
+
"web-tree-sitter": "^0.25.3"
|
|
45
|
+
},
|
|
46
|
+
"devDependencies": {
|
|
47
|
+
"@types/better-sqlite3": "^7.6.0",
|
|
48
|
+
"@types/node": "^20.19.30",
|
|
49
|
+
"@types/picomatch": "^4.0.2",
|
|
50
|
+
"typescript": "^5.0.0",
|
|
51
|
+
"vitest": "^2.1.9"
|
|
52
|
+
},
|
|
53
|
+
"engines": {
|
|
54
|
+
"node": ">=20.0.0 <25.0.0 || >=26.0.0"
|
|
55
|
+
}
|
|
56
|
+
}
|
package/src/cli-help.mjs
CHANGED
|
@@ -86,6 +86,7 @@ Read commands:
|
|
|
86
86
|
phase status --plan <key>
|
|
87
87
|
|
|
88
88
|
Write commands:
|
|
89
|
+
repair-eol --json # Git checkoutでCRLF化された既存storeをcanonical LFへ戻し、EOL保護を追加する
|
|
89
90
|
dashboard adopt --json # 衝突したproject_idの配信元rootを現在repoへ明示的に移す
|
|
90
91
|
dashboard remove <project_id> --json # 登録簿から1件外す(対象repoの外からも叩ける)
|
|
91
92
|
note --plan <key> [--task <id>] (--message <text>|--input <file>)
|
|
@@ -251,6 +252,7 @@ const SUBCOMMAND_USAGE = Object.freeze({
|
|
|
251
252
|
'todo seam-profile': 'todo seam-profile --plan <key> --file <path> [--json]',
|
|
252
253
|
'todo seam-proposal': 'todo seam-proposal [--plan <key>] [--json] | compile --plan <key>',
|
|
253
254
|
'todo verify': 'todo verify [--plan <key>] [--json]',
|
|
255
|
+
'todo repair-eol': 'todo repair-eol --json',
|
|
254
256
|
'todo snapshot': 'todo snapshot --rebuild --plan <key>',
|
|
255
257
|
'todo gantt': 'todo gantt serve --port <port> [--scope live|all] # 動的表示のみ。静的HTML生成は廃止',
|
|
256
258
|
'todo gantt serve': 'todo gantt serve --port <0..65535> [--scope live|all] # loopback動的viewer',
|
package/src/hooks-cli.mjs
CHANGED
|
@@ -1090,7 +1090,6 @@ export async function runHooksCli({
|
|
|
1090
1090
|
}
|
|
1091
1091
|
const [command, , host] = argv;
|
|
1092
1092
|
if (platform === 'win32') {
|
|
1093
|
-
if (command === 'status') return status(host, env, stdout, source, platform, testHooks);
|
|
1094
1093
|
return failure(stdout, 'HOST_PLATFORM_UNSUPPORTED', 'native Windows hooks are unsupported');
|
|
1095
1094
|
}
|
|
1096
1095
|
if (command === 'install') return mutate(host, env, stdout, false, source, platform, testHooks);
|
package/src/project-cli.mjs
CHANGED
|
@@ -325,7 +325,14 @@ async function resolveProjectState({ cwd, cliVersion, diagnoseStructureArtifacts
|
|
|
325
325
|
if (error?.code === 'STRUCTURE_ARTIFACT_INVALID') throw error;
|
|
326
326
|
const reason = error instanceof TodoStoreError
|
|
327
327
|
? `${error.code}:${error.detail?.reason ?? error.message}` : 'store_validation_failed';
|
|
328
|
-
|
|
328
|
+
const nextAction = error instanceof TodoStoreError
|
|
329
|
+
&& error.detail?.next_action === 'lattice todo repair-eol --json'
|
|
330
|
+
? { command: error.detail.next_action, reason: `${reason}:${error.detail.ref}` }
|
|
331
|
+
: null;
|
|
332
|
+
return {
|
|
333
|
+
exitCode: 1, repoRoot, store: null, todo: null,
|
|
334
|
+
result: invalidStatus({ cliVersion, repoRoot, reason, nextAction }),
|
|
335
|
+
};
|
|
329
336
|
}
|
|
330
337
|
}
|
|
331
338
|
|
package/src/todo-cli.mjs
CHANGED
|
@@ -177,6 +177,7 @@ import {
|
|
|
177
177
|
} from './todo-note-store.mjs';
|
|
178
178
|
import { readTodoParallelCandidatesForStatus } from './todo-parallel-candidates.mjs';
|
|
179
179
|
import { commitTodoStoreMutation } from './todo-store-git-transaction.mjs';
|
|
180
|
+
import { repairTodoStoreWorktreeEol } from './todo-store-worktree-eol.mjs';
|
|
180
181
|
|
|
181
182
|
const CLI_ERROR_SCHEMA = 'lattice.cli_error.v2';
|
|
182
183
|
const DEFAULT_GANTT_SCOPE = 'live';
|
|
@@ -254,7 +255,7 @@ function internalFailure(stderr, error) {
|
|
|
254
255
|
|
|
255
256
|
const TODO_COMMAND_NAMES = Object.freeze([
|
|
256
257
|
'status', 'show', 'note', 'bindings', 'independence', 'structure', 'seam-profile', 'seam-proposal',
|
|
257
|
-
'verify', 'snapshot', 'gantt', 'dashboard', 'phase', 'migrate', 'start', 'block',
|
|
258
|
+
'verify', 'repair-eol', 'snapshot', 'gantt', 'dashboard', 'phase', 'migrate', 'start', 'block',
|
|
258
259
|
'unblock', 'done', 'reopen', 'evidence', 'split', 'revise', 'revise-phase', 'revise-set',
|
|
259
260
|
]);
|
|
260
261
|
|
|
@@ -3579,6 +3580,20 @@ async function rebuildSnapshot({ repoRoot, planKey }) {
|
|
|
3579
3580
|
return result;
|
|
3580
3581
|
}
|
|
3581
3582
|
|
|
3583
|
+
async function repairStoreEol({ repoRoot }) {
|
|
3584
|
+
const repair = await repairTodoStoreWorktreeEol({ repoRoot });
|
|
3585
|
+
const store = await readTodoStore({ repoRoot });
|
|
3586
|
+
const result = {
|
|
3587
|
+
schema: 'lattice.todo_eol_repair_result.v1',
|
|
3588
|
+
project_id: store.project_id,
|
|
3589
|
+
...repair,
|
|
3590
|
+
repaired_count: repair.repaired_refs.length,
|
|
3591
|
+
result_digest: '',
|
|
3592
|
+
};
|
|
3593
|
+
result.result_digest = todoSelfDigest(result, 'result_digest');
|
|
3594
|
+
return result;
|
|
3595
|
+
}
|
|
3596
|
+
|
|
3582
3597
|
/**
|
|
3583
3598
|
* `lattice todo` namespace. Exact position, order, and argument count are part of
|
|
3584
3599
|
* the public contract; usage failures never use a JSON envelope.
|
|
@@ -3633,7 +3648,10 @@ export async function runTodoCli({ argv, cwd, stdout, stderr, env = process.env
|
|
|
3633
3648
|
|
|
3634
3649
|
const automatedStructureRealize = parseAutomatedStructureRealizeArgs(argv);
|
|
3635
3650
|
let action = null;
|
|
3636
|
-
if (
|
|
3651
|
+
if (argv.length === 2 && argv[0] === 'repair-eol' && argv[1] === '--json') {
|
|
3652
|
+
// 壊れたstoreを読めない時の入口なので、dashboard所有権pre-hookを通さない。
|
|
3653
|
+
action = (repoRoot) => repairStoreEol({ repoRoot });
|
|
3654
|
+
} else if ((argv.length === 1 && argv[0] === 'status')
|
|
3637
3655
|
|| (argv.length === 2 && argv[0] === 'status' && argv[1] === '--json')) {
|
|
3638
3656
|
action = (repoRoot) => status({ repoRoot });
|
|
3639
3657
|
} else if (argv.length === 3 && argv[0] === 'dashboard'
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
import { randomBytes } from 'node:crypto';
|
|
2
|
+
import {
|
|
3
|
+
lstat, readFile, readdir, rename, rm, writeFile,
|
|
4
|
+
} from 'node:fs/promises';
|
|
5
|
+
import path from 'node:path';
|
|
6
|
+
|
|
7
|
+
import { gitCatFileBatch, gitSpawnSync } from './git-process.mjs';
|
|
8
|
+
import { TodoStoreError } from './todo-store.mjs';
|
|
9
|
+
|
|
10
|
+
const STORE_REF = '.lattice/todo';
|
|
11
|
+
const ATTRIBUTES_REF = '.lattice/.gitattributes';
|
|
12
|
+
const EOL_PROTECTION = '# Lattice store artifacts are canonical JSON+LF bytes; EOL conversion corrupts the store.\n* -text\n';
|
|
13
|
+
const INDEX_REFRESH_BATCH_SIZE = 40;
|
|
14
|
+
|
|
15
|
+
function fail(reason, detail = {}) {
|
|
16
|
+
throw new TodoStoreError('STORE_EOL_REPAIR_UNSAFE', reason, undefined, detail);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
async function regularFileState(absolute, ref) {
|
|
20
|
+
let stats;
|
|
21
|
+
try { stats = await lstat(absolute); } catch (error) {
|
|
22
|
+
if (error?.code === 'ENOENT') return null;
|
|
23
|
+
fail('artifact_unreadable', { ref, message: error.message });
|
|
24
|
+
}
|
|
25
|
+
if (stats.isSymbolicLink() || !stats.isFile()) fail('unsafe_artifact_path', { ref });
|
|
26
|
+
return stats;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
async function assertSafeDirectoryChain(repoRoot, relative) {
|
|
30
|
+
let absolute = repoRoot;
|
|
31
|
+
let ref = '';
|
|
32
|
+
for (const segment of relative.replaceAll('\\', '/').split('/')) {
|
|
33
|
+
ref = path.posix.join(ref, segment);
|
|
34
|
+
absolute = path.join(absolute, segment);
|
|
35
|
+
let stats;
|
|
36
|
+
try { stats = await lstat(absolute); } catch (error) {
|
|
37
|
+
fail(error?.code === 'ENOENT' ? 'store_missing' : 'store_unreadable', {
|
|
38
|
+
ref, message: error.message,
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
if (stats.isSymbolicLink() || !stats.isDirectory()) fail('unsafe_artifact_path', { ref });
|
|
42
|
+
}
|
|
43
|
+
return absolute;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
async function safeRegularFileState(repoRoot, ref) {
|
|
47
|
+
await assertSafeDirectoryChain(repoRoot, path.posix.dirname(ref));
|
|
48
|
+
return regularFileState(path.join(repoRoot, ref), ref);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
async function collectArtifactRefs(repoRoot, relative = STORE_REF) {
|
|
52
|
+
const absolute = await assertSafeDirectoryChain(repoRoot, relative);
|
|
53
|
+
let entries;
|
|
54
|
+
try { entries = await readdir(absolute, { withFileTypes: true }); } catch (error) {
|
|
55
|
+
fail(error?.code === 'ENOENT' ? 'store_missing' : 'store_unreadable', {
|
|
56
|
+
ref: relative, message: error.message,
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
const refs = [];
|
|
60
|
+
for (const entry of entries.sort((left, right) => left.name.localeCompare(right.name))) {
|
|
61
|
+
const ref = path.posix.join(relative.replaceAll('\\', '/'), entry.name);
|
|
62
|
+
if (entry.isSymbolicLink()) fail('unsafe_artifact_path', { ref });
|
|
63
|
+
if (entry.isDirectory()) refs.push(...await collectArtifactRefs(repoRoot, ref));
|
|
64
|
+
else if (entry.isFile() && /\.(?:json|jsonl)$/u.test(entry.name)) refs.push(ref);
|
|
65
|
+
else if (!entry.isFile()) fail('unsafe_artifact_path', { ref });
|
|
66
|
+
}
|
|
67
|
+
return refs;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function normalizePureCrlf(bytes, ref) {
|
|
71
|
+
if (!bytes.includes(13)) return null;
|
|
72
|
+
const normalized = [];
|
|
73
|
+
for (let index = 0; index < bytes.length; index += 1) {
|
|
74
|
+
const byte = bytes[index];
|
|
75
|
+
if (byte !== 13) {
|
|
76
|
+
normalized.push(byte);
|
|
77
|
+
continue;
|
|
78
|
+
}
|
|
79
|
+
if (bytes[index + 1] !== 10) fail('artifact_not_pure_crlf_conversion', { ref });
|
|
80
|
+
}
|
|
81
|
+
return Buffer.from(normalized);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
async function atomicReplace({ repoRoot, ref, absolute, sourceBytes, bytes, mode }) {
|
|
85
|
+
await safeRegularFileState(repoRoot, ref);
|
|
86
|
+
const currentBytes = await readFile(absolute);
|
|
87
|
+
if (!currentBytes.equals(sourceBytes)) fail('artifact_changed_during_repair', { ref });
|
|
88
|
+
const temporary = `${absolute}.eol-repair-${process.pid}-${randomBytes(6).toString('hex')}.tmp`;
|
|
89
|
+
try {
|
|
90
|
+
await writeFile(temporary, bytes, { flag: 'wx', mode: mode & 0o777 });
|
|
91
|
+
await rename(temporary, absolute);
|
|
92
|
+
} catch (error) {
|
|
93
|
+
try { await rm(temporary, { force: true }); } catch { /* noop */ }
|
|
94
|
+
fail('artifact_write_failed', { ref: path.basename(absolute), message: error.message });
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
async function prepareProtection(repoRoot) {
|
|
99
|
+
const absolute = path.join(repoRoot, ATTRIBUTES_REF);
|
|
100
|
+
const stats = await safeRegularFileState(repoRoot, ATTRIBUTES_REF);
|
|
101
|
+
if (stats === null) return { absolute, create: true };
|
|
102
|
+
const text = await readFile(absolute, 'utf8');
|
|
103
|
+
if (!text.split(/\r?\n/u).includes('* -text')) {
|
|
104
|
+
fail('eol_protection_conflict', { ref: ATTRIBUTES_REF, required_rule: '* -text' });
|
|
105
|
+
}
|
|
106
|
+
return { absolute, create: false };
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function refreshGitIndex(repoRoot, refs) {
|
|
110
|
+
for (let offset = 0; offset < refs.length; offset += INDEX_REFRESH_BATCH_SIZE) {
|
|
111
|
+
const batch = refs.slice(offset, offset + INDEX_REFRESH_BATCH_SIZE);
|
|
112
|
+
const refresh = gitSpawnSync(['add', '--refresh', '--', ...batch], {
|
|
113
|
+
cwd: repoRoot, stdio: 'ignore',
|
|
114
|
+
});
|
|
115
|
+
// git add --refresh は内容をstageせずstat cacheだけを更新する。対象pathは下のdiff-filesで検証する。
|
|
116
|
+
if (refresh.error || refresh.signal || ![0, 1].includes(refresh.status)) {
|
|
117
|
+
fail('git_index_refresh_failed', { refs: batch, status: refresh.status ?? null });
|
|
118
|
+
}
|
|
119
|
+
const verified = gitSpawnSync(['diff-files', '--quiet', '--', ...batch], {
|
|
120
|
+
cwd: repoRoot, stdio: 'ignore',
|
|
121
|
+
});
|
|
122
|
+
if (verified.error || verified.signal || verified.status !== 0) {
|
|
123
|
+
fail('git_index_refresh_failed', { refs: batch, status: verified.status ?? null });
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Gitのcheckoutがcanonical LF artifactをCRLFへ変換した既存storeだけを修復する。
|
|
130
|
+
* JSONの意味・順序・空白には触れず、CRLF除去後にcanonical byte列へ完全一致するfileだけを書く。
|
|
131
|
+
*/
|
|
132
|
+
export async function repairTodoStoreWorktreeEol({ repoRoot }) {
|
|
133
|
+
const protection = await prepareProtection(repoRoot);
|
|
134
|
+
const refs = await collectArtifactRefs(repoRoot);
|
|
135
|
+
const converted = [];
|
|
136
|
+
for (const ref of refs) {
|
|
137
|
+
const absolute = path.join(repoRoot, ref);
|
|
138
|
+
const stats = await safeRegularFileState(repoRoot, ref);
|
|
139
|
+
const bytes = await readFile(absolute);
|
|
140
|
+
const normalized = normalizePureCrlf(bytes, ref);
|
|
141
|
+
if (normalized === null) continue;
|
|
142
|
+
converted.push({
|
|
143
|
+
ref, absolute, sourceBytes: bytes, bytes: normalized, mode: stats.mode,
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
let headArtifacts = [];
|
|
148
|
+
let indexArtifacts = [];
|
|
149
|
+
if (converted.length > 0) {
|
|
150
|
+
const maxBodyBytes = Math.max(...converted.map(({ bytes }) => bytes.length));
|
|
151
|
+
try {
|
|
152
|
+
headArtifacts = gitCatFileBatch(converted.map(({ ref }) => `HEAD:${ref}`), {
|
|
153
|
+
cwd: repoRoot, maxBodyBytes,
|
|
154
|
+
});
|
|
155
|
+
} catch (error) {
|
|
156
|
+
fail('git_head_artifacts_unreadable', { message: error.message });
|
|
157
|
+
}
|
|
158
|
+
try {
|
|
159
|
+
indexArtifacts = gitCatFileBatch(converted.map(({ ref }) => `:${ref}`), {
|
|
160
|
+
cwd: repoRoot, maxBodyBytes,
|
|
161
|
+
});
|
|
162
|
+
} catch (error) {
|
|
163
|
+
fail('git_index_artifacts_unreadable', { message: error.message });
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
for (const [index, artifact] of converted.entries()) {
|
|
167
|
+
const head = headArtifacts[index];
|
|
168
|
+
if (head?.type !== 'blob' || !head.bytes.equals(artifact.bytes)) {
|
|
169
|
+
fail('artifact_not_pure_checkout_conversion', { ref: artifact.ref });
|
|
170
|
+
}
|
|
171
|
+
const staged = indexArtifacts[index];
|
|
172
|
+
if (staged?.type !== 'blob' || !staged.bytes.equals(head.bytes)) {
|
|
173
|
+
fail('artifact_staged_change_present', { ref: artifact.ref });
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
for (const artifact of converted) {
|
|
178
|
+
await atomicReplace({ repoRoot, ...artifact });
|
|
179
|
+
}
|
|
180
|
+
refreshGitIndex(repoRoot, converted.map(({ ref }) => ref));
|
|
181
|
+
if (protection.create) {
|
|
182
|
+
await assertSafeDirectoryChain(repoRoot, path.posix.dirname(ATTRIBUTES_REF));
|
|
183
|
+
await writeFile(protection.absolute, EOL_PROTECTION, { flag: 'wx' });
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
return {
|
|
187
|
+
repaired_refs: converted.map(({ ref }) => ref),
|
|
188
|
+
protection_ref: ATTRIBUTES_REF,
|
|
189
|
+
protection_created: protection.create,
|
|
190
|
+
};
|
|
191
|
+
}
|