@ornexus/neocortex 4.61.6 → 4.62.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 (55) hide show
  1. package/dist/release-source.json +1 -1
  2. package/dist/sbom.cdx.json +1193 -1193
  3. package/install.ps1 +31 -34
  4. package/install.sh +1 -1
  5. package/package.json +5 -2
  6. package/packages/client/dist/agent/update-description.d.ts +8 -1
  7. package/packages/client/dist/agent/update-description.js +2 -1
  8. package/packages/client/dist/commands/invoke.d.ts +17 -0
  9. package/packages/client/dist/commands/invoke.js +72 -72
  10. package/packages/client/dist/errors/frontmatter-diagnostics.d.ts +10 -1
  11. package/packages/client/dist/errors/frontmatter-diagnostics.js +1 -1
  12. package/packages/client/dist/git/direct-yolo-checkpoint.d.ts +24 -9
  13. package/packages/client/dist/git/direct-yolo-checkpoint.js +3 -4
  14. package/packages/client/dist/git/git-lifecycle-store.d.ts +66 -0
  15. package/packages/client/dist/git/git-lifecycle-store.js +8 -7
  16. package/packages/client/dist/git/release-gate-env.d.ts +62 -0
  17. package/packages/client/dist/git/release-gate-env.js +1 -0
  18. package/packages/client/dist/git/secure-filesystem-boundary.d.ts +24 -0
  19. package/packages/client/dist/git/secure-filesystem-boundary.js +20 -9
  20. package/packages/client/dist/runner/headless/child-env.d.ts +92 -0
  21. package/packages/client/dist/runner/headless/child-env.js +1 -0
  22. package/packages/client/dist/runner/headless/continuous-story-workspace.js +11 -11
  23. package/packages/client/dist/runner/headless/epic-terminal-git-cli-adapter.d.ts +1 -0
  24. package/packages/client/dist/runner/headless/epic-terminal-git-cli-adapter.js +10 -10
  25. package/packages/client/dist/runner/headless/run-yoloop.js +2 -2
  26. package/packages/client/dist/yolo/invoke-envelope-capability.d.ts +2 -0
  27. package/packages/client/dist/yolo/invoke-envelope-capability.js +1 -1
  28. package/packages/client/dist/yolo/project-manifest-projection-collector.d.ts +28 -0
  29. package/packages/client/dist/yolo/project-manifest-projection-collector.js +1 -0
  30. package/packages/client/dist/yolo/spec-envelope-collector.d.ts +9 -0
  31. package/packages/client/dist/yolo/spec-envelope-collector.js +3 -3
  32. package/packages/client/dist/yoloop/shared-discover-epics.d.ts +16 -0
  33. package/packages/client/dist/yoloop/shared-discover-epics.js +1 -1
  34. package/packages/shared/dist/frontmatter-context-contract.js +164 -52
  35. package/packages/shared/dist/project-manifest-projection.js +199 -0
  36. package/packages/shared/dist/project-validation-commands.js +14 -6
  37. package/packages/shared/dist/yolo/spec-envelope-rules.js +85 -0
  38. package/packages/shared/dist/yolo/spec-envelope.js +33 -7
  39. package/packages/shared/dist/yoloop/epic-terminal-git.js +94 -6
  40. package/packages/shared/dist/yoloop/story-write-scope.js +212 -0
  41. package/targets-stubs/antigravity/gemini.md +1 -1
  42. package/targets-stubs/antigravity/install-antigravity.sh +13 -4
  43. package/targets-stubs/antigravity/skill/SKILL.md +1 -1
  44. package/targets-stubs/claude-code/neocortex-root.agent.yaml +1 -1
  45. package/targets-stubs/claude-code/neocortex-root.md +2 -2
  46. package/targets-stubs/claude-code/neocortex.agent.yaml +1 -1
  47. package/targets-stubs/claude-code/neocortex.md +5 -5
  48. package/targets-stubs/codex/AGENTS.md +1 -1
  49. package/targets-stubs/cursor/agent.md +2 -2
  50. package/targets-stubs/gemini-cli/agent.md +2 -2
  51. package/targets-stubs/lib/managed-config-merge.js +77 -1
  52. package/targets-stubs/lib/managed-profile.sh +7 -0
  53. package/targets-stubs/opencode/neocortex-root.md +1 -1
  54. package/targets-stubs/vscode/install-vscode.sh +21 -0
  55. package/targets-stubs/vscode/neocortex.agent.md +2 -2
