Skip to content

Commit d7cf918

Browse files
committed
initial
0 parents  commit d7cf918

20 files changed

Lines changed: 2855 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: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
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+
Full opt-in rules and the agent workflow live in
29+
[`skills/debug-mode/SKILL.md`](skills/debug-mode/SKILL.md).
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+
Ask your agent explicitly:
60+
61+
```text
62+
Use $debug-mode to investigate this reproducible runtime bug with temporary probes, manual reproduction, log evidence, a minimal fix, and cleanup.
63+
```
64+
65+
When the agent pauses for manual verification, Pi users can select A, B, or C
66+
from the interactive chooser. If you select C, the chooser opens a text editor.
67+
If the chooser is not available, reply with the first letter:
68+
69+
```text
70+
A - Reproduced
71+
B - Fixed
72+
C - Other: describe what happened
73+
```
74+
75+
Checkpoint wording, chooser fallback behavior, evidence format,
76+
troubleshooting, and cleanup steps are in `SKILL.md`.
77+
78+
## Naming and Compatibility
79+
80+
- **Project and display name:** `Cursor-like Debug Mode`.
81+
- **Stable Agent Skills ID:** `debug-mode`. The directory remains
82+
`skills/debug-mode/` so existing `$debug-mode`, update, and direct-install
83+
workflows keep working.
84+
- **Pi tool ID:** `cursor_like_debug_mode_checkpoint`. It is optional and is
85+
loaded only when the repository is installed as a Pi package.
86+
- **Other Agent Skills clients:** receive only `skills/debug-mode/`, including
87+
its scripts and assets. They do not receive or execute the Pi extension and
88+
use the plain-text checkpoint with A, B, and C.
89+
- **Runtime:** Node.js 24+ is required only when the bundled collector or summary
90+
scripts run.
91+
92+
The repository name is `cursor-like-debug-mode`. The stable Skill ID remains
93+
`debug-mode`.
94+
95+
## Install
96+
97+
### Pi: skill and interactive chooser
98+
99+
Install this repository as a Pi package to load both the skill and the
100+
Cursor-like Debug Mode chooser:
101+
102+
```bash
103+
pi install git:github.com/wangnan0916/cursor-like-debug-mode
104+
```
105+
106+
The chooser is a Pi extension and therefore runs only in Pi. In non-interactive
107+
Pi modes, the workflow automatically uses the plain-text checkpoint with A, B,
108+
and C.
109+
110+
### Other agents: skill only
111+
112+
Install or inspect the agent-agnostic skill with the open Agent Skills CLI:
113+
114+
```bash
115+
npx skills add wangnan0916/cursor-like-debug-mode
116+
npx skills add wangnan0916/cursor-like-debug-mode -g
117+
npx skills add wangnan0916/cursor-like-debug-mode -a codex
118+
npx skills add wangnan0916/cursor-like-debug-mode --list
119+
npx skills update debug-mode
120+
```
121+
122+
Use `-g` for global install, `-a codex` for a specific agent, `--list` to list
123+
without installing, and `npx skills update debug-mode` to update later. This
124+
installation path does not load the Pi extension.
125+
126+
## Layout
127+
128+
```text
129+
extensions/
130+
cursor-like-debug-mode.ts # Pi checkpoint tool with A, B, and C
131+
cursor-like-debug-mode-choice.mjs # shared option/result helpers
132+
133+
skills/debug-mode/
134+
SKILL.md # full agent workflow and protocol
135+
agents/openai.yaml # Codex / OpenAI skill UI metadata
136+
assets/
137+
browser-log-helper.js # copy into frontend code
138+
node-log-helper.js # copy into Node/server code
139+
scripts/
140+
start-collector.mjs # safe fixed-host collector entrypoint
141+
log-server.mjs # loopback NDJSON collector
142+
summarize-log.mjs # local NDJSON evidence summarizer
143+
144+
tests/ # Node built-in tests for chooser, collector, helpers, and summarizer
145+
```
146+
147+
## Safety
148+
149+
- Collector binds to loopback only (`127.0.0.1`, `localhost`, or `::1`).
150+
- `start-collector.mjs` fixes host to `127.0.0.1` and port to `0`, then delegates
151+
to the reusable `--ensure` collector path.
152+
- Approval denial stops that collector command. Agents wait for collector
153+
details from the user or a safe fallback through a file.
154+
- Probes must not log secrets, tokens, cookies, auth headers, or raw private
155+
payloads.
156+
- Temporary instrumentation uses `DEBUG_MODE_PROBE <session_id>` region markers
157+
so agents can remove it mechanically.
158+
- Debug logs are local temp evidence and should not be committed.
159+
160+
## Development
161+
162+
```bash
163+
npm run check
164+
npm test
165+
```
166+
167+
Requires Node.js 24+. Tests use only Node.js built-ins.
168+
169+
## License
170+
171+
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+
}
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
2+
3+
import {
4+
checkpointCodeFromChoice,
5+
CURSOR_LIKE_DEBUG_MODE_CHOICE_LIST,
6+
formatCheckpointAnswer,
7+
} from "./cursor-like-debug-mode-choice.mjs";
8+
9+
const TOOL_NAME = "cursor_like_debug_mode_checkpoint";
10+
11+
const CheckpointParams = {
12+
type: "object",
13+
additionalProperties: false,
14+
required: ["phase", "session", "logFile", "debugEndpoint"],
15+
properties: {
16+
phase: {
17+
type: "string",
18+
enum: ["pre-fix", "post-fix"],
19+
description: "The checkpoint phase. Use pre-fix for bug reproduction and post-fix for verification.",
20+
},
21+
session: { type: "string", description: "Debug-mode collector session ID." },
22+
logFile: { type: "string", description: "NDJSON log file that the collector writes." },
23+
debugEndpoint: { type: "string", description: "Collector POST /log endpoint." },
24+
},
25+
} as const;
26+
27+
type CheckpointParamsValue = {
28+
phase: "pre-fix" | "post-fix";
29+
session: string;
30+
logFile: string;
31+
debugEndpoint: string;
32+
};
33+
34+
type CheckpointSelection = "A" | "B" | "C";
35+
36+
function unavailableResult(params: CheckpointParamsValue, reason: "cancelled" | "ui_unavailable") {
37+
return {
38+
content: [
39+
{
40+
type: "text" as const,
41+
text: JSON.stringify(
42+
{
43+
cancelled: true,
44+
reason,
45+
instruction: "Show the plain-text checkpoint with A, B, and C. Wait for the user's reply.",
46+
},
47+
null,
48+
2,
49+
),
50+
},
51+
],
52+
details: { ...params, cancelled: true, reason },
53+
};
54+
}
55+
56+
function answeredResult(params: CheckpointParamsValue, selection: CheckpointSelection, text?: string) {
57+
return {
58+
content: [{ type: "text" as const, text: formatCheckpointAnswer(selection, text) }],
59+
details: { ...params, cancelled: false, selection, ...(selection === "C" ? { text } : {}) },
60+
};
61+
}
62+
63+
export default function cursorLikeDebugMode(pi: ExtensionAPI) {
64+
pi.registerTool({
65+
name: TOOL_NAME,
66+
label: "Cursor-like Debug Mode",
67+
description:
68+
"Show the Cursor-like Debug Mode checkpoint. The chooser has exactly A, B, and C. Option C opens a free-form editor. Use this tool only when the debug-mode skill is active.",
69+
promptSnippet: "Show an interactive Cursor-like Debug Mode checkpoint with A, B, and C",
70+
promptGuidelines: [
71+
"Use cursor_like_debug_mode_checkpoint at a manual checkpoint for the debug-mode skill. Call it only if the tool is available. Make it the only tool call in that assistant response. Do not ask the user to type A, B, or C.",
72+
],
73+
parameters: CheckpointParams,
74+
executionMode: "sequential",
75+
76+
async execute(_toolCallId, params: CheckpointParamsValue, _signal, _onUpdate, ctx) {
77+
if (!ctx.hasUI) return unavailableResult(params, "ui_unavailable");
78+
79+
const action = params.phase === "pre-fix" ? "reproduce the bug" : "verify the original bug";
80+
const title = [
81+
"Cursor-like Debug Mode",
82+
`Please ${action} manually, then choose the result.`,
83+
`Session: ${params.session}`,
84+
`Log file: ${params.logFile}`,
85+
`Debug endpoint: ${params.debugEndpoint}`,
86+
].join("\n");
87+
88+
while (true) {
89+
const choice = await ctx.ui.select(title, [...CURSOR_LIKE_DEBUG_MODE_CHOICE_LIST]);
90+
if (!choice) return unavailableResult(params, "cancelled");
91+
92+
const selection = checkpointCodeFromChoice(choice) as CheckpointSelection | undefined;
93+
if (!selection) return unavailableResult(params, "cancelled");
94+
if (selection !== "C") return answeredResult(params, selection);
95+
96+
while (true) {
97+
const customText = await ctx.ui.editor("Cursor-like Debug Mode — C: Other", "");
98+
if (customText === undefined) break;
99+
100+
const text = customText.trim();
101+
if (text) return answeredResult(params, "C", text);
102+
ctx.ui.notify("Enter text for option C. Press Esc to return to A, B, and C.", "warning");
103+
}
104+
}
105+
},
106+
});
107+
}

0 commit comments

Comments
 (0)