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.
Files changed (90) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +72 -2
  3. package/THIRD_PARTY_NOTICES.md +33 -0
  4. package/VERSION +1 -0
  5. package/adapters/n8n/staging-audit-error-workflow.json +132 -0
  6. package/core/adopt-project.mjs +458 -0
  7. package/core/audit-learning.mjs +68 -0
  8. package/core/audit-provider.mjs +88 -0
  9. package/core/autonomous-audit.mjs +214 -0
  10. package/core/checkpoint.mjs +448 -0
  11. package/core/codebase-map.mjs +886 -0
  12. package/core/compatibility.json +16 -0
  13. package/core/compatibility.mjs +123 -0
  14. package/core/context-cache.mjs +113 -0
  15. package/core/context-compiler.mjs +1315 -0
  16. package/core/evidence-capture.mjs +347 -0
  17. package/core/git-utils.mjs +167 -0
  18. package/core/handoff.mjs +815 -0
  19. package/core/json-schema-lite.mjs +119 -0
  20. package/core/mcp-init.mjs +251 -0
  21. package/core/mcp-server.mjs +915 -0
  22. package/core/operation-approval.mjs +102 -0
  23. package/core/path-safety.mjs +508 -0
  24. package/core/project-locator.mjs +231 -0
  25. package/core/project-lock.mjs +438 -0
  26. package/core/project-status.mjs +635 -0
  27. package/core/project-validator.mjs +544 -0
  28. package/core/promotion.mjs +90 -0
  29. package/core/runtime-files.mjs +40 -0
  30. package/core/skills-history.mjs +572 -0
  31. package/core/skills-lifecycle.mjs +2225 -0
  32. package/core/skills-lint.mjs +365 -0
  33. package/core/skills.mjs +1449 -0
  34. package/core/staging-audit.mjs +454 -0
  35. package/core/staging-evidence.mjs +127 -0
  36. package/core/task-manager.mjs +1044 -0
  37. package/core/template-utils.mjs +190 -0
  38. package/core/text-utils.mjs +48 -0
  39. package/core/verify-task.mjs +48 -0
  40. package/core/worktrees.mjs +64 -0
  41. package/core/yaml-subset.mjs +572 -0
  42. package/package.json +50 -4
  43. package/policies/approval-boundaries.md +42 -0
  44. package/policies/memory-policy.md +53 -0
  45. package/policies/token-efficiency.md +30 -0
  46. package/schemas/README.md +43 -0
  47. package/schemas/adr.schema.json +64 -0
  48. package/schemas/agent-handoff.schema.json +139 -0
  49. package/schemas/approval-record.schema.json +110 -0
  50. package/schemas/conflict-record.schema.json +60 -0
  51. package/schemas/context-pack-manifest.schema.json +194 -0
  52. package/schemas/evidence-manifest.schema.json +83 -0
  53. package/schemas/incident-record.schema.json +53 -0
  54. package/schemas/project-manifest.schema.json +90 -0
  55. package/schemas/project-state.schema.json +64 -0
  56. package/schemas/recovery-checkpoint.schema.json +49 -0
  57. package/schemas/research-record.schema.json +76 -0
  58. package/schemas/task-contract.schema.json +95 -0
  59. package/scripts/bootstrap-project.mjs +357 -0
  60. package/scripts/geloforge.mjs +2512 -0
  61. package/templates/profiles/README.md +19 -0
  62. package/templates/profiles/ai-system/brain/profile.md +21 -0
  63. package/templates/profiles/ai-system/gitignore.append +5 -0
  64. package/templates/profiles/ai-system/profile.json +6 -0
  65. package/templates/profiles/automation/brain/profile.md +19 -0
  66. package/templates/profiles/automation/gitignore.append +5 -0
  67. package/templates/profiles/automation/profile.json +6 -0
  68. package/templates/profiles/desktop/brain/profile.md +21 -0
  69. package/templates/profiles/desktop/gitignore.append +7 -0
  70. package/templates/profiles/desktop/profile.json +6 -0
  71. package/templates/profiles/mobile/brain/profile.md +20 -0
  72. package/templates/profiles/mobile/gitignore.append +8 -0
  73. package/templates/profiles/mobile/profile.json +6 -0
  74. package/templates/profiles/web/brain/profile.md +21 -0
  75. package/templates/profiles/web/gitignore.append +6 -0
  76. package/templates/profiles/web/profile.json +6 -0
  77. package/templates/project-starter/AGENTS.md +27 -0
  78. package/templates/project-starter/GEMINI.md +16 -0
  79. package/templates/project-starter/README.md +26 -0
  80. package/templates/project-starter/brain/INDEX.md +40 -0
  81. package/templates/project-starter/brain/architecture/overview.md +30 -0
  82. package/templates/project-starter/brain/decisions/.gitkeep +0 -0
  83. package/templates/project-starter/brain/manifest.yaml +36 -0
  84. package/templates/project-starter/brain/requirements/constraints.md +29 -0
  85. package/templates/project-starter/brain/requirements/prd.md +37 -0
  86. package/templates/project-starter/brain/state/current.yaml +19 -0
  87. package/templates/project-starter/gitignore.template +25 -0
  88. package/templates/project-starter/src/.gitkeep +0 -0
  89. package/templates/project-starter/tasks/.gitkeep +0 -0
  90. package/templates/project-starter/tests/.gitkeep +0 -0
