@yunhozz/arc 0.2.2 → 0.2.4

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.
Files changed (117) hide show
  1. package/MANIFEST.sha256 +107 -88
  2. package/README.md +4 -6
  3. package/claude/agents/arc-implementer.md +32 -42
  4. package/claude/agents/arc-planner.md +33 -47
  5. package/claude/agents/arc-qa.md +28 -44
  6. package/claude/agents/arc-reviewer.md +28 -41
  7. package/claude/agents/arc-scouter.md +26 -38
  8. package/claude/skill/SKILL.md +41 -59
  9. package/claude/skill/references/arc-visual-companion.md +28 -0
  10. package/claude/skill/references/commit.md +38 -70
  11. package/claude/skill/references/coordination.md +77 -126
  12. package/claude/skill/references/git-recovery.md +17 -35
  13. package/claude/skill/references/handoff-prep.md +91 -103
  14. package/claude/skill/references/handoff.md +110 -208
  15. package/claude/skill/references/limits.md +19 -31
  16. package/claude/skill/references/planning.md +93 -244
  17. package/claude/skill/references/verification.md +105 -261
  18. package/claude/skill/references/visual-companion.md +293 -15
  19. package/claude/skill/runtime/adapters/claude.mjs +10 -9
  20. package/claude/skill/runtime/adapters/codex.mjs +7 -8
  21. package/claude/skill/runtime/bootstrap.mjs +3 -2
  22. package/claude/skill/runtime/capabilities.mjs +12 -0
  23. package/claude/skill/runtime/cooperative-schema.mjs +3 -2
  24. package/claude/skill/runtime/cooperative.mjs +52 -4
  25. package/claude/skill/runtime/evaluate.mjs +115 -2
  26. package/claude/skill/runtime/identity.mjs +22 -0
  27. package/claude/skill/runtime/role-policy.json +18 -18
  28. package/claude/skill/runtime/schema.mjs +19 -0
  29. package/claude/skill/scripts/model_config.py +3 -79
  30. package/codex/agents/arc-implementer.toml +34 -30
  31. package/codex/agents/arc-planner.toml +27 -23
  32. package/codex/agents/arc-qa.toml +24 -15
  33. package/codex/agents/arc-reviewer.toml +25 -16
  34. package/codex/agents/arc-scouter.toml +20 -26
  35. package/codex/skill/SKILL.md +42 -57
  36. package/codex/skill/references/arc-visual-companion.md +33 -0
  37. package/codex/skill/references/commit.md +35 -81
  38. package/codex/skill/references/coordination.md +76 -104
  39. package/codex/skill/references/git-recovery.md +29 -51
  40. package/codex/skill/references/handoff-prep.md +76 -134
  41. package/codex/skill/references/handoff-worktree.md +32 -66
  42. package/codex/skill/references/handoff.md +111 -271
  43. package/codex/skill/references/limits.md +21 -34
  44. package/codex/skill/references/planning.md +125 -299
  45. package/codex/skill/references/verification.md +90 -272
  46. package/codex/skill/references/visual-companion.md +290 -18
  47. package/codex/skill/runtime/adapters/claude.mjs +10 -9
  48. package/codex/skill/runtime/adapters/codex.mjs +7 -8
  49. package/codex/skill/runtime/bootstrap.mjs +3 -2
  50. package/codex/skill/runtime/capabilities.mjs +12 -0
  51. package/codex/skill/runtime/cooperative-schema.mjs +3 -2
  52. package/codex/skill/runtime/cooperative.mjs +52 -4
  53. package/codex/skill/runtime/evaluate.mjs +115 -2
  54. package/codex/skill/runtime/identity.mjs +22 -0
  55. package/codex/skill/runtime/role-policy.json +18 -18
  56. package/codex/skill/runtime/schema.mjs +19 -0
  57. package/lib/installer/global-config.mjs +1 -0
  58. package/lib/installer/install.mjs +5 -7
  59. package/lib/installer/manifest.mjs +23 -8
  60. package/lib/installer/package-references.mjs +10 -5
  61. package/lib/installer/plan.mjs +1 -4
  62. package/lib/installer/superpowers.mjs +26 -1
  63. package/lib/installer/transaction.mjs +3 -3
  64. package/lib/installer/uninstall.mjs +2 -2
  65. package/lib/installer/upgrade.mjs +2 -9
  66. package/lib/management/operations.mjs +6 -8
  67. package/lib/management/update.mjs +3 -3
  68. package/lib/models/profiles.mjs +1 -40
  69. package/lib/policy/render.mjs +1 -5
  70. package/lib/policy/role-policy.json +18 -18
  71. package/lib/release/artifact.mjs +6 -4
  72. package/lib/runtime/adapters/claude.mjs +10 -9
  73. package/lib/runtime/adapters/codex.mjs +7 -8
  74. package/lib/runtime/bootstrap.mjs +3 -2
  75. package/lib/runtime/capabilities.mjs +12 -0
  76. package/lib/runtime/cooperative-schema.mjs +3 -2
  77. package/lib/runtime/cooperative.mjs +52 -4
  78. package/lib/runtime/evaluate.mjs +115 -2
  79. package/lib/runtime/identity.mjs +22 -0
  80. package/lib/runtime/schema.mjs +19 -0
  81. package/lib/tui/app.mjs +12 -8
  82. package/lib/tui/setup.mjs +5 -8
  83. package/package.json +11 -2
  84. package/scripts/update-manifest.mjs +7 -9
  85. package/claude/skill/hooks/git-policy.json +0 -208
  86. package/claude/skill/hooks/role-git-guard.mjs +0 -18
  87. package/claude/skill/hooks/runtime-gate.mjs +0 -12
  88. package/claude/skill/references/superpowers/brainstorming/visual-companion.md +0 -299
  89. package/codex/skill/hooks/runtime-gate.mjs +0 -10
  90. package/codex/skill/references/superpowers/brainstorming/visual-companion.md +0 -299
  91. package/lib/policy/claude-hook.mjs +0 -80
  92. package/scripts/probe-runtime-hooks.mjs +0 -55
  93. package/scripts/update-superpowers-local.sh +0 -4
  94. /package/claude/skill/references/{superpowers/brainstorming/SKILL.md → brainstorming.md} +0 -0
  95. /package/claude/skill/references/{superpowers/brainstorming/builder-check-prompt.md → builder-check-prompt.md} +0 -0
  96. /package/claude/skill/references/{superpowers/brainstorming/scripts → scripts}/frame-template.html +0 -0
  97. /package/claude/skill/references/{superpowers/brainstorming/scripts → scripts}/helper.js +0 -0
  98. /package/claude/skill/references/{superpowers/brainstorming/scripts → scripts}/server.cjs +0 -0
  99. /package/claude/skill/references/{superpowers/brainstorming/scripts → scripts}/start-server.sh +0 -0
  100. /package/claude/skill/references/{superpowers/brainstorming/scripts → scripts}/stop-server.sh +0 -0
  101. /package/claude/skill/references/{superpowers/LICENSE → superpowers-LICENSE} +0 -0
  102. /package/claude/skill/references/{superpowers/provenance.json → superpowers-provenance.json} +0 -0
  103. /package/claude/skill/references/{superpowers/test-driven-development/SKILL.md → test-driven-development.md} +0 -0
  104. /package/claude/skill/references/{superpowers/test-driven-development/writing-good-tests.md → writing-good-tests.md} +0 -0
  105. /package/claude/skill/references/{superpowers/writing-plans/SKILL.md → writing-plans.md} +0 -0
  106. /package/codex/skill/references/{superpowers/brainstorming/SKILL.md → brainstorming.md} +0 -0
  107. /package/codex/skill/references/{superpowers/brainstorming/builder-check-prompt.md → builder-check-prompt.md} +0 -0
  108. /package/codex/skill/references/{superpowers/brainstorming/scripts → scripts}/frame-template.html +0 -0
  109. /package/codex/skill/references/{superpowers/brainstorming/scripts → scripts}/helper.js +0 -0
  110. /package/codex/skill/references/{superpowers/brainstorming/scripts → scripts}/server.cjs +0 -0
  111. /package/codex/skill/references/{superpowers/brainstorming/scripts → scripts}/start-server.sh +0 -0
  112. /package/codex/skill/references/{superpowers/brainstorming/scripts → scripts}/stop-server.sh +0 -0
  113. /package/codex/skill/references/{superpowers/LICENSE → superpowers-LICENSE} +0 -0
  114. /package/codex/skill/references/{superpowers/provenance.json → superpowers-provenance.json} +0 -0
  115. /package/codex/skill/references/{superpowers/test-driven-development/SKILL.md → test-driven-development.md} +0 -0
  116. /package/codex/skill/references/{superpowers/test-driven-development/writing-good-tests.md → writing-good-tests.md} +0 -0
  117. /package/codex/skill/references/{superpowers/writing-plans/SKILL.md → writing-plans.md} +0 -0
