geloforge 0.0.0-stage → 0.7.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/LICENSE +21 -0
- package/README.md +72 -2
- package/THIRD_PARTY_NOTICES.md +33 -0
- package/VERSION +1 -0
- package/adapters/n8n/staging-audit-error-workflow.json +132 -0
- package/core/adopt-project.mjs +458 -0
- package/core/audit-learning.mjs +68 -0
- package/core/audit-provider.mjs +88 -0
- package/core/autonomous-audit.mjs +214 -0
- package/core/checkpoint.mjs +448 -0
- package/core/codebase-map.mjs +886 -0
- package/core/compatibility.json +16 -0
- package/core/compatibility.mjs +123 -0
- package/core/context-cache.mjs +113 -0
- package/core/context-compiler.mjs +1315 -0
- package/core/evidence-capture.mjs +347 -0
- package/core/git-utils.mjs +167 -0
- package/core/handoff.mjs +815 -0
- package/core/json-schema-lite.mjs +119 -0
- package/core/mcp-init.mjs +251 -0
- package/core/mcp-server.mjs +915 -0
- package/core/operation-approval.mjs +102 -0
- package/core/path-safety.mjs +508 -0
- package/core/project-locator.mjs +231 -0
- package/core/project-lock.mjs +438 -0
- package/core/project-status.mjs +635 -0
- package/core/project-validator.mjs +544 -0
- package/core/promotion.mjs +90 -0
- package/core/runtime-files.mjs +40 -0
- package/core/skills-history.mjs +572 -0
- package/core/skills-lifecycle.mjs +2225 -0
- package/core/skills-lint.mjs +365 -0
- package/core/skills.mjs +1449 -0
- package/core/staging-audit.mjs +454 -0
- package/core/staging-evidence.mjs +127 -0
- package/core/task-manager.mjs +1044 -0
- package/core/template-utils.mjs +190 -0
- package/core/text-utils.mjs +48 -0
- package/core/verify-task.mjs +48 -0
- package/core/worktrees.mjs +64 -0
- package/core/yaml-subset.mjs +572 -0
- package/package.json +50 -4
- package/policies/approval-boundaries.md +42 -0
- package/policies/memory-policy.md +53 -0
- package/policies/token-efficiency.md +30 -0
- package/schemas/README.md +43 -0
- package/schemas/adr.schema.json +64 -0
- package/schemas/agent-handoff.schema.json +139 -0
- package/schemas/approval-record.schema.json +110 -0
- package/schemas/conflict-record.schema.json +60 -0
- package/schemas/context-pack-manifest.schema.json +194 -0
- package/schemas/evidence-manifest.schema.json +83 -0
- package/schemas/incident-record.schema.json +53 -0
- package/schemas/project-manifest.schema.json +90 -0
- package/schemas/project-state.schema.json +64 -0
- package/schemas/recovery-checkpoint.schema.json +49 -0
- package/schemas/research-record.schema.json +76 -0
- package/schemas/task-contract.schema.json +95 -0
- package/scripts/bootstrap-project.mjs +357 -0
- package/scripts/geloforge.mjs +2512 -0
- package/templates/profiles/README.md +19 -0
- package/templates/profiles/ai-system/brain/profile.md +21 -0
- package/templates/profiles/ai-system/gitignore.append +5 -0
- package/templates/profiles/ai-system/profile.json +6 -0
- package/templates/profiles/automation/brain/profile.md +19 -0
- package/templates/profiles/automation/gitignore.append +5 -0
- package/templates/profiles/automation/profile.json +6 -0
- package/templates/profiles/desktop/brain/profile.md +21 -0
- package/templates/profiles/desktop/gitignore.append +7 -0
- package/templates/profiles/desktop/profile.json +6 -0
- package/templates/profiles/mobile/brain/profile.md +20 -0
- package/templates/profiles/mobile/gitignore.append +8 -0
- package/templates/profiles/mobile/profile.json +6 -0
- package/templates/profiles/web/brain/profile.md +21 -0
- package/templates/profiles/web/gitignore.append +6 -0
- package/templates/profiles/web/profile.json +6 -0
- package/templates/project-starter/AGENTS.md +27 -0
- package/templates/project-starter/GEMINI.md +16 -0
- package/templates/project-starter/README.md +26 -0
- package/templates/project-starter/brain/INDEX.md +40 -0
- package/templates/project-starter/brain/architecture/overview.md +30 -0
- package/templates/project-starter/brain/decisions/.gitkeep +0 -0
- package/templates/project-starter/brain/manifest.yaml +36 -0
- package/templates/project-starter/brain/requirements/constraints.md +29 -0
- package/templates/project-starter/brain/requirements/prd.md +37 -0
- package/templates/project-starter/brain/state/current.yaml +19 -0
- package/templates/project-starter/gitignore.template +25 -0
- package/templates/project-starter/src/.gitkeep +0 -0
- package/templates/project-starter/tasks/.gitkeep +0 -0
- package/templates/project-starter/tests/.gitkeep +0 -0
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3
|
+
"$id": "https://ai-workspace.local/schemas/task-contract.schema.json",
|
|
4
|
+
"title": "Task Contract",
|
|
5
|
+
"description": "Operational contract defining task scope, inputs, outputs, and acceptance criteria.",
|
|
6
|
+
"type": "object",
|
|
7
|
+
"additionalProperties": false,
|
|
8
|
+
"required": [
|
|
9
|
+
"schema_version",
|
|
10
|
+
"id",
|
|
11
|
+
"title",
|
|
12
|
+
"project_id",
|
|
13
|
+
"status",
|
|
14
|
+
"memory_layer",
|
|
15
|
+
"authority_level",
|
|
16
|
+
"priority",
|
|
17
|
+
"assigned_role",
|
|
18
|
+
"created_by",
|
|
19
|
+
"created_at",
|
|
20
|
+
"updated_at",
|
|
21
|
+
"objective",
|
|
22
|
+
"scope_in",
|
|
23
|
+
"scope_out",
|
|
24
|
+
"required_inputs",
|
|
25
|
+
"expected_outputs",
|
|
26
|
+
"acceptance_criteria",
|
|
27
|
+
"dependencies",
|
|
28
|
+
"approval_required",
|
|
29
|
+
"approval_ref",
|
|
30
|
+
"context_budget",
|
|
31
|
+
"max_retries",
|
|
32
|
+
"evidence_refs"
|
|
33
|
+
],
|
|
34
|
+
"properties": {
|
|
35
|
+
"schema_version": { "type": "string", "enum": ["1.0", "1.1"] },
|
|
36
|
+
"id": { "type": "string", "pattern": "^TASK-\\d{4}$" },
|
|
37
|
+
"title": { "type": "string", "minLength": 3 },
|
|
38
|
+
"project_id": { "type": "string", "pattern": "^proj-[a-z0-9][a-z0-9-]{1,48}[a-z0-9]$" },
|
|
39
|
+
"status": { "type": "string", "enum": ["inbox", "ready", "active", "in_review", "blocked", "completed", "cancelled"] },
|
|
40
|
+
"memory_layer": { "type": "string", "enum": ["L2_OPERATIONAL"] },
|
|
41
|
+
"authority_level": { "type": "string", "enum": ["A0", "A1", "A2", "A3", "A4", "A5", "A6"] },
|
|
42
|
+
"priority": { "type": "string", "enum": ["low", "medium", "high", "critical"] },
|
|
43
|
+
"assigned_role": {
|
|
44
|
+
"type": "string",
|
|
45
|
+
"enum": ["orchestrator", "researcher", "software-architect", "developer", "qa-security-reviewer"]
|
|
46
|
+
},
|
|
47
|
+
"created_by": { "type": "string", "minLength": 1 },
|
|
48
|
+
"created_at": { "type": "string", "minLength": 10 },
|
|
49
|
+
"updated_at": { "type": "string", "minLength": 10 },
|
|
50
|
+
"objective": { "type": "string", "minLength": 1 },
|
|
51
|
+
"scope_in": {
|
|
52
|
+
"type": "array",
|
|
53
|
+
"items": { "type": "string", "minLength": 1 }
|
|
54
|
+
},
|
|
55
|
+
"scope_out": {
|
|
56
|
+
"type": "array",
|
|
57
|
+
"items": { "type": "string", "minLength": 1 }
|
|
58
|
+
},
|
|
59
|
+
"required_inputs": {
|
|
60
|
+
"type": "array",
|
|
61
|
+
"items": {
|
|
62
|
+
"type": "object",
|
|
63
|
+
"additionalProperties": false,
|
|
64
|
+
"required": ["path", "revision"],
|
|
65
|
+
"properties": {
|
|
66
|
+
"path": { "type": "string", "minLength": 1 },
|
|
67
|
+
"revision": { "type": "string", "minLength": 1 }
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
},
|
|
71
|
+
"expected_outputs": {
|
|
72
|
+
"type": "array",
|
|
73
|
+
"items": { "type": "string", "minLength": 1 }
|
|
74
|
+
},
|
|
75
|
+
"acceptance_criteria": {
|
|
76
|
+
"type": "array",
|
|
77
|
+
"minItems": 1,
|
|
78
|
+
"items": { "type": "string", "minLength": 1 }
|
|
79
|
+
},
|
|
80
|
+
"dependencies": {
|
|
81
|
+
"type": "array",
|
|
82
|
+
"items": { "type": "string", "pattern": "^TASK-\\d{4}$" }
|
|
83
|
+
},
|
|
84
|
+
"approval_required": { "type": "boolean" },
|
|
85
|
+
"approval_ref": { "type": ["string", "null"], "pattern": "^APPR-\\d{4}$" },
|
|
86
|
+
"context_budget": { "type": "string", "enum": ["quick", "working", "deep"] },
|
|
87
|
+
"max_retries": { "type": "integer", "minimum": 0, "maximum": 5 },
|
|
88
|
+
"evidence_refs": {
|
|
89
|
+
"type": "array",
|
|
90
|
+
"items": { "type": "string", "pattern": "^EVID-\\d{4}$" }
|
|
91
|
+
},
|
|
92
|
+
"is_example": { "type": "boolean" },
|
|
93
|
+
"example_notice": { "type": "string" }
|
|
94
|
+
}
|
|
95
|
+
}
|
|
@@ -0,0 +1,357 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Transactional, zero-dependency project bootstrapper for the AI Development Harness.
|
|
4
|
+
* Combines templates/project-starter with an optional domain profile overlay,
|
|
5
|
+
* enforces strict path/symlink/overwrite safety, runs validation inside staging,
|
|
6
|
+
* and atomically commits to the target destination.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import crypto from "node:crypto";
|
|
10
|
+
import fs from "node:fs";
|
|
11
|
+
import path from "node:path";
|
|
12
|
+
import { parseArgs } from "node:util";
|
|
13
|
+
import { execFileSync } from "node:child_process";
|
|
14
|
+
import { fileURLToPath } from "node:url";
|
|
15
|
+
import {
|
|
16
|
+
validateProjectName,
|
|
17
|
+
deriveSlug,
|
|
18
|
+
validateSlug,
|
|
19
|
+
validateScalarText,
|
|
20
|
+
validateDestinationPath,
|
|
21
|
+
assertNoSymlinkInTree,
|
|
22
|
+
} from "../core/path-safety.mjs";
|
|
23
|
+
import { loadCompatibilityConfig } from "../core/compatibility.mjs";
|
|
24
|
+
import { validateProject } from "../core/project-validator.mjs";
|
|
25
|
+
import {
|
|
26
|
+
escapeYamlScalarText,
|
|
27
|
+
renderSinglePass,
|
|
28
|
+
resolveProfile,
|
|
29
|
+
validateCreatedAt,
|
|
30
|
+
} from "../core/template-utils.mjs";
|
|
31
|
+
|
|
32
|
+
export { renderSinglePass };
|
|
33
|
+
|
|
34
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
35
|
+
const __dirname = path.dirname(__filename);
|
|
36
|
+
const HARNESS_DIR = path.resolve(__dirname, "..");
|
|
37
|
+
const WORKSPACE_ROOT = path.resolve(HARNESS_DIR, "..");
|
|
38
|
+
const IS_NPM_INSTALL = path.basename(WORKSPACE_ROOT) === "node_modules";
|
|
39
|
+
const TEMPLATE_DIR = path.join(HARNESS_DIR, "templates", "project-starter");
|
|
40
|
+
const PROFILES_DIR = path.join(HARNESS_DIR, "templates", "profiles");
|
|
41
|
+
const VERSION_FILE = path.join(HARNESS_DIR, "VERSION");
|
|
42
|
+
export const DEFAULT_INIT_LOCATION = IS_NPM_INSTALL ? "./projects/<slug>" : "<workspace-root>/projects/<slug>";
|
|
43
|
+
|
|
44
|
+
function printHelp() {
|
|
45
|
+
console.log(`AI Harness Project Bootstrapper
|
|
46
|
+
|
|
47
|
+
Usage:
|
|
48
|
+
node scripts/bootstrap-project.mjs --name "<Project Name>" [options]
|
|
49
|
+
|
|
50
|
+
Options:
|
|
51
|
+
--name <string> Project display name (required, 3-80 chars)
|
|
52
|
+
--slug <string> Lowercase ASCII slug (optional; derived from --name)
|
|
53
|
+
--dest <path> Target directory (default: ${DEFAULT_INIT_LOCATION})
|
|
54
|
+
--owner <string> Project owner name (default: "Project Owner")
|
|
55
|
+
--description <string> Short project description
|
|
56
|
+
--profile <name> Optional project profile (web, desktop, mobile, automation, ai-system)
|
|
57
|
+
--created-at <iso> Optional ISO-8601 timestamp for deterministic generation
|
|
58
|
+
--git Initialize an isolated local Git repository (git init -b main)
|
|
59
|
+
--dry-run Validate inputs and preview planned files without writing anything
|
|
60
|
+
-h, --help Show this help message
|
|
61
|
+
`);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function collectTemplateFiles(rootDir, currentDir = rootDir) {
|
|
65
|
+
const entries = fs.readdirSync(currentDir, { withFileTypes: true });
|
|
66
|
+
entries.sort((a, b) => a.name.localeCompare(b.name));
|
|
67
|
+
const files = [];
|
|
68
|
+
for (const entry of entries) {
|
|
69
|
+
const fullPath = path.join(currentDir, entry.name);
|
|
70
|
+
if (entry.isDirectory()) {
|
|
71
|
+
files.push(...collectTemplateFiles(rootDir, fullPath));
|
|
72
|
+
} else if (entry.isFile()) {
|
|
73
|
+
files.push(path.relative(rootDir, fullPath));
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
return files;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function renderManifest(rawContent, tokens, { gitInit, profileMeta }) {
|
|
80
|
+
let output = renderSinglePass(rawContent, tokens, true, "brain/manifest.yaml");
|
|
81
|
+
output = output.replace(/^status:\s*"template"(?=\r?$)/m, 'status: "initialized"');
|
|
82
|
+
if (gitInit) {
|
|
83
|
+
output = output.replace(/^(\s*initialized:\s*)false(?=\r?$)/m, "$1true");
|
|
84
|
+
}
|
|
85
|
+
if (profileMeta) {
|
|
86
|
+
output = output.replace(/^profile:\s*null(?=\r?$)/m, `profile: "${escapeYamlScalarText(profileMeta.name)}"`);
|
|
87
|
+
output = output.replace(
|
|
88
|
+
/^profile_version:\s*null(?=\r?$)/m,
|
|
89
|
+
`profile_version: "${escapeYamlScalarText(profileMeta.version)}"`
|
|
90
|
+
);
|
|
91
|
+
}
|
|
92
|
+
return output;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function ensureParentDirsTracked(targetParent) {
|
|
96
|
+
const missing = [];
|
|
97
|
+
let cursor = path.resolve(targetParent);
|
|
98
|
+
while (cursor && !fs.existsSync(cursor)) {
|
|
99
|
+
missing.push(cursor);
|
|
100
|
+
const up = path.dirname(cursor);
|
|
101
|
+
if (up === cursor) {
|
|
102
|
+
break;
|
|
103
|
+
}
|
|
104
|
+
cursor = up;
|
|
105
|
+
}
|
|
106
|
+
missing.reverse();
|
|
107
|
+
const created = [];
|
|
108
|
+
for (const dir of missing) {
|
|
109
|
+
fs.mkdirSync(dir);
|
|
110
|
+
created.push(dir);
|
|
111
|
+
}
|
|
112
|
+
return created;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
export function bootstrapProject(options = {}) {
|
|
116
|
+
if (!fs.existsSync(TEMPLATE_DIR)) {
|
|
117
|
+
throw new Error(`Template directory missing: ${TEMPLATE_DIR}`);
|
|
118
|
+
}
|
|
119
|
+
if (!fs.existsSync(VERSION_FILE)) {
|
|
120
|
+
throw new Error(`Harness VERSION file missing: ${VERSION_FILE}`);
|
|
121
|
+
}
|
|
122
|
+
assertNoSymlinkInTree(TEMPLATE_DIR);
|
|
123
|
+
|
|
124
|
+
const compatConfig = loadCompatibilityConfig();
|
|
125
|
+
const projectName = validateProjectName(options.name);
|
|
126
|
+
const derivedOrExplicitSlug = options.slug ? options.slug.trim() : deriveSlug(projectName);
|
|
127
|
+
const slug = validateSlug(derivedOrExplicitSlug);
|
|
128
|
+
const projectId = `proj-${slug}`;
|
|
129
|
+
const owner = validateScalarText("--owner", options.owner ?? "Project Owner");
|
|
130
|
+
const description = validateScalarText(
|
|
131
|
+
"--description",
|
|
132
|
+
options.description ?? "Project initialized from the AI harness Second Brain starter template."
|
|
133
|
+
);
|
|
134
|
+
|
|
135
|
+
const resolvedProfile = resolveProfile(options.profile, compatConfig, PROFILES_DIR);
|
|
136
|
+
const profileMeta = resolvedProfile ? resolvedProfile.meta : null;
|
|
137
|
+
|
|
138
|
+
const defaultDest = path.join(IS_NPM_INSTALL ? process.cwd() : WORKSPACE_ROOT, "projects", slug);
|
|
139
|
+
const destDir = validateDestinationPath(options.dest ?? defaultDest, {
|
|
140
|
+
harnessDir: HARNESS_DIR,
|
|
141
|
+
workspaceRoot: WORKSPACE_ROOT,
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
const dryRun = Boolean(options.dryRun);
|
|
145
|
+
const gitInit = Boolean(options.git);
|
|
146
|
+
const harnessVersion = fs.readFileSync(VERSION_FILE, "utf8").trim();
|
|
147
|
+
const createdAt = validateCreatedAt(options.createdAt);
|
|
148
|
+
const createdDate = createdAt.slice(0, 10);
|
|
149
|
+
|
|
150
|
+
const tokens = {
|
|
151
|
+
PROJECT_NAME: projectName,
|
|
152
|
+
PROJECT_SLUG: slug,
|
|
153
|
+
PROJECT_ID: projectId,
|
|
154
|
+
PROJECT_DESCRIPTION: description,
|
|
155
|
+
PROJECT_OWNER: owner,
|
|
156
|
+
CREATED_AT: createdAt,
|
|
157
|
+
CREATED_DATE: createdDate,
|
|
158
|
+
HARNESS_VERSION: harnessVersion,
|
|
159
|
+
TEMPLATE_VERSION: compatConfig.template_version,
|
|
160
|
+
PROFILE_NAME: profileMeta ? profileMeta.name : "none",
|
|
161
|
+
PROFILE_VERSION: profileMeta ? profileMeta.version : "0.0.0",
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
const baseFiles = collectTemplateFiles(TEMPLATE_DIR);
|
|
165
|
+
const renderedMap = new Map();
|
|
166
|
+
|
|
167
|
+
for (const relPath of baseFiles) {
|
|
168
|
+
// npm omits .gitignore files from tarballs. Restore the name in the generated project.
|
|
169
|
+
const normalizedRel = relPath === "gitignore.template" ? ".gitignore" : relPath.replace(/\\/g, "/");
|
|
170
|
+
const raw = fs.readFileSync(path.join(TEMPLATE_DIR, relPath), "utf8");
|
|
171
|
+
const isYaml = normalizedRel.endsWith(".yaml") || normalizedRel.endsWith(".yml");
|
|
172
|
+
const content =
|
|
173
|
+
normalizedRel === "brain/manifest.yaml"
|
|
174
|
+
? renderManifest(raw, tokens, { gitInit, profileMeta })
|
|
175
|
+
: renderSinglePass(raw, tokens, isYaml, normalizedRel);
|
|
176
|
+
renderedMap.set(normalizedRel, content);
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
if (resolvedProfile) {
|
|
180
|
+
const profileGuideSrc = path.join(resolvedProfile.profileDir, "brain", "profile.md");
|
|
181
|
+
if (fs.existsSync(profileGuideSrc)) {
|
|
182
|
+
const rawGuide = fs.readFileSync(profileGuideSrc, "utf8");
|
|
183
|
+
renderedMap.set("brain/profile.md", renderSinglePass(rawGuide, tokens, false, "brain/profile.md"));
|
|
184
|
+
}
|
|
185
|
+
const gitignoreAppendSrc = path.join(resolvedProfile.profileDir, "gitignore.append");
|
|
186
|
+
if (fs.existsSync(gitignoreAppendSrc)) {
|
|
187
|
+
const baseIgnore = (renderedMap.get(".gitignore") || "").replace(/\r\n/g, "\n").trimEnd();
|
|
188
|
+
const extraIgnore = fs.readFileSync(gitignoreAppendSrc, "utf8").replace(/\r\n/g, "\n").trim();
|
|
189
|
+
if (extraIgnore.length > 0) {
|
|
190
|
+
renderedMap.set(
|
|
191
|
+
".gitignore",
|
|
192
|
+
`${baseIgnore}\n\n# Profile additions (${profileMeta.name} v${profileMeta.version})\n${extraIgnore}\n`
|
|
193
|
+
);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
const orderedFiles = Array.from(renderedMap.entries())
|
|
199
|
+
.sort(([a], [b]) => a.localeCompare(b))
|
|
200
|
+
.map(([relPath, content]) => ({ relPath, content }));
|
|
201
|
+
|
|
202
|
+
if (dryRun) {
|
|
203
|
+
return {
|
|
204
|
+
dryRun: true,
|
|
205
|
+
projectName,
|
|
206
|
+
projectId,
|
|
207
|
+
slug,
|
|
208
|
+
owner,
|
|
209
|
+
profile: profileMeta ? profileMeta.name : null,
|
|
210
|
+
profileVersion: profileMeta ? profileMeta.version : null,
|
|
211
|
+
destDir,
|
|
212
|
+
gitInitialized: false,
|
|
213
|
+
files: orderedFiles.map((f) => f.relPath),
|
|
214
|
+
validation: null,
|
|
215
|
+
};
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
const parentDir = path.dirname(destDir);
|
|
219
|
+
const createdParents = ensureParentDirsTracked(parentDir);
|
|
220
|
+
const stageDir = path.join(parentDir, `.harness-stage-${crypto.randomBytes(6).toString("hex")}`);
|
|
221
|
+
fs.mkdirSync(stageDir, { recursive: false });
|
|
222
|
+
|
|
223
|
+
try {
|
|
224
|
+
for (const file of orderedFiles) {
|
|
225
|
+
const targetPath = path.join(stageDir, file.relPath);
|
|
226
|
+
fs.mkdirSync(path.dirname(targetPath), { recursive: true });
|
|
227
|
+
fs.writeFileSync(targetPath, file.content, { encoding: "utf8", flag: "wx" });
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
if (gitInit) {
|
|
231
|
+
execFileSync("git", ["init", "-b", "main"], {
|
|
232
|
+
cwd: stageDir,
|
|
233
|
+
encoding: "utf8",
|
|
234
|
+
windowsHide: true,
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
const validation = validateProject(stageDir, { compatibilityConfig: compatConfig });
|
|
239
|
+
if (!validation.valid) {
|
|
240
|
+
throw new Error(`Staged project failed validation: ${validation.errors.join("; ")}`);
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
if (typeof options.onBeforeCommit === "function") {
|
|
244
|
+
options.onBeforeCommit(stageDir);
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
fs.renameSync(stageDir, destDir);
|
|
248
|
+
|
|
249
|
+
return {
|
|
250
|
+
dryRun: false,
|
|
251
|
+
projectName,
|
|
252
|
+
projectId,
|
|
253
|
+
slug,
|
|
254
|
+
owner,
|
|
255
|
+
profile: profileMeta ? profileMeta.name : null,
|
|
256
|
+
profileVersion: profileMeta ? profileMeta.version : null,
|
|
257
|
+
destDir,
|
|
258
|
+
gitInitialized: gitInit,
|
|
259
|
+
files: orderedFiles.map((f) => f.relPath),
|
|
260
|
+
validation,
|
|
261
|
+
};
|
|
262
|
+
} catch (err) {
|
|
263
|
+
try {
|
|
264
|
+
fs.rmSync(stageDir, { recursive: true, force: true, maxRetries: 3 });
|
|
265
|
+
} catch {
|
|
266
|
+
// Best-effort cleanup of staging directory.
|
|
267
|
+
}
|
|
268
|
+
for (const dir of createdParents.reverse()) {
|
|
269
|
+
try {
|
|
270
|
+
fs.rmdirSync(dir);
|
|
271
|
+
} catch {
|
|
272
|
+
// Leave non-empty directories untouched.
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
throw err;
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
function runCli() {
|
|
280
|
+
let parsed;
|
|
281
|
+
try {
|
|
282
|
+
parsed = parseArgs({
|
|
283
|
+
options: {
|
|
284
|
+
name: { type: "string" },
|
|
285
|
+
slug: { type: "string" },
|
|
286
|
+
dest: { type: "string" },
|
|
287
|
+
owner: { type: "string" },
|
|
288
|
+
description: { type: "string" },
|
|
289
|
+
profile: { type: "string" },
|
|
290
|
+
"created-at": { type: "string" },
|
|
291
|
+
git: { type: "boolean", default: false },
|
|
292
|
+
"dry-run": { type: "boolean", default: false },
|
|
293
|
+
help: { type: "boolean", short: "h", default: false },
|
|
294
|
+
},
|
|
295
|
+
strict: true,
|
|
296
|
+
allowPositionals: false,
|
|
297
|
+
});
|
|
298
|
+
} catch (err) {
|
|
299
|
+
console.error(`ERROR: ${err.message}`);
|
|
300
|
+
process.exit(1);
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
const opts = parsed.values;
|
|
304
|
+
if (opts.help) {
|
|
305
|
+
printHelp();
|
|
306
|
+
process.exit(0);
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
try {
|
|
310
|
+
const result = bootstrapProject({
|
|
311
|
+
name: opts.name,
|
|
312
|
+
slug: opts.slug,
|
|
313
|
+
dest: opts.dest,
|
|
314
|
+
owner: opts.owner,
|
|
315
|
+
description: opts.description,
|
|
316
|
+
profile: opts.profile,
|
|
317
|
+
createdAt: opts["created-at"],
|
|
318
|
+
git: opts.git,
|
|
319
|
+
dryRun: opts["dry-run"],
|
|
320
|
+
});
|
|
321
|
+
|
|
322
|
+
if (result.dryRun) {
|
|
323
|
+
console.log("DRY RUN — No directories, files, or Git repositories were created.");
|
|
324
|
+
} else {
|
|
325
|
+
console.log("Project Second Brain initialized successfully.");
|
|
326
|
+
}
|
|
327
|
+
console.log(`Project Name : ${result.projectName}`);
|
|
328
|
+
console.log(`Project ID : ${result.projectId}`);
|
|
329
|
+
console.log(`Slug : ${result.slug}`);
|
|
330
|
+
console.log(`Owner : ${result.owner}`);
|
|
331
|
+
console.log(`Profile : ${result.profile ? `${result.profile} (${result.profileVersion})` : "none (base starter)"}`);
|
|
332
|
+
console.log(`Destination : ${result.destDir}`);
|
|
333
|
+
console.log(
|
|
334
|
+
`Git Init : ${
|
|
335
|
+
result.dryRun
|
|
336
|
+
? opts.git
|
|
337
|
+
? "would run: git init -b main"
|
|
338
|
+
: "no"
|
|
339
|
+
: result.gitInitialized
|
|
340
|
+
? "Initialized isolated Git repository on branch 'main' (no remotes, no commits)"
|
|
341
|
+
: "Skipped (pass --git to initialize an isolated project Git repo)"
|
|
342
|
+
}`
|
|
343
|
+
);
|
|
344
|
+
console.log(`${result.dryRun ? "Planned" : "Generated"} Files (${result.files.length}):`);
|
|
345
|
+
for (const f of result.files) {
|
|
346
|
+
console.log(` - ${f}`);
|
|
347
|
+
}
|
|
348
|
+
} catch (err) {
|
|
349
|
+
console.error(`ERROR: ${err.message}`);
|
|
350
|
+
process.exit(1);
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
const isDirectRun = Boolean(process.argv[1] && path.resolve(process.argv[1]) === path.resolve(__filename));
|
|
355
|
+
if (isDirectRun) {
|
|
356
|
+
runCli();
|
|
357
|
+
}
|