@@ -0,0 +1,16 @@
1
+ {
2
+ "harness_version": "0.7.0",
3
+ "template_version": "1.0.0",
4
+ "default_schema_version": "1.1",
5
+ "supported_schema_versions": ["1.0", "1.1"],
6
+ "supported_template_major": 1,
7
+ "supported_profile_major": 1,
8
+ "node_minimum": "20.0.0",
9
+ "profiles": {
10
+ "web": "1.0.0",
11
+ "desktop": "1.0.0",
12
+ "mobile": "1.0.0",
13
+ "automation": "1.0.0",
14
+ "ai-system": "1.0.0"
15
+ }
16
+ }
@@ -0,0 +1,123 @@
1
+ /**
2
+ * Lightweight version and compatibility checking for harness, template, schema, and profile versions.
3
+ * Zero external dependencies.
4
+ */
5
+
6
+ import fs from "node:fs";
7
+ import path from "node:path";
8
+ import { fileURLToPath } from "node:url";
9
+
10
+ const __filename = fileURLToPath(import.meta.url);
11
+ const __dirname = path.dirname(__filename);
12
+ const DEFAULT_COMPAT_PATH = path.join(__dirname, "compatibility.json");
13
+
14
+ export function loadCompatibilityConfig(compatPath = DEFAULT_COMPAT_PATH) {
15
+ return JSON.parse(fs.readFileSync(compatPath, "utf8"));
16
+ }
17
+
18
+ export function parseSemver(version) {
19
+ if (typeof version !== "string") {
20
+ return null;
21
+ }
22
+ const match = version.trim().match(/^(\d+)\.(\d+)\.(\d+)$/);
23
+ if (!match) {
24
+ return null;
25
+ }
26
+ return {
27
+ major: Number.parseInt(match[1], 10),
28
+ minor: Number.parseInt(match[2], 10),
29
+ patch: Number.parseInt(match[3], 10),
30
+ };
31
+ }
32
+
33
+ export function checkRecordSchemaVersion(record, config = loadCompatibilityConfig()) {
34
+ const version = record?.schema_version;
35
+ if (typeof version !== "string" || !config.supported_schema_versions.includes(version)) {
36
+ return {
37
+ compatible: false,
38
+ error: `Unsupported schema_version "${String(version)}" (supported: ${config.supported_schema_versions.join(", ")})`,
39
+ };
40
+ }
41
+ return { compatible: true, error: null };
42
+ }
43
+
44
+ export function checkManifestCompatibility(manifest, config = loadCompatibilityConfig()) {
45
+ const errors = [];
46
+ const warnings = [];
47
+
48
+ if (!manifest || typeof manifest !== "object") {
49
+ return { compatible: false, status: "invalid", errors: ["Manifest must be an object."], warnings };
50
+ }
51
+
52
+ const schemaVer = manifest.schema_version;
53
+ if (typeof schemaVer !== "string" || !config.supported_schema_versions.includes(schemaVer)) {
54
+ errors.push(
55
+ `Unsupported manifest schema_version "${String(schemaVer)}". Supported: ${config.supported_schema_versions.join(", ")}.`
56
+ );
57
+ return { compatible: false, status: "incompatible", errors, warnings };
58
+ }
59
+
60
+ if (schemaVer === "1.0") {
61
+ warnings.push(
62
+ `Project manifest uses legacy schema_version "1.0"; upgrade to "${config.default_schema_version}" when convenient (see docs/versioning-and-upgrades.md).`
63
+ );
64
+ return {
65
+ compatible: true,
66
+ status: "compatible_upgrade_available",
67
+ errors,
68
+ warnings,
69
+ };
70
+ }
71
+
72
+ // Schema 1.1+ requires template_version and optional profile/profile_version consistency.
73
+ const tplParsed = parseSemver(manifest.template_version);
74
+ if (!tplParsed) {
75
+ errors.push(
76
+ `Manifest schema_version "${schemaVer}" requires semver template_version (got "${String(manifest.template_version)}").`
77
+ );
78
+ } else if (tplParsed.major !== config.supported_template_major) {
79
+ errors.push(
80
+ `Incompatible template_version major ${tplParsed.major} (harness supports major ${config.supported_template_major}).`
81
+ );
82
+ }
83
+
84
+ if (manifest.profile !== undefined && manifest.profile !== null) {
85
+ if (!Object.hasOwn(config.profiles, manifest.profile)) {
86
+ errors.push(`Unknown project profile "${String(manifest.profile)}".`);
87
+ } else {
88
+ const profParsed = parseSemver(manifest.profile_version);
89
+ if (!profParsed) {
90
+ errors.push(
91
+ `Profile "${manifest.profile}" requires semver profile_version (got "${String(manifest.profile_version)}").`
92
+ );
93
+ } else if (profParsed.major !== config.supported_profile_major) {
94
+ errors.push(
95
+ `Incompatible profile_version major ${profParsed.major} for "${manifest.profile}" (harness supports major ${config.supported_profile_major}).`
96
+ );
97
+ }
98
+ }
99
+ } else if (manifest.profile_version !== undefined && manifest.profile_version !== null) {
100
+ errors.push("profile_version must be null when profile is null.");
101
+ }
102
+
103
+ return {
104
+ compatible: errors.length === 0,
105
+ status: errors.length === 0 ? "current" : "incompatible",
106
+ errors,
107
+ warnings,
108
+ };
109
+ }
110
+
111
+ export function upgradeManifestFixture10To11(manifest10, config = loadCompatibilityConfig()) {
112
+ if (!manifest10 || manifest10.schema_version !== "1.0") {
113
+ throw new Error('Upgrade helper expects a schema_version "1.0" manifest.');
114
+ }
115
+ return {
116
+ ...manifest10,
117
+ schema_version: config.default_schema_version,
118
+ harness_version: config.harness_version,
119
+ template_version: config.template_version,
120
+ profile: null,
121
+ profile_version: null,
122
+ };
123
+ }
@@ -0,0 +1,113 @@
1
+ /** Opt-in disk cache for query packets. Unsafe or dynamic inputs use the normal compiler. */
2
+ import fs from "node:fs";
3
+ import path from "node:path";
4
+ import { createHash } from "node:crypto";
5
+ import { fileURLToPath } from "node:url";
6
+ import { compileContext } from "./context-compiler.mjs";
7
+ import { getGitRepoInfo } from "./git-utils.mjs";
8
+ import { assertSafeWithinRoot, hasSecretContent, isForbiddenSecretPath, walkNonSymlinkFiles } from "./path-safety.mjs";
9
+ import { parseYaml } from "./yaml-subset.mjs";
10
+ import { TASK_LEASES_PATH } from "./task-manager.mjs";
11
+ import { resolveProjectPaths } from "./project-locator.mjs";
12
+ import { readRegularFile, readRuntimeJson, sha256, writeRuntimeJson } from "./runtime-files.mjs";
13
+
14
+ const CACHE = "local-runtime/context-cache/packet.json";
15
+ const MAX_BYTES = 512 * 1024;
16
+ const DEFAULT_HARNESS_DIR = fileURLToPath(new URL("../", import.meta.url));
17
+ const BUILD_DIGESTS = new Map();
18
+
19
+ function buildDigest(harnessDir) {
20
+ if (!BUILD_DIGESTS.has(harnessDir)) {
21
+ const hash = createHash("sha256");
22
+ const core = path.join(harnessDir, "core");
23
+ for (const name of fs.readdirSync(core).filter((name) => /\.(mjs|json)$/.test(name)).sort()) {
24
+ hash.update(name).update(sha256(fs.readFileSync(path.join(core, name))));
25
+ }
26
+ BUILD_DIGESTS.set(harnessDir, hash.digest("hex"));
27
+ }
28
+ return BUILD_DIGESTS.get(harnessDir);
29
+ }
30
+
31
+ function fingerprint(options) {
32
+ const root = path.resolve(options.projectDir);
33
+ const harnessDir = path.resolve(options.harnessDir ?? DEFAULT_HARNESS_DIR);
34
+ const manifestFile = assertSafeWithinRoot(root, "brain/manifest.yaml");
35
+ const rawManifest = readRegularFile(manifestFile);
36
+ if (!rawManifest || fs.lstatSync(root).isSymbolicLink() ||
37
+ fs.existsSync(assertSafeWithinRoot(root, TASK_LEASES_PATH))) return null;
38
+ const manifest = parseYaml(rawManifest.toString("utf8"), "brain/manifest.yaml");
39
+ const projectPaths = resolveProjectPaths(manifest);
40
+ const git = getGitRepoInfo(root);
41
+ const hash = createHash("sha256").update(JSON.stringify([
42
+ "context-cache-v1", buildDigest(harnessDir), root, harnessDir, git.available, git.head, git.unborn,
43
+ options.query, options.profile, options.budget, options.excludeUnverified, options.includeCompleted, options.referenceDate,
44
+ ]));
45
+ let total = 0;
46
+ let count = 0;
47
+ const hashFile = (base, relativePath) => {
48
+ if (isForbiddenSecretPath(relativePath)) return;
49
+ const bytes = readRegularFile(assertSafeWithinRoot(base, relativePath), MAX_BYTES);
50
+ total += bytes?.length ?? 0;
51
+ count += 1;
52
+ if (total > 16 * 1024 * 1024 || count > 1000) throw new Error("Context cache limits exceeded.");
53
+ hash.update(JSON.stringify([base, relativePath, bytes ? sha256(bytes) : null]));
54
+ };
55
+ const hashTree = (base, dir) => {
56
+ const absolute = assertSafeWithinRoot(base, dir);
57
+ const files = walkNonSymlinkFiles(base, absolute, (file) => /\.(md|ya?ml|json)$/i.test(file), null, {
58
+ onSymlink: () => { throw new Error("Context cache excludes symlinked inputs."); },
59
+ ignoreDirs: new Set([".git", "node_modules", "secrets"]),
60
+ });
61
+ for (const file of files) hashFile(base, path.relative(base, file));
62
+ };
63
+ hashTree(harnessDir, "policies");
64
+ hashTree(harnessDir, "schemas");
65
+ hashFile(root, "brain/manifest.yaml");
66
+ hashFile(root, "brain/profile.md");
67
+ hashTree(root, "brain/lessons");
68
+ for (const [key, file] of Object.entries(projectPaths)) {
69
+ if (key.endsWith("_dir")) hashTree(root, file);
70
+ else hashFile(root, file);
71
+ }
72
+ return hash.digest("hex");
73
+ }
74
+
75
+ export function compileCachedContext(options) {
76
+ const compile = () => ({ ...compileContext(options), diskCache: "bypassed" });
77
+ if (!options.query || options.taskId || options.includeMap || options.fromDiff || options.includeSkills ||
78
+ options.pinnedSkills?.length || options.compiledAt || options.compatibilityConfig ||
79
+ options.mapBudget !== undefined || options.skillsBudget !== undefined) return compile();
80
+
81
+ const prepared = { ...options, referenceDate: options.referenceDate ?? new Date().toISOString().slice(0, 10) };
82
+ let key;
83
+ try {
84
+ key = fingerprint(prepared);
85
+ } catch {
86
+ return compile();
87
+ }
88
+ if (!key) return compile();
89
+ const { projectDir } = options;
90
+ try {
91
+ const entry = readRuntimeJson(projectDir, CACHE, { maxBytes: MAX_BYTES });
92
+ if (entry?.key === key && entry.packet?.manifest?.status === "compiled" && typeof entry.packet.markdown === "string") {
93
+ const saved = JSON.stringify(entry.packet);
94
+ if (sha256(saved) === entry.digest && !hasSecretContent(saved)) {
95
+ return { ...entry.packet, diskCache: "hit" };
96
+ }
97
+ }
98
+ } catch {
99
+ // The compiler still works when a local cache file is unreadable or corrupt.
100
+ }
101
+
102
+ const packet = compileContext(prepared);
103
+ const packetJson = JSON.stringify(packet);
104
+ try {
105
+ if (!hasSecretContent(packetJson) && fingerprint(prepared) === key) {
106
+ const entry = { key, digest: sha256(packetJson), packet };
107
+ if (Buffer.byteLength(JSON.stringify(entry, null, 2), "utf8") < MAX_BYTES) writeRuntimeJson(projectDir, CACHE, entry);
108
+ }
109
+ } catch {
110
+ // Unstable sources and cache-write failures do not change the compiled packet.
111
+ }
112
+ return { ...packet, diskCache: "miss" };
113
+ }