joycraft 0.7.16 → 1.0.0
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 +137 -156
- package/dist/cli.js +1593 -373
- package/dist/cli.js.map +1 -1
- package/dist/index.d.ts +4 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -1
- package/dist/joycraft-release.json +1 -1
- package/package.json +9 -3
- package/payload/.agents/skills/joycraft-context/SKILL.md +36 -0
- package/payload/.agents/skills/joycraft-decompose/SKILL.md +68 -0
- package/payload/.agents/skills/joycraft-entry/SKILL.md +103 -0
- package/payload/.agents/skills/joycraft-implement/SKILL.md +106 -0
- package/payload/.agents/skills/joycraft-retro/SKILL.md +54 -0
- package/payload/.agents/skills/joycraft-retro/agents/openai.yaml +5 -0
- package/payload/.agents/skills/joycraft-session-end/SKILL.md +78 -0
- package/payload/.agents/skills/joycraft-testing/SKILL.md +60 -0
- package/payload/.agents/skills/joycraft-ui-slice/SKILL.md +59 -0
- package/payload/.agents/skills/joycraft-ui-slice/scripts/serve.mjs +97 -0
- package/payload/.agents/skills/joycraft-verify/SKILL.md +103 -0
- package/payload/.claude/agents/joycraft-implementer.md +31 -0
- package/payload/.claude/agents/joycraft-reviewer.md +30 -0
- package/payload/.joycraft/assets/artifacts/kit.css +102 -0
- package/payload/.joycraft/assets/artifacts/kit.js +301 -0
- package/payload/.joycraft/assets/artifacts/transports.js +236 -0
- package/payload/.joycraft/contracts/types.d.ts +185 -0
- package/payload/.joycraft/references/architecture.md +90 -0
- package/payload/.joycraft/references/archive.md +211 -0
- package/payload/.joycraft/references/artifacts.md +176 -0
- package/payload/.joycraft/references/completion.md +109 -0
- package/payload/.joycraft/references/context.md +80 -0
- package/payload/.joycraft/references/delivery.md +32 -0
- package/payload/.joycraft/references/dispatch.md +226 -0
- package/payload/.joycraft/references/recurring-failures.md +33 -0
- package/payload/.joycraft/references/retro.md +94 -0
- package/payload/.joycraft/references/setup.md +279 -0
- package/payload/.joycraft/references/testing.md +120 -0
- package/payload/.joycraft/references/update.md +44 -0
- package/payload/.joycraft/references/workflow.md +113 -0
- package/payload/.joycraft/references/worktrees.md +148 -0
- package/payload/.joycraft/runtime/archive.mjs +463 -0
- package/payload/.joycraft/runtime/artifacts/cli.mjs +61 -0
- package/payload/.joycraft/runtime/artifacts/decisions.mjs +214 -0
- package/payload/.joycraft/runtime/artifacts/model.mjs +161 -0
- package/payload/.joycraft/runtime/artifacts/preferences.mjs +127 -0
- package/payload/.joycraft/runtime/artifacts/render.mjs +21 -0
- package/payload/.joycraft/runtime/artifacts/server.mjs +40 -0
- package/payload/.joycraft/runtime/completion.mjs +300 -0
- package/payload/.joycraft/runtime/context/cli.mjs +75 -0
- package/payload/.joycraft/runtime/context/index.mjs +29 -0
- package/payload/.joycraft/runtime/context/search.mjs +149 -0
- package/payload/.joycraft/runtime/delivery.mjs +142 -0
- package/payload/.joycraft/runtime/dispatch-preflight.mjs +535 -0
- package/payload/.joycraft/runtime/dispatch-start.mjs +98 -0
- package/payload/.joycraft/runtime/evidence.mjs +137 -0
- package/payload/.joycraft/runtime/identity.mjs +486 -0
- package/payload/.joycraft/runtime/kickoff.mjs +174 -0
- package/payload/.joycraft/runtime/redact.mjs +9 -0
- package/payload/.joycraft/runtime/retro.mjs +151 -0
- package/payload/.joycraft/runtime/review-tools.json +34 -0
- package/payload/.joycraft/runtime/review-tools.mjs +331 -0
- package/payload/.joycraft/runtime/scope.mjs +129 -0
- package/payload/.joycraft/runtime/update-check.mjs +142 -0
- package/payload/.joycraft/templates/README.md +7 -0
- package/payload/.joycraft/templates/artifact.json +33 -0
- package/payload/.joycraft/templates/brief.md +35 -0
- package/payload/.joycraft/templates/decisions.md +13 -0
- package/payload/.joycraft/templates/project-context.md +36 -0
- package/payload/.joycraft/templates/queue.json +27 -0
- package/payload/.joycraft/templates/spec.md +39 -0
- package/payload/.joycraft/templates/ui-slice.html +71 -0
- package/payload/PIN +74 -0
- package/payload/scripts/export.mjs +301 -0
- package/payload/scripts/hook-paths.mjs +35 -0
- package/payload/scripts/legacy-hooks.mjs +128 -0
- package/payload/scripts/legacy-inventory.json +117 -0
- package/dist/chunk-35RQLGKM.js +0 -2167
- package/dist/chunk-35RQLGKM.js.map +0 -1
- package/dist/chunk-7BPB2IKY.js +0 -255
- package/dist/chunk-7BPB2IKY.js.map +0 -1
- package/dist/chunk-B73DPYYC.js +0 -377
- package/dist/chunk-B73DPYYC.js.map +0 -1
- package/dist/chunk-GTP7Z52K.js +0 -3942
- package/dist/chunk-GTP7Z52K.js.map +0 -1
- package/dist/chunk-K4AI6FKB.js +0 -417
- package/dist/chunk-K4AI6FKB.js.map +0 -1
- package/dist/chunk-KKDKC4FM.js +0 -115
- package/dist/chunk-KKDKC4FM.js.map +0 -1
- package/dist/chunk-OMFGDJW4.js +0 -97
- package/dist/chunk-OMFGDJW4.js.map +0 -1
- package/dist/chunk-Z5JFEGWG.js +0 -563
- package/dist/chunk-Z5JFEGWG.js.map +0 -1
- package/dist/init-MUB5CC6L.js +0 -60
- package/dist/init-MUB5CC6L.js.map +0 -1
- package/dist/init-autofix-2DMBO4QN.js +0 -122
- package/dist/init-autofix-2DMBO4QN.js.map +0 -1
- package/dist/install-manifest-EQHT4474.js +0 -37
- package/dist/install-manifest-EQHT4474.js.map +0 -1
- package/dist/release-artifact-4TL5L2ZY.js +0 -14
- package/dist/release-artifact-4TL5L2ZY.js.map +0 -1
- package/dist/release-resolver-P2H46QTU.js +0 -293
- package/dist/release-resolver-P2H46QTU.js.map +0 -1
- package/dist/telemetry-store-IBO5GRTA.js +0 -14
- package/dist/telemetry-store-IBO5GRTA.js.map +0 -1
- package/dist/update-LFLQTPUA.js +0 -19
- package/dist/update-LFLQTPUA.js.map +0 -1
- package/dist/update-check-YT765NE7.js +0 -36
- package/dist/update-check-YT765NE7.js.map +0 -1
- package/dist/upgrade-L5WERK4X.js +0 -28
- package/dist/upgrade-L5WERK4X.js.map +0 -1
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
---
|
|
2
|
+
feature: example-feature
|
|
3
|
+
decisions: [
|
|
4
|
+
{"id":"presentation","status":"open","question":"Which presentation fits your task?","answer":null,"options":[{"value":"rows","label":"Compact rows"},{"value":"cards","label":"Visual cards"}],"affected":["collection-presentation"]}
|
|
5
|
+
]
|
|
6
|
+
---
|
|
7
|
+
# Feature intent
|
|
8
|
+
|
|
9
|
+
Replace this example with the user's full request, retaining repairs and new
|
|
10
|
+
behavior together. Link existing briefs when they already own part of the scope.
|
|
11
|
+
|
|
12
|
+
## Context and authorization
|
|
13
|
+
|
|
14
|
+
Link relevant existing decisions/facts and record the authorization already given.
|
|
15
|
+
Keep assumptions explicit. Remove the example decision when no choice is needed.
|
|
16
|
+
|
|
17
|
+
## Goals
|
|
18
|
+
|
|
19
|
+
- Describe each requested outcome with a stable heading below, and give each a
|
|
20
|
+
**Done when** line: example inputs or states with their expected results. For
|
|
21
|
+
a rule over open-ended input, also name the check set, which error costs more,
|
|
22
|
+
and the pass threshold.
|
|
23
|
+
|
|
24
|
+
## Agent work and pending choices
|
|
25
|
+
|
|
26
|
+
Name understood work that can continue and the decision IDs blocking other work.
|
|
27
|
+
|
|
28
|
+
## collection-presentation
|
|
29
|
+
|
|
30
|
+
After the choice is saved above, describe its requirement here and reference the
|
|
31
|
+
decision ID. This heading is the stable source for an affected queue criterion.
|
|
32
|
+
|
|
33
|
+
## Scope and limits
|
|
34
|
+
|
|
35
|
+
Record relevant exclusions without replacing the user's goals.
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# Decision log
|
|
2
|
+
|
|
3
|
+
Copy to `docs/context/decision-log.md` during a kickoff when there is at least
|
|
4
|
+
one decision. One entry per decision, newest first. A feature brief still owns
|
|
5
|
+
its current decisions; this log keeps the reasons that outlive one feature.
|
|
6
|
+
|
|
7
|
+
## <Decision title>
|
|
8
|
+
|
|
9
|
+
- **Status:** decided | proposed | not established
|
|
10
|
+
- **Decision:** what was chosen, or the preference the user stated.
|
|
11
|
+
- **Why:** the user's reason, quoted where possible.
|
|
12
|
+
- **Rejected:** the options considered and why they lost.
|
|
13
|
+
- **Source:** [kickoff notes](kickoff-notes.md) or the brief that owns it.
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# <Project name>
|
|
2
|
+
|
|
3
|
+
Copy to `docs/context/project.md` during a kickoff. Delete every section that
|
|
4
|
+
has no content yet; never leave a placeholder. Mark each statement as the
|
|
5
|
+
user's words, a decision, or an assumption.
|
|
6
|
+
|
|
7
|
+
## Vision
|
|
8
|
+
|
|
9
|
+
What the user wants to exist and why, in two to five sentences. Quote the
|
|
10
|
+
user's own phrasing for the core idea.
|
|
11
|
+
|
|
12
|
+
## Users
|
|
13
|
+
|
|
14
|
+
Who uses it, what they are trying to do, and who else has a stake.
|
|
15
|
+
|
|
16
|
+
## First outcome
|
|
17
|
+
|
|
18
|
+
The first result that counts as done. The first brief owns its "Done when";
|
|
19
|
+
link it here.
|
|
20
|
+
|
|
21
|
+
## Non-goals
|
|
22
|
+
|
|
23
|
+
What this project will not do, as the user stated it.
|
|
24
|
+
|
|
25
|
+
## Glossary
|
|
26
|
+
|
|
27
|
+
| Term | Meaning, in the user's words |
|
|
28
|
+
|---|---|
|
|
29
|
+
|
|
30
|
+
## Open questions
|
|
31
|
+
|
|
32
|
+
Consequential unknowns that are not decided yet. Do not write them as boundaries.
|
|
33
|
+
|
|
34
|
+
## Sources
|
|
35
|
+
|
|
36
|
+
- [Kickoff notes](kickoff-notes.md): the user's verbatim words.
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
{
|
|
2
|
+
"schemaVersion": 1,
|
|
3
|
+
"feature": "example-feature",
|
|
4
|
+
"specs": [
|
|
5
|
+
{
|
|
6
|
+
"id": 1,
|
|
7
|
+
"file": "01-outcome.md",
|
|
8
|
+
"depends_on": [],
|
|
9
|
+
"status": "todo",
|
|
10
|
+
"mode": "batch",
|
|
11
|
+
"execution": { "parallel": false },
|
|
12
|
+
"verification": {
|
|
13
|
+
"inputs": [
|
|
14
|
+
{ "path": "docs/features/example-feature/brief.md", "kind": "requirement" },
|
|
15
|
+
{ "path": "docs/features/example-feature/specs/01-outcome.md", "kind": "requirement" }
|
|
16
|
+
],
|
|
17
|
+
"criteria": [
|
|
18
|
+
{
|
|
19
|
+
"id": "outcome",
|
|
20
|
+
"requirement": { "path": "docs/features/example-feature/specs/01-outcome.md", "anchor": "acceptance" },
|
|
21
|
+
"requiredKinds": ["runtime"]
|
|
22
|
+
}
|
|
23
|
+
]
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
]
|
|
27
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
---
|
|
2
|
+
id: 1
|
|
3
|
+
status: todo
|
|
4
|
+
---
|
|
5
|
+
# Outcome
|
|
6
|
+
|
|
7
|
+
State one testable authorized outcome. Link the parent brief and any decisions
|
|
8
|
+
that constrain it; a material open decision cannot be assumed resolved.
|
|
9
|
+
|
|
10
|
+
## acceptance
|
|
11
|
+
|
|
12
|
+
Describe observable behavior, representative state and failure behavior. End
|
|
13
|
+
each bullet with `Check:` naming a concrete input or state, the expected result,
|
|
14
|
+
and the command or test that shows it. Reference the source requirement instead
|
|
15
|
+
of copying open decisions here; quote settled rulings with their ID.
|
|
16
|
+
|
|
17
|
+
For a rule over open-ended input (names, documents, classifications), add an
|
|
18
|
+
**Open-input rule** line: the closed check set (path), which error costs more,
|
|
19
|
+
and the pass threshold.
|
|
20
|
+
|
|
21
|
+
## Not covered
|
|
22
|
+
|
|
23
|
+
Accepted limits and cases this spec deliberately leaves out.
|
|
24
|
+
|
|
25
|
+
## Implementation and verification scope
|
|
26
|
+
|
|
27
|
+
List the relevant implementation, test/configuration and fixture paths and needed
|
|
28
|
+
evidence. For a change crossing a state, data, or responsibility boundary, name
|
|
29
|
+
the owning and coupled sources plus an observable scenario that distinguishes the
|
|
30
|
+
intended behavior from a stale or mismatched path. Omit that detail for a simple
|
|
31
|
+
local edit. Keep the queue's exact verification inputs current as work reveals
|
|
32
|
+
them.
|
|
33
|
+
|
|
34
|
+
## Deferred until deploy
|
|
35
|
+
|
|
36
|
+
List checks that only a deployed environment can show, such as a preview or
|
|
37
|
+
production URL, live webhooks, DNS, real email or payment delivery, or production
|
|
38
|
+
data. They are not verification criteria and do not block review; the owner
|
|
39
|
+
checks them after deploy. Omit this section when there are none.
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<meta charset="utf-8">
|
|
4
|
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
5
|
+
<title>Try a small slice</title>
|
|
6
|
+
<style>
|
|
7
|
+
*{box-sizing:border-box}body{margin:0;background:#f4f5f2;color:#192b26;font:16px/1.45 system-ui,sans-serif}main{max-width:940px;margin:auto;padding:24px}header{display:flex;align-items:baseline;gap:16px;justify-content:space-between}h1{font-size:20px;margin:0}small{color:#53645d}iframe{display:block;width:100%;height:360px;border:1px solid #d4ded6;border-radius:16px;background:white;margin:18px 0}fieldset{border:0;padding:0;margin:0}legend{font-weight:650;margin-bottom:10px}.options{display:flex;gap:8px;flex-wrap:wrap}label{padding:9px 12px;border:1px solid #aebbb3;border-radius:10px;cursor:pointer;background:white}input{accent-color:#176444;margin-right:7px}button{border:0;background:#176444;color:white;border-radius:10px;padding:11px 18px;font:inherit;font-weight:600;cursor:pointer}button:disabled{opacity:.55;cursor:default}.actions{display:flex;gap:14px;align-items:center;margin:14px 0 8px}#notice{font-size:14px;margin:0}details{font-size:13px;color:#53645d}summary{cursor:pointer}pre{white-space:pre-wrap}#error{color:#97361e}@media(max-width:520px){main{padding:16px}header{display:block}iframe{height:390px;margin:12px 0}.actions{align-items:flex-start;flex-direction:column;gap:8px}}
|
|
8
|
+
</style>
|
|
9
|
+
<main>
|
|
10
|
+
<header><h1>Try a small slice</h1><small>One choice, then keep building</small></header>
|
|
11
|
+
<iframe id="preview" title="Product preview" sandbox="allow-scripts"></iframe>
|
|
12
|
+
<form id="choice-form">
|
|
13
|
+
<fieldset><legend id="question">Loading choice…</legend><div class="options" id="options"></div></fieldset>
|
|
14
|
+
<div class="actions"><button id="save" disabled>Save choice</button><p id="notice" role="status" aria-live="polite"></p></div>
|
|
15
|
+
</form>
|
|
16
|
+
<p id="error" role="alert"></p>
|
|
17
|
+
<details><summary>Context and affected work</summary><p>This explores a choice within your request. Saving updates the feature brief; production work follows its authorized scope.</p><pre id="context"></pre></details>
|
|
18
|
+
</main>
|
|
19
|
+
<script>
|
|
20
|
+
const token = __REQUEST_TOKEN__;
|
|
21
|
+
const form = document.querySelector('#choice-form'), options = document.querySelector('#options');
|
|
22
|
+
const save = document.querySelector('#save'), notice = document.querySelector('#notice'), error = document.querySelector('#error');
|
|
23
|
+
let current, selected;
|
|
24
|
+
function preview(){document.querySelector('#preview').src = '/slice?choice=' + encodeURIComponent(selected)}
|
|
25
|
+
function render(state){
|
|
26
|
+
const previous = current;
|
|
27
|
+
current = state;
|
|
28
|
+
if(!state.decision){
|
|
29
|
+
document.querySelector('#question').textContent = 'All choices are settled.';
|
|
30
|
+
options.replaceChildren(); save.disabled = true;
|
|
31
|
+
notice.textContent = 'The current brief has no unanswered choices.';
|
|
32
|
+
document.querySelector('#context').textContent = 'Read the current brief for settled decisions.';
|
|
33
|
+
document.querySelector('#preview').removeAttribute('src');
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
const decision = state.decision, editable = ['open','assigned'].includes(decision.status);
|
|
37
|
+
const preserveDraft = previous && previous.decision && previous.decision.id === decision.id && decision.options.some(option => option.value === selected);
|
|
38
|
+
selected = preserveDraft ? selected : decision.answer ?? decision.options[0].value;
|
|
39
|
+
document.querySelector('#question').textContent = decision.question;
|
|
40
|
+
options.replaceChildren();
|
|
41
|
+
for(const option of decision.options){
|
|
42
|
+
const label = document.createElement('label'), input = document.createElement('input');
|
|
43
|
+
input.type = 'radio'; input.name = 'choice'; input.value = option.value; input.checked = selected === option.value; input.disabled = !editable;
|
|
44
|
+
input.addEventListener('change',()=>{selected = option.value; preview(); notice.textContent = 'Preview only — save when it fits.'});
|
|
45
|
+
label.append(input, document.createTextNode(option.label)); options.append(label);
|
|
46
|
+
}
|
|
47
|
+
save.disabled = !editable;
|
|
48
|
+
notice.textContent = decision.status === 'clarified' ? 'Saved in the brief. Ready to continue.' : editable ? 'Preview only — no answer saved yet.' : 'Outside current scope. Reopen in the brief to revisit.';
|
|
49
|
+
document.querySelector('#context').textContent = 'Decision: ' + decision.id + '\nAffected: ' + (decision.affected.join(', ') || 'None listed');
|
|
50
|
+
preview();
|
|
51
|
+
}
|
|
52
|
+
form.addEventListener('submit', async event=>{
|
|
53
|
+
event.preventDefault(); save.disabled = true; error.textContent = '';
|
|
54
|
+
try{
|
|
55
|
+
const response = await fetch('/answer',{method:'POST',headers:{'Content-Type':'application/json','X-Slice-Token':token},body:JSON.stringify({id:current.decision.id,answer:selected,revision:current.revision})});
|
|
56
|
+
const result = await response.json();
|
|
57
|
+
if(!response.ok) throw new Error(result.error);
|
|
58
|
+
render(result);
|
|
59
|
+
}catch(problem){error.textContent = problem.message + ' Reload to read the current brief.'}
|
|
60
|
+
});
|
|
61
|
+
async function refresh(){
|
|
62
|
+
try{
|
|
63
|
+
const response = await fetch('/state'), state = await response.json();
|
|
64
|
+
if(!response.ok) throw new Error(state.error);
|
|
65
|
+
if(!current || state.revision !== current.revision) render(state);
|
|
66
|
+
}catch(problem){error.textContent = problem.message}
|
|
67
|
+
}
|
|
68
|
+
refresh();
|
|
69
|
+
setInterval(refresh, 1000);
|
|
70
|
+
</script>
|
|
71
|
+
</html>
|
package/payload/PIN
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
{
|
|
2
|
+
"schemaVersion": 1,
|
|
3
|
+
"source": "joycraft-prototype",
|
|
4
|
+
"tag": "field-7",
|
|
5
|
+
"commit": "df3df23ef782cea2cadbe14933fc4db760ea382c",
|
|
6
|
+
"files": {
|
|
7
|
+
".agents/skills/joycraft-context/SKILL.md": "e0a5f7d82fe8b6b6d3aeab38f7cf570ca939dba07034243af1ef86d24448c084",
|
|
8
|
+
".agents/skills/joycraft-decompose/SKILL.md": "a24c9d9cf2dc7af4b99ad67575b64b9d0c99818044f7fafc3a5243dc4c557b5f",
|
|
9
|
+
".agents/skills/joycraft-entry/SKILL.md": "c8985b43fcd225fbea7622290a83a8d1a994ed19a057634b69d1d7c0324dee56",
|
|
10
|
+
".agents/skills/joycraft-implement/SKILL.md": "49e6b65936649bca22a7862045235538704acfe23e49f415ba1c919c10e2cbde",
|
|
11
|
+
".agents/skills/joycraft-retro/SKILL.md": "156f36cb047604c734bf273bd02822d964b6af86619ed6c2a30fa6d79eb9a986",
|
|
12
|
+
".agents/skills/joycraft-retro/agents/openai.yaml": "f0eb4732261635f41e08f0bbe9a931d62fd8ac645149d3406e6fc7e16a81750b",
|
|
13
|
+
".agents/skills/joycraft-session-end/SKILL.md": "c2d2282e8fed0edfb91db9042380ec9902cddb32cf140a3b6e4e5ee8e227de0e",
|
|
14
|
+
".agents/skills/joycraft-testing/SKILL.md": "89e983b285099c38821dc807311b27d450e6dec9fb691cd687ca74332b091157",
|
|
15
|
+
".agents/skills/joycraft-ui-slice/SKILL.md": "fcb5f109c9bd23d4afe5b47d19c90fd34485754ce9061c64bce1ae2ce0376484",
|
|
16
|
+
".agents/skills/joycraft-ui-slice/scripts/serve.mjs": "c16858800b6fbe6f7a3a21b21e785ad70c9a89a3fe970bc08701fefeac5042fa",
|
|
17
|
+
".agents/skills/joycraft-verify/SKILL.md": "cce30cf1ee39b6a6aa0211a661660ef9be9ec55bb83650456ddac0bac0037274",
|
|
18
|
+
".claude/agents/joycraft-implementer.md": "11281faae296097ea8f5d8780629dc83b6a918830eab8c252d665b1653a34338",
|
|
19
|
+
".claude/agents/joycraft-reviewer.md": "e54107707d453aba73e6acbb4ef1d26b4ad89291183abec7d8ea49a520aed9d5",
|
|
20
|
+
".joycraft/assets/artifacts/kit.css": "9b04b739b3b137d4a3052a939cbc46b5acb9abde085989bd599481ae40e5c6a9",
|
|
21
|
+
".joycraft/assets/artifacts/kit.js": "e54db2157cfee278f5e6777b6b6fe2d2f5297cd2401b173d1a4b72e3fad00562",
|
|
22
|
+
".joycraft/assets/artifacts/transports.js": "e53c67ac030a1d7c9ce4666b998604a471598cb4df08bc83f37e3d166b8017eb",
|
|
23
|
+
".joycraft/contracts/types.d.ts": "5c4e654ea929778c586bc6cce44e60dc031578b2414dd1b8161359cf9f424b41",
|
|
24
|
+
".joycraft/references/architecture.md": "52eaaa4b88053481c9f8cad2418ea0f1db880184c3a50c95901f30f24be75852",
|
|
25
|
+
".joycraft/references/archive.md": "d421e17ed3724fc1dacc9f3397a50d7976329d5dfb5e274791931df5544d5be4",
|
|
26
|
+
".joycraft/references/artifacts.md": "1f21223601342f4ce54c4d76320f89f4eea1c8d0089396495993ba62155f422e",
|
|
27
|
+
".joycraft/references/completion.md": "7df48664861f41e2e503a828e97d6b6f615745591a3f47f17d196fa4d24a122d",
|
|
28
|
+
".joycraft/references/context.md": "22967383c85e36153b57ed301b51f0a5fed9ccd0a1114226ade6d88b81076215",
|
|
29
|
+
".joycraft/references/delivery.md": "1afc417ee3922ebf5e84c0ae87796d6cb6305679c0257ed38a35f396949de5e8",
|
|
30
|
+
".joycraft/references/dispatch.md": "9368b93f35af7271718136c256f325cefc459d428e3aba445fc650d57370484b",
|
|
31
|
+
".joycraft/references/recurring-failures.md": "7080f6c55492bc19c2897f4f0b128a830a71cdb516678c79ff6e97ffa1dc6b86",
|
|
32
|
+
".joycraft/references/retro.md": "f359eae19747777fb4687c1bc7eb280f0319ae629ee62913346e60fc56551562",
|
|
33
|
+
".joycraft/references/setup.md": "39642785bd205e7663914bf186c8747878c6763da408b1ce004123f55bbae755",
|
|
34
|
+
".joycraft/references/testing.md": "064edc82feb4c29485e9b5d9fbc5140d1f908d77006963482445ae1e4793fc2f",
|
|
35
|
+
".joycraft/references/update.md": "8e26ddaa21d3b133902bebcb6662a16f52f3ae3f04c51c69fdb325a8e9c0aeac",
|
|
36
|
+
".joycraft/references/workflow.md": "1e982310f98cb61749ff921f96c7aa2da52fcd3df4eb444608216fbf6e126a53",
|
|
37
|
+
".joycraft/references/worktrees.md": "00c151b62d433bc7aecb669ba17795c1011e3bc18828b9cb63c506d83bd852bc",
|
|
38
|
+
".joycraft/runtime/archive.mjs": "44a2953e60af1aa231f4b8affba3d51058b58bc025a72ae1affdbe7c3182f9d1",
|
|
39
|
+
".joycraft/runtime/artifacts/cli.mjs": "d30152e6829e07d9c7ff6ceedbfa6813931674d8529778f62b0d64e3a4049ab0",
|
|
40
|
+
".joycraft/runtime/artifacts/decisions.mjs": "9cba81346daf59cd020b8d976af98b1f6c2aec8d0a1575e5e0f806334ae622d0",
|
|
41
|
+
".joycraft/runtime/artifacts/model.mjs": "fbe44d37049759387ecc02ba2580c94e26e6c5cb8cac3dcbcc79aeab3b75756b",
|
|
42
|
+
".joycraft/runtime/artifacts/preferences.mjs": "9165e1c753aa8533affe976cacecb135b0ee3cc9f455f5f80b1568103bb49fd6",
|
|
43
|
+
".joycraft/runtime/artifacts/render.mjs": "488673cab94fa6bfde223c2c41650f8e183f7ac0be3840d371ee057d95ea0fa5",
|
|
44
|
+
".joycraft/runtime/artifacts/server.mjs": "a96048fad649e8053c70ce95c5a757929ab57ae9de27198121224326551c0a05",
|
|
45
|
+
".joycraft/runtime/completion.mjs": "11635b11eb7df90398a69b6d41f96d9c7b9d2dc2255ae4a4a129562d46572ec1",
|
|
46
|
+
".joycraft/runtime/context/cli.mjs": "40adc206c8c3b7f4f5bedffb097d9ae1b0718f0586a055796e4987e9c3088eee",
|
|
47
|
+
".joycraft/runtime/context/index.mjs": "5a69d33d9a1a66ef23301e952ecb1ec427ff4b0baf408ede67a2600d3f2a173c",
|
|
48
|
+
".joycraft/runtime/context/search.mjs": "e7f48d8ada52574ddca22d0eaee5ce2a405c4074910879e47c01ca287bba52b4",
|
|
49
|
+
".joycraft/runtime/delivery.mjs": "4fe897714eec33b24003f0d69abe1522a5199193ab7333fa6421776ee048df1c",
|
|
50
|
+
".joycraft/runtime/dispatch-preflight.mjs": "1b8283c06c8a2a41bfca06b1d5f0f83a093825911fbab1e04657dee06fa91c5d",
|
|
51
|
+
".joycraft/runtime/dispatch-start.mjs": "e7879d20348c1e442c7f586eadabf99abf3c52df34b0d352664797d06d0c4d96",
|
|
52
|
+
".joycraft/runtime/evidence.mjs": "80a386dd6d81e5fd32c64e53d5fb089072bc28f36df6c4f6c924077dd064604b",
|
|
53
|
+
".joycraft/runtime/identity.mjs": "f5a10dd58f2dd259502b04eaa2af42d2a74a09614e097a6efc35104c80bba024",
|
|
54
|
+
".joycraft/runtime/kickoff.mjs": "9d96998bff94662863182b9a922f26732c649b7a0b0130b6da7d63ec73eb3590",
|
|
55
|
+
".joycraft/runtime/redact.mjs": "cc8c0fe5e8d8fe78116ef126f6eee757a247739084e19c342bcf09a2b06524bc",
|
|
56
|
+
".joycraft/runtime/retro.mjs": "6f3664b0d50c12d4f2d8eef4b4d0d62897939d03e45860d4dcf35c0f5f92677c",
|
|
57
|
+
".joycraft/runtime/review-tools.json": "e4bc5ba2e0f6ab71a8af90a6f225f4655b9c1e7ee13d9303bd6e219002547a96",
|
|
58
|
+
".joycraft/runtime/review-tools.mjs": "17c13f7ab746478bce5711501a5190991b46616c849780196614950cfc6f0208",
|
|
59
|
+
".joycraft/runtime/scope.mjs": "e2cdd929596246bf24e18850698db440119badc7068a3c5beab03ded45abbd65",
|
|
60
|
+
".joycraft/runtime/update-check.mjs": "324b2eda4ac1feb6bb5b15ef488bea5f2f8a6312bc7b1c24719e0b7fd6a84634",
|
|
61
|
+
".joycraft/templates/README.md": "56a166d0729e8b6c3bcb098afb8145006259357087fd8b1f1f343d9a2b4d36e0",
|
|
62
|
+
".joycraft/templates/artifact.json": "fda5f7c32516d6ab094ee0e8506d84a1a0d6d4d0f49048b01aa392c619996f05",
|
|
63
|
+
".joycraft/templates/brief.md": "03479342500570aba9fb206beef6f6049fd180bec814dd8001987174aecfef25",
|
|
64
|
+
".joycraft/templates/decisions.md": "49e0c9b3efe51d1c2e87345fcefe23ef0579e524d50febef8ef43a35141c8002",
|
|
65
|
+
".joycraft/templates/project-context.md": "d7c81fee08609a7db45c5df0cb2bd5cb3409760169d8b03cc5f19b1ff82d03c2",
|
|
66
|
+
".joycraft/templates/queue.json": "88f922b6cc47b80befc27df86a143d6bae0b30869c46d712958b64291e5ebcc2",
|
|
67
|
+
".joycraft/templates/spec.md": "5f4b1490c2ba2e47ced1ef5b369fe3e41386eb61386c42c7a561b1e8af02ea5e",
|
|
68
|
+
".joycraft/templates/ui-slice.html": "0c3cf45709ff37815f8f0550b4b9431cb935589b282d40e8688b310a91de2274",
|
|
69
|
+
"scripts/export.mjs": "016d675b19ba3122468ce34817b8a9c444be919aa4ec583842cd9bc16d299243",
|
|
70
|
+
"scripts/hook-paths.mjs": "fed8a147a9bf6501bfda1e4c7f015b41947277920dc2bf49c23ad826cfb0c724",
|
|
71
|
+
"scripts/legacy-hooks.mjs": "d44f841e28d10b0a6aacf999bdd3e8bcec0feb742fa18c7459d6265d1d4776ba",
|
|
72
|
+
"scripts/legacy-inventory.json": "92455cceac13cc8bd27a0cbd5c16df71a44a82bf7a18280f5ba05b5dde2908ba"
|
|
73
|
+
}
|
|
74
|
+
}
|
|
@@ -0,0 +1,301 @@
|
|
|
1
|
+
import { createHash, randomUUID } from 'node:crypto';
|
|
2
|
+
import { cp, lstat, mkdir, readFile, readdir, rename, rm, writeFile } from 'node:fs/promises';
|
|
3
|
+
import { execFileSync } from 'node:child_process';
|
|
4
|
+
import { dirname, join, relative, resolve } from 'node:path';
|
|
5
|
+
import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
6
|
+
import { applyLegacyHooks, planLegacyHooks } from './legacy-hooks.mjs';
|
|
7
|
+
import { relativePath } from '../.joycraft/runtime/identity.mjs';
|
|
8
|
+
|
|
9
|
+
export const installationManifestPath = '.joycraft/installation.json';
|
|
10
|
+
const mutableBundlePaths = new Set(['.joycraft/hooks-config.json', installationManifestPath]);
|
|
11
|
+
// Project-owned state shares the .joycraft/ directory with the bundle; it is never exported or replaced.
|
|
12
|
+
const projectOwned = path => /^\.joycraft\/(local\/|preferences\.json$|state\.json$)/.test(path);
|
|
13
|
+
export const previousBundleDir = '.joycraft-prototype';
|
|
14
|
+
const managedHookFiles = ['.claude/settings.json', '.codex/hooks.json', '.github/hooks/joycraft.json'];
|
|
15
|
+
const legacySkillNames = ['add-context', 'add-fact', 'bugfix', 'collaborative-setup', 'decide', 'decompose', 'design', 'gather-context', 'harden', 'implement-feature', 'implement-level5', 'implement', 'interview', 'lockdown', 'new-feature', 'optimize', 'research', 'session-end', 'setup', 'spec-done', 'tune', 'verify'];
|
|
16
|
+
const legacyDiscoveryPaths = ['.agents/skills/joycraft', '.claude/skills/joycraft', '.codex/skills/joycraft', '.agents/commands/joycraft', '.claude/commands/joycraft', '.codex/commands/joycraft', ...['.agents/skills', '.claude/skills', '.github/skills', '.pi/skills', '.omp/skills'].flatMap(root => legacySkillNames.map(name => `${root}/joycraft-${name}`)), '.pi/scripts/joycraft'];
|
|
17
|
+
const sha256 = bytes => createHash('sha256').update(bytes).digest('hex');
|
|
18
|
+
|
|
19
|
+
async function statOrNull(path) {
|
|
20
|
+
try { return await lstat(path); }
|
|
21
|
+
catch (error) { if (error.code === 'ENOENT') return null; throw error; }
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
async function filesUnder(root, relative) {
|
|
25
|
+
const path = join(root, relative);
|
|
26
|
+
const stat = await lstat(path);
|
|
27
|
+
if (stat.isSymbolicLink()) throw new Error(`Symlink in bundle: ${relative}`);
|
|
28
|
+
if (stat.isFile()) return [relative];
|
|
29
|
+
if (!stat.isDirectory()) throw new Error(`Unsupported bundle entry: ${relative}`);
|
|
30
|
+
const names = (await readdir(path)).sort();
|
|
31
|
+
const files = [];
|
|
32
|
+
for (const name of names) files.push(...await filesUnder(root, join(relative, name)));
|
|
33
|
+
return files;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
async function checkDestination(target, relative) {
|
|
37
|
+
const rootStat = await statOrNull(target);
|
|
38
|
+
if (rootStat && (!rootStat.isDirectory() || rootStat.isSymbolicLink())) {
|
|
39
|
+
throw new Error('Target must be a directory, not a symlink');
|
|
40
|
+
}
|
|
41
|
+
const parts = relative.split('/');
|
|
42
|
+
for (let count = 1; count < parts.length; count += 1) {
|
|
43
|
+
const path = join(target, ...parts.slice(0, count));
|
|
44
|
+
const stat = await statOrNull(path);
|
|
45
|
+
if (stat && (!stat.isDirectory() || stat.isSymbolicLink())) {
|
|
46
|
+
throw new Error(`Destination parent is not a plain directory: ${path}`);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
const path = join(target, relative);
|
|
50
|
+
const stat = await statOrNull(path);
|
|
51
|
+
if (stat && (!stat.isFile() || stat.isSymbolicLink())) {
|
|
52
|
+
throw new Error(`Destination is not a plain file: ${path}`);
|
|
53
|
+
}
|
|
54
|
+
return stat;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// Exact generated files from a pinned upstream revision. Other releases and
|
|
58
|
+
// local modifications remain conflicts rather than assumed ownership.
|
|
59
|
+
const legacyInventory = JSON.parse(await readFile(new URL('./legacy-inventory.json', import.meta.url), 'utf8'));
|
|
60
|
+
const isKnownLegacySkill = (path, bytes) => legacyInventory.files[path] === sha256(bytes);
|
|
61
|
+
|
|
62
|
+
async function readInstallationManifest(target) {
|
|
63
|
+
await checkDestination(target, installationManifestPath);
|
|
64
|
+
let text;
|
|
65
|
+
try { text = await readFile(join(target, installationManifestPath), 'utf8'); }
|
|
66
|
+
catch (error) { if (error.code === 'ENOENT') return null; throw error; }
|
|
67
|
+
let manifest;
|
|
68
|
+
try { manifest = JSON.parse(text); } catch { throw new Error('Invalid Joycraft installation manifest; review it before using --upgrade'); }
|
|
69
|
+
if (manifest?.schemaVersion !== 1 || !Array.isArray(manifest.files)
|
|
70
|
+
|| manifest.files.some(entry => !entry || typeof entry.path !== 'string' || !/^[a-f0-9]{64}$/.test(entry.sha256))) {
|
|
71
|
+
throw new Error('Unsupported Joycraft installation manifest; review it before using --upgrade');
|
|
72
|
+
}
|
|
73
|
+
const entries = new Map();
|
|
74
|
+
for (const entry of manifest.files) {
|
|
75
|
+
if (relativePath(entry.path) !== entry.path || entries.has(entry.path)) throw new Error('Unsafe or duplicate installation manifest path');
|
|
76
|
+
entries.set(entry.path, entry.sha256);
|
|
77
|
+
}
|
|
78
|
+
return entries;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
async function prepareBackup(target, backupRoot) {
|
|
82
|
+
const ignored = join(backupRoot, '.gitignore');
|
|
83
|
+
await checkDestination(target, relative(target, ignored));
|
|
84
|
+
await mkdir(backupRoot, { recursive: true, mode: 0o700 });
|
|
85
|
+
await writeFile(ignored, '*\n', { flag: 'wx', mode: 0o600 });
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
async function backupFile(target, path, bytes, backupRoot) {
|
|
89
|
+
const backup = join(backupRoot, path);
|
|
90
|
+
await checkDestination(target, relative(target, backup));
|
|
91
|
+
await mkdir(dirname(backup), { recursive: true, mode: 0o700 });
|
|
92
|
+
await writeFile(backup, bytes, { flag: 'wx', mode: 0o600 });
|
|
93
|
+
return relative(target, backup);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
async function legacyPlan(target, installed, canonicalDestinations) {
|
|
97
|
+
const archive = []; const conflicts = [];
|
|
98
|
+
for (const path of legacyDiscoveryPaths) {
|
|
99
|
+
const parts = path.split('/'); let unsafe = false;
|
|
100
|
+
for (let count = 1; count < parts.length; count += 1) { const parent = await statOrNull(join(target, ...parts.slice(0, count))); if (parent?.isSymbolicLink() || (parent && !parent.isDirectory())) { unsafe = true; break; } }
|
|
101
|
+
if (unsafe) { conflicts.push({ path, reason: 'legacy discovery parent is not a plain directory' }); continue; }
|
|
102
|
+
const stat = await statOrNull(join(target, path));
|
|
103
|
+
if (!stat) continue;
|
|
104
|
+
if (stat.isSymbolicLink()) { conflicts.push({ path, reason: 'symlinked legacy discovery path' }); continue; }
|
|
105
|
+
if (!stat.isDirectory()) { conflicts.push({ path, reason: 'legacy discovery path is not a directory' }); continue; }
|
|
106
|
+
const entries = await readdir(join(target, path));
|
|
107
|
+
const skillPath = `${path}/SKILL.md`;
|
|
108
|
+
const skillStat = entries.length === 1 && entries[0] === 'SKILL.md' ? await lstat(join(target, skillPath)) : null;
|
|
109
|
+
const skillBytes = skillStat?.isFile() && !skillStat.isSymbolicLink() ? await readFile(join(target, skillPath)) : null;
|
|
110
|
+
// A byte-verified installed skill owned by this export is current bundle
|
|
111
|
+
// content, not an unknown legacy directory merely because names overlap.
|
|
112
|
+
if (skillBytes && canonicalDestinations.has(skillPath) && installed?.get(skillPath) === sha256(skillBytes)) continue;
|
|
113
|
+
const known = skillBytes && isKnownLegacySkill(skillPath, skillBytes);
|
|
114
|
+
if (!known) conflicts.push({ path, reason: 'contains bytes not in the pinned legacy inventory' });
|
|
115
|
+
else archive.push(path);
|
|
116
|
+
}
|
|
117
|
+
return { archive, conflicts };
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/** Move an install from the pre-1.0 `.joycraft-prototype/` directory to `.joycraft/`, once.
|
|
121
|
+
* Backs up the old directory first, never touches `.joycraft/local/` or other project-owned
|
|
122
|
+
* state, and refuses to replace a different file. A second run finds nothing to move. */
|
|
123
|
+
export async function migrateBundleDir(targetRoot, { check = false, stamp = new Date().toISOString().replace(/[:.]/g, '-') } = {}) {
|
|
124
|
+
const target = resolve(targetRoot);
|
|
125
|
+
const old = join(target, previousBundleDir);
|
|
126
|
+
const oldStat = await statOrNull(old);
|
|
127
|
+
if (!oldStat) return { moved: [], hookFiles: [], backup: null };
|
|
128
|
+
if (!oldStat.isDirectory() || oldStat.isSymbolicLink()) throw new Error(`${previousBundleDir} is not a plain directory`);
|
|
129
|
+
const moved = (await filesUnder(target, previousBundleDir)).map(path => ({ from: path, to: `.joycraft/${path.slice(previousBundleDir.length + 1)}` }));
|
|
130
|
+
for (const { from, to } of moved) {
|
|
131
|
+
if (projectOwned(to)) throw new Error(`${from} would replace project state at ${to}; move it by hand`);
|
|
132
|
+
await checkDestination(target, to);
|
|
133
|
+
const existing = await statOrNull(join(target, to));
|
|
134
|
+
if (existing && !(await readFile(join(target, to))).equals(await readFile(join(target, from)))) throw new Error(`Both ${from} and a different ${to} exist; reconcile them before upgrading`);
|
|
135
|
+
}
|
|
136
|
+
const hookFiles = [];
|
|
137
|
+
for (const file of managedHookFiles) {
|
|
138
|
+
const text = (await statOrNull(join(target, file))) ? await readFile(join(target, file), 'utf8') : null;
|
|
139
|
+
if (text?.includes(`${previousBundleDir}/`)) hookFiles.push(file);
|
|
140
|
+
}
|
|
141
|
+
if (check) return { moved, hookFiles, backup: null };
|
|
142
|
+
const backup = join('.joycraft-backups', `bundle-dir-${stamp}`);
|
|
143
|
+
await prepareBackup(target, join(target, backup));
|
|
144
|
+
await cp(old, join(target, backup, previousBundleDir), { recursive: true, errorOnExist: true, force: false });
|
|
145
|
+
for (const file of hookFiles) {
|
|
146
|
+
await mkdir(dirname(join(target, backup, file)), { recursive: true });
|
|
147
|
+
await cp(join(target, file), join(target, backup, file));
|
|
148
|
+
// Only Joycraft's own launcher names the bundle directory; user hooks keep their bytes.
|
|
149
|
+
await writeFile(join(target, file), (await readFile(join(target, file), 'utf8')).replaceAll(`${previousBundleDir}/`, '.joycraft/'));
|
|
150
|
+
}
|
|
151
|
+
for (const { from, to } of moved) {
|
|
152
|
+
await mkdir(dirname(join(target, to)), { recursive: true });
|
|
153
|
+
await rename(join(target, from), join(target, to));
|
|
154
|
+
}
|
|
155
|
+
const manifest = join(target, installationManifestPath);
|
|
156
|
+
if (await statOrNull(manifest)) {
|
|
157
|
+
const text = await readFile(manifest, 'utf8');
|
|
158
|
+
await writeFile(manifest, text.replaceAll(`"${previousBundleDir}/`, '".joycraft/'));
|
|
159
|
+
}
|
|
160
|
+
await rm(old, { recursive: true });
|
|
161
|
+
return { moved, hookFiles, backup };
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/** Copy the explicit public bundle only. Never replace a different user file. */
|
|
165
|
+
export async function exportBundle({ sourceRoot, targetRoot, check = false, hooks = false, harness = 'codex', upgrade = false }) {
|
|
166
|
+
if (!['codex', 'claude', 'pi', 'omp', 'github-copilot', 'opencode'].includes(harness)) throw new Error('Unknown harness');
|
|
167
|
+
const source = resolve(sourceRoot);
|
|
168
|
+
const target = resolve(targetRoot);
|
|
169
|
+
if (source === target) throw new Error('Source and target must differ');
|
|
170
|
+
const bundleMove = upgrade ? await migrateBundleDir(target, { check }) : null;
|
|
171
|
+
const files = (await filesUnder(source, '.joycraft')).filter(path => !mutableBundlePaths.has(path) && !projectOwned(path));
|
|
172
|
+
const skillsPath = join(source, '.agents/skills');
|
|
173
|
+
const skillsStat = await statOrNull(skillsPath);
|
|
174
|
+
if (skillsStat) {
|
|
175
|
+
if (!skillsStat.isDirectory() || skillsStat.isSymbolicLink()) throw new Error('Invalid skills directory');
|
|
176
|
+
for (const name of (await readdir(skillsPath)).sort()) {
|
|
177
|
+
if (/^joycraft-[a-z0-9-]+$/.test(name)) {
|
|
178
|
+
files.push(...await filesUnder(source, join('.agents/skills', name)));
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
// Claude Code gets the generic implementer and reviewer agent types.
|
|
183
|
+
if (harness === 'claude' && (await statOrNull(join(source, '.claude/agents')))?.isDirectory()) {
|
|
184
|
+
for (const name of (await readdir(join(source, '.claude/agents'))).sort()) {
|
|
185
|
+
if (/^joycraft-[a-z0-9-]+\.md$/.test(name)) files.push(...await filesUnder(source, join('.claude/agents', name)));
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
files.sort();
|
|
189
|
+
const destinationPath = path => harness === 'claude' ? path.replace(/^\.agents\/skills\//, '.claude/skills/') : path;
|
|
190
|
+
const bundleBytes = async path => {
|
|
191
|
+
const bytes = await readFile(join(source, path));
|
|
192
|
+
return harness === 'claude' && path.endsWith('.md') ? Buffer.from(bytes.toString('utf8').replaceAll('.agents/skills/', '.claude/skills/')) : bytes;
|
|
193
|
+
};
|
|
194
|
+
// Native hooks are optional; their installer loads only when hooks are requested.
|
|
195
|
+
const hookInstaller = hooks ? await import('./install-hooks.mjs') : null;
|
|
196
|
+
if (hooks && !files.includes(hookInstaller.hookRuntimePath)) throw new Error('The source bundle has no hook runtime');
|
|
197
|
+
const installed = await readInstallationManifest(target);
|
|
198
|
+
const legacy = upgrade ? await legacyPlan(target, installed, new Set(files.map(destinationPath))) : { archive: [], conflicts: [] };
|
|
199
|
+
const legacyHooks = upgrade ? await planLegacyHooks({ targetRoot: target }) : null;
|
|
200
|
+
if (legacyHooks?.conflicts.length) throw new Error(`Legacy native hooks need reconciliation before upgrade: ${legacyHooks.conflicts.map(item => item.path).join(', ')}`);
|
|
201
|
+
const pending = [];
|
|
202
|
+
const replacements = [];
|
|
203
|
+
for (const relative of files) {
|
|
204
|
+
const path = destinationPath(relative);
|
|
205
|
+
const stat = await checkDestination(target, path);
|
|
206
|
+
const wanted = await bundleBytes(relative);
|
|
207
|
+
if (!stat) pending.push({ relative, path, wanted });
|
|
208
|
+
else {
|
|
209
|
+
const actual = await readFile(join(target, path));
|
|
210
|
+
if (!wanted.equals(actual)) {
|
|
211
|
+
const known = installed?.get(path) === sha256(actual) || (!installed && isKnownLegacySkill(path, actual));
|
|
212
|
+
if (!upgrade || !known) throw new Error(`Refusing to replace existing file: ${relative}${upgrade ? ' (it is not a recognized prior Joycraft file)' : ''}`);
|
|
213
|
+
replacements.push({ relative, path, wanted, actual });
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
const adapters = hooks ? hookInstaller.hookAdapters(harness) : [];
|
|
218
|
+
for (const adapter of adapters) {
|
|
219
|
+
const stat = await checkDestination(target, adapter.path); const wanted = await readFile(join(source, adapter.source));
|
|
220
|
+
if (!stat) pending.push({ relative: adapter.source, path: adapter.path, wanted });
|
|
221
|
+
else { const actual = await readFile(join(target, adapter.path)); if (!wanted.equals(actual)) {
|
|
222
|
+
const known = installed?.get(adapter.path) === sha256(actual);
|
|
223
|
+
if (!upgrade || !known) throw new Error(`Refusing to replace existing adapter: ${adapter.path}`);
|
|
224
|
+
replacements.push({ relative: adapter.source, path: adapter.path, wanted, actual });
|
|
225
|
+
} }
|
|
226
|
+
}
|
|
227
|
+
let sourceRevision = 'unavailable';
|
|
228
|
+
try { sourceRevision = execFileSync('git', ['rev-parse', 'HEAD'], { cwd: source, encoding: 'utf8', stdio: ['ignore', 'pipe', 'ignore'] }).trim(); } catch {}
|
|
229
|
+
const manifestFiles = await Promise.all(files.map(async relative => ({ path: destinationPath(relative), sha256: sha256(await bundleBytes(relative)) })));
|
|
230
|
+
const adapterFiles = [];
|
|
231
|
+
for (const adapter of adapters) adapterFiles.push({ path: adapter.path, sha256: sha256(await readFile(join(source, adapter.source))) });
|
|
232
|
+
const manifest = { schemaVersion: 1, sourceRevision, harness, files: [...manifestFiles, ...adapterFiles], legacyConflicts: legacy.conflicts };
|
|
233
|
+
manifest.files.sort((a, b) => a.path.localeCompare(b.path));
|
|
234
|
+
const manifestBytes = Buffer.from(`${JSON.stringify(manifest, null, 2)}\n`);
|
|
235
|
+
const manifestStat = await statOrNull(join(target, installationManifestPath));
|
|
236
|
+
const hooksPlan = hooks && !['pi', 'omp', 'opencode'].includes(harness) ? await hookInstaller.planCodexHooks({ targetRoot: target, harness }) : null;
|
|
237
|
+
const backupRoot = join(target, '.joycraft-backups', `upgrade-${new Date().toISOString().replace(/[:.]/g, '-')}-${randomUUID()}`);
|
|
238
|
+
legacy.archive = legacy.archive.filter(path => !manifest.files.some(file => file.path.startsWith(`${path}/`)));
|
|
239
|
+
if (!check) {
|
|
240
|
+
if (replacements.length || legacy.archive.length || legacyHooks?.backups.length) await prepareBackup(target, backupRoot);
|
|
241
|
+
for (const { path, wanted } of pending) {
|
|
242
|
+
const destination = join(target, path);
|
|
243
|
+
await checkDestination(target, path);
|
|
244
|
+
await mkdir(dirname(destination), { recursive: true });
|
|
245
|
+
await writeFile(destination, wanted, { flag: 'wx' });
|
|
246
|
+
}
|
|
247
|
+
for (const { path, wanted, actual } of replacements) {
|
|
248
|
+
const destination = join(target, path);
|
|
249
|
+
if (!(await readFile(destination)).equals(actual)) throw new Error(`Destination changed during upgrade: ${path}; rerun the preview`);
|
|
250
|
+
await backupFile(target, path, actual, backupRoot);
|
|
251
|
+
await writeFile(destination, wanted);
|
|
252
|
+
}
|
|
253
|
+
for (const path of legacy.archive) {
|
|
254
|
+
const sourcePath = join(target, path); const destination = join(backupRoot, 'legacy-discovery', path);
|
|
255
|
+
await mkdir(dirname(destination), { recursive: true }); await rename(sourcePath, destination);
|
|
256
|
+
}
|
|
257
|
+
const previousManifest = manifestStat ? await readFile(join(target, installationManifestPath)) : null;
|
|
258
|
+
if (!previousManifest || !previousManifest.equals(manifestBytes)) {
|
|
259
|
+
await checkDestination(target, installationManifestPath);
|
|
260
|
+
await mkdir(dirname(join(target, installationManifestPath)), { recursive: true });
|
|
261
|
+
const temp = join(target, '.joycraft', `installation.${randomUUID()}.tmp`);
|
|
262
|
+
await writeFile(temp, manifestBytes, { flag: 'wx' });
|
|
263
|
+
await rename(temp, join(target, installationManifestPath));
|
|
264
|
+
}
|
|
265
|
+
if (hooksPlan) await hookInstaller.applyCodexHooks(hooksPlan);
|
|
266
|
+
if (legacyHooks) {
|
|
267
|
+
const currentLegacyHooks = await planLegacyHooks({ targetRoot: target });
|
|
268
|
+
if (currentLegacyHooks.conflicts.length) throw new Error('Legacy hooks changed during upgrade; reconcile them before continuing');
|
|
269
|
+
await applyLegacyHooks(currentLegacyHooks, { backupRoot });
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
return { check, harness, files: manifest.files.map(entry => entry.path), added: pending.map(item => item.path), replaced: replacements.map(item => item.path), archivedLegacyDiscovery: legacy.archive, legacyConflicts: legacy.conflicts, unchanged: manifest.files.length - pending.length - replacements.length, manifest: installationManifestPath,
|
|
273
|
+
...(legacyHooks ? { legacyHooks } : {}),
|
|
274
|
+
...(bundleMove?.moved.length ? { bundleMove } : {}),
|
|
275
|
+
...(replacements.length ? { backups: check ? replacements.map(item => item.path) : replacements.map(item => relative(target, join(backupRoot, item.path))) } : {}),
|
|
276
|
+
...(hooksPlan ? { hooks: hookInstaller.hookPlanSummary(hooksPlan) } : {}) };
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
if (process.argv[1] && import.meta.url === pathToFileURL(resolve(process.argv[1])).href) {
|
|
280
|
+
try {
|
|
281
|
+
const args = process.argv.slice(2);
|
|
282
|
+
let harness = 'codex';
|
|
283
|
+
const harnessIndex = args.indexOf('--harness');
|
|
284
|
+
if (harnessIndex >= 0) { harness = args[harnessIndex + 1]; args.splice(harnessIndex, 2); }
|
|
285
|
+
const targetIndex = args.indexOf('--target');
|
|
286
|
+
const target = targetIndex >= 0 ? args[targetIndex + 1] : undefined;
|
|
287
|
+
const remaining = args.filter((_, index) => index !== targetIndex && index !== targetIndex + 1);
|
|
288
|
+
if (!target || target.startsWith('--') || remaining.some(arg => !['--check', '--without-hooks', '--upgrade'].includes(arg)) || new Set(remaining).size !== remaining.length) {
|
|
289
|
+
throw new Error('Usage: node scripts/export.mjs --target <project> [--check] [--upgrade] [--without-hooks] [--harness codex|claude|pi|omp|github-copilot|opencode]');
|
|
290
|
+
}
|
|
291
|
+
const sourceRoot = fileURLToPath(new URL('..', import.meta.url));
|
|
292
|
+
const hooks = !remaining.includes('--without-hooks') && harness !== 'opencode';
|
|
293
|
+
const result = await exportBundle({ sourceRoot, targetRoot: target, check: remaining.includes('--check'), upgrade: remaining.includes('--upgrade'), hooks, harness });
|
|
294
|
+
let revision = 'unavailable';
|
|
295
|
+
try { revision = execFileSync('git', ['rev-parse', 'HEAD'], { cwd: sourceRoot, encoding: 'utf8', stdio: ['ignore', 'pipe', 'ignore'] }).trim(); } catch {}
|
|
296
|
+
console.log(JSON.stringify({ revision, ...result }, null, 2));
|
|
297
|
+
} catch (error) {
|
|
298
|
+
console.error(error.message);
|
|
299
|
+
process.exitCode = 1;
|
|
300
|
+
}
|
|
301
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
// Hook commands run from whatever directory the agent is in: a worktree, a
|
|
2
|
+
// subdirectory or the project root. A relative script path then exits 127.
|
|
3
|
+
// Claude Code exports the project root as CLAUDE_PROJECT_DIR; quote it so a
|
|
4
|
+
// path with spaces stays one word.
|
|
5
|
+
export const claudeProjectDir = '"$CLAUDE_PROJECT_DIR"';
|
|
6
|
+
|
|
7
|
+
// The stable 0.7 safeguard registered its scripts by bare relative path.
|
|
8
|
+
const relativeJoycraftHook = /^(?:(bash|sh|node)\s+)?(?:\.\/)?(\.claude\/hooks\/joycraft\/[\w.-]+)$/;
|
|
9
|
+
|
|
10
|
+
/** The command that runs a project script from the Claude project root. */
|
|
11
|
+
export function claudeHookCommand(path, interpreter = null) {
|
|
12
|
+
return `${interpreter ? `${interpreter} ` : ''}${claudeProjectDir}/${path}`;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/** Rewrite relative Joycraft hook commands in Claude settings. Every other
|
|
16
|
+
* entry, including user hooks, keeps its exact value. */
|
|
17
|
+
export function resolveRelativeJoycraftHooks(settings) {
|
|
18
|
+
const rewritten = [];
|
|
19
|
+
const hooks = settings?.hooks;
|
|
20
|
+
if (!hooks || typeof hooks !== 'object' || Array.isArray(hooks)) return { settings, rewritten };
|
|
21
|
+
const next = {};
|
|
22
|
+
for (const [event, groups] of Object.entries(hooks)) {
|
|
23
|
+
next[event] = !Array.isArray(groups) ? groups : groups.map(group => {
|
|
24
|
+
if (!Array.isArray(group?.hooks)) return group;
|
|
25
|
+
return { ...group, hooks: group.hooks.map(hook => {
|
|
26
|
+
const match = hook?.type === 'command' && typeof hook.command === 'string' ? relativeJoycraftHook.exec(hook.command.trim()) : null;
|
|
27
|
+
if (!match) return hook;
|
|
28
|
+
const command = claudeHookCommand(match[2], match[1] ?? null);
|
|
29
|
+
rewritten.push({ event, from: hook.command, to: command });
|
|
30
|
+
return { ...hook, command };
|
|
31
|
+
}) };
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
return { settings: rewritten.length ? { ...settings, hooks: next } : settings, rewritten };
|
|
35
|
+
}
|