@varman96/paper 1.0.4 → 1.0.6
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 +67 -25
- package/dist/paper.js +20 -20
- package/package.json +14 -2
package/README.md
CHANGED
|
@@ -4,7 +4,7 @@ Paper captures command failures in a structured Incident Report for coding-agent
|
|
|
4
4
|
|
|
5
5
|
[GitHub](https://github.com/varman96/paper) · [npm](https://www.npmjs.com/package/@varman96/paper)
|
|
6
6
|
|
|
7
|
-
Primary workflow:
|
|
7
|
+
Primary workflow: Run your command normally. If it fails, run Paper.
|
|
8
8
|
|
|
9
9
|
## Install
|
|
10
10
|
|
|
@@ -14,18 +14,22 @@ npm install -g @varman96/paper
|
|
|
14
14
|
|
|
15
15
|
## Use
|
|
16
16
|
|
|
17
|
-
Run
|
|
17
|
+
Run your command normally:
|
|
18
18
|
|
|
19
19
|
```bash
|
|
20
|
-
$
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
20
|
+
$ npm test
|
|
21
|
+
|
|
22
|
+
FAIL src/router.test.js
|
|
23
|
+
TypeError: primaryAction is not a function
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
If it fails, run Paper:
|
|
24
27
|
|
|
25
|
-
|
|
28
|
+
```bash
|
|
29
|
+
$ paper run npm test
|
|
26
30
|
```
|
|
27
31
|
|
|
28
|
-
|
|
32
|
+
Paper creates `.paper/incident_report.md`:
|
|
29
33
|
|
|
30
34
|
```markdown
|
|
31
35
|
# Incident Report
|
|
@@ -54,37 +58,75 @@ Error: Expected 2 tests to pass, received 1
|
|
|
54
58
|
at runTests (test/runner.js:42:11)
|
|
55
59
|
```
|
|
56
60
|
|
|
57
|
-
|
|
61
|
+
Give that report to your coding agent:
|
|
58
62
|
|
|
59
63
|
```text
|
|
60
64
|
Diagnose and fix the failure in .paper/incident_report.md
|
|
61
65
|
```
|
|
62
66
|
|
|
63
|
-
|
|
67
|
+
If the command works, you're done.
|
|
64
68
|
|
|
65
|
-
|
|
69
|
+
## Commands
|
|
66
70
|
|
|
67
|
-
|
|
68
|
-
paper shelf
|
|
69
|
-
```
|
|
71
|
+
- `paper run <command> [args...]` — run a target command through Paper and capture a report if it fails.
|
|
70
72
|
|
|
71
|
-
|
|
73
|
+
- `paper shelf` — move the active Incident Report out of the workspace and preserve it in Paper's local shelf.
|
|
74
|
+
|
|
75
|
+
- `paper --help` — print Paper's usage, examples, report location, shelf command, and metadata flags.
|
|
76
|
+
|
|
77
|
+
- `paper --version` — print the installed package version.
|
|
78
|
+
|
|
79
|
+
## Errors
|
|
80
|
+
|
|
81
|
+
> **Warning:** Do not use `paper run` to run Paper itself or commands that invoke Paper recursively. Paper is designed to capture failures from the command being investigated, not its own execution. Running Paper through Paper can produce recursive or misleading incident context.
|
|
82
|
+
|
|
83
|
+
Paper has no numeric or separately registered error-code system. Its own failures use uppercase cause labels in the CLI output:
|
|
84
|
+
|
|
85
|
+
| Label | When it occurs | Meaning and action |
|
|
86
|
+
| --- | --- | --- |
|
|
87
|
+
| `CLI ENTRYPOINT MISMATCH` | Startup | Paper cannot resolve the executable path to the active CLI entrypoint. Reinstall or relink Paper, then run the command again. |
|
|
88
|
+
| `NO COMMAND` | Argument parsing, with no arguments or with `paper run` alone | No target command was supplied. Use `paper run <command>`. |
|
|
89
|
+
| `INVALID COMMAND` | Argument parsing, when the first argument is not `run` | Paper requires the canonical `paper run <command>` form. |
|
|
90
|
+
| `AGENT RULES WRITE FAILED` | Before `paper run` starts the target | Paper could not create or update the repository's agent-instruction file. Restore write access and run Paper again. |
|
|
91
|
+
| `BINARY MISSING` | Starting the `paper run` target | The target was not found in the active `PATH`. Install it or use a command that exists in the shell. |
|
|
92
|
+
| `PERMISSION DENIED` | Starting the `paper run` target | Paper could not execute the target from the shell. Restore execute permission or use an executable command. |
|
|
93
|
+
| `TARGET START FAILED` | Starting the `paper run` target | The target could not be started for another spawn error. Run it directly in the shell to verify it starts, then run Paper again. |
|
|
94
|
+
| `REPORT WRITE FAILED` | Writing `.paper/incident_report.md` after a target failure | Paper could not persist the Incident Report. Restore write access to the report location and run Paper again. |
|
|
95
|
+
| `NO ACTIVE INCIDENT` | `paper shelf` | `.paper/incident_report.md` was not found, so no files were changed. Run `paper run <command>` first. |
|
|
96
|
+
| `INCIDENT SHELF FAILED` | `paper shelf` while creating the shelf directory or moving the report | Paper could not move the report. The active report is preserved; restore access to the shelf location and run `paper shelf` again. |
|
|
97
|
+
| `PAPER OPERATION FAILED` | An unexpected local operation throws an unclassified error | Paper stopped before the requested operation completed. Resolve the reported local error and run Paper again. |
|
|
98
|
+
|
|
99
|
+
`paper run <command>` also prints `COMMAND FAILED` when the user's command exits nonzero or is terminated by a signal. This is not a Paper error: Paper captured the user's command failure, wrote the Incident Report, and exits successfully if that write succeeds. The command's own stdout/stderr, including errors from its shell or runtime, remain command-generated evidence rather than Paper error labels.
|
|
100
|
+
|
|
101
|
+
### Found a bug?
|
|
102
|
+
|
|
103
|
+
If you encounter a bug or an error that isn't documented here, please let us know.
|
|
104
|
+
|
|
105
|
+
Email **varmanvishnu96@gmail.com**, or join the [Paper Discord](https://discord.gg/9KqwMNTft) and post it in the **#bugs** channel.
|
|
106
|
+
|
|
107
|
+
## How it works
|
|
108
|
+
|
|
109
|
+
Paper is used after a command has failed. `paper run <command>` executes the target command through the local CLI and forwards its stdout and stderr. Before starting it, Paper adds or updates its managed workflow block in the detected agent-instruction file, falling back to `AGENTS.md`.
|
|
110
|
+
|
|
111
|
+
If the target succeeds, `.paper/incident_report.md` is unchanged. If it exits nonzero or is terminated by a signal, Paper traps that failure, captures the evidence locally, writes a structured Incident Report to `.paper/incident_report.md`, and prints `COMMAND FAILED`. The report contains the command, exit code, working directory, timestamp, and stderr or stack trace. Once the report is persisted, Paper exits successfully; Paper-owned failures, such as inability to update instructions or write the report, exit nonzero.
|
|
112
|
+
|
|
113
|
+
The Paper instruction tells coding agents where to find the Incident Report, so an agent can investigate the failure without the user manually copying terminal output. Paper does not diagnose or fix the failure.
|
|
114
|
+
|
|
115
|
+
Paper creates persistent local context and makes it discoverable to the agent. Its operation is local-only and air-gapped: there are no model API calls, telemetry, or command-output uploads.
|
|
116
|
+
|
|
117
|
+
### Shelving an incident
|
|
118
|
+
|
|
119
|
+
Once the incident is resolved, remove it from the active workspace with:
|
|
72
120
|
|
|
73
121
|
```bash
|
|
74
|
-
paper run <command>
|
|
75
122
|
paper shelf
|
|
76
|
-
paper --help
|
|
77
|
-
paper --version
|
|
78
123
|
```
|
|
79
124
|
|
|
80
|
-
|
|
125
|
+
Paper moves `.paper/incident_report.md` out of the repository with a rename and prints the stored path. On Windows, shelved reports are stored under `%LOCALAPPDATA%\Paper\shelf\<repository-hash>\`; on other platforms, under `$XDG_DATA_HOME/Paper/shelf/<repository-hash>/` or `~/.local/share/Paper/shelf/<repository-hash>/`. The report is preserved as a timestamped `.md` file under a repository-specific 16-character SHA-256 directory, but is no longer the active report. The active report is removed from `.paper`, its contents are preserved, and the instruction file is not changed. With no active report, or if the move fails, Paper exits nonzero; a failed move preserves the active report.
|
|
126
|
+
|
|
127
|
+
### Recovering a shelved incident
|
|
81
128
|
|
|
82
|
-
|
|
83
|
-
- Structured Incident Report at `.paper/incident_report.md`.
|
|
84
|
-
- Evidence anchor for coding-agent investigation.
|
|
85
|
-
- Local-only; zero telemetry.
|
|
86
|
-
- No model API calls.
|
|
87
|
-
- No command-output upload.
|
|
129
|
+
Paper currently has no list or recovery command. `paper shelf` prints the exact path of the newly shelved report, which is also how to locate it later. To recover one, manually copy that `.md` file back to the repository as `.paper/incident_report.md`; Paper does not perform this restore or automatically replace an existing active report. Shelving and manual recovery do not update `AGENTS.md`; the existing Paper instruction remains unchanged and will point agents to `.paper/incident_report.md` when that file is present again.
|
|
88
130
|
|
|
89
131
|
## License
|
|
90
132
|
|
package/dist/paper.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{spawn as B}from"node:child_process";import{createHash as Z}from"node:crypto";import{realpathSync as V}from"node:fs";import{lstat as q,mkdir as P,readFile as K,rename as X,stat as F,writeFile as M}from"node:fs/promises";import{homedir as $,platform as O}from"node:os";import{basename as k,dirname as f,join as
|
|
2
|
+
import{spawn as B}from"node:child_process";import{createHash as Z}from"node:crypto";import{realpathSync as V}from"node:fs";import{lstat as q,mkdir as P,readFile as K,rename as X,stat as F,writeFile as M}from"node:fs/promises";import{homedir as $,platform as O}from"node:os";import{basename as k,dirname as f,join as a,resolve as g}from"node:path";import{fileURLToPath as Y}from"node:url";var I=[["1. Scope",[["what-failing","What is failing?"],["still-working","What is still working?"],["failure-breadth","How broad is the failure?"],["deterministic","Is it deterministic?"]]],["2. Delta",[["changed-recently","What changed recently?"],["did-not-change","What did not change?"],["git-runtime-environment-differences","Relevant git/runtime/environment differences"]]],["3. Failure Boundary",[["expected-at-boundary","Expected behavior at the boundary"],["observed-at-boundary","Observed behavior at the boundary"],["input-payload","Exact input/payload entering the boundary"],["output-error","Exact output/error leaving the boundary"]]],["4. Execution Path",[["origin","Origin"],["intermediate-components","Intermediate components"],["first-confirmed-divergence","First confirmed divergence"],["runtime-environment-hops","Runtime/environment at relevant hops"]]],["5. Evidence",[["exit-code","Exit code"],["stderr-stack-trace","stderr / stack trace"],["status-codes","Status codes"],["commands","Commands"],["changed-files","Changed files"],["git-diff-stat","git diff/stat"],["runtime-versions","Runtime versions"],["other-receipts","Other deterministic receipts"]]],["6. Falsified Hypotheses",[["hypothesis","Hypothesis"],["test-check","Test/check performed"],["result","Result"],["why-ruled-out","Why it is ruled out"]]],["7. Current Working Hypothesis",[["working-hypothesis","Hypothesis"],["supporting-evidence","Evidence supporting it"],["opposing-evidence","Evidence against it"]]],["8. Next Test",[["smallest-action","Smallest action to isolate or test next"]]]],ke=I.flatMap(([,e])=>e);function R(e={}){let t=I.flatMap(([n,r])=>{let s=r.flatMap(([o,i])=>{let c=String(e[o]??"").trim();return c?[`### ${i}
|
|
3
3
|
|
|
4
4
|
${c}`]:[]});return s.length?[`## ${n}
|
|
5
5
|
|
|
@@ -9,7 +9,7 @@ ${s.join(`
|
|
|
9
9
|
|
|
10
10
|
${t.join(`
|
|
11
11
|
|
|
12
|
-
`)}`:""}`}var T={name:"@varman96/paper",version:"1.0.
|
|
12
|
+
`)}`:""}`}var T={name:"@varman96/paper",version:"1.0.6",description:"Paper captures command failures in a structured Incident Report for coding-agent investigation.",main:"dist/paper.js",bin:{paper:"./dist/paper.js"},files:["dist/paper.js","README.md","LICENSE"],directories:{test:"test"},scripts:{"alpha:issue":"node scripts/issue-alpha-access.js","alpha:revoke":"node scripts/revoke-alpha-access.js","fail:test":"node scripts/fail-test.js",paper:"node scripts/paper.js","build:cli":"node scripts/build-cli.js",prepack:"npm run build:cli","deploy:production":"wrangler deploy --env production",test:"node test/run-tests.js","test:fast":"node test/run-tests.js --fast","test:browser":"node test/run-tests.js --browser","test:alpha-browser":"node test/alpha-access.browser.js"},repository:{type:"git",url:"git+https://github.com/varman96/paper.git"},keywords:["debugging","cli","developer-tools","coding-agents","ai-coding","incident-report","terminal","error-logs","claude-code","cursor","codex"],author:"",license:"SEE LICENSE IN LICENSE",type:"module",bugs:{url:"https://github.com/varman96/paper/issues"},homepage:"https://paper-ai.paperhq.workers.dev/",devDependencies:{"@biomejs/biome":"2.5.14",esbuild:"^0.28.1",wrangler:"^4.132.0"}};var J=`Paper captures a failed command and writes a local Incident Report.
|
|
13
13
|
|
|
14
14
|
Usage: paper run <command>
|
|
15
15
|
|
|
@@ -22,43 +22,43 @@ Report: .paper/incident_report.md
|
|
|
22
22
|
paper shelf Move the active Incident Report out of the workspace
|
|
23
23
|
|
|
24
24
|
--help Show this help
|
|
25
|
-
--version Show the version`,
|
|
25
|
+
--version Show the version`,y=["<!-- paper:start -->","## Paper Incident Workflow","","When `.paper/incident_report.md` exists, read it before investigating.","","Treat the Incident Report as the current evidence anchor, not as infallible truth. Use it to establish the known failure boundary, then inspect the repository, runtime, tests, configuration, and other source-of-truth evidence as needed.","","Diagnose the issue using this trace:","","### 1. Establish the Failing Invariant","","Identify the exact boundary contract that was violated.","","State:","","Invariant Expected:","The concrete behavior or state that should have held.","","Invariant Observed:","The concrete behavior or state actually observed.","","Use precise system evidence where available:","- exit codes","- status codes","- errno","- ports","- file paths","- symbols","- stack frames","- environment values","- process state","- exact command output","","Do not replace concrete evidence with vague summaries.","","### 2. State Elimination","","Shrink the search space by explicitly ruling out competing explanations using verified evidence.","","For each relevant factor, state whether it is:","- confirmed working","- confirmed failing","- still unverified","","Examples:","- config parsed successfully","- network route reachable","- dependency present or missing","- process listening or not listening","- expected environment variable present or absent","","Do not mark a hypothesis ruled out without evidence.","","Do not repeat theories already ruled out by the Incident Report unless new evidence justifies reopening them.","","### 3. Single-Point Attribution","","Narrow the diagnosis to the smallest confirmed fault boundary.","","State:","","Fault Location:","The exact file, line, symbol, process, dependency, configuration value, environment delta, or runtime boundary responsible.","","Mechanism:","The concrete way that fault caused the observed invariant violation.","","Do not invent a root cause if the evidence only supports a narrower failure boundary.","","If the mechanism is not yet verified, label it as unverified and continue investigating.","","Newer source-of-truth evidence overrides stale or incorrect Incident Report content.","","### 4. Proposed Action Packet \u2014 Zero Execution","","Once the failure is sufficiently explained, STOP before remediation.","","Do not:","- modify files","- start or stop services","- change configuration","- install dependencies","- run a fix","- apply a patch","- mutate the environment","","unless the user explicitly asked for remediation.","","Report:","","What I found:","A concise diagnosis grounded in the Incident Report and verified evidence gathered afterward.","","Proposed fix:","The smallest intervention that addresses the confirmed mechanism.","","Diff preview:","Describe the expected code/config change if applicable. Do not apply it.","","Verification test:","Name the smallest test or command that would verify the proposed fix.","","Clearly distinguish:","- evidence already present in the Incident Report","- findings established during investigation","- hypotheses that remain unverified","","Once the current failure is sufficiently explained, stop widening the investigation unless new evidence connects another issue to the same failure.","","Important behavior:","- The agent may inspect the repo/runtime normally.","- The Incident Report is not the only source of truth.","- The agent must not hallucinate missing telemetry.","- The agent must not convert an unverified hypothesis into a confirmed diagnosis.","- The agent must not execute remediation unless explicitly asked.","- The diagnostic trace is investigative structure, not verbose prose. Keep each section concise and evidence-based.","<!-- paper:end -->"].join(`
|
|
26
26
|
`),d=class extends Error{constructor(t,n,r,s){super(n),this.name="PaperCliError",this.causeLabel=t,this.state=r,this.directive=s}};function N(e){return e instanceof d?[e.causeLabel,e.message,"",e.state,"",e.directive].join(`
|
|
27
27
|
`):["PAPER OPERATION FAILED",e?.message||"Paper encountered an unclassified local operation failure.","","Paper stopped before the requested operation completed.","","Resolve the reported local error and run Paper again."].join(`
|
|
28
|
-
`)}function Q({modulePath:e=Y(import.meta.url),invokedPath:t=process.argv[1],resolvePath:n=V.native}={}){if(!t)return{isCli:!1,startupFailure:!1};try{return{isCli:n(g(e))===n(g(t)),startupFailure:!1}}catch{let r=k(e).toLowerCase(),s=k(t).toLowerCase();return{isCli:!1,startupFailure:r===s}}}async function ee(e){try{let t=await F(e);return t.isDirectory()||t.isFile()}catch{return!1}}async function x(e=process.cwd()){let t=g(e);for(;;){if(await ee(
|
|
28
|
+
`)}function Q({modulePath:e=Y(import.meta.url),invokedPath:t=process.argv[1],resolvePath:n=V.native}={}){if(!t)return{isCli:!1,startupFailure:!1};try{return{isCli:n(g(e))===n(g(t)),startupFailure:!1}}catch{let r=k(e).toLowerCase(),s=k(t).toLowerCase();return{isCli:!1,startupFailure:r===s}}}async function ee(e){try{let t=await F(e);return t.isDirectory()||t.isFile()}catch{return!1}}async function x(e=process.cwd()){let t=g(e);for(;;){if(await ee(a(t,".git")))return t;let n=f(t);if(n===t)return g(e);t=n}}async function v(e,t){try{let n=await F(e);return t==="directory"?n.isDirectory():t==="file"?n.isFile():!0}catch{return!1}}async function m(e){try{if((await q(e)).isSymbolicLink())throw new Error(`Refusing to write through a symbolic link: ${e}`)}catch(t){if(t.code!=="ENOENT")throw t}}async function te(e){let t=[],n=["AGENTS.md","CLAUDE.md","GEMINI.md",a(".github","copilot-instructions.md"),".cursorrules",a(".cursor","rules.md"),a(".cursor","instructions.md")];for(let r of n)await v(a(e,r),"file")&&t.push(a(e,r));return await v(a(e,".cursor","rules"),"directory")&&t.push(a(e,".cursor","rules","paper.mdc")),t.length?t:[a(e,"AGENTS.md")]}function ne(e){let t=/<!-- paper:start -->[\s\S]*?<!-- paper:end -->/g;if(e.match(t)?.length){let r=0,s=e.replace(t,()=>r++===0?y:"");return{next:s,changed:s!==e}}return{next:e?`${e}${e.endsWith(`
|
|
29
29
|
`)?`
|
|
30
30
|
`:`
|
|
31
31
|
|
|
32
|
-
`}${
|
|
33
|
-
`:`${
|
|
34
|
-
`,changed:!0}}async function re(e=process.cwd()){let t=await x(e),n=await te(t),r=[],s=[];for(let
|
|
32
|
+
`}${y}
|
|
33
|
+
`:`${y}
|
|
34
|
+
`,changed:!0}}async function re(e=process.cwd()){let t=await x(e),n=await te(t),r=[],s=[];for(let o of n){await m(o),await m(f(o)),await m(f(f(o)));let i="";try{i=await K(o,"utf8")}catch(l){if(l.code!=="ENOENT")throw l}let{next:c,changed:u}=ne(i);u&&(await P(f(o),{recursive:!0}),await M(o,c,"utf8"),r.push(o),i||s.push(o))}return{repoRoot:t,targetPaths:n,changedPaths:r,created:s.length>0,changed:r.length>0}}async function ie(e,t){let n=a(e,".paper","incident_report.md");return await m(a(e,".paper")),await m(n),await P(f(n),{recursive:!0}),await M(n,t,"utf8"),n}function se(e=process.env,t=O()){return t==="win32"?e.LOCALAPPDATA||a($(),"AppData","Local","Paper"):a(e.XDG_DATA_HOME||a($(),".local","share"),"Paper")}function oe(e,t=process.env,n=O()){let r=Z("sha256").update(g(e)).digest("hex").slice(0,16);return a(se(t,n),"shelf",r)}function ae(e=new Date){return e.toISOString().replace(/[:.]/g,"-")}async function ce(e,t){let n=0;for(;;){let r=a(e,`${t}${n?`-${n}`:""}.md`);if(!await v(r,"file"))return r;n+=1}}async function de(){let e=await x(),t=a(e,".paper","incident_report.md");if(!await v(t,"file"))throw new d("NO ACTIVE INCIDENT","Paper could not find an active Incident Report.","No files were changed.","Run `paper run <command>` to capture a failure first.");let n=oe(e),r=await ce(n,ae());try{await P(n,{recursive:!0}),await X(t,r)}catch(s){throw new d("INCIDENT SHELF FAILED",`Paper could not move the Incident Report out of the workspace${s?.code?` (${s.code})`:"."}`,"The active Incident Report was preserved in the workspace.","Restore access to the Paper shelf location and run `paper shelf` again.")}process.stdout.write(`INCIDENT SHELVED
|
|
35
35
|
Moved the active Incident Report out of the workspace.
|
|
36
36
|
|
|
37
37
|
Stored at:
|
|
38
38
|
${r}
|
|
39
|
-
`)}function H(e,t){return[e,...t].join(" ")}function pe(e,t,n){return new Promise((r,s)=>{let
|
|
40
|
-
`)}function
|
|
41
|
-
${
|
|
39
|
+
`)}function H(e,t){return[e,...t].join(" ")}function pe(e,t,n){return new Promise((r,s)=>{let o=!1,i=B(e,t,{cwd:n,windowsHide:!0,stdio:["inherit","pipe","pipe"]}),c="",u="";i.stdout.on("data",l=>{c+=l}),i.stderr.on("data",l=>{u+=l}),i.once("error",l=>{o||(o=!0,s(l))}),i.once("close",(l,w)=>{o||(o=!0,r({code:l,signal:w,stdout:c,stderr:u}))})})}function le(e,t,n){let r=n.signal?`Process terminated by signal ${n.signal}`:`Process exited with code ${n.code}`;return[`$ ${H(e,t)}`,n.stdout,n.stderr,r].filter(Boolean).join(`
|
|
40
|
+
`)}function ue(e,t){let n=`\`${e}\``;return t?.code==="ENOENT"?new d("BINARY MISSING",`${n} was not found in the active PATH.`,"Execution stopped before the target command started.",`Install ${n} or run Paper with a command that exists in this shell.`):t?.code==="EACCES"?new d("PERMISSION DENIED",`Paper could not execute ${n} from this shell.`,"Execution stopped before the target command started.",`Restore execute permission for ${n} or run Paper with an executable command.`):new d("TARGET START FAILED",`Paper could not start ${n}${t?.message?`: ${t.message}`:"."}`,"Execution stopped before the target command started.",`Run ${n} directly in this shell to verify that it can start, then run Paper again.`)}function he(e,t,n){return new d("REPORT WRITE FAILED",`Paper could not persist the Incident Report at \`${t}\`${e?.code?` (${e.code})`:"."}`,n?"The target command finished, but the report was not persisted.":"Paper stopped before the target command started.","Restore write access to the report location and run Paper again.")}function fe(e){return new d("AGENT RULES WRITE FAILED",`Paper could not update the repository instruction file${e?.code?` (${e.code})`:"."}`,"Execution stopped before the target command started.","Restore write access to the repository instruction file and run Paper again.")}async function me(e,t){let n=await x();try{await re()}catch(i){throw fe(i)}let r;try{r=await pe(e,t,n)}catch(i){throw ue(e,i)}let s=a(n,".paper","incident_report.md");r.stdout&&process.stdout.write(r.stdout),r.stderr&&process.stderr.write(r.stderr);let o=`\`${H(e,t)}\``;if(r.code!==0||r.signal){let i=$e(le(e,t,r));try{await ie(n,i)}catch(u){throw he(u,s,!0)}let c=r.signal?`signal ${r.signal}`:`code ${r.code}`;process.stderr.write(`COMMAND FAILED
|
|
41
|
+
${o} exited with ${c}.
|
|
42
42
|
|
|
43
43
|
Paper captured the failure and persisted the Incident Report at \`${s}\`.
|
|
44
|
-
`)}}var ge=[/\b(?:error|fatal|exception|panic|failed|failure|traceback|segmentation fault|command not found|exited with code)\b|ERR!/i,/\b(?:HTTP\/\d(?:\.\d)?\s+)?[45]\d{2}\b/i,/\b(?:exit(?:ed| status| code)?|status code)\s*[:=]?\s*[1-9]\d*/i],we=/HTTP\/\d(?:\.\d)?\s+[1-5]\d{2}\b|\bstatus(?: code)?\s*[:=]?\s*[1-5]\d{2}\b/i,ve=/\b(?:exited with code|exit(?: status| code)?|status code)\s*[:=]?\s*[1-9]\d*/i,W=/^\s*(?:at\s+.+|File\s+["'].+["'],\s*line\s+\d+|[\w.]+\.[\w$]+\([^)]*:\d+(?::\d+)?\))/i,_=/^\s*(?:[$>]|(?:curl|wget|git|docker|kubectl|wrangler|npm|npx|node|python(?:\d+)?|pytest|cargo|go|dotnet|java|bun|deno|yarn|pnpm)\b)/i,
|
|
44
|
+
`)}}var ge=[/\b(?:error|fatal|exception|panic|failed|failure|traceback|segmentation fault|command not found|exited with code)\b|ERR!/i,/\b(?:HTTP\/\d(?:\.\d)?\s+)?[45]\d{2}\b/i,/\b(?:exit(?:ed| status| code)?|status code)\s*[:=]?\s*[1-9]\d*/i],we=/HTTP\/\d(?:\.\d)?\s+[1-5]\d{2}\b|\bstatus(?: code)?\s*[:=]?\s*[1-5]\d{2}\b/i,ve=/\b(?:exited with code|exit(?: status| code)?|status code)\s*[:=]?\s*[1-9]\d*/i,W=/^\s*(?:at\s+.+|File\s+["'].+["'],\s*line\s+\d+|[\w.]+\.[\w$]+\([^)]*:\d+(?::\d+)?\))/i,_=/^\s*(?:[$>]|(?:curl|wget|git|docker|kubectl|wrangler|npm|npx|node|python(?:\d+)?|pytest|cargo|go|dotnet|java|bun|deno|yarn|pnpm)\b)/i,be=/\b(?:node(?:\.js)?|npm|npx|pnpm|yarn|bun|deno|python(?:\d+)?|pytest|ruby|java|dotnet|cargo|rustc|go version|windows|linux|darwin|macos|runtime|version)\b/i,ye=/(?:[A-Za-z]:[\\/][^\s,;()[\]{}]+|(?:\.{0,2}[\\/])?[A-Za-z0-9_.-]+(?:[\\/][A-Za-z0-9_.-]+)+\.[A-Za-z0-9_.-]+)/g,A=/^\s*(?:\+\s*)?(?:CategoryInfo|FullyQualifiedErrorId)\b/i,S=/^\s*At line:\d+ char:\d+\s*$/i,C=/^\s*(?:\+\s*)?~+\s*$/,D=/^\s*\+\s*npm(?:\.cmd)?\b/i,Pe=/^\s*\+\s*curl(?:\.exe)?\b/i,xe=/^\s*\|\s*(?:node|npm|npx)\b/i,j=/^\s*(?:npm(?:\.cmd)?|curl(?:\.exe)?)\s*:\s+/i,Ee=/^\s*[a-z]:\/\//i;function Ie(e=""){let t=String(e??""),n=t.replace(/\r\n?/g,`
|
|
45
45
|
`).split(`
|
|
46
|
-
`);if(!(n.some(i=>A.test(i))&&n.some(i=>j.test(i))))return t;let s=[],
|
|
47
|
-
`)}function h(e){return[...new Set(e.map(t=>t.trim()).filter(Boolean))]}function Re(e){return h([...e.matchAll(
|
|
46
|
+
`);if(!(n.some(i=>A.test(i))&&n.some(i=>j.test(i))))return t;let s=[],o=!1;for(let i of n){if(A.test(i)){o=!0;continue}if(o){if(!i.trim()){o=!1,s.push(i);continue}if(S.test(i)||C.test(i)||D.test(i))continue;if(W.test(i)||_.test(i))o=!1;else continue}if(S.test(i)||C.test(i)||D.test(i)||xe.test(i))continue;if(Pe.test(i)){let u=i.replace(/^\s*\+\s*/,"");s.at(-1)!==u&&s.push(u);continue}if(Ee.test(i))continue;let c=i.replace(j,"");s.at(-1)!==c&&s.push(c)}return s.join(`
|
|
47
|
+
`)}function h(e){return[...new Set(e.map(t=>t.trim()).filter(Boolean))]}function Re(e){return h([...e.matchAll(ye)].map(([t])=>t.replace(/[.:]+$/,"")).filter(t=>!/^HTTP\/\d(?:\.\d)?$/i.test(t)&&!/^[a-z]:\/\//i.test(t)))}function Te(e=""){let t=Ie(e),r=t.replace(/\r\n?/g,`
|
|
48
48
|
`).split(`
|
|
49
|
-
`).filter(p=>p.trim()),s=h(r.filter(p=>ge.some(G=>G.test(p)))),
|
|
50
|
-
`),
|
|
49
|
+
`).filter(p=>p.trim()),s=h(r.filter(p=>ge.some(G=>G.test(p)))),o=h(r.filter(p=>W.test(p))),i=h(r.filter(p=>_.test(p))),c=h(r.filter(p=>be.test(p))),u=h(r.filter(p=>we.test(p))),l=h(r.filter(p=>ve.test(p))),w=Re(t),E=h([...s,...o]).join(`
|
|
50
|
+
`),b=i.join(`
|
|
51
51
|
`),z=w.length?`${w.join(`
|
|
52
52
|
`)}
|
|
53
53
|
|
|
54
54
|
${t}`:t;return{"what-failing":s.join(`
|
|
55
55
|
`),"observed-at-boundary":s.join(`
|
|
56
|
-
`),"input-payload":
|
|
57
|
-
`),"exit-code":
|
|
58
|
-
`),"stderr-stack-trace":E,"status-codes":
|
|
59
|
-
`),commands:
|
|
56
|
+
`),"input-payload":b,"output-error":E,origin:b,"first-confirmed-divergence":s[0]||o[0]||"","runtime-environment-hops":c.join(`
|
|
57
|
+
`),"exit-code":l.join(`
|
|
58
|
+
`),"stderr-stack-trace":E,"status-codes":u.join(`
|
|
59
|
+
`),commands:b,"runtime-versions":c.join(`
|
|
60
60
|
`),"other-receipts":z}}function $e(e=""){return R(Te(e))}var L=Q();if(L.startupFailure)process.stderr.write(`${N(new d("CLI ENTRYPOINT MISMATCH","Paper loaded, but the executable path could not be resolved to the active CLI entrypoint.","No target command was started.","Reinstall or relink Paper and run the command again."))}
|
|
61
61
|
`),process.exitCode=1;else if(L.isCli)try{let e=process.argv.slice(2);if(e[0]==="--help")process.stdout.write(`${J}
|
|
62
62
|
`);else if(e[0]==="--version")process.stdout.write(`${T.version}
|
|
63
63
|
`);else if(e[0]==="shelf"&&e.length===1)await de();else if(e.length){if(e[0]!=="run")throw new d("INVALID COMMAND","Paper expected `run` before the target command.","No target command was started.","Use `paper run <command>`.");if(e.length===1)throw new d("NO COMMAND","Paper needs a command to capture.","No target command was started.","Use `paper run <command>`. ");await me(e[1],e.slice(2))}else throw new d("NO COMMAND","Paper needs a command to capture.","No target command was started.","Use `paper run <command>`.")}catch(e){process.stderr.write(`${N(e)}
|
|
64
|
-
`),process.exitCode=1}export{
|
|
64
|
+
`),process.exitCode=1}export{y as MANAGED_AGENT_RULES_BLOCK,d as PaperCliError,$e as buildTerminalPacket,te as detectAgentInstructionPaths,re as ensureManagedAgentRules,Te as extractTerminalPacket,x as findRepoRoot,N as formatPaperCliError,Ie as normalizeTerminalOutput,Q as resolveCliEntrypoint,oe as shelfPathForRepo,ie as writeIncidentReport};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@varman96/paper",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.6",
|
|
4
4
|
"description": "Paper captures command failures in a structured Incident Report for coding-agent investigation.",
|
|
5
5
|
"main": "dist/paper.js",
|
|
6
6
|
"bin": {
|
|
@@ -31,7 +31,19 @@
|
|
|
31
31
|
"type": "git",
|
|
32
32
|
"url": "git+https://github.com/varman96/paper.git"
|
|
33
33
|
},
|
|
34
|
-
"keywords": [
|
|
34
|
+
"keywords": [
|
|
35
|
+
"debugging",
|
|
36
|
+
"cli",
|
|
37
|
+
"developer-tools",
|
|
38
|
+
"coding-agents",
|
|
39
|
+
"ai-coding",
|
|
40
|
+
"incident-report",
|
|
41
|
+
"terminal",
|
|
42
|
+
"error-logs",
|
|
43
|
+
"claude-code",
|
|
44
|
+
"cursor",
|
|
45
|
+
"codex"
|
|
46
|
+
],
|
|
35
47
|
"author": "",
|
|
36
48
|
"license": "SEE LICENSE IN LICENSE",
|
|
37
49
|
"type": "module",
|