@@ -1,299 +0,0 @@
1
- # Visual Companion Guide
2
-
3
- Browser-based visual brainstorming companion for showing mockups, diagrams, and options.
4
-
5
- ## When to Use
6
-
7
- Decide per-question, not per-session. The test: **would the user understand this better by seeing it than reading it?**
8
-
9
- **Use the browser** when the content itself is visual:
10
-
11
- - **UI mockups** — wireframes, layouts, navigation structures, component designs
12
- - **Architecture diagrams** — system components, data flow, relationship maps
13
- - **Side-by-side visual comparisons** — comparing two layouts, two color schemes, two design directions
14
- - **Design polish** — when the question is about look and feel, spacing, visual hierarchy
15
- - **Spatial relationships** — state machines, flowcharts, entity relationships rendered as diagrams
16
-
17
- **Use the terminal** when the content is text or tabular:
18
-
19
- - **Requirements and scope questions** — "what does X mean?", "which features are in scope?"
20
- - **Conceptual A/B/C choices** — picking between approaches described in words
21
- - **Tradeoff lists** — pros/cons, comparison tables
22
- - **Technical decisions** — API design, data modeling, architectural approach selection
23
- - **Clarifying questions** — anything where the answer is words, not a visual preference
24
-
25
- A question *about* a UI topic is not automatically a visual question. "What kind of wizard do you want?" is conceptual — use the terminal. "Which of these wizard layouts feels right?" is visual — use the browser.
26
-
27
- ## How It Works
28
-
29
- The server watches a directory for HTML files and serves the newest one to the browser. You write HTML content to `screen_dir`, the user sees it in their browser and can click to select options. Selections are recorded to `state_dir/events` that you read on your next turn.
30
-
31
- **Content fragments vs full documents:** If your HTML file starts with `<!DOCTYPE` or `<html`, the server serves it as-is (just injects the helper script). Otherwise, the server automatically wraps your content in the frame template — adding the header, CSS theme, connection status, and all interactive infrastructure. **Write content fragments by default.** Only write full documents when you need complete control over the page.
32
-
33
- ## Starting a Session
34
-
35
- ```bash
36
- # Start AFTER the user approves the companion. --open auto-opens their browser on
37
- # the first screen; --project-dir persists mockups and enables same-port restart.
38
- bash scripts/start-server.sh --project-dir /path/to/project --open
39
-
40
- # Returns: {"type":"server-started","port":52341,
41
- # "url":"http://localhost:52341/?key=ab12…",
42
- # "screen_dir":"/path/to/project/.superpowers/brainstorm/12345-1706000000/content",
43
- # "state_dir":"/path/to/project/.superpowers/brainstorm/12345-1706000000/state"}
44
- ```
45
-
46
- Save `screen_dir` and `state_dir` from the response. With `--open`, the browser opens itself when you push the first screen — you don't need to ask the user to open it, but still share the URL as a fallback (headless/remote setups won't auto-open).
47
-
48
- **The URL contains a session key (`?key=…`).** The server rejects any request
49
- without it, so always give the user the **complete** URL from the `url` field —
50
- never strip the query string, and never hand out a bare `http://host:port`. The
51
- key gates HTTP and WebSocket access so a stray browser tab or another machine on
52
- the network can't read the screens or inject events. After the first load the
53
- browser remembers the key via a cookie, so reloads and `/files/*` assets work
54
- without repeating it.
55
-
56
- **Finding connection info:** The server writes its startup JSON to `$STATE_DIR/server-info`. If you launched the server in the background and didn't capture stdout, read that file to get the URL and port. When using `--project-dir`, check `<project>/.superpowers/brainstorm/` for the session directory.
57
-
58
- **Note:** Pass the project root as `--project-dir` so mockups persist in `.superpowers/brainstorm/` and survive server restarts. Without it, files go to `/tmp` and get cleaned up. Remind the user to add `.superpowers/` to `.gitignore` if it's not already there.
59
-
60
- **Launching the server by platform:**
61
-
62
- **Claude Code:**
63
- ```bash
64
- # Default mode works — the script backgrounds the server itself.
65
- bash scripts/start-server.sh --project-dir /path/to/project --open
66
- ```
67
-
68
- On Windows, the script auto-detects and switches to foreground mode (which blocks the tool call). Use `run_in_background: true` on the Bash tool call so the server survives across conversation turns, then read `$STATE_DIR/server-info` on the next turn to get the URL and port.
69
-
70
- **Codex:**
71
- ```bash
72
- # Codex reaps background processes. The script auto-detects CODEX_CI and
73
- # switches to foreground mode. Run it normally — no extra flags needed.
74
- bash scripts/start-server.sh --project-dir /path/to/project --open
75
- ```
76
-
77
- **Gemini CLI:**
78
- ```bash
79
- # Use --foreground and set is_background: true on your shell tool call
80
- # so the process survives across turns
81
- bash scripts/start-server.sh --project-dir /path/to/project --open --foreground
82
- ```
83
-
84
- **Copilot CLI:**
85
- ```bash
86
- # Start it with Copilot CLI's non-blocking/background shell mechanism so the
87
- # server survives across turns. Keep --foreground so the harness, not the
88
- # script, owns backgrounding. The launcher is a .sh, so invoke it via bash
89
- # (on Windows, call Git Bash's bash.exe from the PowerShell tool).
90
- bash scripts/start-server.sh --project-dir /path/to/project --open --foreground
91
- ```
92
-
93
- **Other environments:** The server must keep running in the background across conversation turns. If your environment reaps detached processes, use `--foreground` and launch the command with your platform's background execution mechanism.
94
-
95
- If the URL is unreachable from your browser (common in remote/containerized setups), bind a non-loopback host:
96
-
97
- ```bash
98
- bash scripts/start-server.sh \
99
- --project-dir /path/to/project \
100
- --host 0.0.0.0 \
101
- --url-host localhost
102
- ```
103
-
104
- Use `--url-host` to control what hostname is printed in the returned URL JSON.
105
-
106
- ## The Loop
107
-
108
- 1. **Check server is alive**, then **write HTML** to a new file in `screen_dir`:
109
- - **Required: confirm the server is alive before referring to the URL or pushing a screen.** Check that `$STATE_DIR/server-info` exists and `$STATE_DIR/server-stopped` does not. If it has shut down, restart it with `start-server.sh` using the **same `--project-dir`** — it reuses the same port, so the user's open tab reconnects on its own (it shows a "paused" overlay while the server is down) and you don't need to send a new URL. The server auto-exits after 4 hours idle (configurable with `--idle-timeout-minutes`).
110
- - Use semantic filenames: `platform.html`, `visual-style.html`, `layout.html`
111
- - **Never reuse filenames** — each screen gets a fresh file
112
- - Use your file-creation tool — **never use cat/heredoc** (dumps noise into terminal)
113
- - Server automatically serves the newest file
114
-
115
- 2. **Tell user what to expect and end your turn:**
116
- - Remind them of the URL (every step, not just first)
117
- - Give a brief text summary of what's on screen (e.g., "Showing 3 layout options for the homepage")
118
- - Ask them to respond in the terminal: "Take a look and let me know what you think. Click to select an option if you'd like."
119
-
120
- 3. **On your next turn** — after the user responds in the terminal:
121
- - Read `$STATE_DIR/events` if it exists — this contains the user's browser interactions (clicks, selections) as JSON lines
122
- - Merge with the user's terminal text to get the full picture
123
- - The terminal message is the primary feedback; `state_dir/events` provides structured interaction data
124
-
125
- 4. **Iterate or advance** — if feedback changes current screen, write a new file (e.g., `layout-v2.html`). Only move to the next question when the current step is validated.
126
-
127
- 5. **Unload when returning to terminal** — when the next step doesn't need the browser (e.g., a clarifying question, a tradeoff discussion), push a waiting screen to clear the stale content:
128
-
129
- ```html
130
- <!-- filename: waiting.html (or waiting-2.html, etc.) -->
131
- <div style="display:flex;align-items:center;justify-content:center;min-height:60vh">
132
- <p class="subtitle">Continuing in terminal...</p>
133
- </div>
134
- ```
135
-
136
- This prevents the user from staring at a resolved choice while the conversation has moved on. When the next visual question comes up, push a new content file as usual.
137
-
138
- 6. Repeat until done.
139
-
140
- ## Writing Content Fragments
141
-
142
- Write just the content that goes inside the page. The server wraps it in the frame template automatically (header, theme CSS, connection status, and all interactive infrastructure).
143
-
144
- **Minimal example:**
145
-
146
- ```html
147
- <h2>Which layout works better?</h2>
148
- <p class="subtitle">Consider readability and visual hierarchy</p>
149
-
150
- <div class="options">
151
- <div class="option" data-choice="a" onclick="toggleSelect(this)">
152
- <div class="letter">A</div>
153
- <div class="content">
154
- <h3>Single Column</h3>
155
- <p>Clean, focused reading experience</p>
156
- </div>
157
- </div>
158
- <div class="option" data-choice="b" onclick="toggleSelect(this)">
159
- <div class="letter">B</div>
160
- <div class="content">
161
- <h3>Two Column</h3>
162
- <p>Sidebar navigation with main content</p>
163
- </div>
164
- </div>
165
- </div>
166
- ```
167
-
168
- That's it. No `<html>`, no CSS, no `<script>` tags needed. The server provides all of that.
169
-
170
- ## CSS Classes Available
171
-
172
- The frame template provides these CSS classes for your content:
173
-
174
- ### Options (A/B/C choices)
175
-
176
- ```html
177
- <div class="options">
178
- <div class="option" data-choice="a" onclick="toggleSelect(this)">
179
- <div class="letter">A</div>
180
- <div class="content">
181
- <h3>Title</h3>
182
- <p>Description</p>
183
- </div>
184
- </div>
185
- </div>
186
- ```
187
-
188
- **Multi-select:** Add `data-multiselect` to the container to let users select multiple options. Each click toggles the item's selected styling.
189
-
190
- ```html
191
- <div class="options" data-multiselect>
192
- <!-- same option markup — users can select/deselect multiple -->
193
- </div>
194
- ```
195
-
196
- ### Cards (visual designs)
197
-
198
- ```html
199
- <div class="cards">
200
- <div class="card" data-choice="design1" onclick="toggleSelect(this)">
201
- <div class="card-image"><!-- mockup content --></div>
202
- <div class="card-body">
203
- <h3>Name</h3>
204
- <p>Description</p>
205
- </div>
206
- </div>
207
- </div>
208
- ```
209
-
210
- ### Mockup container
211
-
212
- ```html
213
- <div class="mockup">
214
- <div class="mockup-header">Preview: Dashboard Layout</div>
215
- <div class="mockup-body"><!-- your mockup HTML --></div>
216
- </div>
217
- ```
218
-
219
- ### Split view (side-by-side)
220
-
221
- ```html
222
- <div class="split">
223
- <div class="mockup"><!-- left --></div>
224
- <div class="mockup"><!-- right --></div>
225
- </div>
226
- ```
227
-
228
- ### Pros/Cons
229
-
230
- ```html
231
- <div class="pros-cons">
232
- <div class="pros"><h4>Pros</h4><ul><li>Benefit</li></ul></div>
233
- <div class="cons"><h4>Cons</h4><ul><li>Drawback</li></ul></div>
234
- </div>
235
- ```
236
-
237
- ### Mock elements (wireframe building blocks)
238
-
239
- ```html
240
- <div class="mock-nav">Logo | Home | About | Contact</div>
241
- <div style="display: flex;">
242
- <div class="mock-sidebar">Navigation</div>
243
- <div class="mock-content">Main content area</div>
244
- </div>
245
- <button class="mock-button">Action Button</button>
246
- <input class="mock-input" placeholder="Input field">
247
- <div class="placeholder">Placeholder area</div>
248
- ```
249
-
250
- ### Typography and sections
251
-
252
- - `h2` — page title
253
- - `h3` — section heading
254
- - `.subtitle` — secondary text below title
255
- - `.section` — content block with bottom margin
256
- - `.label` — small uppercase label text
257
-
258
- ## Browser Events Format
259
-
260
- When the user clicks options in the browser, their interactions are recorded to `$STATE_DIR/events` (one JSON object per line). The file is cleared automatically when you push a new screen.
261
-
262
- ```jsonl
263
- {"type":"click","choice":"a","text":"Option A - Simple Layout","timestamp":1706000101}
264
- {"type":"click","choice":"c","text":"Option C - Complex Grid","timestamp":1706000108}
265
- {"type":"click","choice":"b","text":"Option B - Hybrid","timestamp":1706000115}
266
- ```
267
-
268
- The full event stream shows the user's exploration path — they may click multiple options before settling. The last `choice` event is typically the final selection, but the pattern of clicks can reveal hesitation or preferences worth asking about.
269
-
270
- If `$STATE_DIR/events` doesn't exist, the user didn't interact with the browser — use only their terminal text.
271
-
272
- ## Design Tips
273
-
274
- - **Scale fidelity to the question** — wireframes for layout, polish for polish questions
275
- - **Explain the question on each page** — "Which layout feels more professional?" not just "Pick one"
276
- - **Iterate before advancing** — if feedback changes current screen, write a new version
277
- - **2-4 options max** per screen
278
- - **Use real content when it matters** — for a photography portfolio, use actual images (Unsplash). Placeholder content obscures design issues.
279
- - **Keep mockups simple** — focus on layout and structure, not pixel-perfect design
280
-
281
- ## File Naming
282
-
283
- - Use semantic names: `platform.html`, `visual-style.html`, `layout.html`
284
- - Never reuse filenames — each screen must be a new file
285
- - For iterations: append version suffix like `layout-v2.html`, `layout-v3.html`
286
- - Server serves newest file by modification time
287
-
288
- ## Cleaning Up
289
-
290
- ```bash
291
- bash scripts/stop-server.sh $SESSION_DIR
292
- ```
293
-
294
- If the session used `--project-dir`, mockup files persist in `.superpowers/brainstorm/` for later reference. Only `/tmp` sessions get deleted on stop.
295
-
296
- ## Reference
297
-
298
- - Frame template (CSS reference): `scripts/frame-template.html`
299
- - Helper script (client-side): `scripts/helper.js`
@@ -1,80 +0,0 @@
1
- import path from 'node:path';
2
- import {pathToFileURL} from 'node:url';
3
- // Only this fixed bootstrap is executed. The separately encoded path is data.
4
- const bootstrap="import(Buffer.from(process.argv[1],'base64').toString('utf8')).then(module=>module.runHook()).catch(()=>{process.stderr.write('ARC Git guard failed to load\\n');process.exitCode=2;});";
5
- const prefix=`node -e "eval(Buffer.from('${Buffer.from(bootstrap).toString('base64')}','base64').toString('utf8'))" `;
6
- export function buildClaudeHookCommand(scriptPath) {
7
- if(typeof scriptPath!=='string'||/[\x00-\x1f]/.test(scriptPath)||!path.isAbsolute(scriptPath)&&!path.win32.isAbsolute(scriptPath))throw Error('Claude hook requires an absolute script path');
8
- let url;
9
- if(path.win32.isAbsolute(scriptPath)&&/^[A-Za-z]:[\\/]/.test(scriptPath)) {
10
- const normalized=path.win32.normalize(scriptPath).replaceAll('\\','/');url='file:///'+normalized.split('/').map((part,i)=>i===0?part:encodeURIComponent(part)).join('/');
11
- } else {if(!path.isAbsolute(scriptPath)||path.normalize(scriptPath)!==scriptPath)throw Error('Invalid absolute hook path');url=pathToFileURL(scriptPath).href;}
12
- return prefix+`"${Buffer.from(url).toString('base64')}"`;
13
- }
14
- export const templateHookCommand=buildClaudeHookCommand('/__ARC_INSTALLED_SKILL__/hooks/role-git-guard.mjs');
15
- export function validateClaudeHookCommand(command) {
16
- if(typeof command!=='string'||!command.startsWith(prefix))throw Error('Unmanaged Claude hook command');
17
- const encoded=/^"([A-Za-z0-9+/]+={0,2})"$/.exec(command.slice(prefix.length));if(!encoded)throw Error('Invalid Claude hook command');
18
- const decoded=Buffer.from(encoded[1],'base64');if(decoded.toString('base64')!==encoded[1])throw Error('Invalid hook path encoding');
19
- const url=new URL(decoded.toString('utf8'));if(url.protocol!=='file:'||url.host||!['/hooks/role-git-guard.mjs','/hooks/runtime-gate.mjs'].some(suffix=>url.pathname.endsWith(suffix))||url.search||url.hash)throw Error('Invalid hook file URL');
20
- return command;
21
- }
22
- function entry(command,matcher,eol){
23
- validateClaudeHookCommand(command);
24
- return [` - matcher: ${matcher}`,' hooks:',' - type: command',` command: ${JSON.stringify(command)}`,' onFailure: block'].join(eol);
25
- }
26
- function entries(skillPath,eol){
27
- return entry(buildClaudeHookCommand(path.join(skillPath,'hooks/role-git-guard.mjs')),'Bash',eol);
28
- }
29
- export function hookFrontmatter(command=templateHookCommand,eol='\n') {
30
- validateClaudeHookCommand(command);
31
- return ['hooks:',' PreToolUse:',entry(command,'Bash',eol)].join(eol);
32
- }
33
- function update(text,skillPath,requireManaged){
34
- const eol=/\r?\n/.exec(text)?.[0]??'\n';
35
- const fm=/^---\r?\n([\s\S]*?)\r?\n---(?=\r?\n|$)/.exec(text);
36
- if(!fm)throw Error('Missing Claude frontmatter for hook generation');
37
- let lines=fm[1].split(/\r?\n/);
38
- const headers=lines.flatMap((line,i)=>/^hooks:/.test(line)?[i]:[]);
39
- if(headers.length>1)throw Error('Duplicate Claude hooks');
40
- let count=0;
41
- if(headers.length){
42
- const h=headers[0];if(lines[h]!=='hooks:')throw Error('Malformed Claude hooks');
43
- let end=h+1;while(end<lines.length&&(/^[ \t]/.test(lines[end])||lines[end]===''))end++;
44
- const indexes=[];for(let i=h+1;i<end;i++)if(/^ PreToolUse:/.test(lines[i]))indexes.push(i);
45
- if(indexes.length>1)throw Error('Duplicate PreToolUse');
46
- if(indexes.length){
47
- const pre=indexes[0];if(lines[pre]!==' PreToolUse:')throw Error('Malformed PreToolUse');
48
- let finish=pre+1;while(finish<end&&!/^ \S/.test(lines[finish]))finish++;
49
- const kept=[];const seen=new Set();
50
- for(let i=pre+1;i<finish;){
51
- if(lines[i]===''){kept.push(lines[i++]);continue;}
52
- if(!/^ - /.test(lines[i]))throw Error('Malformed Claude hook entry');
53
- let j=i+1;while(j<finish&&!/^ - /.test(lines[j]))j++;
54
- const chunk=lines.slice(i,j),body=chunk.join('\n');
55
- const commands=chunk.filter(line=>/^ command: /.test(line));
56
- const managed=commands.some(line=>{try{validateClaudeHookCommand(JSON.parse(line.slice(' command: '.length)));return true;}catch{return false;}});
57
- if(managed){
58
- if(commands.length!==1)throw Error('Malformed managed Claude hook');
59
- const command=JSON.parse(commands[0].slice(' command: '.length));
60
- const encoded=/"([A-Za-z0-9+/]+={0,2})"$/.exec(command)[1];const file=new URL(Buffer.from(encoded,'base64').toString('utf8')).pathname.split('/').at(-1);
61
- if(seen.has(file))throw Error('Duplicate managed Claude hook');seen.add(file);count++;
62
- const matcher=file==='runtime-gate.mjs'?' - matcher: "*"':' - matcher: Bash';
63
- const base=[matcher,' hooks:',' - type: command',commands[0]];
64
- // Legacy four-line guard upgrades once; malformed failure behavior is never repaired silently.
65
- if(JSON.stringify(chunk)!==JSON.stringify(base)&&JSON.stringify(chunk)!==JSON.stringify([...base,' onFailure: block']))throw Error('Malformed managed Claude hook');
66
- }else{
67
- if(body.includes(prefix)||/role-git-guard\.mjs|runtime-gate\.mjs/.test(body))throw Error('Malformed managed Claude hook command');
68
- kept.push(...chunk);
69
- }
70
- i=j;
71
- }
72
- lines.splice(pre+1,finish-pre-1,...kept,...entries(skillPath,eol).split(eol));
73
- }else lines.splice(end,0,' PreToolUse:',...entries(skillPath,eol).split(eol));
74
- }else lines.push('hooks:',' PreToolUse:',...entries(skillPath,eol).split(eol));
75
- if(requireManaged&&!count)throw Error('Missing managed Claude hook');
76
- const replacement='---'+eol+lines.join(eol)+eol+'---';
77
- return replacement+text.slice(fm[0].length);
78
- }
79
- export function installClaudeHook(bytes,skillPath){return Buffer.from(update(bytes.toString('utf8'),skillPath,true));}
80
- export function renderSourceClaudeHook(text){return update(text,'/__ARC_INSTALLED_SKILL__',false);}
@@ -1,55 +0,0 @@
1
- import fs from 'node:fs';
2
- import path from 'node:path';
3
- import os from 'node:os';
4
- import {pathToFileURL} from 'node:url';
5
- import {summarizeProbe} from '../lib/runtime/capabilities.mjs';
6
-
7
- // This tool does not install hooks, grant trust, or execute the tool being probed.
8
- // Host-result receipts must be supplied by the trusted probe host after checking
9
- // actual non-execution. A hook-decision receipt alone never verifies denial.
10
- export function writeProbeReceipt(receipt,data,write = fs.writeFileSync) {
11
- let fd;
12
- try {
13
- fd=fs.openSync(receipt,fs.constants.O_WRONLY|fs.constants.O_CREAT|fs.constants.O_EXCL|fs.constants.O_NOFOLLOW,0o600);
14
- write(fd,JSON.stringify(data)+'\n');
15
- } catch(error) {
16
- if(fd !== undefined) fs.unlinkSync(receipt);
17
- throw error;
18
- } finally { if(fd !== undefined) fs.closeSync(fd); }
19
- }
20
-
21
- if(process.argv[1] && import.meta.url === pathToFileURL(path.resolve(process.argv[1])).href) {
22
- try {
23
- const [mode,...args] = process.argv.slice(2);
24
- const options = {};
25
- for(let i=0;i<args.length;i+=2) {
26
- if(!['--platform','--session','--version','--receipt','--attempt','--scratch'].includes(args[i]) || !args[i+1]) throw new Error('Invalid probe options');
27
- options[args[i].slice(2)] = args[i+1];
28
- }
29
- const {platform,session:sessionRef,version:platformVersion,attempt:attemptRef,scratch,receipt} = options;
30
- if(!['codex','claude'].includes(platform) || !sessionRef || !platformVersion || !attemptRef || !receipt || !path.isAbsolute(receipt)) throw new Error('Explicit platform, session, version and absolute scratch receipt required');
31
- if(mode === 'summary') {
32
- const parsed = JSON.parse(fs.readFileSync(receipt,'utf8'));
33
- console.log(JSON.stringify(summarizeProbe(Array.isArray(parsed)?parsed:[parsed],{platform,sessionRef,platformVersion,attemptRef})));
34
- } else if(mode === 'hook') {
35
- const input = JSON.parse(fs.readFileSync(0,'utf8'));
36
- if(input.hook_event_name !== 'PreToolUse' || typeof input.tool_name !== 'string' || !/^[A-Za-z_][A-Za-z0-9_]{0,79}$/.test(input.tool_name)) throw new Error('Only PreToolUse canary requests supported');
37
- if(!scratch || !path.isAbsolute(scratch)) throw new Error('Explicit private scratch directory required');
38
- const realScratch=fs.realpathSync(scratch);
39
- const stat=fs.lstatSync(scratch);
40
- if(stat.isSymbolicLink() || !stat.isDirectory() || (stat.mode & 0o077) !== 0 ||
41
- (typeof process.getuid === 'function' && stat.uid !== process.getuid()) ||
42
- path.dirname(realScratch) !== fs.realpathSync(os.tmpdir()) ||
43
- !path.basename(realScratch).startsWith('arc-runtime-probe-') ||
44
- fs.realpathSync(path.dirname(path.resolve(receipt))) !== realScratch) throw new Error('Receipt must be directly inside private probe scratch');
45
- const data={source:'native',kind:'hook-decision',platform,platformVersion,sessionRef,attemptRef,
46
- event:'PreToolUse',toolPath:input.tool_name,
47
- operation:input.tool_name === 'Agent' ? (platform === 'codex' ? 'spawn_agent' : 'Agent') : null,decision:'deny'};
48
- // Exclusive creation prevents truncation and symlink following. No staging
49
- // file is needed; remove our own new receipt if its write fails.
50
- writeProbeReceipt(receipt,data);
51
- console.log(JSON.stringify({hookSpecificOutput:{hookEventName:'PreToolUse',permissionDecision:'deny',permissionDecisionReason:'ARC scratch canary deny'}}));
52
- } else throw new Error('Expected hook or summary mode');
53
- } catch(error) { console.error(error.message); process.exitCode=1; }
54
-
55
- }
@@ -1,4 +0,0 @@
1
- #!/bin/sh
2
- set -eu
3
- script_dir=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)
4
- exec node "$script_dir/update-superpowers.mjs" "$@"