@@ -0,0 +1,85 @@
1
+ /**
2
+ * P226.06 named content rules for the YOLO spec envelope.
3
+ *
4
+ * Each rule keeps the exact body and flags of the former single
5
+ * `PROHIBITED_CONTENT` alternative, so every previously blocked input stays
6
+ * blocked. The only exception is an `inline-credential-assignment` whose whole
7
+ * value is a strict placeholder. Findings expose a rule id and a 1-based line,
8
+ * never the matched text.
9
+ */
10
+ export const YOLO_SPEC_ENVELOPE_RULE_IDS = [
11
+ 'private-key-pem',
12
+ 'inline-credential-assignment',
13
+ 'email-address',
14
+ 'vendor-key-prefix',
15
+ 'absolute-home-path',
16
+ ];
17
+ const RULES = [
18
+ { id: 'private-key-pem', source: '-----BEGIN [A-Z ]*PRIVATE KEY-----', priority: 0 },
19
+ { id: 'vendor-key-prefix', source: '\\b(?:sk-|ghp_|github_pat_|npm_)[A-Za-z0-9_-]{12,}\\b', priority: 1 },
20
+ { id: 'inline-credential-assignment', source: '\\b(?:bearer|token|password|secret|api[_-]?key)\\s*[:=]\\s*(\\S+)', priority: 2 },
21
+ { id: 'email-address', source: '\\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\\.[A-Z]{2,}\\b', priority: 3 },
22
+ { id: 'absolute-home-path', source: '(?:^|[\\s"\'(])\\/(?:home|media|root|etc|var|Users)\\/', priority: 4 },
23
+ ];
24
+ /**
25
+ * A whole value that is exactly `<UPPER_SNAKE>`, `${UPPER_SNAKE}` or
26
+ * `{{ identifier }}`, optionally wrapped by one identical pair of quotes or
27
+ * backticks and followed by at most one closing delimiter. Case-sensitive.
28
+ */
29
+ const STRICT_PLACEHOLDER_VALUE = /^(["'`]?)(?:<[A-Z][A-Z0-9_]*>|\$\{[A-Z][A-Z0-9_]*\}|\{\{[ \t]*[A-Za-z_][A-Za-z0-9_.-]*[ \t]*\}\})\1[`"'),;.]?(?=[ \t]|$)/;
30
+ /** True only when the value (rest of its line) starts with a strict placeholder token. */
31
+ export function isStrictYoloSpecPlaceholder(value) {
32
+ const line = value.split('\n', 1)[0] ?? '';
33
+ return STRICT_PLACEHOLDER_VALUE.test(line);
34
+ }
35
+ function lineAt(content, index) {
36
+ let line = 1;
37
+ for (let cursor = content.indexOf('\n'); cursor !== -1 && cursor < index; cursor = content.indexOf('\n', cursor + 1)) {
38
+ line += 1;
39
+ }
40
+ return line;
41
+ }
42
+ function firstFindingIndex(rule, content) {
43
+ const pattern = new RegExp(rule.source, 'gim');
44
+ for (let match = pattern.exec(content); match; match = pattern.exec(content)) {
45
+ if (rule.id === 'inline-credential-assignment') {
46
+ const value = match[1] ?? '';
47
+ const valueStart = match.index + match[0].length - value.length;
48
+ if (isStrictYoloSpecPlaceholder(content.slice(valueStart))) {
49
+ // Re-scan from the next character so an overlapping assignment is never hidden.
50
+ pattern.lastIndex = match.index + 1;
51
+ continue;
52
+ }
53
+ }
54
+ const leading = /^\s*/.exec(match[0])?.[0].length ?? 0;
55
+ return match.index + leading;
56
+ }
57
+ return null;
58
+ }
59
+ /**
60
+ * Return the reported prohibited-content finding for normalized content, or
61
+ * `null`. Lowest line wins; same-line ties follow rule priority.
62
+ */
63
+ export function findYoloSpecProhibitedContent(content) {
64
+ let best = null;
65
+ for (const rule of RULES) {
66
+ const index = firstFindingIndex(rule, content);
67
+ if (index === null)
68
+ continue;
69
+ const line = lineAt(content, index);
70
+ if (!best || line < best.line || (line === best.line && rule.priority < best.priority)) {
71
+ best = { ruleId: rule.id, line, priority: rule.priority };
72
+ }
73
+ }
74
+ return best ? { ruleId: best.ruleId, line: best.line } : null;
75
+ }
76
+ const UNSAFE_REASON_CODE = new RegExp(`^yolo-spec-envelope-unsafe:(?:${YOLO_SPEC_ENVELOPE_RULE_IDS.join('|')}):[A-Za-z0-9_./-]{1,240}:[1-9][0-9]{0,8}$`);
77
+ /** `yolo-spec-envelope-unsafe:<rule>:<path>:<line>`; callers pass an allow-listed relative path. */
78
+ export function yoloSpecEnvelopeUnsafeReasonCode(ruleId, path, line) {
79
+ const code = `yolo-spec-envelope-unsafe:${ruleId}:${path}:${line}`;
80
+ return UNSAFE_REASON_CODE.test(code) ? code : 'yolo-spec-envelope-unsafe';
81
+ }
82
+ /** Strict recognizer for the qualified unsafe reason code. */
83
+ export function isYoloSpecEnvelopeUnsafeReasonCode(value) {
84
+ return typeof value === 'string' && UNSAFE_REASON_CODE.test(value);
85
+ }
@@ -1,21 +1,26 @@
1
1
  import { createHash } from 'node:crypto';
2
2
  import { posix } from 'node:path';
3
3
  import { inspectFrontmatterContext } from '../frontmatter-context-contract.js';
4
+ import { findYoloSpecProhibitedContent, yoloSpecEnvelopeUnsafeReasonCode } from './spec-envelope-rules.js';
5
+ export { findYoloSpecProhibitedContent, isStrictYoloSpecPlaceholder, isYoloSpecEnvelopeUnsafeReasonCode, YOLO_SPEC_ENVELOPE_RULE_IDS, yoloSpecEnvelopeUnsafeReasonCode, } from './spec-envelope-rules.js';
4
6
  // Artifact bytes are intentionally not capped here. The invoke transport owns
5
7
  // the request-level byte guardrail; this contract owns count, shape, content,
6
8
  // target, freshness and digest integrity without a smaller duplicate ceiling.
7
9
  export const YOLO_SPEC_MAX_ARTIFACTS = 12;
8
10
  export const YOLO_SPEC_MAX_AGE_MS = 120_000;
9
11
  export const YOLO_SPEC_FUTURE_SKEW_MS = 30_000;
12
+ /** P226.07: cited foreign stories/epics are public IDs only, never content. */
13
+ export const YOLO_SPEC_MAX_REFERENCED_STORIES = 32;
10
14
  /** Public server capability for both mandatory top-level YOLO invoke fields. */
11
15
  export const YOLO_INVOKE_ENVELOPE_CAPABILITY = 'yolo-invoke-envelope-v1';
12
16
  const HASH = /^[a-f0-9]{64}$/;
13
17
  const HEAD = /^(?:[a-f0-9]{40}|[a-f0-9]{64})$/;
14
18
  const STORY_ID = /^[A-Za-z0-9]+(?:\.[A-Za-z0-9]+)+$/;
15
19
  const EPIC_ID = /^[A-Za-z0-9]+$/;
20
+ const REFERENCED_ID = /^[A-Za-z0-9]+(?:\.[A-Za-z0-9]+)*$/;
21
+ const ENVELOPE_KEYS = ['schemaVersion', 'storyId', 'epicId', 'targetPath', 'inputSha256', 'sourceRevision', 'collectedAt', 'artifacts', 'envelopeSha256'];
16
22
  const KINDS = ['story', 'epic', 'spec', 'contract', 'adr', 'nfr', 'example', 'bdd', 'traceability', 'template'];
17
23
  const ALLOWED_PATH = /^(?:docs\/(?:stories|epics|specs|architecture|examples)\/|core\/templates\/specs\/)[A-Za-z0-9_./-]+$/;
18
- const PROHIBITED_CONTENT = /(?:-----BEGIN [A-Z ]*PRIVATE KEY-----|\b(?:bearer|token|password|secret|api[_-]?key)\s*[:=]\s*\S+|\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}\b|\b(?:sk-|ghp_|github_pat_|npm_)[A-Za-z0-9_-]{12,}\b|(?:^|[\s"'(])\/(?:home|media|root|etc|var|Users)\/)/im;
19
24
  function deny(code) {
20
25
  throw new Error(code);
21
26
  }
@@ -37,12 +42,18 @@ function validPath(value) {
37
42
  && !value.includes('\\') && !value.split('/').includes('..')
38
43
  && posix.normalize(value) === value;
39
44
  }
40
- function normalizeContent(content) {
45
+ /**
46
+ * P226.06: named rules replace the former single regex. `path` is already
47
+ * allow-listed by `validPath`; the reason code carries rule/path/line only and
48
+ * never the matched text.
49
+ */
50
+ function normalizeContent(content, path) {
41
51
  if (content.includes('\0') || /\r(?!\n)/.test(content))
42
52
  deny('yolo-spec-envelope-unsafe');
43
53
  const normalized = content.replaceAll('\r\n', '\n');
44
- if (PROHIBITED_CONTENT.test(normalized))
45
- deny('yolo-spec-envelope-unsafe');
54
+ const finding = findYoloSpecProhibitedContent(normalized);
55
+ if (finding)
56
+ deny(yoloSpecEnvelopeUnsafeReasonCode(finding.ruleId, path, finding.line));
46
57
  return normalized;
47
58
  }
48
59
  function artifactManifestSha256(artifacts) {
@@ -51,6 +62,14 @@ function artifactManifestSha256(artifacts) {
51
62
  function unsignedEnvelopeSha256(value) {
52
63
  return sha256(JSON.stringify(value));
53
64
  }
65
+ function checkReferencedStories(value, storyId, epicId) {
66
+ if (!Array.isArray(value) || value.length < 1 || value.length > YOLO_SPEC_MAX_REFERENCED_STORIES
67
+ || value.some((id, index) => typeof id !== 'string' || id.length > 80 || !REFERENCED_ID.test(id)
68
+ || (index > 0 && !(String(value[index - 1]) < id))))
69
+ deny('yolo-spec-envelope-unsafe');
70
+ if (value.includes(storyId) || value.includes(epicId))
71
+ deny('yolo-spec-envelope-target-mismatch');
72
+ }
54
73
  function checkArtifact(value) {
55
74
  if (!isRecord(value) || !hasExactKeys(value, ['kind', 'path', 'content', 'byteLength', 'sha256'])
56
75
  || !KINDS.includes(String(value.kind)) || !validPath(value.path))
@@ -58,7 +77,7 @@ function checkArtifact(value) {
58
77
  if (typeof value.content !== 'string' || !Number.isSafeInteger(value.byteLength) || !HASH.test(String(value.sha256))) {
59
78
  deny('yolo-spec-envelope-unsafe');
60
79
  }
61
- const content = normalizeContent(value.content);
80
+ const content = normalizeContent(value.content, value.path);
62
81
  const bytes = Buffer.byteLength(content, 'utf8');
63
82
  if (content !== value.content || bytes !== value.byteLength || sha256(content) !== value.sha256) {
64
83
  deny('yolo-spec-envelope-digest-mismatch');
@@ -71,7 +90,7 @@ export function createYoloSpecEnvelopeV1(input) {
71
90
  if (!isRecord(artifact) || !KINDS.includes(String(artifact.kind)) || !validPath(artifact.path)
72
91
  || typeof artifact.content !== 'string')
73
92
  deny('yolo-spec-envelope-path-out-of-scope');
74
- const content = normalizeContent(artifact.content);
93
+ const content = normalizeContent(artifact.content, artifact.path);
75
94
  return {
76
95
  kind: artifact.kind,
77
96
  path: artifact.path,
@@ -89,6 +108,9 @@ export function createYoloSpecEnvelopeV1(input) {
89
108
  sourceRevision: { headSha: input.headSha, manifestSha256: artifactManifestSha256(artifacts) },
90
109
  collectedAt: input.collectedAt,
91
110
  artifacts,
111
+ ...(input.referencedStories && input.referencedStories.length > 0
112
+ ? { referencedStories: [...new Set(input.referencedStories)].sort() }
113
+ : {}),
92
114
  };
93
115
  const envelope = { ...unsigned, envelopeSha256: unsignedEnvelopeSha256(unsigned) };
94
116
  assertYoloSpecEnvelopeV1(envelope, {
@@ -98,7 +120,8 @@ export function createYoloSpecEnvelopeV1(input) {
98
120
  return envelope;
99
121
  }
100
122
  export function assertYoloSpecEnvelopeV1(value, context) {
101
- if (!isRecord(value) || !hasExactKeys(value, ['schemaVersion', 'storyId', 'epicId', 'targetPath', 'inputSha256', 'sourceRevision', 'collectedAt', 'artifacts', 'envelopeSha256'])
123
+ const hasReferences = isRecord(value) && Object.prototype.hasOwnProperty.call(value, 'referencedStories');
124
+ if (!isRecord(value) || !hasExactKeys(value, hasReferences ? [...ENVELOPE_KEYS, 'referencedStories'] : ENVELOPE_KEYS)
102
125
  || value.schemaVersion !== 1 || typeof value.storyId !== 'string' || !STORY_ID.test(value.storyId)
103
126
  || typeof value.epicId !== 'string' || !EPIC_ID.test(value.epicId)
104
127
  || !validPath(value.targetPath) || !HASH.test(String(value.inputSha256))
@@ -108,6 +131,8 @@ export function assertYoloSpecEnvelopeV1(value, context) {
108
131
  || value.targetPath !== context.targetPath || value.inputSha256 !== context.inputSha256
109
132
  || value.targetPath !== `docs/stories/${value.storyId}.story.md`)
110
133
  deny('yolo-spec-envelope-target-mismatch');
134
+ if (hasReferences)
135
+ checkReferencedStories(value.referencedStories, value.storyId, value.epicId);
111
136
  const source = value.sourceRevision;
112
137
  if (!isRecord(source) || !hasExactKeys(source, ['headSha', 'manifestSha256'])
113
138
  || !HEAD.test(String(source.headSha)) || !HASH.test(String(source.manifestSha256)))
@@ -154,6 +179,7 @@ export function assertYoloSpecEnvelopeV1(value, context) {
154
179
  sourceRevision: value.sourceRevision,
155
180
  collectedAt: value.collectedAt,
156
181
  artifacts: value.artifacts,
182
+ ...(hasReferences ? { referencedStories: value.referencedStories } : {}),
157
183
  };
158
184
  if (unsignedEnvelopeSha256(unsigned) !== value.envelopeSha256)
159
185
  deny('yolo-spec-envelope-digest-mismatch');
@@ -1,5 +1,7 @@
1
1
  /** Public contracts and pure safety decisions for epic-owned terminal Git. */
2
2
  import { createHash } from 'node:crypto';
3
+ // P226.05 (AC4/F2): reconciliation coverage delegates to the shared matcher.
4
+ import { storyWriteSetCoversWithControlFiles } from './story-write-scope.js';
3
5
  /**
4
6
  * P205 complete-gate budgets are declared in config/release-gates.v2.json and
5
7
  * mirrored here so installed clients keep the same closed runtime bounds.
@@ -98,6 +100,14 @@ export function epicHeadReconciliationInputDigest(value) {
98
100
  changedPathsDigest: value.changedPathsDigest,
99
101
  allowedWriteSet: value.allowedWriteSet,
100
102
  allowedWriteSetDigest: value.allowedWriteSetDigest,
103
+ // Absent optional fields are omitted by JSON.stringify, so legacy receipts
104
+ // keep a byte-identical digest (P226.15 NFR-COMPAT).
105
+ originSyncHeadSha: value.originSyncHeadSha,
106
+ originSyncCommitShas: value.originSyncCommitShas,
107
+ originSyncPaths: value.originSyncPaths,
108
+ originSyncPathsDigest: value.originSyncPathsDigest,
109
+ originSyncResolvedPaths: value.originSyncResolvedPaths,
110
+ originSyncResolvedPathsDigest: value.originSyncResolvedPathsDigest,
101
111
  aggregateReceiptRef: value.aggregateReceiptRef,
102
112
  aggregateManifestDigest: value.aggregateManifestDigest,
103
113
  aggregateResultDigest: value.aggregateResultDigest,
@@ -141,7 +151,9 @@ export function validateEpicHeadReconciliationReceipt(value, expected) {
141
151
  || !sameOrdered(value.allowedWriteSet, [...new Set(value.allowedWriteSet)].sort())
142
152
  || value.changedPaths.some((path) => !safeRepositoryPath(path))
143
153
  || value.allowedWriteSet.some((path) => !safeWriteScope(path))
144
- || value.changedPaths.some((path) => !value.allowedWriteSet.some((scope) => writeScopeCovers(scope, path)))
154
+ || !validOriginSyncEvidence(value)
155
+ || value.changedPaths.some((path) => !storyWriteSetCoversWithControlFiles(value.allowedWriteSet, value.acceptedCheckpointIds, path) && !(value.originSyncPaths ?? []).includes(path)
156
+ && !(value.originSyncResolvedPaths ?? []).includes(path))
145
157
  || value.commitRangeDigest !== epicHeadReconciliationRangeDigest(value.lastAcceptedCheckpointHeadSha, value.executionHeadSha, value.reconciliationCommitShas)
146
158
  || value.changedPathsDigest !== epicHeadReconciliationPathsDigest(value.changedPaths)
147
159
  || value.allowedWriteSetDigest !== epicHeadReconciliationPathsDigest(value.allowedWriteSet)
@@ -157,6 +169,86 @@ export function validateEpicHeadReconciliationReceipt(value, expected) {
157
169
  && now - revalidatedAt <= P205_RELEASE_GATE_BUDGETS.aggregateValidityMs
158
170
  && revalidatedAt - now <= P205_RELEASE_GATE_BUDGETS.cancellationGraceMs;
159
171
  }
172
+ /** P226.15 bounds for origin-sync evidence in the reconciliation receipt. */
173
+ export const EPIC_HEAD_RECONCILIATION_ORIGIN_SYNC_LIMITS = Object.freeze({
174
+ maxCommits: 256,
175
+ maxResolvedPaths: 64,
176
+ });
177
+ const ORIGIN_SYNC_FIELDS = [
178
+ 'originSyncHeadSha', 'originSyncCommitShas', 'originSyncPaths',
179
+ 'originSyncPathsDigest', 'originSyncResolvedPaths', 'originSyncResolvedPathsDigest',
180
+ ];
181
+ function validOriginSyncEvidence(value) {
182
+ const present = ORIGIN_SYNC_FIELDS.filter((field) => value[field] !== undefined);
183
+ if (present.length === 0)
184
+ return true;
185
+ if (present.length !== ORIGIN_SYNC_FIELDS.length)
186
+ return false;
187
+ const commits = value.originSyncCommitShas;
188
+ const paths = value.originSyncPaths;
189
+ const resolved = value.originSyncResolvedPaths;
190
+ if (typeof value.originSyncHeadSha !== 'string' || !isFullSha(value.originSyncHeadSha)
191
+ || !Array.isArray(commits) || !Array.isArray(paths) || !Array.isArray(resolved)
192
+ || commits.length === 0 || commits.length > EPIC_HEAD_RECONCILIATION_ORIGIN_SYNC_LIMITS.maxCommits
193
+ || resolved.length > EPIC_HEAD_RECONCILIATION_ORIGIN_SYNC_LIMITS.maxResolvedPaths
194
+ || paths.length > 2_048
195
+ || commits.some((sha) => typeof sha !== 'string' || !isFullSha(sha))
196
+ || unique(commits).length !== commits.length)
197
+ return false;
198
+ // Sync merges are first-parent commits of the reconciled range, in order.
199
+ let cursor = 0;
200
+ for (const sha of commits) {
201
+ while (cursor < value.reconciliationCommitShas.length && value.reconciliationCommitShas[cursor] !== sha)
202
+ cursor += 1;
203
+ if (cursor >= value.reconciliationCommitShas.length)
204
+ return false;
205
+ cursor += 1;
206
+ }
207
+ const changed = new Set(value.changedPaths);
208
+ const covered = (path) => storyWriteSetCoversWithControlFiles(value.allowedWriteSet, value.acceptedCheckpointIds, path);
209
+ for (const list of [paths, resolved]) {
210
+ if (list.some((path) => typeof path !== 'string' || !safeRepositoryPath(path) || !changed.has(path) || covered(path))
211
+ || !sameOrdered(list, [...new Set(list)].sort()))
212
+ return false;
213
+ }
214
+ const pathSet = new Set(paths);
215
+ return !resolved.some((path) => pathSet.has(path))
216
+ && value.originSyncPathsDigest === epicHeadReconciliationPathsDigest(paths)
217
+ && value.originSyncResolvedPathsDigest === epicHeadReconciliationPathsDigest(resolved);
218
+ }
219
+ const ORIGIN_BINDING_V1_KEYS = ['schemaVersion', 'originBranch', 'originHeadSha', 'executionBranch', 'capturedFromCurrentCheckout', 'capturedAt'];
220
+ const ORIGIN_BINDING_V2_KEYS = ['schemaVersion', 'originBranch', 'originHeadSha', 'executionBranch', 'capturedFrom', 'capturedAt'];
221
+ /**
222
+ * P226.15 (D-01 from P226.08): accept exactly the v1 or the v2 origin binding.
223
+ * Mixed shapes, extra keys, unknown sources, equal branches or malformed SHAs
224
+ * fail closed. Consumers still prove ancestry physically where they have Git.
225
+ */
226
+ export function isEpicOriginBindingEvidence(value) {
227
+ if (typeof value !== 'object' || value === null || Array.isArray(value))
228
+ return false;
229
+ const item = value;
230
+ const keys = Object.keys(item).sort();
231
+ const common = typeof item.originBranch === 'string' && typeof item.executionBranch === 'string'
232
+ && safeBindingBranch(item.originBranch) && safeBindingBranch(item.executionBranch)
233
+ && item.originBranch !== item.executionBranch
234
+ && typeof item.originHeadSha === 'string' && isFullSha(item.originHeadSha)
235
+ && typeof item.capturedAt === 'string' && Number.isFinite(Date.parse(item.capturedAt));
236
+ if (!common)
237
+ return false;
238
+ if (item.schemaVersion === 1) {
239
+ return sameOrdered(keys, [...ORIGIN_BINDING_V1_KEYS].sort()) && item.capturedFromCurrentCheckout === true;
240
+ }
241
+ if (item.schemaVersion === 2) {
242
+ return sameOrdered(keys, [...ORIGIN_BINDING_V2_KEYS].sort())
243
+ && (item.capturedFrom === 'current-checkout' || item.capturedFrom === 'branch-ref');
244
+ }
245
+ return false;
246
+ }
247
+ function safeBindingBranch(value) {
248
+ return value.length > 0 && value.length <= 240 && !value.startsWith('-') && !value.startsWith('/')
249
+ && !value.endsWith('/') && !value.endsWith('.lock') && !value.includes('..') && !value.includes('\\')
250
+ && !value.includes('@{') && !value.includes('//') && /^[A-Za-z0-9._/-]+$/.test(value);
251
+ }
160
252
  /**
161
253
  * P225.06 ownership of a registered worktree: managed only with both the
162
254
  * journal entry and the nonce marker; anything else is manual and preserved.
@@ -210,8 +302,7 @@ export function validateEpicTerminalGitDirective(directive, actual) {
210
302
  }
211
303
  const originBinding = actual.originBinding;
212
304
  if (!originBinding
213
- || originBinding.schemaVersion !== 1
214
- || originBinding.capturedFromCurrentCheckout !== true
305
+ || !isEpicOriginBindingEvidence(originBinding)
215
306
  || originBinding.originBranch !== directive.originBranch
216
307
  || originBinding.executionBranch !== directive.executionBranch
217
308
  || !isSha(originBinding.originHeadSha)
@@ -404,6 +495,3 @@ function safeWriteScope(value) {
404
495
  return parts.length > 0 && parts.every((part) => part.length > 0 && part !== '.' && part !== '..')
405
496
  && parts[0] !== '.git';
406
497
  }
407
- function writeScopeCovers(scope, path) {
408
- return scope === path || scope.endsWith('/') && path.startsWith(scope);
409
- }
@@ -0,0 +1,212 @@
1
+ /**
2
+ * Story P226.05 (P226-CON-WRITESET) -- shared story write-scope semantics.
3
+ *
4
+ * One pure, deterministic module owns how a story write-set is expanded and
5
+ * matched. The direct checkpoint, the Git lifecycle store and `*create-epic`
6
+ * materialization delegate here so the three decisions are identical.
7
+ *
8
+ * Grammar (closed subset, fail-closed): exact relative path, directory scope
9
+ * ending in `/`, and globs where `*` matches within one segment and a segment
10
+ * equal to `**` matches zero or more whole segments (at most 8 segments).
11
+ * Braces, negation, traversal, absolute paths and drive letters are refused
12
+ * with stable reason codes; brackets and `?` are refused inside globs and
13
+ * matched literally in exact/directory scopes. Matching never compiles a RegExp from
14
+ * the scope and runs in O(segments * path segments). Directory and glob scopes
15
+ * never cover governance paths (`.neocortex/`, `.claude/`, `.git*`,
16
+ * `docs/stories/`); those need an exact scope.
17
+ */
18
+ export const STORY_WRITE_SCOPE_MAX_LENGTH = 1024;
19
+ export const STORY_WRITE_SCOPE_MAX_GLOB_SEGMENTS = 8;
20
+ const STORY_ID_PATTERN = /^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/;
21
+ // eslint-disable-next-line no-control-regex
22
+ const CONTROL_CHAR_PATTERN = /[\u0000-\u001f\u007f]/;
23
+ /** The five story control files, in canonical order (WS-01). */
24
+ export function storyControlFiles(storyId) {
25
+ if (!isSafeStoryId(storyId))
26
+ return [];
27
+ return [
28
+ '.neocortex/state.json',
29
+ `docs/stories/${storyId}.story.md`,
30
+ `.neocortex/stories/${storyId}/qa-gate-result.json`,
31
+ `.neocortex/stories/${storyId}/validation-evidence.md`,
32
+ `.neocortex/stories/${storyId}/review.md`,
33
+ ];
34
+ }
35
+ /** Validate one write scope against the closed grammar (WS-03). */
36
+ export function validateStoryWriteScope(scope) {
37
+ if (typeof scope !== 'string' || scope.length === 0)
38
+ return fail('story-write-scope-empty');
39
+ if (scope.length > STORY_WRITE_SCOPE_MAX_LENGTH)
40
+ return fail('story-write-scope-too-long');
41
+ if (CONTROL_CHAR_PATTERN.test(scope) || scope.includes('\\'))
42
+ return fail('story-write-scope-invalid-char');
43
+ if (scope.startsWith('/'))
44
+ return fail('story-write-scope-absolute');
45
+ if (scope.startsWith('-'))
46
+ return fail('story-write-scope-leading-dash');
47
+ if (/^[A-Za-z]:/.test(scope))
48
+ return fail('story-write-scope-drive-letter');
49
+ const body = scope.endsWith('/') ? scope.slice(0, -1) : scope;
50
+ const segments = body.split('/');
51
+ if (segments.some((segment) => segment === '' || segment === '.' || segment === '..')) {
52
+ return fail('story-write-scope-traversal');
53
+ }
54
+ if (segments[0].toLowerCase() === '.git')
55
+ return fail('story-write-scope-git-dir');
56
+ if (scope.includes('{') || scope.includes('}'))
57
+ return fail('story-write-scope-brace');
58
+ if (scope.includes('!'))
59
+ return fail('story-write-scope-negation');
60
+ if (!isGlob(scope))
61
+ return { ok: true };
62
+ // Character classes and `?` are glob syntax outside the supported subset.
63
+ // Exact and directory scopes match them literally (e.g. `app/[id]/page.tsx`),
64
+ // which cannot widen the scope; inside a glob they fail closed.
65
+ if (scope.includes('[') || scope.includes(']'))
66
+ return fail('story-write-scope-bracket');
67
+ if (scope.includes('?'))
68
+ return fail('story-write-scope-wildcard-invalid');
69
+ if (segments.some((segment) => segment.includes('**') && segment !== '**')) {
70
+ return fail('story-write-scope-wildcard-invalid');
71
+ }
72
+ if (segments.length > STORY_WRITE_SCOPE_MAX_GLOB_SEGMENTS)
73
+ return fail('story-write-scope-too-many-segments');
74
+ return { ok: true };
75
+ }
76
+ /** Whether `scope` (exact, `dir/` or bounded glob) covers repository `path` (WS-04). */
77
+ export function storyWriteScopeCovers(scope, path) {
78
+ if (!validateStoryWriteScope(scope).ok || !isSafeRepositoryPath(path))
79
+ return false;
80
+ if (scope === path)
81
+ return true;
82
+ // Governance surfaces are authorized only by an exact scope: a directory or
83
+ // glob never reaches them. Own-story control files come from the exact
84
+ // expansion (P226.05 F3; mirrors the write-set extension path rule).
85
+ if (isGovernancePath(path))
86
+ return false;
87
+ if (scope.endsWith('/') && !isGlob(scope))
88
+ return path.startsWith(scope);
89
+ if (!isGlob(scope) || path.includes('*'))
90
+ return false;
91
+ // A directory glob (`src/*/`) covers at least one entry below the directory.
92
+ const scopeSegments = collapseGlobstars((scope.endsWith('/') ? `${scope}*/**` : scope).split('/'));
93
+ return matchSegments(scopeSegments, path.split('/'));
94
+ }
95
+ /** Paths a non-exact scope never covers: `.neocortex/`, `.claude/`, `.git*` and `docs/stories/`. */
96
+ export function isStoryWriteScopeGovernancePath(path) {
97
+ return isGovernancePath(path);
98
+ }
99
+ /** Whether any scope in `scopes` covers `path`. */
100
+ export function storyWriteSetCovers(scopes, path) {
101
+ return scopes.some((scope) => storyWriteScopeCovers(scope, path));
102
+ }
103
+ /**
104
+ * Aggregate coverage over authored scopes plus the exact control files of the
105
+ * given stories. Used where an epic-level `allowedWriteSet` is the union of
106
+ * authored write-sets, so stories that omit their control files stay covered
107
+ * without changing the persisted `allowedWriteSet` digest.
108
+ */
109
+ export function storyWriteSetCoversWithControlFiles(scopes, storyIds, path) {
110
+ return storyWriteSetCovers(scopes, path) || storyIds.some((storyId) => storyControlFiles(storyId).includes(path));
111
+ }
112
+ /**
113
+ * Expand authored refs with the five control files exactly once, deduplicated
114
+ * and sorted (WS-02). Any invalid ref fails the whole expansion closed.
115
+ */
116
+ export function expandStoryWriteScope(storyId, refs) {
117
+ if (!isSafeStoryId(storyId))
118
+ return fail('story-write-scope-story-id-invalid');
119
+ const normalized = [];
120
+ for (const ref of refs) {
121
+ const value = typeof ref === 'string' ? stripDotSlash(ref) : ref;
122
+ const validation = validateStoryWriteScope(value);
123
+ if (!validation.ok)
124
+ return validation;
125
+ normalized.push(value);
126
+ }
127
+ const scopes = [...new Set([...normalized, ...storyControlFiles(storyId)])].sort(compareCodeUnits);
128
+ return { ok: true, scopes: Object.freeze(scopes) };
129
+ }
130
+ /** Consecutive `**` segments are equivalent to one. */
131
+ function collapseGlobstars(segments) {
132
+ return segments.filter((segment, index) => segment !== '**' || segments[index - 1] !== '**');
133
+ }
134
+ /**
135
+ * Segment matcher as a bottom-up dynamic program over (scope index, path
136
+ * index): O(S * P) segment comparisons, no recursion and no backtracking
137
+ * blow-up for pathological `**` scopes (P226.05 F1).
138
+ */
139
+ function matchSegments(scope, path) {
140
+ const width = path.length + 1;
141
+ // next[pi] = whether scope[si+1..] matches path[pi..]
142
+ let next = new Array(width).fill(false);
143
+ next[path.length] = true;
144
+ for (let si = scope.length - 1; si >= 0; si -= 1) {
145
+ const segment = scope[si];
146
+ const current = new Array(width).fill(false);
147
+ if (segment === '**') {
148
+ // `**` matches zero or more segments: current[pi] = OR_{k>=pi} next[k].
149
+ let any = false;
150
+ for (let pi = path.length; pi >= 0; pi -= 1) {
151
+ any = any || next[pi];
152
+ current[pi] = any;
153
+ }
154
+ }
155
+ else {
156
+ for (let pi = 0; pi < path.length; pi += 1) {
157
+ current[pi] = next[pi + 1] && matchSegment(segment, path[pi]);
158
+ }
159
+ }
160
+ next = current;
161
+ }
162
+ return next[0];
163
+ }
164
+ /** `*` matches zero or more characters inside one segment. */
165
+ function matchSegment(pattern, value) {
166
+ const parts = pattern.split('*');
167
+ if (parts.length === 1)
168
+ return pattern === value;
169
+ const first = parts[0];
170
+ const last = parts[parts.length - 1];
171
+ if (value.length < first.length + last.length || !value.startsWith(first) || !value.endsWith(last))
172
+ return false;
173
+ let cursor = first.length;
174
+ const end = value.length - last.length;
175
+ for (const middle of parts.slice(1, -1)) {
176
+ const found = value.indexOf(middle, cursor);
177
+ if (found < 0 || found + middle.length > end)
178
+ return false;
179
+ cursor = found + middle.length;
180
+ }
181
+ return cursor <= end;
182
+ }
183
+ function isGlob(scope) {
184
+ return scope.includes('*');
185
+ }
186
+ function isSafeRepositoryPath(path) {
187
+ if (typeof path !== 'string' || path.length === 0 || path.length > STORY_WRITE_SCOPE_MAX_LENGTH)
188
+ return false;
189
+ if (CONTROL_CHAR_PATTERN.test(path) || path.includes('\\') || path.startsWith('/') || path.startsWith('-')
190
+ || /^[A-Za-z]:/.test(path))
191
+ return false;
192
+ const segments = path.split('/');
193
+ return !segments.some((segment) => segment === '' || segment === '.' || segment === '..')
194
+ && segments[0].toLowerCase() !== '.git';
195
+ }
196
+ function isGovernancePath(path) {
197
+ const lower = path.toLowerCase();
198
+ const first = lower.split('/')[0];
199
+ return first === '.neocortex' || first === '.claude' || first.startsWith('.git') || lower.startsWith('docs/stories/');
200
+ }
201
+ function isSafeStoryId(storyId) {
202
+ return typeof storyId === 'string' && STORY_ID_PATTERN.test(storyId) && !storyId.includes('..');
203
+ }
204
+ function stripDotSlash(value) {
205
+ return value.startsWith('./') ? value.slice(2) : value;
206
+ }
207
+ function compareCodeUnits(left, right) {
208
+ return left < right ? -1 : left > right ? 1 : 0;
209
+ }
210
+ function fail(reasonCode) {
211
+ return { ok: false, reasonCode };
212
+ }
@@ -1,4 +1,4 @@
1
- # 🧠 Neocortex v4.61.6 | OrNexus Team
1
+ # 🧠 Neocortex v4.62.0 | OrNexus Team
2
2
 
3
3
  This project uses Neocortex, a Development Orchestrator.
4
4
 
@@ -33,13 +33,22 @@ install_antigravity() {
33
33
  echo "[ANTIGRAVITY] Installing Neocortex for Google Antigravity (thin-client mode)..."
34
34
  echo "[ANTIGRAVITY] WARNING: Antigravity is in public preview - APIs may change"
35
35
 
36
+ # P226.13: a global install passes $HOME as the destination; never create
37
+ # the project .agent/skills folder there. Existing folders are kept.
38
+ local global_destination=false
39
+ if neocortex_is_global_destination "$dest_dir"; then
40
+ global_destination=true
41
+ fi
42
+
36
43
  # Create destination directories
37
- mkdir -p "$dest_dir/.agent/skills/neocortex" \
38
- "$gemini_home/antigravity" \
44
+ mkdir -p "$gemini_home/antigravity" \
39
45
  "$gemini_home/config/agents"
46
+ if [ "$global_destination" != true ]; then
47
+ mkdir -p "$dest_dir/.agent/skills/neocortex"
48
+ fi
40
49
 
41
- # 1. Copy SKILL.md stub
42
- if [ -f "$ag_target/skill/SKILL.md" ]; then
50
+ # 1. Copy SKILL.md stub (project installs only)
51
+ if [ "$global_destination" != true ] && [ -f "$ag_target/skill/SKILL.md" ]; then
43
52
  neocortex_managed_profile "$source_dir" "$ag_target/skill/SKILL.md" "$dest_dir/.agent/skills/neocortex/SKILL.md" "$dest_dir" "project-antigravity-skill"
44
53
  neocortex_managed_report "[ANTIGRAVITY]" ".agent/skills/neocortex/SKILL.md (skill stub)"
45
54
  fi
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: neocortex
3
- description: "🧠 Neocortex v4.61.6 | OrNexus Team"
3
+ description: "🧠 Neocortex v4.62.0 | OrNexus Team"
4
4
  ---
5
5
 
6
6
  <!--
@@ -4,7 +4,7 @@ agent:
4
4
  name: 'Neocortex Root Agent'
5
5
  title: 'Development Orchestrator (Root)'
6
6
  icon: '>'
7
- version: '4.61.6'
7
+ version: '4.62.0'
8
8
  architecture: 'thin-client'
9
9
  module: stand-alone
10
10
  hasSidecar: false
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: neocortex-root
3
- description: "🧠 Neocortex Root Agent v4.61.6 | OrNexus Team"
3
+ description: "🧠 Neocortex Root Agent v4.62.0 | OrNexus Team"
4
4
  model: opus
5
5
  color: blue
6
6
  tools:
@@ -108,7 +108,7 @@ SEMPRE que este agente for invocado, imprima o banner abaixo como PRIMEIRO outpu
108
108
  ┌────────────────────────────────────────────────────────────┐
109
109
  │ │
110
110
  │ ####### N E O C O R T E X │
111
- │ ### ######## v4.61.6 │
111
+ │ ### ######## v4.62.0 │
112
112
  │ ######### ##### │
113
113
  │ ## ############## Development Orchestrator │
114
114
  │ ## ### ###### ## OrNexus Team │
@@ -4,7 +4,7 @@ agent:
4
4
  name: 'Neocortex'
5
5
  title: 'Development Orchestrator'
6
6
  icon: '>'
7
- version: '4.61.6'
7
+ version: '4.62.0'
8
8
  architecture: 'thin-client'
9
9
  module: stand-alone
10
10
  hasSidecar: false