@punks/cli 1.0.1 → 1.0.3
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/README.md +47 -4
- package/dist/data/AGENTS.md +0 -6
- package/dist/data/catalog/hooks.ts +26 -0
- package/dist/data/catalog/lint.ts +11 -26
- package/dist/data/catalog/packs.ts +5 -3
- package/dist/data/catalog/skills.ts +9 -1
- package/dist/data/catalog/tools.ts +13 -1
- package/dist/data/scripts/sync-subagents.mjs +163 -120
- package/dist/data/subagents/manifest.mjs +148 -0
- package/dist/index.js +2589 -1944
- package/dist/skills/agnostic/backend/logging-best-practices/SKILL.md +127 -0
- package/dist/skills/agnostic/backend/logging-best-practices/rules/context.md +157 -0
- package/dist/skills/agnostic/backend/logging-best-practices/rules/pitfalls.md +118 -0
- package/dist/skills/agnostic/backend/logging-best-practices/rules/structure.md +193 -0
- package/dist/skills/agnostic/backend/logging-best-practices/rules/wide-events.md +113 -0
- package/dist/skills/agnostic/cli/dp-cli/SKILL.md +84 -0
- package/dist/skills/agnostic/cli/dp-cli/references/commands.md +33 -0
- package/dist/skills/agnostic/cli/dp-cli/references/post-command-flow.md +47 -0
- package/dist/skills/agnostic/debug/debug-agent/SKILL.md +184 -0
- package/dist/skills/agnostic/requirements/write-backlog/REFERENCE.md +1 -1
- package/dist/skills/languages/python/async-python-patterns/SKILL.md +735 -0
- package/dist/skills/languages/python/python-code-style/SKILL.md +360 -0
- package/dist/skills/languages/python/python-design-patterns/SKILL.md +433 -0
- package/dist/skills/languages/python/python-project-structure/SKILL.md +252 -0
- package/dist/skills/languages/python/python-testing-patterns/SKILL.md +622 -0
- package/dist/skills/languages/python/python-testing-patterns/references/advanced-patterns.md +411 -0
- package/dist/skills/languages/typescript/quality-types/SKILL.md +93 -0
- package/docs/README.md +14 -4
- package/docs/reference/dp-requirements.md +16 -1
- package/docs/runbooks/dp-cli-scaffolding.md +82 -10
- package/package.json +5 -2
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Wide Events / Canonical Log Lines
|
|
3
|
+
impact: CRITICAL
|
|
4
|
+
tags: logging, wide-events, canonical-log-lines
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## Wide Events / Canonical Log Lines
|
|
8
|
+
|
|
9
|
+
**Impact: CRITICAL**
|
|
10
|
+
|
|
11
|
+
Wide events (also called canonical log lines) are the foundation of effective logging. For each request, emit **a single context-rich event per service**. Instead of scattering 10-20 log lines throughout your request handler, consolidate everything into one comprehensive event emitted at the end of the request.
|
|
12
|
+
|
|
13
|
+
### The Pattern
|
|
14
|
+
|
|
15
|
+
Build the event throughout the request lifecycle, then emit once at completion in a `finally` block. This ensures the event is always emitted with complete context, even during failures.
|
|
16
|
+
|
|
17
|
+
**Incorrect:**
|
|
18
|
+
|
|
19
|
+
```typescript
|
|
20
|
+
app.post('/articles', async (c) => {
|
|
21
|
+
console.log('Received POST /articles request');
|
|
22
|
+
|
|
23
|
+
const body = await c.req.json();
|
|
24
|
+
console.log('Request body parsed', { title: body.title });
|
|
25
|
+
|
|
26
|
+
const user = await getUser(c.get('userId'));
|
|
27
|
+
console.log('User fetched', { userId: user.id });
|
|
28
|
+
|
|
29
|
+
const article = await database.saveArticle({ ...body, ownerId: user.id });
|
|
30
|
+
console.log('Article saved', { articleId: article.id });
|
|
31
|
+
|
|
32
|
+
await cache.set(article.id, article);
|
|
33
|
+
console.log('Cache updated');
|
|
34
|
+
|
|
35
|
+
console.log('Request completed successfully');
|
|
36
|
+
return c.json({ article }, 201);
|
|
37
|
+
});
|
|
38
|
+
// 6 disconnected log lines with scattered context
|
|
39
|
+
// Cannot query: "show me all article creates by free trial users"
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
**Correct:**
|
|
43
|
+
|
|
44
|
+
```typescript
|
|
45
|
+
app.post('/articles', async (c) => {
|
|
46
|
+
const startTime = Date.now();
|
|
47
|
+
const wideEvent: Record<string, unknown> = {
|
|
48
|
+
method: 'POST',
|
|
49
|
+
path: '/articles',
|
|
50
|
+
service: 'articles',
|
|
51
|
+
requestId: c.get('requestId'),
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
try {
|
|
55
|
+
const body = await c.req.json();
|
|
56
|
+
const user = await getUser(c.get('userId'));
|
|
57
|
+
wideEvent.user = {
|
|
58
|
+
id: user.id,
|
|
59
|
+
subscription: user.subscription,
|
|
60
|
+
trial: user.trial,
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
const article = await database.saveArticle({ ...body, ownerId: user.id });
|
|
64
|
+
wideEvent.article = {
|
|
65
|
+
id: article.id,
|
|
66
|
+
title: article.title,
|
|
67
|
+
published: article.published,
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
await cache.set(article.id, article);
|
|
71
|
+
wideEvent.cache = { operation: 'write', key: article.id };
|
|
72
|
+
|
|
73
|
+
wideEvent.status_code = 201;
|
|
74
|
+
wideEvent.outcome = 'success';
|
|
75
|
+
return c.json({ article }, 201);
|
|
76
|
+
} catch (error) {
|
|
77
|
+
wideEvent.status_code = 500;
|
|
78
|
+
wideEvent.outcome = 'error';
|
|
79
|
+
wideEvent.error = { message: error.message, type: error.name };
|
|
80
|
+
throw error;
|
|
81
|
+
} finally {
|
|
82
|
+
wideEvent.duration_ms = Date.now() - startTime;
|
|
83
|
+
wideEvent.timestamp = new Date().toISOString();
|
|
84
|
+
logger.info(JSON.stringify(wideEvent));
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
// Single event with all context - queryable by any field
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
### Connect Events with Request ID
|
|
91
|
+
|
|
92
|
+
Every wide event must include a unique request ID that is propagated across all service hops. This is the only way to reconstruct the full journey of a request through a distributed system.
|
|
93
|
+
|
|
94
|
+
```typescript
|
|
95
|
+
// Service A - generate and propagate
|
|
96
|
+
const requestId = c.get('requestId') || crypto.randomUUID();
|
|
97
|
+
wideEvent.requestId = requestId;
|
|
98
|
+
|
|
99
|
+
await fetch('http://downstream-service/endpoint', {
|
|
100
|
+
headers: { 'x-request-id': requestId },
|
|
101
|
+
body: JSON.stringify(data),
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
// Service B - extract and use
|
|
105
|
+
const requestId = c.req.header('x-request-id');
|
|
106
|
+
wideEvent.requestId = requestId; // Same ID links events together
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
### Emit in Finally Block
|
|
110
|
+
|
|
111
|
+
Always emit wide events in a `finally` block or equivalent. This ensures the event is emitted with complete context regardless of success or failure.
|
|
112
|
+
|
|
113
|
+
Reference: [Stripe Blog - Canonical Log Lines](https://stripe.com/blog/canonical-log-lines)
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: dp-cli
|
|
3
|
+
description: Operates the Devpunks `dp` CLI and interactively follows scaffold, stage, update, and post-command handoff artifacts through to completion. Use when a repo contains `.devpunks/` output, when the user mentions `dp scaffold`, `dp update`, Devpunks CLI setup, or asks what to do after running a `dp` command.
|
|
4
|
+
metadata: {"Devpunks":{"entrypoint":true}}
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# DP CLI
|
|
8
|
+
|
|
9
|
+
The `dp` CLI scaffolds Devpunks agent assets and writes follow-up instructions for the next agent.
|
|
10
|
+
|
|
11
|
+
## Quick Start
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
dp scaffold setup
|
|
15
|
+
dp scaffold init
|
|
16
|
+
dp scaffold backlog
|
|
17
|
+
dp update --check
|
|
18
|
+
dp update --write
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
After any command, read the command output and generated artifacts before acting.
|
|
22
|
+
|
|
23
|
+
## Core Rule
|
|
24
|
+
|
|
25
|
+
`.devpunks/` is an active work queue.
|
|
26
|
+
|
|
27
|
+
Do not summarize the generated files and stop. Read the handoff, execute the specs, reconcile generated assets, and report only remaining unresolved items.
|
|
28
|
+
|
|
29
|
+
## Interactive Rule
|
|
30
|
+
|
|
31
|
+
Prompt the user frequently when post-scaffold choices affect project policy or shape.
|
|
32
|
+
|
|
33
|
+
Ask before:
|
|
34
|
+
|
|
35
|
+
- choosing which generated prompt scopes to collapse, split, or prioritize
|
|
36
|
+
- replacing existing lint or format tooling with Oxlint/Oxfmt
|
|
37
|
+
- deciding which core libraries to clone and inspect with `opensrc`
|
|
38
|
+
- changing package scripts, task pipelines, CI, hooks, or docs
|
|
39
|
+
- resolving conflicts between existing repo guidance and scaffold specs
|
|
40
|
+
|
|
41
|
+
Do not ask for trivial file reads, validation commands, or direct execution of already-approved scaffold instructions.
|
|
42
|
+
|
|
43
|
+
## Command Workflows
|
|
44
|
+
|
|
45
|
+
See [references/commands.md](references/commands.md) for command intent and when to use each command.
|
|
46
|
+
|
|
47
|
+
See [references/post-command-flow.md](references/post-command-flow.md) for the required agent flow after `dp scaffold` or `dp update`.
|
|
48
|
+
|
|
49
|
+
## Scaffold Setup
|
|
50
|
+
|
|
51
|
+
After `dp scaffold setup`, expect artifacts such as:
|
|
52
|
+
|
|
53
|
+
- `.devpunks/AGENT-SYSTEM-PROMPT.md`
|
|
54
|
+
- `.devpunks/AGENT-HANDOFF.md`
|
|
55
|
+
- `.devpunks/scaffold-manifest.json`
|
|
56
|
+
- `.devpunks/required-tools.json`
|
|
57
|
+
- `.devpunks/specs/prompts/**/*.md`
|
|
58
|
+
- `.devpunks/specs/lint/*`
|
|
59
|
+
- `.devpunks/specs/subagents/manifest-spec.json`
|
|
60
|
+
|
|
61
|
+
Read `.devpunks/AGENT-SYSTEM-PROMPT.md` first when present.
|
|
62
|
+
|
|
63
|
+
Then author or reconcile the final repo files requested by the specs, including prompt files, harness mirrors, lint configuration, and subagent manifests.
|
|
64
|
+
|
|
65
|
+
Before authoring prompts or plans, identify the detected core libraries whose source behavior matters. Ask the user which ones to prioritize if the choice is not obvious, then run `opensrc path <package>` or `opensrc path owner/repo` only for that focused set.
|
|
66
|
+
|
|
67
|
+
When lint specs suggest Oxlint or hooks suggest Oxfmt, treat migration as a repo-policy change. Ask before replacing existing ESLint/Prettier/Biome scripts or CI, then update package scripts, task pipelines, editor/docs references, and hooks together.
|
|
68
|
+
|
|
69
|
+
## Update
|
|
70
|
+
|
|
71
|
+
After `dp update`, inspect `.devpunks/scaffold-manifest.json` and the update summary.
|
|
72
|
+
|
|
73
|
+
- `--check` reports managed-file drift without writing.
|
|
74
|
+
- `--write` refreshes scaffold-managed assets.
|
|
75
|
+
- pack drift is a setup decision point, not a silent auto-fix.
|
|
76
|
+
|
|
77
|
+
## Completion Checklist
|
|
78
|
+
|
|
79
|
+
- `.devpunks/AGENT-SYSTEM-PROMPT.md` was followed or consciously superseded.
|
|
80
|
+
- `.devpunks/specs/**` items were implemented or listed as unresolved.
|
|
81
|
+
- required tools were checked when `.devpunks/required-tools.json` exists.
|
|
82
|
+
- final prompt files and harness mirrors match the handoff contract.
|
|
83
|
+
- subagent manifests were reconciled when specs exist.
|
|
84
|
+
- user decisions were requested for policy-level choices instead of guessed silently.
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# DP CLI Commands
|
|
2
|
+
|
|
3
|
+
## `dp scaffold setup`
|
|
4
|
+
|
|
5
|
+
Use for repo-aware full scaffold setup.
|
|
6
|
+
|
|
7
|
+
It detects package manifests, resolves packs, writes `.agents/`, harness files, selected skills, prompt specs, lint specs, subagent specs, required tools metadata, and `.devpunks/scaffold-manifest.json`.
|
|
8
|
+
|
|
9
|
+
It does not finish all repo-specific authoring. The next agent must use `.devpunks/AGENT-SYSTEM-PROMPT.md` and `.devpunks/specs/**` to generate final scoped guidance and reconcile assets.
|
|
10
|
+
|
|
11
|
+
## `dp scaffold init`
|
|
12
|
+
|
|
13
|
+
Use before boilerplate exists.
|
|
14
|
+
|
|
15
|
+
It scaffolds requirements-stage assets and prints an operator prompt. Follow that prompt before moving to another stage.
|
|
16
|
+
|
|
17
|
+
## `dp scaffold backlog`
|
|
18
|
+
|
|
19
|
+
Use to inspect or enter the backlog stage.
|
|
20
|
+
|
|
21
|
+
When no backlog-stage packs are available, the command still prints the operator prompt so the stage boundary is explicit.
|
|
22
|
+
|
|
23
|
+
## `dp update --check`
|
|
24
|
+
|
|
25
|
+
Use to preview managed scaffold drift from `.devpunks/scaffold-manifest.json`.
|
|
26
|
+
|
|
27
|
+
Report missing, changed, or pack-drift findings. Do not write files.
|
|
28
|
+
|
|
29
|
+
## `dp update --write`
|
|
30
|
+
|
|
31
|
+
Use to refresh scaffold-managed files recorded in `.devpunks/scaffold-manifest.json`.
|
|
32
|
+
|
|
33
|
+
After writing, verify the refreshed files still fit the repo shape and any pack drift is handled intentionally.
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# Post-Command Flow
|
|
2
|
+
|
|
3
|
+
## Read Order
|
|
4
|
+
|
|
5
|
+
When `.devpunks/` exists, read in this order:
|
|
6
|
+
|
|
7
|
+
1. `.devpunks/AGENT-SYSTEM-PROMPT.md`
|
|
8
|
+
2. `.devpunks/AGENT-HANDOFF.md`
|
|
9
|
+
3. `.devpunks/scaffold-manifest.json`
|
|
10
|
+
4. `.devpunks/required-tools.json`
|
|
11
|
+
5. `.devpunks/specs/**`
|
|
12
|
+
|
|
13
|
+
If a file is missing, continue with the next available artifact and say what was missing.
|
|
14
|
+
|
|
15
|
+
## Artifact Meaning
|
|
16
|
+
|
|
17
|
+
- `.devpunks/AGENT-SYSTEM-PROMPT.md`: paste-ready instructions for the next agent.
|
|
18
|
+
- `.devpunks/AGENT-HANDOFF.md`: human-readable scaffold summary and required follow-up.
|
|
19
|
+
- `.devpunks/scaffold-manifest.json`: source of truth for managed files and update behavior.
|
|
20
|
+
- `.devpunks/required-tools.json`: tools implied by selected skills.
|
|
21
|
+
- `.devpunks/specs/prompts/**`: instructions for final prompt files, not final prompt bodies.
|
|
22
|
+
- `.devpunks/specs/lint/**`: lint asset selection and starter config guidance.
|
|
23
|
+
- `.devpunks/specs/subagents/**`: desired subagent manifest shape.
|
|
24
|
+
|
|
25
|
+
## Required Follow-Through
|
|
26
|
+
|
|
27
|
+
After `dp scaffold setup`:
|
|
28
|
+
|
|
29
|
+
- Generate final root/docs/workspace `AGENTS.md` files from prompt specs.
|
|
30
|
+
- Create sibling `CLAUDE.md` symlink mirrors for those neutral prompt files.
|
|
31
|
+
- Keep `.agents/AGENTS.md` as the shared global prompt source.
|
|
32
|
+
- Keep `.agents/skills/` as the main skill directory; only `.claude/skills` mirrors it.
|
|
33
|
+
- Reconcile `.agents/subagents/manifest.mjs` with both `.agents/subagents/manifest.prompt.md` and `.devpunks/specs/subagents/manifest-spec.json`.
|
|
34
|
+
- Use lint specs to produce or update the repo's real lint config when requested.
|
|
35
|
+
- Ask before replacing existing lint/format tooling with Oxlint/Oxfmt. If approved, update scripts, CI/task pipelines, hooks, and docs together.
|
|
36
|
+
- Ask which detected core libraries to inspect when source context is broad; then use `opensrc path <package>` or `opensrc path owner/repo` for only the chosen set.
|
|
37
|
+
|
|
38
|
+
Do not stop after saying the files exist.
|
|
39
|
+
|
|
40
|
+
## Reporting
|
|
41
|
+
|
|
42
|
+
Final reports should say:
|
|
43
|
+
|
|
44
|
+
- what artifacts were consumed
|
|
45
|
+
- what final files were authored or reconciled
|
|
46
|
+
- what validation ran
|
|
47
|
+
- what remains unresolved, if anything
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: debug-agent
|
|
3
|
+
description: >-
|
|
4
|
+
Systematic evidence-based debugging using runtime logs. Generates hypotheses,
|
|
5
|
+
instruments code with NDJSON logs, guides reproduction, analyzes log evidence,
|
|
6
|
+
and iterates until root cause is proven with cited log lines. Use when the
|
|
7
|
+
user reports a bug, unexpected behavior, or asks to debug an issue.
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
# Debug Mode
|
|
11
|
+
|
|
12
|
+
You are now in **DEBUG MODE**. You must debug with **runtime evidence**.
|
|
13
|
+
|
|
14
|
+
**Why this approach:** Traditional AI agents jump to fixes claiming 100% confidence, but fail due to lacking runtime information.
|
|
15
|
+
They guess based on code alone. You **cannot** and **must NOT** fix bugs this way — you need actual runtime data.
|
|
16
|
+
|
|
17
|
+
**Your systematic workflow:**
|
|
18
|
+
|
|
19
|
+
1. **Generate 3-5 precise hypotheses** about WHY the bug occurs (be detailed, aim for MORE not fewer)
|
|
20
|
+
2. **Instrument code** with logs (see Logging section) to test all hypotheses in parallel
|
|
21
|
+
3. **Reproduce the bug.**
|
|
22
|
+
- **If a failing test already exists**: run it directly.
|
|
23
|
+
- **If reproduction is straightforward** (e.g., a single CLI command, a curl request, a simple script): write and run an ad hoc reproduction script yourself. Tailor it to the runtime — Playwright/Puppeteer for browser bugs, a Node/Python/shell script for backend bugs, etc.
|
|
24
|
+
- **Otherwise**: ask the user to reproduce it. Provide clear, numbered steps. Remind them to restart apps/services if instrumented files are cached or bundled. Offer: "If you'd like me to write a reproduction script instead, let me know."
|
|
25
|
+
- Once the user confirms a reproduction pathway (manual or automated), reuse it for all subsequent iterations without re-asking.
|
|
26
|
+
4. **Analyze logs**: evaluate each hypothesis (CONFIRMED/REJECTED/INCONCLUSIVE) with cited log line evidence
|
|
27
|
+
5. **Fix only with 100% confidence** and log proof; do NOT remove instrumentation yet
|
|
28
|
+
6. **Verify with logs**: ask user to run again, compare before/after logs with cited entries
|
|
29
|
+
7. **If logs prove success** and user confirms: remove all instrumentation by searching for `#region debug log` / `#endregion` markers and deleting those blocks (see Cleanup section). **If failed**: FIRST remove any code changes from rejected hypotheses (keep only instrumentation and proven fixes), THEN generate NEW hypotheses from different subsystems and add more instrumentation
|
|
30
|
+
8. **After confirmed success**: explain the problem and provide a concise summary of the fix (1-2 lines)
|
|
31
|
+
|
|
32
|
+
**Critical constraints:**
|
|
33
|
+
|
|
34
|
+
- NEVER fix without runtime evidence first
|
|
35
|
+
- ALWAYS rely on runtime information + code (never code alone)
|
|
36
|
+
- Do NOT remove instrumentation before post-fix verification logs prove success and user confirms that there are no more issues
|
|
37
|
+
- Fixes often fail; iteration is expected and preferred. Taking longer with more data yields better, more precise fixes
|
|
38
|
+
|
|
39
|
+
---
|
|
40
|
+
|
|
41
|
+
## Logging
|
|
42
|
+
|
|
43
|
+
### STEP 0: Start the logging server (MANDATORY BEFORE ANY INSTRUMENTATION)
|
|
44
|
+
|
|
45
|
+
Run the debug server in **daemon mode** before any instrumentation. The `--daemon` flag starts the server in the background and exits immediately with the server info — no backgrounding or `&` required.
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
npx debug-agent --daemon
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
The command prints a single JSON line to stdout and exits:
|
|
52
|
+
|
|
53
|
+
```json
|
|
54
|
+
{
|
|
55
|
+
"sessionId": "a1b2c3",
|
|
56
|
+
"port": 54321,
|
|
57
|
+
"endpoint": "http://127.0.0.1:54321/ingest/a1b2c3",
|
|
58
|
+
"logPath": "/tmp/debug-agent/debug-a1b2c3.log"
|
|
59
|
+
}
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
Capture and remember these values:
|
|
63
|
+
|
|
64
|
+
- **Server endpoint**: The `endpoint` value (the HTTP endpoint URL where logs will be sent via POST requests)
|
|
65
|
+
- **Log path**: The `logPath` value (NDJSON logs are written here)
|
|
66
|
+
- **Session ID**: The `sessionId` value (unique identifier for this debug session)
|
|
67
|
+
|
|
68
|
+
If the server fails to start, STOP IMMEDIATELY and inform the user.
|
|
69
|
+
|
|
70
|
+
- DO NOT PROCEED with instrumentation without valid logging configuration.
|
|
71
|
+
- The server is idempotent — if one is already running, it returns the existing server's info instead of starting a duplicate.
|
|
72
|
+
- You do not need to pre-create the log file; it will be created automatically when your instrumentation first writes to it.
|
|
73
|
+
|
|
74
|
+
### STEP 1: Understand the log format
|
|
75
|
+
|
|
76
|
+
- Logs are written in **NDJSON format** (one JSON object per line) to the file specified by the **log path**.
|
|
77
|
+
- For JavaScript/TypeScript, logs are sent via a POST request to the **server endpoint** during runtime, and the logging server writes these as NDJSON lines to the **log path** file.
|
|
78
|
+
- For other languages (Python, Go, Rust, Java, C/C++, Ruby, etc.), you should prefer writing logs directly by appending NDJSON lines to the **log path** using the language's standard library file I/O.
|
|
79
|
+
|
|
80
|
+
Example log entry:
|
|
81
|
+
|
|
82
|
+
```json
|
|
83
|
+
{
|
|
84
|
+
"sessionId": "a1b2c3",
|
|
85
|
+
"id": "log_1733456789_abc",
|
|
86
|
+
"timestamp": 1733456789000,
|
|
87
|
+
"location": "test.js:42",
|
|
88
|
+
"message": "User score",
|
|
89
|
+
"data": { "userId": 5, "score": 85 },
|
|
90
|
+
"runId": "run1",
|
|
91
|
+
"hypothesisId": "A"
|
|
92
|
+
}
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
### STEP 2: Insert instrumentation logs
|
|
96
|
+
|
|
97
|
+
- In **JavaScript/TypeScript files**, use this one-line fetch template (replace `ENDPOINT` and `SESSION_ID` with values from Step 0), even if filesystem access is available:
|
|
98
|
+
|
|
99
|
+
```
|
|
100
|
+
fetch('ENDPOINT',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({sessionId:'SESSION_ID',location:'file.js:LINE',message:'desc',data:{k:v},timestamp:Date.now()})}).catch(()=>{});
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
- In **non-JavaScript languages** (Python, Go, Rust, Java, C, C++, Ruby), instrument by opening the **log path** in append mode using standard library file I/O, writing a single NDJSON line with your payload, and then closing the file. Keep these snippets as tiny and compact as possible (ideally one line, or just a few).
|
|
104
|
+
|
|
105
|
+
- Decide how many instrumentation logs to insert based on the complexity of the code under investigation and the hypotheses you are testing. A single well-placed log may be enough when the issue is highly localized; complex multi-step flows may need more. Aim for the minimum number that can confirm or reject ALL your hypotheses. Guidelines:
|
|
106
|
+
- At least 1 log is required; never skip instrumentation entirely
|
|
107
|
+
- Do not exceed 10 logs — if you think you need more, narrow your hypotheses first
|
|
108
|
+
- Typical range is 2-6 logs, but use your judgment
|
|
109
|
+
|
|
110
|
+
- Choose log placements from these categories as relevant to your hypotheses:
|
|
111
|
+
- Function entry with parameters
|
|
112
|
+
- Function exit with return values
|
|
113
|
+
- Values BEFORE critical operations
|
|
114
|
+
- Values AFTER critical operations
|
|
115
|
+
- Branch execution paths (which if/else executed)
|
|
116
|
+
- Suspected error/edge case values
|
|
117
|
+
- State mutations and intermediate values
|
|
118
|
+
|
|
119
|
+
- Each log must map to at least one hypothesis (include `hypothesisId` in payload).
|
|
120
|
+
- Use this payload structure: `{sessionId, runId, hypothesisId, location, message, data, timestamp}`
|
|
121
|
+
- **REQUIRED:** Wrap EACH debug log in a collapsible code region:
|
|
122
|
+
- Use language-appropriate region syntax (e.g., `// #region debug log`, `// #endregion` for JS/TS)
|
|
123
|
+
- This keeps the editor clean by auto-folding debug instrumentation
|
|
124
|
+
- **FORBIDDEN:** Logging secrets (tokens, passwords, API keys, PII)
|
|
125
|
+
|
|
126
|
+
### STEP 3: Clear previous log file before each run (MANDATORY)
|
|
127
|
+
|
|
128
|
+
- Send a `DELETE` request to the **server endpoint** to clear the log file before each run. For example: `curl -X DELETE ENDPOINT` (replace `ENDPOINT` with the endpoint value from Step 0).
|
|
129
|
+
- This ensures clean logs for the new run without mixing old and new data.
|
|
130
|
+
- Clearing the log file is NOT the same as removing instrumentation; do not remove any debug logs from code here.
|
|
131
|
+
- **CRITICAL:** Only clear YOUR session's logs (via your endpoint from Step 0). NEVER delete, modify, or overwrite log files belonging to other debug sessions.
|
|
132
|
+
|
|
133
|
+
### STEP 4: Read logs after user runs the program
|
|
134
|
+
|
|
135
|
+
- After the user runs the program and confirms completion in their interface, do NOT ask them to type "done"; then use the file-read tool to read the file at the **log path**.
|
|
136
|
+
- The log file will contain NDJSON entries (one JSON object per line) from your instrumentation.
|
|
137
|
+
- Analyze these logs to evaluate your hypotheses and identify the root cause.
|
|
138
|
+
- If log file is empty or missing: tell user the reproduction may have failed and ask them to try again.
|
|
139
|
+
|
|
140
|
+
### STEP 5: Keep logs during fixes
|
|
141
|
+
|
|
142
|
+
- When implementing a fix, DO NOT remove debug logs yet.
|
|
143
|
+
- Logs MUST remain active for verification runs.
|
|
144
|
+
- You may tag logs with `runId="post-fix"` to distinguish verification runs from initial debugging runs.
|
|
145
|
+
- FORBIDDEN: Removing or modifying any previously added logs in any files before post-fix verification logs are analyzed or the user explicitly confirms success.
|
|
146
|
+
- Only remove logs after a successful post-fix verification run (log-based proof) or explicit user request to remove.
|
|
147
|
+
|
|
148
|
+
---
|
|
149
|
+
|
|
150
|
+
## Critical Reminders (must follow)
|
|
151
|
+
|
|
152
|
+
- Keep instrumentation active during fixes; do not remove or modify logs until verification succeeds or the user explicitly confirms.
|
|
153
|
+
- FORBIDDEN: Using `setTimeout`, `sleep`, or artificial delays as a "fix"; use proper reactivity/events/lifecycles.
|
|
154
|
+
- FORBIDDEN: Removing instrumentation before analyzing post-fix verification logs or receiving explicit user confirmation.
|
|
155
|
+
- Verification requires before/after log comparison with cited log lines; do not claim success without log proof.
|
|
156
|
+
- Clear logs by sending a DELETE request to the server endpoint.
|
|
157
|
+
- Do not create the log file manually; it's created automatically.
|
|
158
|
+
- Clearing the log file is not removing instrumentation.
|
|
159
|
+
- NEVER delete or modify log files that do not belong to this session. Only touch the log file at the exact path from Step 0.
|
|
160
|
+
- Always try to rely on generating new hypotheses and using evidence from the logs to provide fixes.
|
|
161
|
+
- If all hypotheses are rejected, you MUST generate more and add more instrumentation accordingly.
|
|
162
|
+
- **Remove code changes from rejected hypotheses:** When logs prove a hypothesis wrong, revert the code changes made for that hypothesis. Do not let defensive guards, speculative fixes, or unproven changes accumulate. Only keep modifications that are supported by runtime evidence.
|
|
163
|
+
- Prefer reusing existing architecture, patterns, and utilities; avoid overengineering. Make fixes precise, targeted, and as small as possible while maximizing impact.
|
|
164
|
+
|
|
165
|
+
## Cleanup
|
|
166
|
+
|
|
167
|
+
When it is time to remove instrumentation (after verified fix or user request):
|
|
168
|
+
|
|
169
|
+
1. Search all files for `#region debug log` markers (e.g., grep/ripgrep for `#region debug log`)
|
|
170
|
+
2. For each match, delete everything from the `#region debug log` line through its corresponding `#endregion` line (inclusive)
|
|
171
|
+
3. Grep again to verify zero markers remain
|
|
172
|
+
4. Run `git diff` to review all changes — confirm only your intentional fix remains and no stray debug code was missed
|
|
173
|
+
|
|
174
|
+
This is why wrapping every debug log in `#region debug log` / `#endregion` is mandatory — it enables deterministic cleanup.
|
|
175
|
+
|
|
176
|
+
---
|
|
177
|
+
|
|
178
|
+
## Server API reference
|
|
179
|
+
|
|
180
|
+
| Method | Effect |
|
|
181
|
+
| --------------------------- | ------------------------------------------- |
|
|
182
|
+
| `POST /ingest/:sessionId` | Append JSON body as NDJSON line to log file |
|
|
183
|
+
| `GET /ingest/:sessionId` | Read full log file contents |
|
|
184
|
+
| `DELETE /ingest/:sessionId` | Clear the log file |
|
|
@@ -25,7 +25,7 @@ Downstream contract:
|
|
|
25
25
|
|
|
26
26
|
- a raw requirements discussion
|
|
27
27
|
- an existing messy backlog
|
|
28
|
-
- `requirements-grill` artifacts from `/Users/stefan/Desktop/repos/
|
|
28
|
+
- `requirements-grill` artifacts from `/Users/stefan/Desktop/repos/weareDevpunks-multiplai/.agents/skills/requirements-grill`
|
|
29
29
|
|
|
30
30
|
When grill artifacts exist, treat them as the highest-signal structured source for backlog derivation.
|
|
31
31
|
|