genesis-compiler 1.7.4 → 1.7.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/docs/prompt-integration.md +9 -0
- package/docs/templates.md +9 -3
- package/package.json +1 -1
- package/src/cli.js +24 -3
- package/src/index/claude-hooks.js +12 -4
- package/src/index/hook-command.js +3 -3
- package/src/index/template-project.js +29 -15
- package/src/index/template-source.js +10 -1
|
@@ -198,6 +198,15 @@ init`. All receive the same short operating guide for a new session and after
|
|
|
198
198
|
compaction. The Codex session hook sets `additionalContextLimit: 0` so native
|
|
199
199
|
truncation cannot remove part of the bounded guide or host contribution.
|
|
200
200
|
Codex and Claude Code use `SessionStart` for startup, resume, clear, and compact events.
|
|
201
|
+
Claude's generated session hooks use `genesis hook session --claude-part <1-4>`.
|
|
202
|
+
Claude caps each hook output at 10,000 characters, so four hooks deliver the
|
|
203
|
+
unchanged guide in numbered parts below that limit. Empty parts emit nothing.
|
|
204
|
+
A guide above 36,000 characters delivers an explicit guidance-unavailable
|
|
205
|
+
warning instead of a partial guide. Claude does not enforce startup hook stop
|
|
206
|
+
requests; this warning instructs the model to report the problem before work,
|
|
207
|
+
and is not a runtime admission control. Turn guidance is already bounded at 512
|
|
208
|
+
bytes and uses the ordinary turn command. This is provider transport only;
|
|
209
|
+
composition and the host bridge remain shared.
|
|
201
210
|
Claude settings preserve unrelated hooks and configuration. The common operating
|
|
202
211
|
guide lists installed project skills and their canonical `.agents/skills/` paths;
|
|
203
212
|
an agent reads the relevant skill before following its workflow. Genesis exposes
|
package/docs/templates.md
CHANGED
|
@@ -23,8 +23,8 @@ components or authored project contracts when no catalogue technology matches.
|
|
|
23
23
|
The exact bootstrap allowlist is `GENESIS_BOOTSTRAP_PATHS` in
|
|
24
24
|
`src/index/project-inspection.js`: the four core Markdown documents and version,
|
|
25
25
|
the two derived Cities, Genesis's Codex/OpenCode integration files, its managed
|
|
26
|
-
skills manifest, and the SKILL.md/openai.yaml
|
|
27
|
-
workflow skills. Whole `.agents/`, `.codex/`, or `genesis/` directories are not
|
|
26
|
+
skills manifest, the relative Claude discovery link, and the SKILL.md/openai.yaml
|
|
27
|
+
pair for each of the three Genesis workflow skills. Whole `.agents/`, `.codex/`, or `genesis/` directories are not
|
|
28
28
|
exempt. A README, `.gitignore`, application manifest, unfamiliar source file, or
|
|
29
29
|
custom agent tool counts as existing content. Ignored files also count, except
|
|
30
30
|
installed `node_modules` dependencies. Source recognition does not depend on a
|
|
@@ -56,8 +56,14 @@ Each branch is a complete, current Genesis project with actual application
|
|
|
56
56
|
source, dependency lockfile, setup/run contracts and focused checks.
|
|
57
57
|
|
|
58
58
|
Applying fetches the explicitly named branch once, resolves its commit and reads
|
|
59
|
-
its ordinary Git blobs into a temporary project. Genesis rejects links,
|
|
59
|
+
its ordinary Git blobs into a temporary project. Genesis rejects arbitrary links,
|
|
60
60
|
submodules, unsafe paths, dependencies and private dotenv files in the template.
|
|
61
|
+
The only link exception is the exact generated Claude skill discovery link
|
|
62
|
+
`.claude/skills/<name>` → `../../.agents/skills/<name>`. Incoming discovery links
|
|
63
|
+
are omitted and regenerated from the canonical skill directories by initialization.
|
|
64
|
+
Existing exact generated links are preserved and checked again before copying;
|
|
65
|
+
links with another target remain rejected. A bare destination receives the same
|
|
66
|
+
generated links without following links supplied by a template.
|
|
61
67
|
It validates the prepared project before changing the destination. A project
|
|
62
68
|
lock serializes competing imports; the source and authored bootstrap files are
|
|
63
69
|
checked again immediately before the copy. An ordinary copy failure rolls back
|
package/package.json
CHANGED
package/src/cli.js
CHANGED
|
@@ -88,6 +88,7 @@ Options:
|
|
|
88
88
|
--directory <path> Parser cache directory (parsers commands only)
|
|
89
89
|
--all Select every parser (parsers install/verify only)
|
|
90
90
|
--json Emit one machine-readable result
|
|
91
|
+
--claude-part <1-4> Emit one bounded Claude session-hook part
|
|
91
92
|
-h, --help Show this help
|
|
92
93
|
|
|
93
94
|
Genesis generates prompts; it never starts or manages an AI agent. Give the
|
|
@@ -111,6 +112,7 @@ function parseCommand(argv) {
|
|
|
111
112
|
strict: true,
|
|
112
113
|
options: {
|
|
113
114
|
json: { type: 'boolean', default: false },
|
|
115
|
+
'claude-part': { type: 'string' },
|
|
114
116
|
all: { type: 'boolean', default: false },
|
|
115
117
|
directory: { type: 'string' },
|
|
116
118
|
'project-root': { type: 'string' },
|
|
@@ -124,6 +126,7 @@ function parseCommand(argv) {
|
|
|
124
126
|
}
|
|
125
127
|
const options = {
|
|
126
128
|
json: parsed.values.json,
|
|
129
|
+
claudePart: parsed.values['claude-part'],
|
|
127
130
|
all: parsed.values.all,
|
|
128
131
|
directory: parsed.values.directory,
|
|
129
132
|
projectRoot: parsed.values['project-root'],
|
|
@@ -138,6 +141,9 @@ function parseCommand(argv) {
|
|
|
138
141
|
task: parsed.values.task,
|
|
139
142
|
};
|
|
140
143
|
const operands = parsed.positionals;
|
|
144
|
+
if (options.claudePart !== undefined && (command !== 'hook' || operands[0] !== 'session' || !/^[1-4]$/u.test(options.claudePart) || options.json)) {
|
|
145
|
+
fail('CLI_OPTION_NOT_APPLICABLE', 'Option --claude-part requires hook session, a part from 1 to 4, and no --json.');
|
|
146
|
+
}
|
|
141
147
|
if (command !== 'parsers' && (options.all || options.directory !== undefined)) {
|
|
142
148
|
fail('CLI_OPTION_NOT_APPLICABLE', 'Options --all and --directory apply only to parsers commands.');
|
|
143
149
|
}
|
|
@@ -665,9 +671,24 @@ export async function runCli(argv = process.argv.slice(2)) {
|
|
|
665
671
|
projectFormat,
|
|
666
672
|
formatDiagnostic,
|
|
667
673
|
);
|
|
668
|
-
if (options.
|
|
669
|
-
|
|
670
|
-
|
|
674
|
+
if (options.claudePart !== undefined) {
|
|
675
|
+
// Claude spills each hook output over 10,000 characters to a file.
|
|
676
|
+
// Four native hooks deliver the exact text in bounded parts instead.
|
|
677
|
+
if (result.output.length > 36000) {
|
|
678
|
+
if (options.claudePart === '1') line(process.stdout,
|
|
679
|
+
'GENESIS GUIDANCE UNAVAILABLE: The session guide exceeds the Claude hook capacity of 36,000 characters. The guide was not delivered. Tell the user before doing project work. Shorten the project guidance and restart the conversation to load it completely.');
|
|
680
|
+
return 0;
|
|
681
|
+
}
|
|
682
|
+
let start = (Number(options.claudePart) - 1) * 9000;
|
|
683
|
+
let end = start + 9000;
|
|
684
|
+
// Keep UTF-16 surrogate pairs together at the shared part boundaries.
|
|
685
|
+
if (/[\uDC00-\uDFFF]/u.test(result.output[start] || '')) start--;
|
|
686
|
+
if (/[\uDC00-\uDFFF]/u.test(result.output[end] || '')) end--;
|
|
687
|
+
const part = result.output.slice(start, end);
|
|
688
|
+
if (part) process.stdout.write(`Genesis session guidance, part ${options.claudePart} of ${Math.ceil(result.output.length / 9000)} (read in numeric order):\n${part}`);
|
|
689
|
+
} else if (options.json) line(process.stdout, JSON.stringify(result));
|
|
690
|
+
else writeResult(parsed.command, result);
|
|
691
|
+
if (!options.json) {
|
|
671
692
|
for (const warning of result.warnings || []) {
|
|
672
693
|
if (warning.code !== formatDiagnostic?.code) line(process.stderr, `WARNING: ${warning.code}: ${warning.message}`);
|
|
673
694
|
}
|
|
@@ -7,8 +7,11 @@ import { genesisHookCommand } from './hook-command.js';
|
|
|
7
7
|
import { writeFileAtomic } from './utils.js';
|
|
8
8
|
|
|
9
9
|
const SETTINGS_PATH = '.claude/settings.json';
|
|
10
|
-
const
|
|
10
|
+
const SESSION_COMMANDS = [1, 2, 3, 4].map((claudePart) => genesisHookCommand('session', { claudePart }));
|
|
11
11
|
const TURN_COMMAND = genesisHookCommand('turn');
|
|
12
|
+
// Refresh exact generated commands, including the previous plain-text output.
|
|
13
|
+
const OWNED_COMMANDS = new Set([...SESSION_COMMANDS, TURN_COMMAND,
|
|
14
|
+
genesisHookCommand('session')]);
|
|
12
15
|
|
|
13
16
|
async function renderedSettings(projectRoot) {
|
|
14
17
|
const root = (await gitContext(projectRoot)).repositoryRoot;
|
|
@@ -34,13 +37,13 @@ async function renderedSettings(projectRoot) {
|
|
|
34
37
|
}
|
|
35
38
|
value.hooks[event] = groups.flatMap((group) => {
|
|
36
39
|
if (!Array.isArray(group?.hooks)) return [group];
|
|
37
|
-
const hooks = group.hooks.filter((hook) => !
|
|
40
|
+
const hooks = group.hooks.filter((hook) => !OWNED_COMMANDS.has(hook?.command));
|
|
38
41
|
return hooks.length ? [{ ...group, hooks }] : [];
|
|
39
42
|
});
|
|
40
43
|
}
|
|
41
44
|
(value.hooks.SessionStart ||= []).push({
|
|
42
45
|
matcher: '^(startup|resume|clear|compact)$',
|
|
43
|
-
hooks:
|
|
46
|
+
hooks: SESSION_COMMANDS.map((command) => ({ type: 'command', command, timeout: 30 })),
|
|
44
47
|
});
|
|
45
48
|
(value.hooks.UserPromptSubmit ||= []).push({
|
|
46
49
|
hooks: [{ type: 'command', command: TURN_COMMAND, timeout: 30 }],
|
|
@@ -50,6 +53,11 @@ async function renderedSettings(projectRoot) {
|
|
|
50
53
|
|
|
51
54
|
// Claude discovers .claude/skills; the canonical files remain in .agents/skills.
|
|
52
55
|
// Only exact generated links are owned here. User-owned Claude skills win.
|
|
56
|
+
export function claudeSkillLinkTarget(relative) {
|
|
57
|
+
const name = /^\.claude\/skills\/([^/\\]+)$/u.exec(relative)?.[1];
|
|
58
|
+
return name && name !== '.' && name !== '..' ? `../../.agents/skills/${name}` : null;
|
|
59
|
+
}
|
|
60
|
+
|
|
53
61
|
export async function claudeSkillLinks(root, write = false) {
|
|
54
62
|
const [canonical, installed] = await Promise.all(['.agents/skills', '.claude/skills'].map(async (directory) => {
|
|
55
63
|
try { return await readdir(path.join(root, directory), { withFileTypes: true }); }
|
|
@@ -62,7 +70,7 @@ export async function claudeSkillLinks(root, write = false) {
|
|
|
62
70
|
for (const name of new Set([...names, ...existing.keys()])) {
|
|
63
71
|
const relative = `.claude/skills/${name}`;
|
|
64
72
|
const location = path.join(root, relative);
|
|
65
|
-
const target =
|
|
73
|
+
const target = claudeSkillLinkTarget(relative);
|
|
66
74
|
const entry = existing.get(name);
|
|
67
75
|
const owned = entry?.isSymbolicLink() && await readlink(location) === target;
|
|
68
76
|
if (!names.has(name)) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export function genesisHookCommand(action) {
|
|
2
|
-
const local = `const {runCli}=await import('genesis-compiler/cli');process.exitCode=await runCli(['hook','${action}'])`;
|
|
3
|
-
return `if command -v genesis >/dev/null 2>&1; then genesis hook ${action}; else node --input-type=module --eval "${local}"; fi`;
|
|
1
|
+
export function genesisHookCommand(action, { claudePart } = {}) {
|
|
2
|
+
const local = `const {runCli}=await import('genesis-compiler/cli');process.exitCode=await runCli(['hook','${action}'${claudePart ? `,'--claude-part','${claudePart}'` : ''}])`;
|
|
3
|
+
return `if command -v genesis >/dev/null 2>&1; then genesis hook ${action}${claudePart ? ` --claude-part ${claudePart}` : ''}; else node --input-type=module --eval "${local}"; fi`;
|
|
4
4
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { lstat, mkdir, mkdtemp, readFile, readdir, rm, rmdir, writeFile } from 'node:fs/promises';
|
|
1
|
+
import { lstat, mkdir, mkdtemp, readFile, readdir, readlink, rm, rmdir, symlink, writeFile } from 'node:fs/promises';
|
|
2
2
|
import os from 'node:os';
|
|
3
3
|
import path from 'node:path';
|
|
4
4
|
import { parseBlueprintSource } from './blueprint.js';
|
|
@@ -13,6 +13,7 @@ import { listTemplates, resolveTemplate } from './template-catalog.js';
|
|
|
13
13
|
import { readGitSnapshot } from './template-source.js';
|
|
14
14
|
import { readStack } from './stack.js';
|
|
15
15
|
import { writeFileAtomic } from './utils.js';
|
|
16
|
+
import { claudeSkillLinkTarget } from './claude-hooks.js';
|
|
16
17
|
|
|
17
18
|
function sections(source) {
|
|
18
19
|
const result = new Map();
|
|
@@ -43,8 +44,12 @@ async function existingFile(root, name) {
|
|
|
43
44
|
const location = path.join(root, name);
|
|
44
45
|
try {
|
|
45
46
|
const state = await lstat(location);
|
|
47
|
+
if (state.isSymbolicLink()) {
|
|
48
|
+
const linkTarget = claudeSkillLinkTarget(name);
|
|
49
|
+
if (linkTarget && await readlink(location) === linkTarget) return { contents: Buffer.from(linkTarget), linkTarget };
|
|
50
|
+
}
|
|
46
51
|
if (!state.isFile()) throw new GenesisError('TEMPLATE_DESTINATION_CONFLICT', `Template destination is not an ordinary file: ${name}.`);
|
|
47
|
-
return await readFile(location);
|
|
52
|
+
return { contents: await readFile(location), linkTarget: null };
|
|
48
53
|
} catch (error) {
|
|
49
54
|
if (error.code === 'ENOENT') return null;
|
|
50
55
|
throw error;
|
|
@@ -57,7 +62,7 @@ async function filesBelow(root, relative = '') {
|
|
|
57
62
|
if (!relative && entry.name === '.git') continue;
|
|
58
63
|
const name = relative ? `${relative}/${entry.name}` : entry.name;
|
|
59
64
|
if (entry.isDirectory()) files.push(...await filesBelow(root, name));
|
|
60
|
-
else if (entry.isFile()) files.push({ path: name,
|
|
65
|
+
else if (entry.isFile() || entry.isSymbolicLink()) files.push({ path: name, ...await existingFile(root, name), mode: (await lstat(path.join(root, name))).mode & 0o111 ? 0o777 : 0o666 });
|
|
61
66
|
else throw new GenesisError('TEMPLATE_TREE_INVALID', `Template contains a non-ordinary file: ${name}.`);
|
|
62
67
|
}
|
|
63
68
|
return files;
|
|
@@ -96,28 +101,34 @@ export async function applyTemplate({ projectRoot, templateId, stackPackages = [
|
|
|
96
101
|
await mkdir(path.dirname(path.join(stagingRoot, file.path)), { recursive: true });
|
|
97
102
|
await writeFile(path.join(stagingRoot, file.path), file.contents, { flag: 'wx', mode: file.mode });
|
|
98
103
|
}
|
|
99
|
-
const
|
|
100
|
-
if (!
|
|
104
|
+
const stackFile = await existingFile(stagingRoot, 'genesis/stack.md');
|
|
105
|
+
if (!stackFile) throw new GenesisError('TEMPLATE_STACK_REQUIRED', 'A template must contain its complete genesis/stack.md.');
|
|
101
106
|
const seedStack = await readStack(stagingRoot, { stackPackages });
|
|
102
107
|
if (!seedStack.components.some(({ id }) => id === template.technology)) {
|
|
103
108
|
throw new GenesisError('TEMPLATE_STACK_MISMATCH', 'The template Stack does not contain its advertised technology.');
|
|
104
109
|
}
|
|
105
|
-
for (const [name,
|
|
106
|
-
if (
|
|
110
|
+
for (const [name, previous] of preserved) {
|
|
111
|
+
if (previous === null || name.startsWith('.genesis/')) continue;
|
|
112
|
+
const { contents, linkTarget } = previous;
|
|
107
113
|
if (name === 'genesis/blueprint.md' && !parseBlueprintSource(contents.toString('utf8')).description) continue;
|
|
108
114
|
let value = contents;
|
|
109
|
-
if (name === 'genesis/stack.md') value = mergeTemplateStack(
|
|
110
|
-
|
|
111
|
-
await
|
|
115
|
+
if (name === 'genesis/stack.md') value = mergeTemplateStack(stackFile.contents.toString('utf8'), contents.toString('utf8'));
|
|
116
|
+
const location = path.join(stagingRoot, name);
|
|
117
|
+
await mkdir(path.dirname(location), { recursive: true });
|
|
118
|
+
if (linkTarget) {
|
|
119
|
+
await rm(location, { force: true });
|
|
120
|
+
await symlink(linkTarget, location, 'dir');
|
|
121
|
+
} else await writeFile(location, value);
|
|
112
122
|
}
|
|
113
123
|
await initializeProject({ projectRoot: stagingRoot, stackPackages });
|
|
114
124
|
await buildProjectIndex({ projectRoot: stagingRoot, stackPackages });
|
|
115
125
|
const prepared = await inspectProject({ projectRoot: stagingRoot, stackPackages });
|
|
116
126
|
if (prepared.state !== 'ready') throw new GenesisError('TEMPLATE_PROJECT_INVALID', 'The prepared template does not contain a usable Genesis project.', { inspection: prepared });
|
|
117
127
|
await assertSeedable(root, stackPackages);
|
|
118
|
-
for (const [name,
|
|
128
|
+
for (const [name, previous] of preserved) {
|
|
119
129
|
const current = await existingFile(root, name);
|
|
120
|
-
if ((
|
|
130
|
+
if ((previous === null) !== (current === null) || previous &&
|
|
131
|
+
(previous.linkTarget !== current.linkTarget || !previous.contents.equals(current.contents))) {
|
|
121
132
|
throw new GenesisError('TEMPLATE_DESTINATION_CHANGED', 'Project context changed while the template was being prepared. Nothing was applied.');
|
|
122
133
|
}
|
|
123
134
|
}
|
|
@@ -126,16 +137,19 @@ export async function applyTemplate({ projectRoot, templateId, stackPackages = [
|
|
|
126
137
|
try {
|
|
127
138
|
for (const file of files) {
|
|
128
139
|
const previous = await existingFile(root, file.path);
|
|
129
|
-
if (previous && previous.equals(file.contents)) continue;
|
|
140
|
+
if (previous && previous.linkTarget === file.linkTarget && previous.contents.equals(file.contents)) continue;
|
|
130
141
|
if (previous && !preserved.has(file.path)) throw new GenesisError('TEMPLATE_DESTINATION_CHANGED', `Existing project content was preserved: ${file.path}.`);
|
|
131
142
|
await mkdir(path.dirname(path.join(root, file.path)), { recursive: true });
|
|
132
|
-
if (
|
|
143
|
+
if (file.linkTarget || previous?.linkTarget) {
|
|
144
|
+
if (previous) throw new GenesisError('TEMPLATE_DESTINATION_CHANGED', `Existing project link was preserved: ${file.path}.`);
|
|
145
|
+
await symlink(file.linkTarget, path.join(root, file.path), 'dir');
|
|
146
|
+
} else if (previous) await writeFileAtomic(path.join(root, file.path), file.contents);
|
|
133
147
|
else await writeFile(path.join(root, file.path), file.contents, { flag: 'wx', mode: file.mode });
|
|
134
148
|
applied.push({ path: file.path, previous });
|
|
135
149
|
}
|
|
136
150
|
} catch (error) {
|
|
137
151
|
for (const file of applied.reverse()) {
|
|
138
|
-
if (file.previous) await writeFileAtomic(path.join(root, file.path), file.previous);
|
|
152
|
+
if (file.previous) await writeFileAtomic(path.join(root, file.path), file.previous.contents);
|
|
139
153
|
else await rm(path.join(root, file.path));
|
|
140
154
|
}
|
|
141
155
|
throw error;
|
|
@@ -3,6 +3,7 @@ import os from 'node:os';
|
|
|
3
3
|
import path from 'node:path';
|
|
4
4
|
import { GenesisError } from './errors.js';
|
|
5
5
|
import { runGit, runGitText } from './process.js';
|
|
6
|
+
import { claudeSkillLinkTarget } from './claude-hooks.js';
|
|
6
7
|
|
|
7
8
|
function validateRepository(repository) {
|
|
8
9
|
if (typeof repository !== 'string' || !repository || repository.startsWith('-')) {
|
|
@@ -35,11 +36,19 @@ export async function readGitSnapshot({ repository, branch }) {
|
|
|
35
36
|
const separator = item.indexOf('\t');
|
|
36
37
|
const [mode, type, object] = item.slice(0, separator).split(' ');
|
|
37
38
|
const name = item.slice(separator + 1);
|
|
38
|
-
if (!['100644', '100755'].includes(mode) || type !== 'blob' || path.isAbsolute(name)
|
|
39
|
+
if (!['100644', '100755', '120000'].includes(mode) || type !== 'blob' || path.isAbsolute(name)
|
|
39
40
|
|| name.includes('\\') || name.split('/').some((part) => !part || ['.', '..', '.git'].includes(part.toLowerCase()))) {
|
|
40
41
|
throw new GenesisError('TEMPLATE_TREE_INVALID', `Template contains an unsupported path or file: ${name}.`);
|
|
41
42
|
}
|
|
42
43
|
const blob = await runGit(temporaryRoot, ['cat-file', 'blob', object]);
|
|
44
|
+
if (mode === '120000') {
|
|
45
|
+
const target = claudeSkillLinkTarget(name);
|
|
46
|
+
if (!target || !blob.stdout.equals(Buffer.from(target))) {
|
|
47
|
+
throw new GenesisError('TEMPLATE_TREE_INVALID', `Template contains an unsupported link: ${name}.`);
|
|
48
|
+
}
|
|
49
|
+
// Regenerate these through initialization from the canonical skill files.
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
43
52
|
bytes += blob.stdout.length;
|
|
44
53
|
if (bytes > 64 * 1024 * 1024 || files.length >= 10_000) {
|
|
45
54
|
throw new GenesisError('TEMPLATE_TREE_TOO_LARGE', 'Template exceeds the source size limit.');
|