@yunhozz/arc 0.2.1 → 0.2.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/MANIFEST.sha256 +77 -51
- package/README.md +4 -2
- package/claude/agents/arc-implementer.md +8 -8
- package/claude/agents/arc-planner.md +10 -12
- package/claude/agents/arc-qa.md +7 -7
- package/claude/agents/arc-reviewer.md +6 -6
- package/claude/agents/arc-scouter.md +6 -6
- package/claude/skill/SKILL.md +16 -17
- package/claude/skill/references/arc-visual-companion.md +33 -0
- package/claude/skill/references/commit.md +1 -1
- package/claude/skill/references/coordination.md +23 -39
- package/claude/skill/references/handoff-prep.md +3 -3
- package/claude/skill/references/handoff.md +10 -9
- package/claude/skill/references/limits.md +3 -4
- package/claude/skill/references/planning.md +53 -51
- package/claude/skill/references/verification.md +8 -8
- package/claude/skill/references/visual-companion.md +293 -15
- package/codex/agents/arc-implementer.toml +7 -7
- package/codex/agents/arc-planner.toml +11 -13
- package/codex/agents/arc-qa.toml +7 -7
- package/codex/agents/arc-reviewer.toml +6 -6
- package/codex/agents/arc-scouter.toml +6 -6
- package/codex/skill/SKILL.md +16 -20
- package/codex/skill/references/arc-visual-companion.md +39 -0
- package/codex/skill/references/commit.md +4 -6
- package/codex/skill/references/coordination.md +25 -44
- package/codex/skill/references/git-recovery.md +2 -3
- package/codex/skill/references/handoff-prep.md +4 -4
- package/codex/skill/references/handoff-worktree.md +5 -9
- package/codex/skill/references/handoff.md +15 -18
- package/codex/skill/references/limits.md +3 -4
- package/codex/skill/references/planning.md +56 -55
- package/codex/skill/references/verification.md +13 -15
- package/codex/skill/references/visual-companion.md +290 -18
- package/lib/installer/install.mjs +5 -7
- package/lib/installer/manifest.mjs +23 -8
- package/lib/installer/package-references.mjs +10 -5
- package/lib/installer/plan.mjs +1 -1
- package/lib/installer/superpowers.mjs +26 -1
- package/lib/installer/transaction.mjs +3 -3
- package/lib/installer/upgrade.mjs +2 -9
- package/lib/management/operations.mjs +17 -8
- package/lib/management/update.mjs +19 -10
- package/lib/npm/context.mjs +22 -0
- package/lib/npm/uninstall.mjs +17 -0
- package/lib/npm/upgrade.mjs +25 -0
- package/lib/policy/role-policy.json +9 -9
- package/lib/release/artifact.mjs +6 -4
- package/lib/tui/app.mjs +32 -63
- package/lib/tui/render.mjs +10 -12
- package/lib/tui/setup.mjs +11 -9
- package/lib/tui/terminal.mjs +8 -8
- package/package.json +12 -2
- package/scripts/update-manifest.mjs +7 -9
- package/claude/skill/references/superpowers/brainstorming/visual-companion.md +0 -299
- package/codex/skill/references/superpowers/brainstorming/visual-companion.md +0 -299
- package/lib/tui/workflow.mjs +0 -12
- /package/claude/skill/references/{superpowers/brainstorming/SKILL.md → brainstorming.md} +0 -0
- /package/claude/skill/references/{superpowers/brainstorming/builder-check-prompt.md → builder-check-prompt.md} +0 -0
- /package/claude/skill/references/{superpowers/brainstorming/scripts → scripts}/frame-template.html +0 -0
- /package/claude/skill/references/{superpowers/brainstorming/scripts → scripts}/helper.js +0 -0
- /package/claude/skill/references/{superpowers/brainstorming/scripts → scripts}/server.cjs +0 -0
- /package/claude/skill/references/{superpowers/brainstorming/scripts → scripts}/start-server.sh +0 -0
- /package/claude/skill/references/{superpowers/brainstorming/scripts → scripts}/stop-server.sh +0 -0
- /package/claude/skill/references/{superpowers/LICENSE → superpowers-LICENSE} +0 -0
- /package/claude/skill/references/{superpowers/provenance.json → superpowers-provenance.json} +0 -0
- /package/claude/skill/references/{superpowers/test-driven-development/SKILL.md → test-driven-development.md} +0 -0
- /package/claude/skill/references/{superpowers/test-driven-development/writing-good-tests.md → writing-good-tests.md} +0 -0
- /package/claude/skill/references/{superpowers/writing-plans/SKILL.md → writing-plans.md} +0 -0
- /package/codex/skill/references/{superpowers/brainstorming/SKILL.md → brainstorming.md} +0 -0
- /package/codex/skill/references/{superpowers/brainstorming/builder-check-prompt.md → builder-check-prompt.md} +0 -0
- /package/codex/skill/references/{superpowers/brainstorming/scripts → scripts}/frame-template.html +0 -0
- /package/codex/skill/references/{superpowers/brainstorming/scripts → scripts}/helper.js +0 -0
- /package/codex/skill/references/{superpowers/brainstorming/scripts → scripts}/server.cjs +0 -0
- /package/codex/skill/references/{superpowers/brainstorming/scripts → scripts}/start-server.sh +0 -0
- /package/codex/skill/references/{superpowers/brainstorming/scripts → scripts}/stop-server.sh +0 -0
- /package/codex/skill/references/{superpowers/LICENSE → superpowers-LICENSE} +0 -0
- /package/codex/skill/references/{superpowers/provenance.json → superpowers-provenance.json} +0 -0
- /package/codex/skill/references/{superpowers/test-driven-development/SKILL.md → test-driven-development.md} +0 -0
- /package/codex/skill/references/{superpowers/test-driven-development/writing-good-tests.md → writing-good-tests.md} +0 -0
- /package/codex/skill/references/{superpowers/writing-plans/SKILL.md → writing-plans.md} +0 -0
|
@@ -1,27 +1,299 @@
|
|
|
1
|
-
# Visual
|
|
1
|
+
# Visual Companion Guide
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Browser-based visual brainstorming companion for showing mockups, diagrams, and options.
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## When to Use
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
Decide per-question, not per-session. The test: **would the user understand this better by seeing it than reading it?**
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
and a complete content draft; Planner does not write screens, start a server, operate a browser, or request approval.
|
|
11
|
-
Orchestrator makes a just-in-time offer as its own message only when a question is clearer visually, then waits for
|
|
12
|
-
acceptance. If declined, continue in text and do not offer again unless the user raises it. If accepted, decide per
|
|
13
|
-
question whether to use the companion. Orchestrator owns its guide, server/browser, workspace paths, live-session
|
|
14
|
-
checks, complete keyed URL, screens, session state, feedback/events, stale-screen clearing when returning to text, and
|
|
15
|
-
cleanup. Check the server before showing a screen; after the user's reply, treat terminal text as primary and events as
|
|
16
|
-
supplemental. A UI topic or accepted companion alone does not route every question through a browser.
|
|
9
|
+
**Use the browser** when the content itself is visual:
|
|
17
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
|
|
18
16
|
|
|
19
|
-
|
|
20
|
-
ARC guide: `references/visual-companion.md`; Orchestrator briefs absolute paths and retains approval/server/browser
|
|
21
|
-
ownership. Missing files stop dependent work. MUST NOT use a global fallback.
|
|
17
|
+
**Use the terminal** when the content is text or tabular:
|
|
22
18
|
|
|
23
|
-
|
|
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
24
|
|
|
25
|
-
|
|
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
26
|
|
|
27
|
-
|
|
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,7 +1,7 @@
|
|
|
1
1
|
import {validatePlanSet} from './plan.mjs';
|
|
2
2
|
import {assertPlanSnapshot,applyTransaction} from './transaction.mjs';
|
|
3
3
|
function pending(plan){return{platform:plan.target.platform,status:'not-started',rollback:'not-needed',residualPaths:[],error:null};}
|
|
4
|
-
export async function installTargets(plans,{safeFs,
|
|
4
|
+
export async function installTargets(plans,{safeFs,signal,hooks={}}){
|
|
5
5
|
const ordered=[...plans].sort((a,b)=>(a.target.platform==='codex'?0:1)-(b.target.platform==='codex'?0:1));const results=ordered.map(pending);let interrupted=false;
|
|
6
6
|
let invalid=false;
|
|
7
7
|
for(let index=0;index<ordered.length;index++){
|
|
@@ -14,14 +14,12 @@ export async function installTargets(plans,{safeFs,acquisition,signal,hooks={}})
|
|
|
14
14
|
if(invalid)return{results,interrupted};
|
|
15
15
|
for(let index=0;index<ordered.length;index++){
|
|
16
16
|
const plan=ordered[index];if(signal?.aborted){interrupted=true;break;}
|
|
17
|
-
let
|
|
17
|
+
let failed=false;
|
|
18
18
|
try{
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
hooks.fault?.({phase:'after-acquisition',plan});assertPlanSnapshot(plan,{safeFs});
|
|
22
|
-
const installed=applyTransaction(plan,{safeFs,acquired,signal,hooks});
|
|
19
|
+
assertPlanSnapshot(plan,{safeFs});
|
|
20
|
+
const installed=applyTransaction(plan,{safeFs,signal,hooks});
|
|
23
21
|
results[index]={...results[index],status:'installed',error:installed.cleanupError??null,residualPaths:[...results[index].residualPaths,...(installed.residualPaths??[])]};if(installed.cleanupError)failed=true;
|
|
24
|
-
}catch(error){const cancelled=signal?.aborted||error.code==='
|
|
22
|
+
}catch(error){const cancelled=signal?.aborted||error.code==='ARC_INSTALL_CANCELLED';interrupted=Boolean(cancelled);results[index]={...results[index],status:'failed',rollback:error.rollback??'not-needed',residualPaths:[...results[index].residualPaths,...(error.residualPaths??[])],error};failed=true;}
|
|
25
23
|
if(failed)break;
|
|
26
24
|
}
|
|
27
25
|
return{results,interrupted};
|
|
@@ -1,31 +1,46 @@
|
|
|
1
1
|
import {COOPERATIVE_RUNTIME_MODULES} from '../runtime/bootstrap.mjs';
|
|
2
2
|
import {RUNTIME_MODULE_PATHS} from './runtime-assets.mjs';
|
|
3
3
|
import {POLICY_TARGETS,buildPolicyOutputs} from '../policy/render.mjs';
|
|
4
|
-
import {
|
|
4
|
+
import {validateFlatReferenceFiles,REFERENCE_PATH_MAP} from './superpowers.mjs';
|
|
5
5
|
import path from 'node:path';import crypto from 'node:crypto';import{loadModelConfig,resolveModelSettings,renderProfiles}from '../models/index.mjs';import{readCheckedFile,typeOf,sameIdentity,metadataOf}from './targets.mjs';
|
|
6
6
|
export class PayloadValidationError extends Error{constructor(message,options){super(message,options);this.name='PayloadValidationError';this.code='ARC_PAYLOAD_VALIDATION';}}
|
|
7
7
|
const MUTABLE=new Set(['codex/skill/models.toml','claude/skill/models.toml']);
|
|
8
|
+
export const LOCAL_UPDATER_PATH='scripts/update-superpowers-local.sh';
|
|
8
9
|
const ROOTS=['bin','lib','scripts','vendor','prebuilds','codex/skill','codex/agents','claude/skill','claude/agents'];
|
|
9
10
|
const FIXED=['README.md','install.command','package.json','native/binding.c','native/binding.gyp'];
|
|
10
11
|
function safeName(name){return typeof name==='string'&&name.length>0&&!name.includes('\\')&&!name.includes('\0')&&!name.startsWith('/')&&name.split('/').every(p=>p&&p!=='.'&&p!=='..')&&path.posix.normalize(name)===name;}
|
|
11
12
|
function allowed(name){return FIXED.includes(name)||ROOTS.some(root=>name.startsWith(root+'/'));}
|
|
12
|
-
export function
|
|
13
|
+
export function renderManifest(files){return Buffer.from([...files].filter(([name])=>!MUTABLE.has(name)&&name!==LOCAL_UPDATER_PATH&&!name.split('/').includes('.DS_Store')).sort(([a],[b])=>a<b?-1:a>b?1:0).map(([name,bytes])=>{if(!safeName(name)||!allowed(name)||!Buffer.isBuffer(bytes))throw Error('Invalid protected manifest file');return crypto.createHash('sha256').update(bytes).digest('hex')+' '+name+'\n';}).join(''));}
|
|
14
|
+
const LIFECYCLE_HOOKS=['preinstall','install','postinstall','prepublish','prepare','prepublishOnly','prepack','postpack','publish','postpublish','preuninstall','uninstall','postuninstall'];
|
|
15
|
+
function sourcePayload(root,mode){
|
|
16
|
+
if(!['auto','source','package'].includes(mode))throw Error('Invalid payload mode');if(mode==='package')return false;
|
|
17
|
+
if(mode==='auto'){let marker;try{marker=root.lstat('.git');}catch(error){if(error.code==='ENOENT')return false;throw error;}
|
|
18
|
+
if(typeOf(marker)===0o040000){const directory=root.openDir('.git');try{if(!sameIdentity(marker,directory.stat()))throw Error('Source marker changed');}finally{directory.close();}}
|
|
19
|
+
else if(typeOf(marker)===0o100000){const bytes=readCheckedFile(root,'.git',marker).bytes;let text;try{text=new TextDecoder('utf-8',{fatal:true}).decode(bytes);}catch{throw Error('Invalid source Git marker');}if(!/^gitdir: [^\0\r\n]+\r?\n?$/.test(text))throw Error('Invalid source Git marker');}
|
|
20
|
+
else throw Error('Unsafe source Git marker');
|
|
21
|
+
}
|
|
22
|
+
let pkg,lock;try{pkg=JSON.parse(readCheckedFile(root,'package.json').bytes);lock=JSON.parse(readCheckedFile(root,'package-lock.json').bytes);}catch{throw Error('Source package identity or lock is invalid');}
|
|
23
|
+
const recorded=lock?.packages?.[''];if(pkg?.name!=='@yunhozz/arc'||!/^\d+\.\d+\.\d+$/.test(pkg.version)||lock.name!==pkg.name||lock.version!==pkg.version||recorded?.name!==pkg.name||recorded?.version!==pkg.version||LIFECYCLE_HOOKS.some(name=>Object.hasOwn(pkg.scripts??{},name))||Object.hasOwn(pkg.scripts??{},'build')||Object.hasOwn(pkg,'workspaces')||Object.hasOwn(recorded,'hasInstallScript'))throw Error('Source package identity or lifecycle contract is invalid');return true;
|
|
24
|
+
}
|
|
25
|
+
export function verifyPayload({packageRoot,safeFs,payloadMode='auto'}){
|
|
13
26
|
let root;try{
|
|
14
|
-
root=safeFs.openRoot(packageRoot);const manifest=readCheckedFile(root,'MANIFEST.sha256').bytes;let text;try{text=new TextDecoder('utf-8',{fatal:true}).decode(manifest);}catch{throw Error('Manifest is not UTF-8');}
|
|
15
|
-
const listed=new Map();for(const line of text.split(/\r?\n/)){if(!line)continue;const m=/^([a-fA-F0-9]{64}) (.+)$/.exec(line);if(!m||!safeName(m[2]))throw Error('Malformed or escaping manifest path');const name=m[2];if(MUTABLE.has(name)||
|
|
27
|
+
root=safeFs.openRoot(packageRoot);const source=sourcePayload(root,payloadMode),manifest=readCheckedFile(root,'MANIFEST.sha256').bytes;let text;try{text=new TextDecoder('utf-8',{fatal:true}).decode(manifest);}catch{throw Error('Manifest is not UTF-8');}
|
|
28
|
+
const listed=new Map();for(const line of text.split(/\r?\n/)){if(!line)continue;const m=/^([a-fA-F0-9]{64}) (.+)$/.exec(line);if(!m||!safeName(m[2]))throw Error('Malformed or escaping manifest path');const name=m[2];if(MUTABLE.has(name)||name===LOCAL_UPDATER_PATH||!allowed(name)||name.split('/').includes('.DS_Store')||listed.has(name))throw Error(`Duplicate, mutable or unexpected manifest entry: ${name}`);listed.set(name,m[1].toLowerCase());}
|
|
16
29
|
const files=new Map(),snapshot=new Map(),referenceTrees={};
|
|
17
30
|
function walk(directory,prefix){const before=directory.stat();for(const name of directory.readDir()){
|
|
18
31
|
const relative=prefix?prefix+'/'+name:name;const stat=directory.lstat(name),type=typeOf(stat);
|
|
32
|
+
if(relative===LOCAL_UPDATER_PATH){if(!source)throw Error('Local updater wrapper is forbidden in package payload');if(type!==0o100000||!sameIdentity(stat,directory.lstat(name)))throw Error('Local updater wrapper must be a stable regular file');continue;}
|
|
19
33
|
if(name==='.DS_Store'){if(type!==0o100000)throw Error('DS_Store must be a regular file');continue;}
|
|
20
|
-
if(type===0o040000){const sub=directory.openDir(name);try{if(!sameIdentity(stat,sub.stat()))throw Error('Payload directory changed');snapshot.set(relative,{...metadataOf(stat),type:'directory'});
|
|
34
|
+
if(type===0o040000){const sub=directory.openDir(name);try{if(!sameIdentity(stat,sub.stat()))throw Error('Payload directory changed');snapshot.set(relative,{...metadataOf(stat),type:'directory'});walk(sub,relative);}finally{sub.close();}}
|
|
21
35
|
else if(type===0o100000){const item=readCheckedFile(directory,name,stat);if(!MUTABLE.has(relative)&&(!listed.has(relative)||crypto.createHash('sha256').update(item.bytes).digest('hex')!==listed.get(relative)))throw Error(`Missing entry or hash mismatch: ${relative}`);files.set(relative,item.bytes);snapshot.set(relative,item.metadata);}
|
|
22
36
|
else throw Error(`Unsafe payload type: ${relative}`);
|
|
23
37
|
}if(!sameIdentity(before,directory.stat()))throw Error('Payload directory changed while reading');}
|
|
24
|
-
function select(relative,isTree){const parts=relative.split('/');let parent=root;const opened=[];try{for(const component of parts.slice(0,-1)){let st;try{st=parent.lstat(component);}catch(e){if(e.code==='ENOENT')return;throw e;}if(typeOf(st)!==0o040000)throw Error('Unsafe payload parent');const next=parent.openDir(component);if(!sameIdentity(st,next.stat())){next.close();throw Error('Payload parent changed');}opened.push(next);parent=next;}const name=parts.at(-1);let st;try{st=parent.lstat(name);}catch(e){if(e.code==='ENOENT')return;throw e;}if(isTree){if(typeOf(st)!==0o040000)throw Error('Payload root is not a directory');const sub=parent.openDir(name);try{if(!sameIdentity(st,sub.stat()))throw Error('Payload root changed');snapshot.set(relative,{...metadataOf(st),type:'directory'});
|
|
38
|
+
function select(relative,isTree){const parts=relative.split('/');let parent=root;const opened=[];try{for(const component of parts.slice(0,-1)){let st;try{st=parent.lstat(component);}catch(e){if(e.code==='ENOENT')return;throw e;}if(typeOf(st)!==0o040000)throw Error('Unsafe payload parent');const next=parent.openDir(component);if(!sameIdentity(st,next.stat())){next.close();throw Error('Payload parent changed');}opened.push(next);parent=next;}const name=parts.at(-1);let st;try{st=parent.lstat(name);}catch(e){if(e.code==='ENOENT')return;throw e;}if(isTree){if(typeOf(st)!==0o040000)throw Error('Payload root is not a directory');const sub=parent.openDir(name);try{if(!sameIdentity(st,sub.stat()))throw Error('Payload root changed');snapshot.set(relative,{...metadataOf(st),type:'directory'});walk(sub,relative);}finally{sub.close();}}else{if(typeOf(st)!==0o100000)throw Error('Payload file is not regular');const item=readCheckedFile(parent,name,st);if(!listed.has(relative)||crypto.createHash('sha256').update(item.bytes).digest('hex')!==listed.get(relative))throw Error(`Missing entry or hash mismatch: ${relative}`);files.set(relative,item.bytes);snapshot.set(relative,item.metadata);}}finally{for(const h of opened.reverse())h.close();}}
|
|
25
39
|
for(const item of FIXED)select(item,false);for(const item of ROOTS)select(item,true);
|
|
26
|
-
for(const platform of ['codex','claude'])
|
|
40
|
+
for(const platform of ['codex','claude'])referenceTrees[platform]=validateFlatReferenceFiles(files,platform);
|
|
41
|
+
for(const{destination}of REFERENCE_PATH_MAP)if(!referenceTrees.codex.entries.get(destination).bytes.equals(referenceTrees.claude.entries.get(destination).bytes))throw Error('Imported platform parity mismatch: '+destination);
|
|
27
42
|
for(const name of listed.keys())if(!files.has(name))throw Error(`Manifest entry is missing: ${name}`);
|
|
28
|
-
const required=['claude/skill/hooks/role-git-guard.mjs','claude/skill/hooks/git-policy.json','lib/policy/claude-hook.mjs','lib/policy/role-policy.json','lib/policy/render.mjs','scripts/update-role-policy.mjs','lib/limits.mjs','lib/installer/limits.mjs','lib/installer/runtime-config.mjs','README.md','install.command','package.json','bin/arc.mjs','lib/cli/root.mjs','lib/tui/app.mjs','lib/tui/terminal.mjs','lib/tui/render.mjs','lib/tui/setup.mjs','lib/
|
|
43
|
+
const required=['claude/skill/hooks/role-git-guard.mjs','claude/skill/hooks/git-policy.json','lib/policy/claude-hook.mjs','lib/policy/role-policy.json','lib/policy/render.mjs','scripts/update-role-policy.mjs','lib/limits.mjs','lib/installer/limits.mjs','lib/installer/runtime-config.mjs','README.md','install.command','package.json','bin/arc.mjs','lib/cli/root.mjs','lib/tui/app.mjs','lib/tui/terminal.mjs','lib/tui/render.mjs','lib/tui/setup.mjs','lib/management/operations.mjs','lib/management/status.mjs','lib/management/update.mjs','lib/management/workflow.mjs','lib/cli/postinstall.mjs','scripts/postinstall.mjs','lib/cli/upgrade.mjs','bin/arc-upgrade.mjs','lib/installer/shell-completion.mjs','lib/installer/manifest.mjs','lib/installer/targets.mjs','lib/installer/global-config.mjs','lib/installer/plan.mjs','lib/safe-fs/index.mjs','lib/safe-fs/native.mjs','lib/models/index.mjs','lib/models/config.mjs','lib/models/profiles.mjs','vendor/toml/LICENSE','vendor/toml/package.json','vendor/toml/provenance.json','vendor/toml/dist/index.js','prebuilds/index.json'];
|
|
29
44
|
required.push('lib/installer/runtime-assets.mjs',...RUNTIME_MODULE_PATHS);
|
|
30
45
|
for(const platform of ['codex','claude'])required.push(`${platform}/skill/runtime/role-policy.json`,...RUNTIME_MODULE_PATHS.map(name=>`${platform}/skill/runtime/${name.slice('lib/runtime/'.length)}`));
|
|
31
46
|
for(const tuple of ['darwin-arm64','darwin-x64','linux-arm64-gnu','linux-x64-gnu'])required.push(`prebuilds/${tuple}/arc_safe_fs.node`);
|
|
@@ -4,14 +4,17 @@ import path from 'node:path';
|
|
|
4
4
|
import {openRoot} from '../safe-fs/index.mjs';
|
|
5
5
|
import {loadNative} from '../safe-fs/native.mjs';
|
|
6
6
|
import {acquireExternalSkills} from './acquisition.mjs';
|
|
7
|
-
import {
|
|
7
|
+
import {REFERENCE_PATH_MAP,flattenReferenceBundle} from './superpowers.mjs';
|
|
8
|
+
import {verifyPayload,renderManifest} from './manifest.mjs';
|
|
8
9
|
import {inspectPath} from './targets.mjs';
|
|
9
10
|
import {applyTransaction} from './transaction.mjs';
|
|
10
11
|
|
|
11
12
|
export async function refreshPackageReferences({packageRoot,safeFs,acquisition,signal,hooks={}}){
|
|
12
13
|
if(!safeFs){const native=loadNative({root:packageRoot});safeFs={openRoot:p=>openRoot(p,{native})};}
|
|
13
|
-
const paths=
|
|
14
|
-
|
|
14
|
+
const payload=verifyPayload({packageRoot,safeFs,payloadMode:'source'}),paths=['codex','claude'].flatMap(platform=>REFERENCE_PATH_MAP.map(({destination})=>path.join(packageRoot,platform,'skill/references',destination)));
|
|
15
|
+
paths.push(path.join(packageRoot,'MANIFEST.sha256'));
|
|
16
|
+
const snapshot=new Map([...payload.snapshot].map(([name,item])=>[path.join(packageRoot,name),item]));
|
|
17
|
+
for(const name of ['MANIFEST.sha256','package-lock.json'])inspectPath(safeFs,path.join(packageRoot,name),{kind:'file',snapshot});
|
|
15
18
|
let acquired;
|
|
16
19
|
try{
|
|
17
20
|
if(acquisition)acquired=await acquisition({signal});
|
|
@@ -20,9 +23,11 @@ export async function refreshPackageReferences({packageRoot,safeFs,acquisition,s
|
|
|
20
23
|
try{acquired=await acquireExternalSkills({work,safeFs,signal});}catch(error){if(!error.residualPaths?.length)fs.rmdirSync(work);throw error;}
|
|
21
24
|
const dispose=acquired.dispose;acquired.dispose=async()=>{await dispose();fs.rmdirSync(work);};
|
|
22
25
|
}
|
|
23
|
-
|
|
26
|
+
const flat=flattenReferenceBundle(acquired.references),candidate=new Map(payload.files),specs=[];
|
|
27
|
+
for(const platform of ['codex','claude'])for(const[destination,entry]of flat){const name=platform+'/skill/references/'+destination;candidate.set(name,entry.bytes);specs.push({path:path.join(packageRoot,name),bytes:entry.bytes});}
|
|
28
|
+
specs.push({path:path.join(packageRoot,'MANIFEST.sha256'),bytes:renderManifest(candidate)});
|
|
24
29
|
const plan={target:{home:packageRoot},managedPaths:paths,externalPaths:[],snapshot};
|
|
25
|
-
const result=applyTransaction(plan,{safeFs,signal,hooks,specs
|
|
30
|
+
const result=applyTransaction(plan,{safeFs,signal,hooks,specs});
|
|
26
31
|
if(result.cleanupError)throw result.cleanupError;
|
|
27
32
|
return{...result,provenance:acquired.references.provenance};
|
|
28
33
|
}catch(error){
|
package/lib/installer/plan.mjs
CHANGED
|
@@ -61,7 +61,7 @@ export function buildInstallPlan({payload,target,preset,skipGlobal=false,safeFs,
|
|
|
61
61
|
for(const name of [home,skills,agents])inspectPath(safeFs,name,{kind:'directory',snapshot});
|
|
62
62
|
inspectPath(safeFs,arc,{kind:'directory',tree:true,allowLinks:true,snapshot});
|
|
63
63
|
const profilePaths=target.profileNames.map(name=>path.join(agents,name));for(const name of profilePaths)inspectPath(safeFs,name,{kind:'file',snapshot});
|
|
64
|
-
const externalPaths=[],summary=['
|
|
64
|
+
const externalPaths=[],summary=['Verified packaged Superpowers references will be installed inside ARC'];
|
|
65
65
|
summary.push(`ARC limits: total ${limits.max_total_subagents}; concurrent ${limits.max_concurrent_subagents} (policy: ${arc}/limits.toml)`);
|
|
66
66
|
const globalChanges=renderNativeChanges({target,safeFs,snapshot,skipGlobal,preview,concurrentExplicit,limits,summary,language});
|
|
67
67
|
const managedPaths=[arc,...profilePaths,...(skipGlobal?[]:target.globalPaths)];
|
|
@@ -2,7 +2,7 @@ import path from 'node:path';
|
|
|
2
2
|
import {createHash} from 'node:crypto';
|
|
3
3
|
import {readCheckedFile,sameIdentity,typeOf,metadataOf} from './targets.mjs';
|
|
4
4
|
export const REQUIRED=Object.freeze({
|
|
5
|
-
'brainstorming':['SKILL.md','visual-companion.md','scripts/start-server.sh','scripts/stop-server.sh','scripts/server.cjs','scripts/helper.js','scripts/frame-template.html'],
|
|
5
|
+
'brainstorming':['SKILL.md','visual-companion.md','builder-check-prompt.md','scripts/start-server.sh','scripts/stop-server.sh','scripts/server.cjs','scripts/helper.js','scripts/frame-template.html'],
|
|
6
6
|
'writing-plans':['SKILL.md'],
|
|
7
7
|
'test-driven-development':['SKILL.md','writing-good-tests.md'],
|
|
8
8
|
});
|
|
@@ -10,6 +10,12 @@ export const SKILLS=Object.freeze(Object.keys(REQUIRED));
|
|
|
10
10
|
export const REPOSITORY='https://github.com/obra/superpowers';
|
|
11
11
|
export const DYNAMIC_ROOTS=Object.freeze(['codex','claude'].map(platform=>`${platform}/skill/references/superpowers`));
|
|
12
12
|
export const isDynamicReferencePath=name=>DYNAMIC_ROOTS.some(root=>name===root||name.startsWith(root+'/'));
|
|
13
|
+
export const REFERENCE_PATH_MAP=Object.freeze([
|
|
14
|
+
['brainstorming/SKILL.md','brainstorming.md'],['writing-plans/SKILL.md','writing-plans.md'],['test-driven-development/SKILL.md','test-driven-development.md'],
|
|
15
|
+
['brainstorming/visual-companion.md','visual-companion.md'],['brainstorming/builder-check-prompt.md','builder-check-prompt.md'],['test-driven-development/writing-good-tests.md','writing-good-tests.md'],
|
|
16
|
+
['brainstorming/scripts/start-server.sh','scripts/start-server.sh'],['brainstorming/scripts/stop-server.sh','scripts/stop-server.sh'],['brainstorming/scripts/server.cjs','scripts/server.cjs'],['brainstorming/scripts/helper.js','scripts/helper.js'],['brainstorming/scripts/frame-template.html','scripts/frame-template.html'],
|
|
17
|
+
['LICENSE','superpowers-LICENSE'],['provenance.json','superpowers-provenance.json'],
|
|
18
|
+
].map(([source,destination])=>Object.freeze({source,destination})));
|
|
13
19
|
const hash=bytes=>createHash('sha256').update(bytes).digest('hex');
|
|
14
20
|
function failure(message){throw new Error(message);}
|
|
15
21
|
export function snapshotSkill(root,absolute,required){
|
|
@@ -111,3 +117,22 @@ export function composeArcSkillTree(skillFiles,references){
|
|
|
111
117
|
entries.set('references',{type:'directory',mode:0o700n});entries.set('references/superpowers',{type:'directory',mode:0o700n});
|
|
112
118
|
for(const[name,entry]of references.entries)entries.set('references/superpowers/'+name,{...entry});return entries;
|
|
113
119
|
}
|
|
120
|
+
export function flattenReferenceBundle(bundle){
|
|
121
|
+
validateReferenceBundle(bundle);const allowedFiles=new Set(REFERENCE_PATH_MAP.map(item=>item.source)),allowedDirectories=new Set();
|
|
122
|
+
for(const name of allowedFiles){const parts=name.split('/');for(let i=1;i<parts.length;i++)allowedDirectories.add(parts.slice(0,i).join('/'));}
|
|
123
|
+
for(const[name,entry]of bundle.entries){if(entry.type==='symlink')failure('Unsupported reference link in flat payload');if(entry.type==='file'&&!allowedFiles.has(name)||entry.type==='directory'&&!allowedDirectories.has(name))failure('Unsupported reference file in flat payload');}
|
|
124
|
+
return new Map(REFERENCE_PATH_MAP.map(({source,destination})=>{const entry=bundle.entries.get(source);if(entry?.type!=='file')failure('Required flat reference is missing or not regular');return[destination,{...entry,bytes:Buffer.from(entry.bytes)}];}));
|
|
125
|
+
}
|
|
126
|
+
export function validateFlatReferenceFiles(files,platform){
|
|
127
|
+
if(!(files instanceof Map)||!['codex','claude'].includes(platform))failure('Invalid flat reference input');
|
|
128
|
+
const prefix=platform+'/skill/references/',entries=new Map();
|
|
129
|
+
for(const name of files.keys())if(name.startsWith(prefix+'superpowers/'))failure('Unexpected nested reference payload');
|
|
130
|
+
for(const{source,destination}of REFERENCE_PATH_MAP){const bytes=files.get(prefix+destination);if(!Buffer.isBuffer(bytes))failure('Required flat reference file is missing: '+prefix+destination);const parts=source.split('/');for(let i=1;i<parts.length;i++)entries.set(parts.slice(0,i).join('/'),{type:'directory',mode:0o755n});entries.set(source,{type:'file',bytes,mode:0o644n});}
|
|
131
|
+
let provenance;try{provenance=JSON.parse(entries.get('provenance.json').bytes);}catch{failure('Malformed flat reference provenance');}
|
|
132
|
+
const bundle=validateReferenceBundle({entries,provenance});return{provenance,entries:flattenReferenceBundle(bundle)};
|
|
133
|
+
}
|
|
134
|
+
export function composeStaticArcSkillTree(skillFiles){
|
|
135
|
+
const entries=new Map();
|
|
136
|
+
for(const[name,bytes]of skillFiles){const parts=name.split('/');if(parts.some(part=>!part||part==='.'||part==='..')||name.includes('\\')||name.includes('\0')||name==='references/superpowers'||name.startsWith('references/superpowers/'))failure('Unsafe static ARC path');if(!Buffer.isBuffer(bytes))failure('Invalid static ARC bytes');for(let i=1;i<parts.length;i++)entries.set(parts.slice(0,i).join('/'),{type:'directory',mode:0o700n});entries.set(name,{type:'file',bytes:Buffer.from(bytes),mode:0o600n});}
|
|
137
|
+
return entries;
|
|
138
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {composeStaticArcSkillTree} from './superpowers.mjs';
|
|
2
2
|
import path from 'node:path';
|
|
3
3
|
import {cleanupStage,captureCleanupEntry} from './stage-cleanup.mjs';
|
|
4
4
|
import {randomUUID,createHash} from 'node:crypto';
|
|
@@ -53,13 +53,13 @@ function writeTree(directory,entries){
|
|
|
53
53
|
}
|
|
54
54
|
function snapshotEntry(parent,name){const stat=exists(parent,name);if(!stat)return null;const type=typeOf(stat);if(type===0o100000)return readCheckedFile(parent,name,stat).metadata;if(type===0o120000)return{...metadataOf(stat),type:'symlink',link:parent.readlink(name)};if(type===0o040000){const dir=parent.openDir(name);try{if(!sameObjectIdentity(stat,dir.stat()))fail('Entry directory changed');const entries=treeFromDirectory(dir);const hash=createHash('sha256');for(const[k,v]of entries){hash.update(JSON.stringify([k,v.type,...['dev','ino','mode','size','mtimeNs','ctimeNs'].map(field=>String(v.times[field])),v.bytes?.toString('hex')??v.link??null]));}return{...metadataOf(stat),type:'directory',sha256:hash.digest('hex'),children:captureCleanupEntry(parent,name).children};}finally{dir.close();}}fail('Special target entry');}
|
|
55
55
|
function equalMoved(a,b){return a&&b&&['dev','ino','mode','size','mtimeNs','type','sha256','link'].every(k=>a[k]===b[k]);}
|
|
56
|
-
export function applyTransaction(plan,{safeFs,
|
|
56
|
+
export function applyTransaction(plan,{safeFs,signal,hooks={},specs:explicitSpecs}){
|
|
57
57
|
assertPlanSnapshot(plan,{safeFs});const actions=[],areas=[],parents=[],created=[],actionLog=[],byParent=new Map();
|
|
58
58
|
const cleanAreas=()=>{const paths=[],errors=[];for(const area of areas){const result=cleanupStage(area,{safeFs,hooks:{fault:event=>hooks.fault?.({...event,plan})}});paths.push(...result.residualPaths);if(result.cleanupError)errors.push(result.cleanupError);}return{paths,error:errors.length?Object.assign(new AggregateError(errors,errors.map(error=>error.message).join('; ')),{code:'ARC_INSTALL_CLEANUP',residualPaths:paths}):null};};
|
|
59
59
|
const event=(phase,details={})=>{actionLog.push({phase,...details});if(signal?.aborted)throw new InstallError('Install interrupted','ARC_INSTALL_CANCELLED');hooks.fault?.({phase,...details,plan});};
|
|
60
60
|
try{
|
|
61
61
|
event('before-prepare');
|
|
62
|
-
const specs=explicitSpecs??plan.uninstallSpecs??[
|
|
62
|
+
const specs=explicitSpecs??plan.uninstallSpecs??[{path:plan.target.home+'/skills/arc',tree:composeStaticArcSkillTree(plan.generated.skill)},...[...plan.generated.profiles].map(([name,bytes])=>({path:plan.target.home+'/agents/'+name,bytes})),...plan.globalChanges.map(change=>({path:change.path,bytes:change.content}))];
|
|
63
63
|
for(const spec of specs){if(!spec.remove&&!spec.tree&&!Buffer.isBuffer(spec.bytes))fail('Missing verified staged data');const parent=openParent(safeFs,spec.path,created);parents.push(parent);const name=path.basename(spec.path);event('before-stage',{path:spec.path});let area=byParent.get(path.dirname(spec.path));if(area&&!sameObjectIdentity(parent.stat(),area.parent.stat()))fail('Reused staging parent identity changed','ARC_INSTALL_DRIFT');if(!area){const stageName='.arc-stage-'+randomUUID();parent.mkdir(stageName,0o700);const stage=parent.openDir(stageName);area={parent,stage,name:stageName,path:path.dirname(spec.path)+'/'+stageName,identity:stage.stat(),expected:new Map()};areas.push(area);byParent.set(path.dirname(spec.path),area);}const stage=area.stage,preparedName='prepared-'+actions.length,previousName='previous-'+actions.length,rollbackName='rollback-installed-'+actions.length;
|
|
64
64
|
if(spec.remove){}
|
|
65
65
|
else if(spec.tree){stage.mkdir(preparedName,0o700);const dir=stage.openDir(preparedName);try{writeTree(dir,spec.tree);if(spec.rootMetadata)finishDirectory(dir,spec.rootMetadata.mode,spec.rootMetadata);else dir.sync();}finally{dir.close();}}
|
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
import fs from 'node:fs';
|
|
2
|
-
import os from 'node:os';
|
|
3
|
-
import path from 'node:path';
|
|
4
1
|
import {buildInstallPlan,validatePlanSet} from './plan.mjs';
|
|
5
2
|
import {assertPlanSnapshot} from './transaction.mjs';
|
|
6
3
|
import {inspectPath} from './targets.mjs';
|
|
@@ -8,7 +5,6 @@ import {renderManagedBlock,removeManagedBlock,agentsBlockBody} from './global-co
|
|
|
8
5
|
import {attachShellCompletionCleanup} from './shell-completion.mjs';
|
|
9
6
|
import {verifyPayload} from './manifest.mjs';
|
|
10
7
|
import {installTargets} from './install.mjs';
|
|
11
|
-
import {acquireExternalSkills} from './acquisition.mjs';
|
|
12
8
|
export function buildUpgradePlans({payload,state,safeFs}){
|
|
13
9
|
for(const entry of state.targets)assertPlanSnapshot(entry,{safeFs});
|
|
14
10
|
const plans=state.targets.map(entry=>{
|
|
@@ -22,10 +18,7 @@ export function buildUpgradePlans({payload,state,safeFs}){
|
|
|
22
18
|
attachShellCompletionCleanup(plans,{safeFs});
|
|
23
19
|
validatePlanSet(plans);return plans;
|
|
24
20
|
}
|
|
25
|
-
export async function upgradeInstalledTargets({packageRoot,state,safeFs,signal
|
|
21
|
+
export async function upgradeInstalledTargets({packageRoot,state,safeFs,signal}){
|
|
26
22
|
const payload=verifyPayload({packageRoot,safeFs}),version=JSON.parse(payload.files.get('package.json').toString('utf8')).version,plans=buildUpgradePlans({payload,state,safeFs});
|
|
27
|
-
|
|
28
|
-
try{acquired=await acquireExternalSkills({work,safeFs,signal});}catch(error){if(!error.residualPaths?.length)try{fs.rmdirSync(work);}catch(cleanup){throw Object.assign(new AggregateError([error,cleanup],'Cannot clean private acquisition work'),{code:'ARC_ACQUISITION_CLEANUP',residualPaths:[work]});}throw error;}
|
|
29
|
-
return{...acquired,dispose:async()=>{await acquired.dispose();fs.rmdirSync(work);}};});
|
|
30
|
-
return{version,...await installTargets(plans,{safeFs,signal,acquisition:acquire})};
|
|
23
|
+
return{version,...await installTargets(plans,{safeFs,signal})};
|
|
31
24
|
}
|