dsh-clear-debug 0.0.0-stage → 0.1.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.
- package/LICENSE +21 -0
- package/README.md +64 -2
- package/cordis.patch.yml +3 -0
- package/docs/DETAIL.md +184 -0
- package/icon.svg +6 -0
- package/index.js +872 -0
- package/lib/checks.js +322 -0
- package/lib/config.js +37 -0
- package/lib/fingerprint.js +127 -0
- package/lib/gate.js +71 -0
- package/lib/invariants.js +231 -0
- package/lib/paths.js +101 -0
- package/lib/scope-store.js +205 -0
- package/lib/session.js +114 -0
- package/lib/site-history.js +63 -0
- package/locale/en.json +7 -0
- package/locale/zh.json +7 -0
- package/package.json +56 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 dsh-clear-debug contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,65 @@
|
|
|
1
|
-
#
|
|
1
|
+
# dsh-clear-debug
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
An agent's only verifiable signal is that the reported error stopped. A local patch
|
|
4
|
+
restores that signal cheaply, so it wins by default over a change whose correctness
|
|
5
|
+
has no oracle. This plugin replaces "did the error go away" with "is the change
|
|
6
|
+
inside a boundary you can state, and does the evidence you cite actually exist".
|
|
7
|
+
|
|
8
|
+
It is a **process constraint**, not a diagnostician. It makes shallow work visible
|
|
9
|
+
and expensive. It does not tell a correct diagnosis from a plausible one.
|
|
10
|
+
|
|
11
|
+
> **What it gates:** only the agent's `edit` and `write` tool calls. Your own editor
|
|
12
|
+
> is outside DSH and is never blocked. A file you change there during an open scope
|
|
13
|
+
> is reported at close as a warning — "this changed outside DSH, if it was you the
|
|
14
|
+
> change stands" — not refused.
|
|
15
|
+
|
|
16
|
+
## What it enforces
|
|
17
|
+
|
|
18
|
+
| Requirement | How it is checked |
|
|
19
|
+
|---|---|
|
|
20
|
+
| No source edit without a declaration | `edit` and `write` are refused |
|
|
21
|
+
| Edits stay inside the declared targets | path match against `targets` |
|
|
22
|
+
| A deep fix names where state departs from intent | `observation.command`, `expected` ≠ `actual`, `site` exists and lies inside `targets` |
|
|
23
|
+
| The expectation is frozen before the fix | `revise` cannot change it |
|
|
24
|
+
| A deep fix names the broken contract, the defect class, and a sweep | `cause.contract`, `cause.class`, `cause.sweep` |
|
|
25
|
+
| A deep rewrite says what must disappear, and it does | identifiers in `discard` are searched in the touched files |
|
|
26
|
+
| Close proves the same step now produces the frozen value | `verification` must match command and value |
|
|
27
|
+
| **The verification output really exists in the session** | a real `tool/call` with the command plus its `tool/result` containing the value |
|
|
28
|
+
| A rewrite with an unchanged public surface is not a rewrite | fingerprint comparison |
|
|
29
|
+
| A fix that only added conditionals is not a root fix | branch-count comparison |
|
|
30
|
+
| One invariant per change, keyed and executable | `docs/invariants.json`, rendered to `docs/INVARIANTS.md` |
|
|
31
|
+
| Every recorded invariant can actually fail | `action: "verify"` runs each check via the host subprocess service |
|
|
32
|
+
|
|
33
|
+
## What it does not do
|
|
34
|
+
|
|
35
|
+
- It cannot tell whether the observation crosses the actual cause. The command is
|
|
36
|
+
chosen by the agent.
|
|
37
|
+
- It cannot verify a sweep is complete; the entries are statements, not results.
|
|
38
|
+
- A shell command that writes files is not gated.
|
|
39
|
+
- An invariant with no check is a claim nothing defends; `verify` reports it as
|
|
40
|
+
`unchecked` rather than passing.
|
|
41
|
+
|
|
42
|
+
## Install
|
|
43
|
+
|
|
44
|
+
Bring the package into the profile as a bundle (a local directory works during
|
|
45
|
+
development). The bundle inserts one row, `clear-debug`.
|
|
46
|
+
|
|
47
|
+
## Files it creates in your workspace
|
|
48
|
+
|
|
49
|
+
| Path | Purpose |
|
|
50
|
+
|---|---|
|
|
51
|
+
| `docs/invariants.json` | source of truth for invariants |
|
|
52
|
+
| `docs/INVARIANTS.md` | generated view; a hand-written file is copied to `INVARIANTS.manual.md` once |
|
|
53
|
+
| `.dsh/change-scope/` | per-session scope records, survive reload |
|
|
54
|
+
| `.dsh/site-history.json` | per-file attribution history surfaced on declare |
|
|
55
|
+
| `.dsh/ledger.json` | finding counts, aged out after 180 days |
|
|
56
|
+
|
|
57
|
+
Add `.dsh/` to your ignore file if the records should not be committed.
|
|
58
|
+
|
|
59
|
+
## Environment
|
|
60
|
+
|
|
61
|
+
- A check starting with `node` runs on the host's own executable, so it works without
|
|
62
|
+
node on `PATH`.
|
|
63
|
+
- The git history in a declaration briefing is optional: it needs `git` in the
|
|
64
|
+
provider's execution world and a workspace that is a repository. Otherwise the
|
|
65
|
+
briefing says so.
|
package/cordis.patch.yml
ADDED
package/docs/DETAIL.md
ADDED
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
# Change scope
|
|
2
|
+
|
|
3
|
+
Change scope makes a code change declare its boundary before it starts, keeps the
|
|
4
|
+
edit inside that boundary, checks the finished change against the shape it claimed,
|
|
5
|
+
and records one invariant when the change closes.
|
|
6
|
+
|
|
7
|
+
It exists because an agent's only verifiable signal is that the reported error
|
|
8
|
+
stopped. A local patch restores that signal cheaply, so it wins by default over a
|
|
9
|
+
change whose correctness has no oracle. This plugin replaces "did the error go
|
|
10
|
+
away" with "is the change inside a boundary you can state and defend".
|
|
11
|
+
|
|
12
|
+
## What it does
|
|
13
|
+
|
|
14
|
+
- **A protocol in the prompt.** Before a source edit, the agent investigates until
|
|
15
|
+
it can name the first point where observed state departs from the state the code
|
|
16
|
+
intends, and the defect class that point belongs to — or, for a rewrite, the new
|
|
17
|
+
contract and boundaries. Only then does it ask the user to authorize a scope.
|
|
18
|
+
- **A declaration, not a plan.** `change_scope` with `action: "declare"` records the
|
|
19
|
+
mode (`fix`, `rewrite`, `feature`), the depth (`deep`, `quick`), the reason the
|
|
20
|
+
target set is the minimal sufficient one, who authorized it, the glob targets the
|
|
21
|
+
change may edit, and the contracts it may move.
|
|
22
|
+
- **A rewrite is a claim about what disappears.** A `deep` rewrite must declare
|
|
23
|
+
`discard`: the symbols it deletes or the behaviors it replaces. At close every
|
|
24
|
+
identifier in `discard` is searched in the files that were actually touched, with
|
|
25
|
+
word boundaries; one that is still there is refused as `discard_retained` unless it
|
|
26
|
+
is listed in `retained` with the reason it had to stay. A rewrite that touched no
|
|
27
|
+
file at all is refused as `rewrite_without_edits`. Identifiers are checkable;
|
|
28
|
+
prose entries are reported as `unverified` rather than silently accepted.
|
|
29
|
+
- **Re-diagnosis is a first-class step.** When an observation contradicts the current
|
|
30
|
+
cause, `rediagnose` records the refutation — the contradicted cause, the evidence,
|
|
31
|
+
and the reason — and replaces the cause. The gate writes the retraction itself, so
|
|
32
|
+
the agent contributes data rather than an admission; the symptom observation stays
|
|
33
|
+
frozen, so the close still verifies against the same measurement.
|
|
34
|
+
- **Relapse is a fact, not a feeling.** A declaration after a closed one at the same
|
|
35
|
+
site carries the earlier diagnosis forward and reports it. Declaring the same
|
|
36
|
+
contract and class again is refused: repeating a falsified diagnosis is the one
|
|
37
|
+
thing re-diagnosis exists to prevent.
|
|
38
|
+
- **The user is asked twice, and only twice.** A `deep` declaration requires an
|
|
39
|
+
`ask_user_question` in the session log since the last user message, and a `deep`
|
|
40
|
+
close requires one after the declaration. The check reads the session log, so it
|
|
41
|
+
verifies that a question was actually asked rather than that the agent says it did.
|
|
42
|
+
When the session log is unavailable the result says `askedUser: "unverified"`
|
|
43
|
+
instead of pretending the check ran.
|
|
44
|
+
- **A gate.** In `deep` depth, `edit` and `write` are refused outside the declared
|
|
45
|
+
targets, and refused entirely when no declaration exists. The refusal names the
|
|
46
|
+
boundary and asks for an explicit `revise` rather than a silent widening.
|
|
47
|
+
- **A deep fix is a different strategy.** Declaring `deep` for a `fix` requires
|
|
48
|
+
`cause`: the contract that should always be true at the divergence, the defect
|
|
49
|
+
class that point belongs to, and `sweep` — at least one other place that class
|
|
50
|
+
could live, each with a verdict. A single sweep entry is allowed only when it says
|
|
51
|
+
why the class is contained there. Without the dossier, `deep` would only be a
|
|
52
|
+
stricter gate on the same patching strategy: the agent would still be looking for
|
|
53
|
+
the smallest change that silences the symptom, and merely have to justify it
|
|
54
|
+
afterwards.
|
|
55
|
+
- **Durable records.** The scope of each session is written to
|
|
56
|
+
`<workspace>/.dsh/change-scope/<session>.json` on every declaration, revision,
|
|
57
|
+
first edit of a file, and close. A plugin reload, a restart, or a resumed session
|
|
58
|
+
reloads it, so an open declaration keeps gating until it is closed. The record is
|
|
59
|
+
versioned plain JSON; a file that fails to parse or carries another version is
|
|
60
|
+
ignored rather than trusted, and a failed write never blocks an edit.
|
|
61
|
+
- **Observed evidence.** A `deep` fix must carry `observation` when it declares: the
|
|
62
|
+
step that reproduces the symptom, the value the code intends, the value it actually
|
|
63
|
+
produces, and the site. `expected` and `actual` must differ — an observation with
|
|
64
|
+
nothing to explain is refused — the site must exist, and the expectation is frozen:
|
|
65
|
+
`revise` cannot change it. At close the agent passes `verification` with the same
|
|
66
|
+
step and what it now produces. The plugin refuses a missing verification, a
|
|
67
|
+
different step, or a value that is not the expectation frozen before the fix.
|
|
68
|
+
- **A site inside the scope.** The observation's site must fall inside the declared
|
|
69
|
+
`targets` and must not be listed in `excluded`. A scope cannot explain a place it
|
|
70
|
+
is not allowed to change, and `revise` that would detach the two is refused: the
|
|
71
|
+
observation is frozen, so the boundary may not stop containing the place it
|
|
72
|
+
explains.
|
|
73
|
+
- **A shape check at close.** The plugin snapshots each file's public surface just
|
|
74
|
+
before its first edit, and compares it when the scope closes:
|
|
75
|
+
- `rewrite_shape_unchanged` — declared a rewrite, but exports, exported
|
|
76
|
+
signatures, and conditional count are all unchanged. A rewrite must be
|
|
77
|
+
re-derived, not inherited.
|
|
78
|
+
- `branch_only_change` — conditionals were added with no exported signature
|
|
79
|
+
moved, in a `fix` or `rewrite`. This is the fingerprint of a symptom patch. A
|
|
80
|
+
`feature` is expected to add branches and is not flagged.
|
|
81
|
+
- `contract_changed_undeclared` — an export or exported signature moved while the
|
|
82
|
+
declaration names no contract change.
|
|
83
|
+
- `verification_missing` / `verification_command_mismatch` /
|
|
84
|
+
`verification_unresolved` — the close-time evidence does not form a pair with the
|
|
85
|
+
frozen observation: no verification, a different step, or a value that is not the
|
|
86
|
+
expectation recorded before the fix.
|
|
87
|
+
- `edited_outside_targets` / `edited_excluded_path` — a file changed outside the
|
|
88
|
+
declared boundary, which `quick` depth allows through the gate and reports here.
|
|
89
|
+
|
|
90
|
+
Refusal is not a verdict. Close again with `acknowledge` listing the codes and an
|
|
91
|
+
`acknowledgeReason` that says what the change actually did and why that shape is
|
|
92
|
+
right; the acknowledgement is recorded on the closed scope.
|
|
93
|
+
- **Invariant store, not an append-only log.** `close` requires the one invariant the
|
|
94
|
+
change established, or an explicit reason that the change was containment. The entry
|
|
95
|
+
is written to `docs/invariants.json` — the source of truth — and `docs/INVARIANTS.md`
|
|
96
|
+
is regenerated from it. Entries are keyed: `invariantKey` defaults to the contract in
|
|
97
|
+
`cause`, slugified. Closing again with the same key and the same statement updates
|
|
98
|
+
the entry in place; a changed statement marks the earlier entry `superseded` instead
|
|
99
|
+
of leaving two contradictory rules. An `invariantCheck` records what would fail if
|
|
100
|
+
the invariant broke; an entry without one is rendered as low trust.
|
|
101
|
+
- **Invariants are executed, not just recorded.** `action: "verify"` runs every active
|
|
102
|
+
entry that has an `invariantCheck`, through the host's own subprocess service, so the
|
|
103
|
+
command runs inside the same execution world and policy as any other tool. Each run
|
|
104
|
+
records `lastResult`, `lastExit`, and `lastRun` on the entry, and the generated view
|
|
105
|
+
shows them. A failing check makes `verify` return `ok: false`: a recorded invariant
|
|
106
|
+
that no longer holds is worse than none. Entries without a check are reported as
|
|
107
|
+
`unchecked` rather than passing silently.
|
|
108
|
+
- **Exception ledger.** Every finding a close encounters is recorded in
|
|
109
|
+
`.dsh/ledger.json`, with `quick` usage counted as `quick_scope`. When the same code
|
|
110
|
+
reaches three occurrences at the same site, the close result reports it under
|
|
111
|
+
`repeats` — so acknowledged exceptions become a visible trend rather than an
|
|
112
|
+
invisible habit. Rows older than 180 days are dropped when the ledger is written.
|
|
113
|
+
|
|
114
|
+
## Usage
|
|
115
|
+
|
|
116
|
+
1. Report a bug, or ask for part of the code to be rewritten.
|
|
117
|
+
2. The agent investigates, then proposes a scope with a depth and its consequences.
|
|
118
|
+
3. On your approval the agent declares it; edits outside the scope are refused.
|
|
119
|
+
4. The agent may call `status` at any time to see the findings before closing.
|
|
120
|
+
5. At the end the agent closes the scope, which writes the invariant — or is refused
|
|
121
|
+
until it explains a shape that contradicts the declaration.
|
|
122
|
+
|
|
123
|
+
Say no to the protocol and the change is not gated. That is deliberate: the gate is
|
|
124
|
+
only armed where the user chose a depth, so a one-line fix does not pay the full cost.
|
|
125
|
+
|
|
126
|
+
## Limitations
|
|
127
|
+
|
|
128
|
+
- The shape check is lexical, not semantic. It counts exports, exported signatures,
|
|
129
|
+
and `if`/`case`/`catch` occurrences. It cannot tell a good guard from a mask; that
|
|
130
|
+
is exactly why it asks for an acknowledgement rather than deciding.
|
|
131
|
+
- **The evidence is self-reported.** The plugin never runs the command. It enforces
|
|
132
|
+
the pairing — same step before and after, an expectation frozen before the fix, a
|
|
133
|
+
value after that matches it — and it checks that the site exists. It cannot verify
|
|
134
|
+
that the command was actually run or that its output was what is written. A
|
|
135
|
+
fabricated pair is possible; the difference from prose is that it is frozen,
|
|
136
|
+
structured, and recorded where a human can check it against the log.
|
|
137
|
+
- It parses JavaScript and TypeScript (plus JSX/Vue/Svelte/Astro), Python, Go, Rust,
|
|
138
|
+
Java, C#, and Kotlin heuristically. Other languages are recorded but not compared,
|
|
139
|
+
and the report says so.
|
|
140
|
+
- The "before" snapshot is taken when the first edit of a file passes the gate. A file
|
|
141
|
+
changed before the declaration, or outside the plugin, has no baseline.
|
|
142
|
+
- A rewrite that keeps its public surface and its conditional count, while changing
|
|
143
|
+
everything inside, still triggers `rewrite_shape_unchanged`. That is intended: the
|
|
144
|
+
point is to make the agent state that it re-derived the design, not to detect it.
|
|
145
|
+
- The `cause` dossier is articulation, not verification. The plugin checks that the
|
|
146
|
+
contract, the class, and a sweep with verdicts are present and non-empty; it cannot
|
|
147
|
+
check that the class is the right one or that the sweep is complete. Its value is
|
|
148
|
+
the pivot it forces before the first edit and the record it leaves behind.
|
|
149
|
+
- Scope records live under `<workspace>/.dsh/change-scope/`. They are per workspace
|
|
150
|
+
and per session, and they are not cleaned up automatically: a session abandoned
|
|
151
|
+
mid-scope leaves an open record that keeps gating if that session resumes. Delete
|
|
152
|
+
the session's file to reset it. Add `.dsh/` to the project's ignore file if the
|
|
153
|
+
records should not be committed.
|
|
154
|
+
- The confirmation check reads the session log: it proves a question tool was called
|
|
155
|
+
after the last user message (or after the declaration), not what the question asked
|
|
156
|
+
or whether the answer was understood. A well-worded question and a useless one look
|
|
157
|
+
the same to it.
|
|
158
|
+
- **Environment prerequisites.** A check whose first token is `node` uses the host's
|
|
159
|
+
own executable, so it works without node on PATH. The git history in a declaration
|
|
160
|
+
briefing is an optional enhancement: it needs the workspace to be a git repository
|
|
161
|
+
and `git` to resolve in the provider's execution world. Without either, the briefing
|
|
162
|
+
says so plainly instead of failing.
|
|
163
|
+
- A check is split on whitespace into argv and run without a shell, so quoting, pipes,
|
|
164
|
+
and `&&` are not supported: wrap such a check in a script file and point the entry at
|
|
165
|
+
it. A check whose first token is `node` runs on the host's own node executable, so it
|
|
166
|
+
works on installs whose PATH carries none; every other bare name goes through the
|
|
167
|
+
provider's executable lookup and must be on that PATH.
|
|
168
|
+
- If `docs/INVARIANTS.md` already exists and was not generated by this plugin, it is
|
|
169
|
+
copied once to `docs/INVARIANTS.manual.md` before the first render, and the close
|
|
170
|
+
result names that file. Nothing is destroyed, but the generated view replaces the
|
|
171
|
+
original at its own path.
|
|
172
|
+
- An invariant with no `invariantCheck` is a claim nothing defends. It is labelled
|
|
173
|
+
low trust in the generated view, but it is still trusted by whoever reads it without
|
|
174
|
+
noticing the label. `verify` reports it as `unchecked`, never as passing.
|
|
175
|
+
- The store cannot notice that an entry quietly stopped being true; only an explicit
|
|
176
|
+
close supersedes one. A failing `verify` is the only signal, and only for entries
|
|
177
|
+
that carry a check.
|
|
178
|
+
- Only `edit` and `write` are gated. A shell command that writes files is not
|
|
179
|
+
intercepted.
|
|
180
|
+
- Markdown and other non-source files are not gated; `docs/INVARIANTS.md` and `.dsh/`
|
|
181
|
+
are always writable.
|
|
182
|
+
- The plugin adds a prompt section; its exact position in the assembled prompt was
|
|
183
|
+
not verified. The same protocol is also carried by the `change_scope` tool
|
|
184
|
+
description, so a misplaced section does not remove the instruction.
|
package/icon.svg
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="36" height="36" viewBox="0 0 36 36" role="img" aria-label="Change scope">
|
|
2
|
+
<path d="M28 15.5 L28 12 A4 4 0 0 0 24 8 L12 8 A4 4 0 0 0 8 12 L8 24 A4 4 0 0 0 12 28 L24 28 A4 4 0 0 0 28 24 L28 20.5"
|
|
3
|
+
fill="none" stroke="#3D6E8F" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"/>
|
|
4
|
+
<path d="M32 18 L14 18" fill="none" stroke="#2C5570" stroke-width="2.5" stroke-linecap="round"/>
|
|
5
|
+
<path d="M18.5 13.5 L14 18 L18.5 22.5" fill="none" stroke="#2C5570" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"/>
|
|
6
|
+
</svg>
|