joycraft 1.1.0 → 1.1.1
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/dist/joycraft-release.json +1 -1
- package/package.json +3 -3
- package/payload/.joycraft/runtime/cleanup.mjs +19 -1
- package/payload/.joycraft/runtime/config.mjs +3 -1
- package/payload/.joycraft/runtime/coordinator.mjs +28 -5
- package/payload/.joycraft/runtime/status.mjs +2 -2
- package/payload/.joycraft/runtime/trace.mjs +8 -3
- package/payload/.joycraft/runtime/worktrees.mjs +9 -7
- package/payload/PIN +8 -8
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "joycraft",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.1",
|
|
4
4
|
"description": "Install and update Joycraft, a skill bundle and runtime for agent-led software work, in any project",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -13,8 +13,8 @@
|
|
|
13
13
|
"payload"
|
|
14
14
|
],
|
|
15
15
|
"joycraft": {
|
|
16
|
-
"release": "1.1.
|
|
17
|
-
"summary": "
|
|
16
|
+
"release": "1.1.1",
|
|
17
|
+
"summary": "Fixes from the 1.0.1 and 1.1 re-reviews: cleanup reads code fences correctly, trace reads folders like tests/[slug], prune skips the tree it runs from, and stale locks are taken over safely.",
|
|
18
18
|
"autoSafeEligible": false
|
|
19
19
|
},
|
|
20
20
|
"scripts": {
|
|
@@ -30,12 +30,30 @@ function markdownFiles(root, folder, skip = []) {
|
|
|
30
30
|
|
|
31
31
|
const read = (root, file) => { try { return readFileSync(path.join(root, file), 'utf8'); } catch { return null; } };
|
|
32
32
|
|
|
33
|
+
// A fence opens with three or more backticks or tildes at any indent (list items
|
|
34
|
+
// indent theirs) and closes on a line of the same character, at least as long.
|
|
35
|
+
// An unclosed fence runs to the end of the file, as in CommonMark.
|
|
36
|
+
function blankFences(text) {
|
|
37
|
+
let fence = null;
|
|
38
|
+
return text.split('\n').map(line => {
|
|
39
|
+
const marker = /^\s*(`{3,}|~{3,})/.exec(line)?.[1];
|
|
40
|
+
if (!fence) {
|
|
41
|
+
// A backtick fence's info string has no backtick; ```npm test``` is inline code.
|
|
42
|
+
if (!marker || (marker[0] === '`' && line.trimStart().slice(marker.length).includes('`'))) return line;
|
|
43
|
+
fence = marker;
|
|
44
|
+
} else if (marker && marker[0] === fence[0] && marker.length >= fence.length && /^\s*[`~]+\s*$/.test(line)) {
|
|
45
|
+
fence = null;
|
|
46
|
+
}
|
|
47
|
+
return ' '.repeat(line.length);
|
|
48
|
+
}).join('\n');
|
|
49
|
+
}
|
|
50
|
+
|
|
33
51
|
/** Markdown links (checked for existence) and backticked project paths (references only). */
|
|
34
52
|
export function references(file, text) {
|
|
35
53
|
const dir = path.posix.dirname(file);
|
|
36
54
|
const links = [], mentions = [];
|
|
37
55
|
// Blank out fenced code so examples are not read as links; keep line numbers.
|
|
38
|
-
text = text
|
|
56
|
+
text = blankFences(text);
|
|
39
57
|
const lineOf = index => text.slice(0, index).split('\n').length;
|
|
40
58
|
const add = (raw, index) => {
|
|
41
59
|
const target = raw.split('#')[0];
|
|
@@ -16,7 +16,9 @@ export const defaults = Object.freeze({
|
|
|
16
16
|
function scalar(text, line) {
|
|
17
17
|
const value = text.trim();
|
|
18
18
|
if (value === '') return null;
|
|
19
|
-
if (/^"(?:[^"\\]|\\.)*"$/.test(value))
|
|
19
|
+
if (/^"(?:[^"\\]|\\.)*"$/.test(value)) {
|
|
20
|
+
try { return JSON.parse(value); } catch { throw new Error(`${configFile} line ${line}: a double-quoted value has an escape YAML does not allow here: ${value}`); }
|
|
21
|
+
}
|
|
20
22
|
if (/^'(?:[^']|'')*'$/.test(value)) return value.slice(1, -1).replaceAll("''", "'");
|
|
21
23
|
requireValue(!/^["']/.test(value), `${configFile} line ${line}: a quoted value must end with its closing quote and nothing after it: ${value}`);
|
|
22
24
|
if (/^\[.*\]$/.test(value)) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { execFileSync } from 'node:child_process';
|
|
2
|
-
import {
|
|
2
|
+
import { existsSync, mkdirSync, readFileSync, realpathSync, rmSync, statSync, unlinkSync, writeFileSync } from 'node:fs';
|
|
3
3
|
import path from 'node:path';
|
|
4
4
|
import { pathToFileURL } from 'node:url';
|
|
5
5
|
import { isObject, nonempty, parseJson, readLocal, relativePath, requireValue, validateQueue } from './identity.mjs';
|
|
@@ -25,21 +25,44 @@ export function leasePath(root, feature) {
|
|
|
25
25
|
return path.join(mainTree(root), leaseRelative(feature));
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
+
function lockIsStale(lock, waitMs) {
|
|
29
|
+
const pid = Number(readFileSync(lock, 'utf8'));
|
|
30
|
+
if (!Number.isInteger(pid) || pid <= 0) return Date.now() - statSync(lock).mtimeMs > waitMs;
|
|
31
|
+
try { process.kill(pid, 0); return false; } catch (error) { return error.code === 'ESRCH'; }
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// Waiters that see a stale lock take turns through a guard file, so two of them
|
|
35
|
+
// cannot both remove it and one remove the other's new lock.
|
|
36
|
+
function takeOver(lock, waitMs) {
|
|
37
|
+
const guard = `${lock}.takeover`;
|
|
38
|
+
try { writeFileSync(guard, String(process.pid), { flag: 'wx' }); } catch (error) {
|
|
39
|
+
if (error.code !== 'EEXIST') throw error;
|
|
40
|
+
try { if (Date.now() - statSync(guard).mtimeMs > waitMs) rmSync(guard, { force: true }); } catch { /* another waiter removed it */ }
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
try { if (lockIsStale(lock, waitMs)) unlinkSync(lock); } catch { /* the holder released it */ } finally { rmSync(guard, { force: true }); }
|
|
44
|
+
}
|
|
45
|
+
|
|
28
46
|
/** Serialize a read-modify-write of a small local record with an exclusive lock file. */
|
|
29
47
|
export function withLock(file, action, { waitMs = 5000 } = {}) {
|
|
30
48
|
const lock = `${file}.lock`;
|
|
31
49
|
mkdirSync(path.dirname(file), { recursive: true });
|
|
32
50
|
const deadline = Date.now() + waitMs;
|
|
33
51
|
for (;;) {
|
|
34
|
-
try {
|
|
52
|
+
try { writeFileSync(lock, String(process.pid), { flag: 'wx' }); break; } catch (error) {
|
|
35
53
|
if (error.code !== 'EEXIST') throw error;
|
|
36
|
-
//
|
|
37
|
-
|
|
54
|
+
// The lock names its holder. Take it over only when that process is gone, or,
|
|
55
|
+
// for a lock with no readable holder, when it is older than the wait limit.
|
|
56
|
+
let stale = false;
|
|
57
|
+
try { stale = lockIsStale(lock, waitMs); } catch { continue; }
|
|
58
|
+
if (stale) { takeOver(lock, waitMs); continue; }
|
|
38
59
|
requireValue(Date.now() < deadline, `Another Joycraft process holds ${path.basename(lock)}; try again`);
|
|
39
60
|
Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, 25);
|
|
40
61
|
}
|
|
41
62
|
}
|
|
42
|
-
try { return action(); } finally {
|
|
63
|
+
try { return action(); } finally {
|
|
64
|
+
try { if (readFileSync(lock, 'utf8') === String(process.pid)) unlinkSync(lock); } catch { /* already gone */ }
|
|
65
|
+
}
|
|
43
66
|
}
|
|
44
67
|
|
|
45
68
|
/** No lease can exist for a feature name that is not a slug, so 1.0.0 queues keep working. */
|
|
@@ -4,7 +4,7 @@ import { pathToFileURL } from 'node:url';
|
|
|
4
4
|
import { journalPath } from './completion.mjs';
|
|
5
5
|
import { workPaths } from './config.mjs';
|
|
6
6
|
import { briefDecisionRecords, isObject, localPath, parseJson, readLocal, specStatus, validateQueue } from './identity.mjs';
|
|
7
|
-
import { listWorktrees } from './worktrees.mjs';
|
|
7
|
+
import { decide, listWorktrees } from './worktrees.mjs';
|
|
8
8
|
|
|
9
9
|
// The queue is the status authority; spec frontmatter mirrors it. This report
|
|
10
10
|
// shows where the mirror or the working folders have drifted, so a session can
|
|
@@ -34,7 +34,7 @@ function worktreeCounts(root) {
|
|
|
34
34
|
const { trees } = listWorktrees({ root, sizes: false });
|
|
35
35
|
return {
|
|
36
36
|
owned: trees.filter(tree => tree.owner === 'joycraft' && !tree.missing).length,
|
|
37
|
-
prunable: trees.filter(tree => tree.
|
|
37
|
+
prunable: trees.filter(tree => decide(tree).action === 'remove').length,
|
|
38
38
|
unknown: trees.filter(tree => tree.owner !== 'joycraft').length,
|
|
39
39
|
};
|
|
40
40
|
} catch { return null; }
|
|
@@ -11,6 +11,11 @@ const tag = /\[AC:([A-Za-z0-9_.-]+)\]/g;
|
|
|
11
11
|
|
|
12
12
|
function filesMatching(root, glob) {
|
|
13
13
|
const pattern = globToRegExp(checkGlob(glob, '--tests'));
|
|
14
|
+
return filesUnder(root, '', file => pattern.test(file));
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
// A declared folder is a literal path, so names like tests/[slug] need no glob escaping.
|
|
18
|
+
function filesUnder(root, base, keep = () => true) {
|
|
14
19
|
const out = [];
|
|
15
20
|
const walk = relative => {
|
|
16
21
|
let entries;
|
|
@@ -19,10 +24,10 @@ function filesMatching(root, glob) {
|
|
|
19
24
|
if (entry.name === 'node_modules' || entry.name === '.git' || entry.name === '.joycraft') continue;
|
|
20
25
|
const child = relative ? `${relative}/${entry.name}` : entry.name;
|
|
21
26
|
if (entry.isDirectory()) walk(child);
|
|
22
|
-
else if (entry.isFile() &&
|
|
27
|
+
else if (entry.isFile() && keep(child)) out.push(child);
|
|
23
28
|
}
|
|
24
29
|
};
|
|
25
|
-
walk(
|
|
30
|
+
walk(base);
|
|
26
31
|
return out;
|
|
27
32
|
}
|
|
28
33
|
|
|
@@ -36,7 +41,7 @@ export function traceSpec({ root = process.cwd(), queuePath, specId, tests = []
|
|
|
36
41
|
const criteria = (spec.verification.criteria ?? []).map(item => item.id);
|
|
37
42
|
const declared = spec.verification.inputs.filter(input => input.kind === 'check' && input.state !== 'absent').map(input => relativePath(input.path));
|
|
38
43
|
// A declared check folder stands for every file inside it.
|
|
39
|
-
const expanded = declared.flatMap(file => existsSync(path.join(root, file)) && statSync(path.join(root, file)).isDirectory() ?
|
|
44
|
+
const expanded = declared.flatMap(file => existsSync(path.join(root, file)) && statSync(path.join(root, file)).isDirectory() ? filesUnder(root, file) : [file]);
|
|
40
45
|
const files = [...new Set([...expanded, ...tests.flatMap(glob => filesMatching(root, glob))])].sort();
|
|
41
46
|
const untraceableIds = criteria.filter(id => !/^[A-Za-z0-9_.-]+$/.test(id));
|
|
42
47
|
const traced = Object.fromEntries(criteria.map(id => [id, []]));
|
|
@@ -66,7 +66,7 @@ export function createWorktree({ root = process.cwd(), queuePath, specId, sessio
|
|
|
66
66
|
});
|
|
67
67
|
}
|
|
68
68
|
|
|
69
|
-
function linkedTrees(root) {
|
|
69
|
+
function linkedTrees(root, here = root) {
|
|
70
70
|
const blocks = git(root, ['worktree', 'list', '--porcelain']).split(/\n\n+/).filter(Boolean);
|
|
71
71
|
const trees = blocks.map(block => {
|
|
72
72
|
const tree = {};
|
|
@@ -76,8 +76,8 @@ function linkedTrees(root) {
|
|
|
76
76
|
}
|
|
77
77
|
return tree;
|
|
78
78
|
});
|
|
79
|
-
// The first entry is the main working tree; the
|
|
80
|
-
return trees.slice(1).filter(tree => !existsSync(tree.worktree) || realpathSync(tree.worktree) !==
|
|
79
|
+
// The first entry is the main working tree; the tree prune runs from is never listed.
|
|
80
|
+
return trees.slice(1).filter(tree => !existsSync(tree.worktree) || realpathSync(tree.worktree) !== here);
|
|
81
81
|
}
|
|
82
82
|
|
|
83
83
|
function sizeOf(target) {
|
|
@@ -113,12 +113,14 @@ function evidenceOnlyHere(root, tree, spec) {
|
|
|
113
113
|
|
|
114
114
|
/** Every linked tree with its owner, spec status, merged and clean state. */
|
|
115
115
|
export function listWorktrees({ root = process.cwd(), into = 'HEAD', sizes = true } = {}) {
|
|
116
|
-
|
|
116
|
+
const main = gitRoot(root);
|
|
117
|
+
const here = realpathSync(git(root, ['rev-parse', '--show-toplevel']).trim());
|
|
118
|
+
root = main;
|
|
117
119
|
const ledger = readLedger(root);
|
|
118
120
|
const owned = new Map(ledger.trees.map(entry => [path.resolve(root, entry.path), entry]));
|
|
119
121
|
const queues = new Map();
|
|
120
122
|
const seen = new Set();
|
|
121
|
-
const trees = linkedTrees(root).map(tree => {
|
|
123
|
+
const trees = linkedTrees(root, here).map(tree => {
|
|
122
124
|
const absolute = existsSync(tree.worktree) ? realpathSync(tree.worktree) : tree.worktree;
|
|
123
125
|
const entry = owned.get(absolute) ?? owned.get(tree.worktree);
|
|
124
126
|
if (entry) seen.add(entry.path);
|
|
@@ -137,11 +139,11 @@ export function listWorktrees({ root = process.cwd(), into = 'HEAD', sizes = tru
|
|
|
137
139
|
if (sizes) record.bytes = exists ? sizeOf(absolute) : 0;
|
|
138
140
|
return record;
|
|
139
141
|
});
|
|
140
|
-
const missing = ledger.trees.filter(entry => !seen.has(entry.path)).map(entry => ({ path: entry.path, branch: entry.branch, owner: 'joycraft', feature: entry.feature, specId: entry.specId, exists: false, missing: true }));
|
|
142
|
+
const missing = ledger.trees.filter(entry => !seen.has(entry.path) && path.resolve(root, entry.path) !== here).map(entry => ({ path: entry.path, branch: entry.branch, owner: 'joycraft', feature: entry.feature, specId: entry.specId, exists: false, missing: true }));
|
|
141
143
|
return { root, into, trees: [...trees, ...missing] };
|
|
142
144
|
}
|
|
143
145
|
|
|
144
|
-
function decide(tree) {
|
|
146
|
+
export function decide(tree) {
|
|
145
147
|
if (tree.owner === 'joycraft' && !tree.exists) return { action: 'forget', reason: 'Recorded tree no longer exists; drop the ledger entry.' };
|
|
146
148
|
if (tree.owner !== 'joycraft') return { action: 'keep', reason: 'Not created by worktrees.mjs; inspect it, then remove it with git worktree remove if it is yours.' };
|
|
147
149
|
if (tree.specStatus !== 'done') return { action: 'keep', reason: `Spec ${tree.specId} is ${tree.specStatus}; keep the tree until it is done.` };
|
package/payload/PIN
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"schemaVersion": 1,
|
|
3
3
|
"source": "joycraft-prototype",
|
|
4
|
-
"tag": "field-
|
|
5
|
-
"commit": "
|
|
4
|
+
"tag": "field-10",
|
|
5
|
+
"commit": "c535c1dcbfd1256b06a4c981352d8bbf358a182b",
|
|
6
6
|
"files": {
|
|
7
7
|
".agents/skills/joycraft-cleanup/SKILL.md": "e9a6eda4773332d87cc6a13cc939aaa5d3ea1ec1f980b1132a6794740cdfe39f",
|
|
8
8
|
".agents/skills/joycraft-context/SKILL.md": "e0a5f7d82fe8b6b6d3aeab38f7cf570ca939dba07034243af1ef86d24448c084",
|
|
@@ -44,13 +44,13 @@
|
|
|
44
44
|
".joycraft/runtime/artifacts/preferences.mjs": "9165e1c753aa8533affe976cacecb135b0ee3cc9f455f5f80b1568103bb49fd6",
|
|
45
45
|
".joycraft/runtime/artifacts/render.mjs": "488673cab94fa6bfde223c2c41650f8e183f7ac0be3840d371ee057d95ea0fa5",
|
|
46
46
|
".joycraft/runtime/artifacts/server.mjs": "a96048fad649e8053c70ce95c5a757929ab57ae9de27198121224326551c0a05",
|
|
47
|
-
".joycraft/runtime/cleanup.mjs": "
|
|
47
|
+
".joycraft/runtime/cleanup.mjs": "99aa8ba12e856893e47232f2944013e56c3925e8ab8f732c195c092497690c3f",
|
|
48
48
|
".joycraft/runtime/completion.mjs": "11635b11eb7df90398a69b6d41f96d9c7b9d2dc2255ae4a4a129562d46572ec1",
|
|
49
|
-
".joycraft/runtime/config.mjs": "
|
|
49
|
+
".joycraft/runtime/config.mjs": "9b64d7f6928bbcc8145c8de51994d82dd8e3323878d321bce0fb3bc11975eedf",
|
|
50
50
|
".joycraft/runtime/context/cli.mjs": "40adc206c8c3b7f4f5bedffb097d9ae1b0718f0586a055796e4987e9c3088eee",
|
|
51
51
|
".joycraft/runtime/context/index.mjs": "5a69d33d9a1a66ef23301e952ecb1ec427ff4b0baf408ede67a2600d3f2a173c",
|
|
52
52
|
".joycraft/runtime/context/search.mjs": "e32a42ba9b168ca7c68fed46d47a79250c27aa4c07c0835feae084b5d1e0d0ca",
|
|
53
|
-
".joycraft/runtime/coordinator.mjs": "
|
|
53
|
+
".joycraft/runtime/coordinator.mjs": "9252a40ee3a82808a780158427b02129d8075679ed329bce2dd74168c7eb42ab",
|
|
54
54
|
".joycraft/runtime/delivery.mjs": "4fe897714eec33b24003f0d69abe1522a5199193ab7333fa6421776ee048df1c",
|
|
55
55
|
".joycraft/runtime/dispatch-preflight.mjs": "1b8283c06c8a2a41bfca06b1d5f0f83a093825911fbab1e04657dee06fa91c5d",
|
|
56
56
|
".joycraft/runtime/dispatch-start.mjs": "b8d27b53566062c79cb95bf3f89bcb3e4abc9dd9dc15612cfced8685cf3a1c41",
|
|
@@ -62,10 +62,10 @@
|
|
|
62
62
|
".joycraft/runtime/review-tools.json": "c00e4209d67fd655a351946509a2aba2ee287dbaa0a1ad60c22e1286de0b4893",
|
|
63
63
|
".joycraft/runtime/review-tools.mjs": "17c13f7ab746478bce5711501a5190991b46616c849780196614950cfc6f0208",
|
|
64
64
|
".joycraft/runtime/scope.mjs": "e2cdd929596246bf24e18850698db440119badc7068a3c5beab03ded45abbd65",
|
|
65
|
-
".joycraft/runtime/status.mjs": "
|
|
66
|
-
".joycraft/runtime/trace.mjs": "
|
|
65
|
+
".joycraft/runtime/status.mjs": "0e1d2cc23f8d847ae14e8fc2dd909910d6b5655a0bb0305355f6f4d9709f1e33",
|
|
66
|
+
".joycraft/runtime/trace.mjs": "b7924f759b07991f4135698df9c32654631a325957f0f8de5c2ca1262c0a836a",
|
|
67
67
|
".joycraft/runtime/update-check.mjs": "324b2eda4ac1feb6bb5b15ef488bea5f2f8a6312bc7b1c24719e0b7fd6a84634",
|
|
68
|
-
".joycraft/runtime/worktrees.mjs": "
|
|
68
|
+
".joycraft/runtime/worktrees.mjs": "d463e1df5735550acf4f3a0e6f96f723d8f55806ba64d38190163d0cc0154f03",
|
|
69
69
|
".joycraft/templates/README.md": "56a166d0729e8b6c3bcb098afb8145006259357087fd8b1f1f343d9a2b4d36e0",
|
|
70
70
|
".joycraft/templates/artifact.json": "fda5f7c32516d6ab094ee0e8506d84a1a0d6d4d0f49048b01aa392c619996f05",
|
|
71
71
|
".joycraft/templates/brief.md": "03479342500570aba9fb206beef6f6049fd180bec814dd8001987174aecfef25",
|