Skip to content

Commit 2319d5d

Browse files
committed
initial
0 parents  commit 2319d5d

24 files changed

Lines changed: 2973 additions & 0 deletions

‎.github/workflows/ci.yml‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
pull_request:
6+
7+
jobs:
8+
test:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/checkout@v4
12+
- uses: actions/setup-node@v4
13+
with:
14+
node-version: 24
15+
- run: npm run check
16+
- run: npm test

‎.gitignore‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
.DS_Store
2+
node_modules/
3+
npm-debug.log*
4+
5+
.runtime-debug/
6+
*.ndjson

‎LICENSE‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2026 wangnan0916
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.

‎README.md‎

Lines changed: 196 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,196 @@
1+
# Cursor-like Debug Mode
2+
3+
Agent-agnostic, opt-in debug mode for reproducible runtime bugs. It includes
4+
first-class probe helpers for browser/frontend JavaScript and Node.js, while
5+
the local collector accepts the same structured events from other runtimes.
6+
Pi installations can also load the bundled interactive checkpoint chooser.
7+
The `debug-mode` skill ID remains unchanged for compatibility.
8+
9+
Agents add temporary structured probes, collect NDJSON evidence through a
10+
local loopback collector, wait for you to reproduce manually, fix from log proof,
11+
verify once, then clean up.
12+
13+
```text
14+
hypothesize -> instrument -> reproduce -> inspect evidence -> fix -> verify -> clean up
15+
```
16+
17+
## When to Use
18+
19+
Use this skill only when you explicitly ask for it, for example:
20+
21+
- `$debug-mode` or `debug mode`
22+
- instrumented debugging
23+
- collection of local runtime logs with temporary probes
24+
25+
For ordinary bug reports, test failures, build errors, or explained issues,
26+
agents should use the normal debug process.
27+
28+
The evidence loop lives in [`skills/debug-mode/SKILL.md`](skills/debug-mode/SKILL.md).
29+
Detailed contracts load progressively from `skills/debug-mode/references/`.
30+
31+
## How It Works
32+
33+
1. The agent states ranked hypotheses and adds 3–8 targeted probes.
34+
2. A small loopback collector receives structured events at `POST /log` and
35+
writes one NDJSON line per event.
36+
3. The agent stops and asks you to reproduce the bug manually. In Pi, the
37+
bundled chooser presents exactly `A - Reproduced`, `B - Fixed`, and
38+
`C - Other: enter details`. If the user selects C, the chooser opens a
39+
free-form editor.
40+
4. After you choose or type a reply, it summarizes the log, confirms or rejects
41+
hypotheses, states the fix acceptance criteria, makes a minimal fix, verifies
42+
once with probes still active, then removes all instrumentation.
43+
44+
Probe templates for browser or front-end JavaScript and Node.js are in
45+
`skills/debug-mode/assets/`. Agents start collection with
46+
`skills/debug-mode/scripts/start-collector.mjs`. The lower-level collector is
47+
`skills/debug-mode/scripts/log-server.mjs`. The NDJSON summary script is
48+
`skills/debug-mode/scripts/summarize-log.mjs`.
49+
50+
Agents run `node <skill-dir>/scripts/start-collector.mjs --session <id>`. The
51+
wrapper fixes host to `127.0.0.1` and port to `0`, then delegates to
52+
`log-server.mjs --ensure`. It reuses a healthy collector when available. A new
53+
child binds only to loopback. It writes state and log files in the temporary
54+
directory. If command authorization denies the request, the agent stops. The
55+
agent waits for you to run the same command before it adds probes.
56+
57+
## Usage
58+
59+
### Pi package command
60+
61+
If you installed the Pi package, use the short command:
62+
63+
```text
64+
/cursor-like-debug-mode <problem description>
65+
```
66+
67+
This command loads the bundled `debug-mode` skill and starts the same workflow.
68+
Pi also keeps its native skill command as a compatible alternative:
69+
70+
```text
71+
/skill:debug-mode <problem description>
72+
```
73+
74+
### Agent Skills clients
75+
76+
For Codex and similar clients, invoke the stable Skill ID:
77+
78+
```text
79+
$debug-mode <problem description>
80+
```
81+
82+
When the agent pauses for manual verification, Pi users can select A, B, or C
83+
from the interactive chooser. If you select C, the chooser opens a text editor.
84+
If the chooser is not available, reply with the first letter:
85+
86+
```text
87+
A - Reproduced
88+
B - Fixed
89+
C - Other: describe what happened
90+
```
91+
92+
Checkpoint wording and fallback behavior live in
93+
[`references/checkpoints.md`](skills/debug-mode/references/checkpoints.md).
94+
The main skill owns the evidence format and cleanup criteria.
95+
96+
## Naming and Compatibility
97+
98+
- **Project and display name:** `Cursor-like Debug Mode`.
99+
- **Stable Agent Skills ID:** `debug-mode`. The directory remains
100+
`skills/debug-mode/` so existing `$debug-mode`, update, and direct-install
101+
workflows keep working.
102+
- **Pi command:** `/cursor-like-debug-mode`. It loads the bundled `debug-mode`
103+
skill.
104+
- **Pi tool ID:** `cursor_like_debug_mode_checkpoint`. It is optional and is
105+
loaded only when the repository is installed as a Pi package.
106+
- **Other Agent Skills clients:** receive only `skills/debug-mode/`, including
107+
its scripts and assets. They do not receive or execute the Pi extension and
108+
use the plain-text checkpoint with A, B, and C.
109+
- **Runtime:** Node.js 24+ is required only when the bundled collector or summary
110+
scripts run.
111+
112+
The repository name is `cursor-like-debug-mode`. The stable Skill ID remains
113+
`debug-mode`.
114+
115+
## Install
116+
117+
### Pi: skill and interactive chooser
118+
119+
Install this repository as a Pi package to load the command, skill, and
120+
Cursor-like Debug Mode chooser:
121+
122+
```bash
123+
pi install git:github.com/wangnan0916/cursor-like-debug-mode
124+
```
125+
126+
The chooser is a Pi extension and therefore runs only in Pi. In non-interactive
127+
Pi modes, the workflow automatically uses the plain-text checkpoint with A, B,
128+
and C.
129+
130+
### Other agents: skill only
131+
132+
Install or inspect the agent-agnostic skill with the open Agent Skills CLI:
133+
134+
```bash
135+
npx skills add wangnan0916/cursor-like-debug-mode
136+
npx skills add wangnan0916/cursor-like-debug-mode -g
137+
npx skills add wangnan0916/cursor-like-debug-mode -a codex
138+
npx skills add wangnan0916/cursor-like-debug-mode --list
139+
npx skills update debug-mode
140+
```
141+
142+
Use `-g` for global install, `-a codex` for a specific agent, `--list` to list
143+
without installing, and `npx skills update debug-mode` to update later. This
144+
installation path does not load the Pi extension.
145+
146+
## Layout
147+
148+
```text
149+
extensions/
150+
cursor-like-debug-mode.ts # Pi checkpoint tool with A, B, and C
151+
cursor-like-debug-mode-choice.mjs # shared option/result helpers
152+
153+
skills/debug-mode/
154+
SKILL.md # evidence loop and completion criteria
155+
agents/openai.yaml # Codex / OpenAI skill UI metadata
156+
assets/
157+
browser-log-helper.js # copy into frontend code
158+
node-log-helper.js # copy into Node/server code
159+
references/
160+
checkpoints.md # interactive and plain-text checkpoint protocol
161+
collector.md # collector contract and authorization branch
162+
probes.md # event shape, privacy, markers, and helpers
163+
troubleshooting.md # failure-only branches
164+
scripts/
165+
start-collector.mjs # safe fixed-host collector entrypoint
166+
log-server.mjs # loopback NDJSON collector
167+
summarize-log.mjs # local NDJSON evidence summarizer
168+
169+
tests/ # Node built-in tests for chooser, collector, helpers, and summarizer
170+
```
171+
172+
## Safety
173+
174+
- Collector binds to loopback only (`127.0.0.1`, `localhost`, or `::1`).
175+
- `start-collector.mjs` fixes host to `127.0.0.1` and port to `0`, then delegates
176+
to the reusable `--ensure` collector path.
177+
- Approval denial stops that collector command. Agents wait for collector
178+
details from the user or a safe fallback through a file.
179+
- Probes must not log secrets, tokens, cookies, auth headers, or raw private
180+
payloads.
181+
- Temporary instrumentation uses `DEBUG_MODE_PROBE <session_id>` region markers
182+
so agents can remove it mechanically.
183+
- Debug logs are local temp evidence and should not be committed.
184+
185+
## Development
186+
187+
```bash
188+
npm run check
189+
npm test
190+
```
191+
192+
Requires Node.js 24+. Tests use only Node.js built-ins.
193+
194+
## License
195+
196+
MIT. See [LICENSE](LICENSE).
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/** @typedef {"A" | "B" | "C"} CheckpointSelection */
2+
/** @typedef {{ selection: CheckpointSelection, meaning: "Reproduced" | "Fixed" | "Other", text?: string }} CheckpointAnswer */
3+
4+
export const CURSOR_LIKE_DEBUG_MODE_CHOICES = Object.freeze({
5+
A: "A - Reproduced",
6+
B: "B - Fixed",
7+
C: "C - Other: enter details",
8+
});
9+
10+
export const CURSOR_LIKE_DEBUG_MODE_CHOICE_LIST = Object.freeze(
11+
Object.values(CURSOR_LIKE_DEBUG_MODE_CHOICES),
12+
);
13+
14+
/**
15+
* @param {string | undefined} choice
16+
* @returns {CheckpointSelection | undefined}
17+
*/
18+
export function checkpointCodeFromChoice(choice) {
19+
for (const [code, label] of Object.entries(CURSOR_LIKE_DEBUG_MODE_CHOICES)) {
20+
if (choice === label) return /** @type {CheckpointSelection} */ (code);
21+
}
22+
return undefined;
23+
}
24+
25+
/**
26+
* @param {CheckpointSelection} selection
27+
* @param {string | undefined} [text]
28+
*/
29+
export function formatCheckpointAnswer(selection, text) {
30+
/** @type {CheckpointAnswer} */
31+
const answer = {
32+
selection,
33+
meaning:
34+
selection === "A"
35+
? "Reproduced"
36+
: selection === "B"
37+
? "Fixed"
38+
: "Other",
39+
};
40+
41+
if (selection === "C") answer.text = text;
42+
return JSON.stringify(answer, null, 2);
43+
}

0 commit comments

Comments
 (0)