@ornexus/neocortex 4.60.71 → 4.60.73
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/release-source.json +1 -1
- package/dist/sbom.cdx.json +1211 -1217
- package/install.ps1 +1 -1
- package/install.sh +1 -1
- package/package.json +2 -2
- package/packages/client/dist/adapters/adapter-registry.js +108 -1
- package/packages/client/dist/adapters/antigravity-adapter.js +77 -2
- package/packages/client/dist/adapters/claude-code-adapter.js +79 -3
- package/packages/client/dist/adapters/codex-adapter.js +80 -2
- package/packages/client/dist/adapters/cursor-adapter.js +115 -4
- package/packages/client/dist/adapters/gemini-adapter.js +71 -2
- package/packages/client/dist/adapters/grok-adapter.js +42 -2
- package/packages/client/dist/adapters/index.js +22 -1
- package/packages/client/dist/adapters/platform-detector.js +212 -1
- package/packages/client/dist/adapters/target-adapter.js +12 -0
- package/packages/client/dist/adapters/vscode-adapter.js +72 -2
- package/packages/client/dist/agent/refresh-stubs.js +417 -2
- package/packages/client/dist/agent/update-agent-yaml.js +102 -1
- package/packages/client/dist/agent/update-description.js +251 -1
- package/packages/client/dist/cache/crypto-utils.js +78 -1
- package/packages/client/dist/cache/encrypted-cache.js +108 -1
- package/packages/client/dist/cache/in-memory-asset-cache.js +73 -1
- package/packages/client/dist/cache/index.js +13 -1
- package/packages/client/dist/cache/protected-pi-boundary.js +44 -1
- package/packages/client/dist/checkpoint/checkpoint-client-reader.js +127 -2
- package/packages/client/dist/checkpoint/index.js +11 -1
- package/packages/client/dist/checkpoint/shared-checkpoint-types.js +32 -1
- package/packages/client/dist/cli.js +358 -5
- package/packages/client/dist/commands/activate.js +394 -8
- package/packages/client/dist/commands/architecture-answers.js +274 -7
- package/packages/client/dist/commands/architecture-memory-terminal.js +253 -4
- package/packages/client/dist/commands/architecture-non-ui-continuation.js +100 -1
- package/packages/client/dist/commands/architecture-root-binding.js +51 -1
- package/packages/client/dist/commands/cache-status.js +112 -2
- package/packages/client/dist/commands/config.js +88 -1
- package/packages/client/dist/commands/doctor.js +635 -2
- package/packages/client/dist/commands/invoke.js +7200 -143
- package/packages/client/dist/commands/legacy-epic-terminal.js +71 -1
- package/packages/client/dist/commands/legacy-story-branch.js +96 -1
- package/packages/client/dist/commands/legacy-story-pr.js +276 -1
- package/packages/client/dist/commands/mutation-qa-checkpoint.js +285 -5
- package/packages/client/dist/commands/mutation-qa-gate.js +54 -1
- package/packages/client/dist/commands/mutation-qa-git.js +41 -1
- package/packages/client/dist/commands/mutation-qa-policy.js +102 -1
- package/packages/client/dist/commands/mutation-qa-run.js +219 -3
- package/packages/client/dist/commands/mutation-qa-verdict.js +149 -1
- package/packages/client/dist/commands/mutation-qa.js +220 -1
- package/packages/client/dist/commands/native-agent.js +136 -2
- package/packages/client/dist/commands/planning-diagnosis.js +43 -1
- package/packages/client/dist/commands/planning-generation.js +53 -1
- package/packages/client/dist/commands/planning-memory.js +40 -1
- package/packages/client/dist/commands/planning-research.js +42 -1
- package/packages/client/dist/commands/private-session.js +75 -1
- package/packages/client/dist/commands/property-qa.js +139 -1
- package/packages/client/dist/commands/qa-control.js +16 -1
- package/packages/client/dist/commands/qa-scan-browser-launch.js +55 -1
- package/packages/client/dist/commands/qa-scan-browser-route.js +28 -1
- package/packages/client/dist/commands/qa-scan-capture.js +663 -5
- package/packages/client/dist/commands/qa-scan-discovery.js +376 -3
- package/packages/client/dist/commands/qa-scan-review.js +826 -5
- package/packages/client/dist/commands/qa-synthetic-backend-capture.js +266 -1
- package/packages/client/dist/commands/qa-synthetic-backend-review.js +297 -1
- package/packages/client/dist/commands/qa-synthetic-backend.js +340 -2
- package/packages/client/dist/commands/qa-synthetic-broker-port.js +85 -1
- package/packages/client/dist/commands/qa-synthetic-browser.js +39 -1
- package/packages/client/dist/commands/refactor-characterization.js +671 -21
- package/packages/client/dist/commands/refactor-commit.js +399 -13
- package/packages/client/dist/commands/refactor-control.js +142 -3
- package/packages/client/dist/commands/refactor-cpp-assertions.js +93 -3
- package/packages/client/dist/commands/refactor-review.js +283 -5
- package/packages/client/dist/commands/refactor-root.js +588 -7
- package/packages/client/dist/commands/refresh-memory.js +156 -3
- package/packages/client/dist/commands/shared-architecture-non-ui.js +24 -1
- package/packages/client/dist/commands/story-checkpoint.js +171 -1
- package/packages/client/dist/config/profile-directory.js +13 -1
- package/packages/client/dist/config/resolver-selection.js +278 -1
- package/packages/client/dist/config/secure-config.js +281 -12
- package/packages/client/dist/config.js +223 -2
- package/packages/client/dist/constants.js +25 -1
- package/packages/client/dist/context/context-collector.js +222 -2
- package/packages/client/dist/context/context-sanitizer.js +145 -1
- package/packages/client/dist/continuity/autonomous-governance.js +285 -1
- package/packages/client/dist/continuity/continuity-client-state-store.js +1587 -1
- package/packages/client/dist/continuity/invoke-hooks.js +129 -1
- package/packages/client/dist/continuity/migrations/001-initial-schema.js +12 -2
- package/packages/client/dist/continuity/migrations/002-processing-output-summary-indexes.js +12 -2
- package/packages/client/dist/continuity/migrations/003-headless-execution-attempts.js +12 -2
- package/packages/client/dist/continuity/migrations/004-outbox-delivery-state.js +12 -2
- package/packages/client/dist/continuity/migrations/005-bounded-headless-queue.js +12 -2
- package/packages/client/dist/continuity/migrations/006-native-agent-dispatches.js +10 -2
- package/packages/client/dist/continuity/native-agent-store.js +69 -1
- package/packages/client/dist/continuity/native-agent-types.js +90 -1
- package/packages/client/dist/continuity/outbox.js +117 -1
- package/packages/client/dist/continuity/runner-bootstrap-policy.js +172 -1
- package/packages/client/dist/continuity/sqlite-store.d.ts +22 -1
- package/packages/client/dist/continuity/sqlite-store.js +2612 -81
- package/packages/client/dist/effects/invoke-effect-gateways.js +62 -1
- package/packages/client/dist/errors/error-messages.js +228 -2
- package/packages/client/dist/errors/frontmatter-diagnostics.js +125 -1
- package/packages/client/dist/evidence/collector.js +347 -1
- package/packages/client/dist/evidence/index.js +1 -1
- package/packages/client/dist/evidence/types.js +2 -0
- package/packages/client/dist/fs/atomic-state-replace.js +152 -1
- package/packages/client/dist/generated/command-registry.generated.js +4076 -1
- package/packages/client/dist/generated/public-projections.generated.js +149 -1
- package/packages/client/dist/git/direct-yolo-c01-retry.js +138 -4
- package/packages/client/dist/git/direct-yolo-checkpoint.js +1234 -4
- package/packages/client/dist/git/epic-operational-state.d.ts +198 -0
- package/packages/client/dist/git/epic-operational-state.js +672 -0
- package/packages/client/dist/git/git-lifecycle-step-ids.js +14 -1
- package/packages/client/dist/git/git-lifecycle-store.d.ts +9 -1
- package/packages/client/dist/git/git-lifecycle-store.js +1981 -9
- package/packages/client/dist/git/legacy-story-branch-checkpoint.js +259 -9
- package/packages/client/dist/git/legacy-story-branch-setup.js +348 -4
- package/packages/client/dist/git/legacy-story-pr.js +3538 -70
- package/packages/client/dist/git/secure-filesystem-boundary.js +182 -5
- package/packages/client/dist/graph-retrieval/pre-command-hook.js +284 -1
- package/packages/client/dist/graph-retrieval/shared-graph-retrieval-contract.js +237 -1
- package/packages/client/dist/i18n/first-run.js +60 -2
- package/packages/client/dist/index.js +47 -1
- package/packages/client/dist/invocation/invoke-input.js +24 -1
- package/packages/client/dist/license/index.js +5 -1
- package/packages/client/dist/license/license-client.js +304 -1
- package/packages/client/dist/machine/fingerprint.js +163 -2
- package/packages/client/dist/machine/index.js +5 -1
- package/packages/client/dist/memory/project-memory-path-scope.js +62 -1
- package/packages/client/dist/memory/project-memory-writer.js +1007 -40
- package/packages/client/dist/memory/shared-project-memory-types.js +253 -2
- package/packages/client/dist/migrations/epic-lifecycle-backfill.d.ts +97 -0
- package/packages/client/dist/migrations/epic-lifecycle-backfill.js +1060 -0
- package/packages/client/dist/migrations/project-identity-capability.js +50 -1
- package/packages/client/dist/migrations/project-identity.js +493 -7
- package/packages/client/dist/migrations/state-json.d.ts +22 -0
- package/packages/client/dist/migrations/state-json.js +393 -4
- package/packages/client/dist/policy/architecture-policy.js +184 -2
- package/packages/client/dist/policy/index.js +7 -1
- package/packages/client/dist/policy/shared-policy-types.js +38 -0
- package/packages/client/dist/policy/subagent-approval-policy.js +55 -1
- package/packages/client/dist/private-execution/clean-baseline.js +279 -2
- package/packages/client/dist/private-execution/codex-executor.js +574 -4
- package/packages/client/dist/private-execution/codex-host-runtime.js +137 -1
- package/packages/client/dist/private-execution/codex-lifecycle-guard.js +97 -1
- package/packages/client/dist/private-execution/codex-scoped-permissions.js +128 -1
- package/packages/client/dist/private-execution/delivery.js +410 -13
- package/packages/client/dist/private-execution/diagnosis-root-review.js +294 -2
- package/packages/client/dist/private-execution/frozen-handoff.js +19 -6
- package/packages/client/dist/private-execution/implementation-validation.js +106 -2
- package/packages/client/dist/private-execution/isolated-admission.js +1432 -23
- package/packages/client/dist/private-execution/isolated-session.js +725 -5
- package/packages/client/dist/private-execution/isolated-workspace.js +122 -1
- package/packages/client/dist/private-execution/pact-consumer-runtime.js +409 -3
- package/packages/client/dist/private-execution/pact-test-source.js +258 -1
- package/packages/client/dist/private-execution/pact-toolchain.js +290 -3
- package/packages/client/dist/private-execution/pact-write-set.js +172 -1
- package/packages/client/dist/private-execution/planning-diagnosis-checkpoint.js +406 -5
- package/packages/client/dist/private-execution/planning-generation-checkpoint.js +462 -5
- package/packages/client/dist/private-execution/planning-memory-checkpoint.js +139 -3
- package/packages/client/dist/private-execution/planning-research-checkpoint.js +325 -4
- package/packages/client/dist/private-execution/private-report-store.js +42 -1
- package/packages/client/dist/private-execution/property-test-candidate.js +103 -1
- package/packages/client/dist/private-execution/property-test-choices.js +147 -3
- package/packages/client/dist/private-execution/property-test-plan.js +271 -7
- package/packages/client/dist/private-execution/property-test-review.js +258 -4
- package/packages/client/dist/private-execution/property-test-runtime.js +372 -9
- package/packages/client/dist/private-execution/property-test-source.js +139 -1
- package/packages/client/dist/private-execution/root-checkpoint.js +80 -1
- package/packages/client/dist/private-execution/root-memory-git-evidence.js +135 -3
- package/packages/client/dist/private-execution/root-memory-recovery.js +93 -1
- package/packages/client/dist/private-execution/root-memory-request.js +29 -1
- package/packages/client/dist/private-execution/root-memory-scope.js +178 -1
- package/packages/client/dist/private-execution/root-memory-writer.js +102 -1
- package/packages/client/dist/private-execution/session-lease.js +63 -1
- package/packages/client/dist/private-execution/shared-private-admission-types.js +50 -1
- package/packages/client/dist/private-execution/shared-project-validation.js +66 -1
- package/packages/client/dist/private-execution/shared-root-memory-types.js +61 -1
- package/packages/client/dist/private-execution/ux-source-validation.js +372 -1
- package/packages/client/dist/private-execution/ux-write-set.js +191 -2
- package/packages/client/dist/registry/registry-reconciliation.js +234 -1
- package/packages/client/dist/resilience/circuit-breaker.js +170 -1
- package/packages/client/dist/resilience/degradation-manager.js +164 -1
- package/packages/client/dist/resilience/freshness-indicator.js +100 -1
- package/packages/client/dist/resilience/index.js +8 -1
- package/packages/client/dist/resilience/recovery-detector.js +74 -1
- package/packages/client/dist/resolvers/asset-resolver.js +13 -0
- package/packages/client/dist/resolvers/local-resolver.js +255 -8
- package/packages/client/dist/resolvers/remote-resolver.js +233 -1
- package/packages/client/dist/runner/binary.js +404 -1
- package/packages/client/dist/runner/cli.js +1571 -17
- package/packages/client/dist/runner/headless/adapters.js +49 -1
- package/packages/client/dist/runner/headless/claude-code-adapter.js +79 -1
- package/packages/client/dist/runner/headless/continuous-story-workspace.js +1628 -11
- package/packages/client/dist/runner/headless/epic-git-reconciliation-inventory.js +69 -1
- package/packages/client/dist/runner/headless/epic-merge-candidate-qa.js +110 -2
- package/packages/client/dist/runner/headless/epic-terminal-git-cli-adapter.js +1236 -8
- package/packages/client/dist/runner/headless/epic-terminal-git-runner.js +318 -2
- package/packages/client/dist/runner/headless/fake-adapter.js +62 -1
- package/packages/client/dist/runner/headless/managed-profile.js +132 -1
- package/packages/client/dist/runner/headless/opencode-adapter.js +145 -2
- package/packages/client/dist/runner/headless/prepared-story-bundle.js +43 -1
- package/packages/client/dist/runner/headless/resolver.js +231 -1
- package/packages/client/dist/runner/headless/run-yolo.js +885 -1
- package/packages/client/dist/runner/headless/run-yoloop.js +2574 -2
- package/packages/client/dist/runner/headless/types.js +574 -2
- package/packages/client/dist/runner/local-console.js +396 -13
- package/packages/client/dist/runner/portal-sync-worker.js +1487 -1
- package/packages/client/dist/runner/project-identity.js +106 -1
- package/packages/client/dist/runner/scheduler.js +995 -7
- package/packages/client/dist/runner-cli.js +18 -2
- package/packages/client/dist/state/invocation-shape.js +13 -1
- package/packages/client/dist/state/project-state-snapshot.d.ts +8 -0
- package/packages/client/dist/state/project-state-snapshot.js +1731 -1
- package/packages/client/dist/state/state-json-repair.js +785 -3
- package/packages/client/dist/state/structural-dag-projection.js +118 -1
- package/packages/client/dist/telemetry/index.js +5 -1
- package/packages/client/dist/telemetry/offline-queue.js +131 -1
- package/packages/client/dist/tier/index.js +5 -1
- package/packages/client/dist/tier/tier-aware-client.js +405 -1
- package/packages/client/dist/types/index.js +38 -1
- package/packages/client/dist/version.js +27 -1
- package/packages/client/dist/yolo/change-evidence-collector.js +126 -1
- package/packages/client/dist/yolo/invoke-envelope-capability.js +62 -1
- package/packages/client/dist/yolo/spec-envelope-collector.js +184 -5
- package/packages/client/dist/yoloop/discovery-hook.js +300 -2
- package/packages/client/dist/yoloop/index.js +8 -1
- package/packages/client/dist/yoloop/invoke-hooks.js +669 -12
- package/packages/client/dist/yoloop/shared-discover-epics.js +1007 -1
- package/packages/client/dist/yoloop/shared-yoloop-types.d.ts +65 -1
- package/packages/client/dist/yoloop/shared-yoloop-types.js +33 -1
- package/packages/client/dist/yoloop/target-normalization.js +180 -1
- package/packages/client/dist/yoloop/yoloop-client-state-store.d.ts +8 -0
- package/packages/client/dist/yoloop/yoloop-client-state-store.js +1920 -1
- package/packages/shared/dist/yolo/spec-envelope.js +3 -6
- package/targets-stubs/antigravity/gemini.md +1 -1
- package/targets-stubs/antigravity/skill/SKILL.md +1 -1
- package/targets-stubs/claude-code/neocortex-root.agent.yaml +1 -1
- package/targets-stubs/claude-code/neocortex-root.md +2 -2
- package/targets-stubs/claude-code/neocortex.agent.yaml +1 -1
- package/targets-stubs/claude-code/neocortex.md +2 -2
- package/targets-stubs/codex/AGENTS.md +1 -1
- package/targets-stubs/cursor/agent.md +2 -2
- package/targets-stubs/gemini-cli/agent.md +2 -2
- package/targets-stubs/opencode/neocortex-root.md +1 -1
- package/targets-stubs/vscode/neocortex.agent.md +2 -2
|
@@ -1 +1,405 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* @license FSL-1.1
|
|
3
|
+
* Copyright (c) 2026 OrNexus AI
|
|
4
|
+
*
|
|
5
|
+
* This file is part of Neocortex CLI, licensed under the
|
|
6
|
+
* Functional Source License, Version 1.1 (FSL-1.1).
|
|
7
|
+
*
|
|
8
|
+
* Change Date: February 20, 2029
|
|
9
|
+
* Change License: MIT
|
|
10
|
+
*
|
|
11
|
+
* See the LICENSE file in the project root for full license text.
|
|
12
|
+
*/
|
|
13
|
+
import { GENERATED_CLIENT_COMMANDS } from '../generated/command-registry.generated.js';
|
|
14
|
+
// ── Constants ────────────────────────────────────────────────────────────
|
|
15
|
+
const TIER_CACHE_KEY = 'neocortex:tier';
|
|
16
|
+
const QUOTA_CACHE_KEY_PREFIX = 'neocortex:quota:';
|
|
17
|
+
const QUOTA_TTL_MS = 5 * 60 * 1000; // 5 minutes
|
|
18
|
+
const TIER_CACHE_TTL_MS = 60 * 60 * 1000; // 1 hour (Story 31.05: reduced from 24h to align with short-lived JWTs)
|
|
19
|
+
const VALID_TIERS = new Set(['free', 'pro', 'enterprise']);
|
|
20
|
+
const DEFAULT_TIER = 'free';
|
|
21
|
+
// ── Trigger Gates (inlined from shared tier-config to avoid import issues) ─
|
|
22
|
+
const LEGACY_TRIGGER_GATES = {
|
|
23
|
+
'status': 'free',
|
|
24
|
+
'create-epic': 'free',
|
|
25
|
+
'idea-diagnose': 'free',
|
|
26
|
+
'idea-research': 'free',
|
|
27
|
+
'generate-epic': 'free',
|
|
28
|
+
'exec': 'pro',
|
|
29
|
+
'yolo': 'pro',
|
|
30
|
+
'epic': 'pro',
|
|
31
|
+
'setup-branch': 'free',
|
|
32
|
+
'diagnose': 'free',
|
|
33
|
+
'research': 'free',
|
|
34
|
+
'write-spec': 'free',
|
|
35
|
+
'create-tasks': 'free',
|
|
36
|
+
'implement': 'free',
|
|
37
|
+
'update-memory': 'free',
|
|
38
|
+
'commit': 'free',
|
|
39
|
+
'sync': 'free',
|
|
40
|
+
'create-pr': 'free',
|
|
41
|
+
'review': 'pro',
|
|
42
|
+
'merge': 'free',
|
|
43
|
+
'fix-blocked': 'free',
|
|
44
|
+
'finalize-epic': 'free',
|
|
45
|
+
'cleanup': 'free',
|
|
46
|
+
'resolve-conflicts': 'free',
|
|
47
|
+
'audit': 'free',
|
|
48
|
+
'menu': 'free',
|
|
49
|
+
'plans': 'free',
|
|
50
|
+
'billing': 'free',
|
|
51
|
+
'subscribe': 'free',
|
|
52
|
+
'arch-plan': 'free',
|
|
53
|
+
'arch-prd': 'free',
|
|
54
|
+
'arch-architecture': 'free',
|
|
55
|
+
'arch-api-contracts': 'free',
|
|
56
|
+
'arch-api-integrations': 'free',
|
|
57
|
+
'arch-database': 'free',
|
|
58
|
+
'arch-security': 'free',
|
|
59
|
+
'arch-design-system': 'free',
|
|
60
|
+
'arch-ux-design': 'free',
|
|
61
|
+
'arch-review': 'free',
|
|
62
|
+
'arch-fitness-functions': 'pro',
|
|
63
|
+
'arch-performance': 'pro',
|
|
64
|
+
'arch-testing': 'pro',
|
|
65
|
+
'arch-infrastructure': 'pro',
|
|
66
|
+
'refactor': 'pro',
|
|
67
|
+
'tech-debt': 'free',
|
|
68
|
+
'tech-debt-scan': 'pro',
|
|
69
|
+
'qa-scan': 'pro',
|
|
70
|
+
'mutation-test': 'pro',
|
|
71
|
+
'yoloop': 'pro',
|
|
72
|
+
'migrate-state': 'free',
|
|
73
|
+
'policy-audit': 'pro',
|
|
74
|
+
'sync-openapi': 'free',
|
|
75
|
+
'generate-pacts': 'pro',
|
|
76
|
+
'verify-pacts': 'free',
|
|
77
|
+
'property-test': 'pro',
|
|
78
|
+
'chaos-plan': 'pro',
|
|
79
|
+
'ui-ux-review': 'pro',
|
|
80
|
+
'solyd-system': 'enterprise',
|
|
81
|
+
'goal': 'enterprise',
|
|
82
|
+
'goal-tick': 'enterprise',
|
|
83
|
+
'loop': 'enterprise',
|
|
84
|
+
'loop-tick': 'enterprise',
|
|
85
|
+
'jobs': 'enterprise',
|
|
86
|
+
'runner': 'enterprise',
|
|
87
|
+
};
|
|
88
|
+
const TRIGGER_GATES = Object.freeze(Object.fromEntries(GENERATED_CLIENT_COMMANDS.map((entry) => [entry.id, entry.policy.minimumTier])));
|
|
89
|
+
void LEGACY_TRIGGER_GATES;
|
|
90
|
+
// P126.07: runtime mirror of shared COMMAND_REGISTRY command identity only.
|
|
91
|
+
// Keep this small to avoid a runtime @neocortex/shared dependency in the
|
|
92
|
+
// standalone client package; flexible-preflight.test.ts validates drift.
|
|
93
|
+
const LEGACY_CLIENT_PREFLIGHT_COMMAND_REGISTRY = [
|
|
94
|
+
{ id: 'status', number: 1, aliases: ['st'] },
|
|
95
|
+
{ id: 'arch-plan', number: 3, aliases: ['arquitetura', 'architecture', 'arch'] },
|
|
96
|
+
{ id: 'arch-prd', number: 4, aliases: ['prd', 'product-requirements'] },
|
|
97
|
+
{ id: 'arch-architecture', number: 5, aliases: ['arch-doc', 'tech-architecture'] },
|
|
98
|
+
{ id: 'arch-api-contracts', number: 6, aliases: ['api-contracts', 'api-contract'] },
|
|
99
|
+
{ id: 'arch-api-integrations', number: 7, aliases: ['api-integrations', 'api-int'] },
|
|
100
|
+
{ id: 'arch-database', number: 8, aliases: ['database-schema', 'db-schema', 'db'] },
|
|
101
|
+
{ id: 'arch-security', number: 9, aliases: ['cyber-security', 'security', 'sec'] },
|
|
102
|
+
{ id: 'arch-design-system', number: 10, aliases: ['design-system', 'ds', 'atomic-design'] },
|
|
103
|
+
{ id: 'arch-ux-design', number: 11, aliases: ['ux-design', 'ux', 'wireframes', 'wireframe', 'user-flows'] },
|
|
104
|
+
{ id: 'arch-performance', number: 12, aliases: ['performance', 'perf', 'capacity-planning', 'capacity', 'arch-perf', 'performance-strategy'] },
|
|
105
|
+
{ id: 'arch-testing', number: 13, aliases: ['testing-strategy', 'test-plan', 'test-strategy', 'arch-test'] },
|
|
106
|
+
{ id: 'arch-infrastructure', number: 14, aliases: ['infrastructure', 'infra', 'deploy-plan', 'deployment', 'arch-infra', 'arch-deploy'] },
|
|
107
|
+
{ id: 'arch-review', number: 15, aliases: ['review-consolidation', 'consolidation', 'architecture-review', 'arch-consolidation'] },
|
|
108
|
+
{ id: 'arch-fitness-functions', number: 16, aliases: ['fitness', 'fitness-functions', 'archfit', 'arch-fit', 'fit-funcs'] },
|
|
109
|
+
{ id: 'create-epic', number: 17, aliases: ['criar-epic', 'planejamento'] },
|
|
110
|
+
{ id: 'idea-diagnose', number: 18, aliases: ['idea-diag'] },
|
|
111
|
+
{ id: 'idea-research', number: 19, aliases: ['idea-pesq'] },
|
|
112
|
+
{ id: 'generate-epic', number: 20, aliases: ['gerar-epic'] },
|
|
113
|
+
{ id: 'exec', number: 21, aliases: ['executar', 'pipeline'] },
|
|
114
|
+
{ id: 'yolo', number: 22, aliases: [] },
|
|
115
|
+
{ id: 'epic', number: 23, aliases: ['parallel-epic'] },
|
|
116
|
+
{ id: 'setup-branch', number: 24, aliases: ['setup', 'branch'] },
|
|
117
|
+
{ id: 'diagnose', number: 25, aliases: ['diag', 'diagnostico', 'c02'] },
|
|
118
|
+
{ id: 'research', number: 26, aliases: ['pesquisar', 'pesq', 'research-fix', 'c03'] },
|
|
119
|
+
{ id: 'write-spec', number: 27, aliases: ['spec', 'especificacao', 'c04'] },
|
|
120
|
+
{ id: 'create-tasks', number: 28, aliases: ['tasks', 'tarefas', 'c05'] },
|
|
121
|
+
{ id: 'implement', number: 29, aliases: ['impl', 'implementar', 'c06'] },
|
|
122
|
+
{ id: 'commit', number: 30, aliases: ['push', 'commit-push', 'commit_push', 'cp', 'c07'] },
|
|
123
|
+
{ id: 'sync', number: 31, aliases: ['sincronizar', 'c08'] },
|
|
124
|
+
{ id: 'create-pr', number: 32, aliases: ['pr', 'c09'] },
|
|
125
|
+
{ id: 'review', number: 33, aliases: ['revisar', 'c11'] },
|
|
126
|
+
{ id: 'merge', number: 34, aliases: ['mesclar', 'c12'] },
|
|
127
|
+
{ id: 'fix-blocked', number: 35, aliases: ['fix', 'corrigir'] },
|
|
128
|
+
{ id: 'finalize-epic', number: 36, aliases: ['finalizar'] },
|
|
129
|
+
{ id: 'resolve-conflicts', number: 37, aliases: ['conflitos'] },
|
|
130
|
+
{ id: 'update-memory', number: 38, aliases: ['memoria'] },
|
|
131
|
+
{ id: 'refactor', number: 39, aliases: ['refactoring', 'refact', 'refac', 'rf', 'cleanup-code', 'code-cleanup', 'code-quality', 'improve-code', 'modernize', 'modernization', 'legacy', 'legacy-code', 'debt-pay', 'pay-debt', 'debt-reduction', 'smell-fix', 'fix-smells', 'code-smells', 'strangler', 'strangler-fig'] },
|
|
132
|
+
{ id: 'cleanup', number: 40, aliases: ['limpar', 'limpeza'] },
|
|
133
|
+
{ id: 'audit', number: 41, aliases: ['auditar', 'auditoria'] },
|
|
134
|
+
{ id: 'tech-debt', number: 42, aliases: ['debt', 'debts', 'debt-list', 'tech-debts', 'td'] },
|
|
135
|
+
{ id: 'menu', number: 43, aliases: ['help', 'ajuda', '?', 'commands', 'cmds'] },
|
|
136
|
+
{ id: 'plans', number: 44, aliases: ['planos', 'pricing'] },
|
|
137
|
+
{ id: 'billing', number: 45, aliases: ['bill', 'subscription', 'sub'] },
|
|
138
|
+
{ id: 'subscribe', number: 46, aliases: ['upgrade', 'checkout'] },
|
|
139
|
+
{ id: 'qa-scan', number: 47, aliases: ['qa', 'qa-test', 'visual-qa', 'e2e-scan', 'troubleshoot', 'debug-ui', 'scan', 'a11y', 'accessibility', 'wcag'] },
|
|
140
|
+
{ id: 'yoloop', number: 48, aliases: ['auto-yolo', 'epic-runner', 'story-runner', 'loop-yolo', 'auto-epic'] },
|
|
141
|
+
{ id: 'migrate-state', number: 49, aliases: ['migrate', 'state-migrate', 'schema-migrate'] },
|
|
142
|
+
{ id: 'policy-audit', number: 50, aliases: ['policy', 'audit-policy', 'policy-history', 'policies'] },
|
|
143
|
+
{ id: 'mutation-test', number: 51, aliases: ['mutation', 'stryker', 'kill-mutants'] },
|
|
144
|
+
{ id: 'sync-openapi', number: 52, aliases: ['openapi-sync', 'api-sync', 'spec-sync', 'regen-openapi'] },
|
|
145
|
+
{ id: 'generate-pacts', number: 53, aliases: ['pacts', 'gen-pacts', 'regen-pacts', 'create-pacts'] },
|
|
146
|
+
{ id: 'verify-pacts', number: 54, aliases: ['verify-pact', 'pact-verify', 'check-pacts', 'pact-check'] },
|
|
147
|
+
{ id: 'property-test', number: 55, aliases: ['property', 'pbt', 'proptest', 'property-tests', 'invariant-test'] },
|
|
148
|
+
{ id: 'chaos-plan', number: 56, aliases: ['chaos', 'gameday', 'resilience-test'] },
|
|
149
|
+
{ id: 'ui-ux-review', number: 57, aliases: ['ux-review', 'design-review', 'visual-review', 'product-polish'] },
|
|
150
|
+
{ id: 'solyd-system', number: 58, aliases: ['security-system', 'authorized-security', 'sec-system'] },
|
|
151
|
+
{ id: 'goal', number: 59, aliases: ['goals', 'durable-goal', 'continuity-goal'] },
|
|
152
|
+
{ id: 'loop', number: 60, aliases: ['loops', 'durable-loop', 'continuity-loop'] },
|
|
153
|
+
{ id: 'jobs', number: 61, aliases: ['job', 'continuity-jobs'] },
|
|
154
|
+
{ id: 'runner', number: 62, aliases: ['neocortex-runner', 'continuity-runner'] },
|
|
155
|
+
];
|
|
156
|
+
export const CLIENT_PREFLIGHT_COMMAND_REGISTRY = Object.freeze(GENERATED_CLIENT_COMMANDS.map((entry) => Object.freeze({
|
|
157
|
+
id: entry.id,
|
|
158
|
+
number: entry.number,
|
|
159
|
+
aliases: entry.aliases,
|
|
160
|
+
})));
|
|
161
|
+
void LEGACY_CLIENT_PREFLIGHT_COMMAND_REGISTRY;
|
|
162
|
+
const CLIENT_COMMAND_BY_ID = new Map(CLIENT_PREFLIGHT_COMMAND_REGISTRY.map((entry) => [entry.id, entry]));
|
|
163
|
+
const CLIENT_COMMAND_BY_NUMBER = new Map(CLIENT_PREFLIGHT_COMMAND_REGISTRY.map((entry) => [entry.number, entry]));
|
|
164
|
+
const CLIENT_COMMAND_ALIAS_MAP = new Map(CLIENT_PREFLIGHT_COMMAND_REGISTRY.flatMap((entry) => entry.aliases.map((alias) => [normalizeCommandToken(alias), entry.id])));
|
|
165
|
+
export function normalizeCommandToken(input) {
|
|
166
|
+
if (/[^\x20-\x7e]/.test(input))
|
|
167
|
+
return '';
|
|
168
|
+
const trimmed = input.replace(/^[\t\n\r ]+|[\t\n\r ]+$/g, '');
|
|
169
|
+
if (!trimmed || trimmed.startsWith('**'))
|
|
170
|
+
return '';
|
|
171
|
+
const token = (trimmed.startsWith('*') ? trimmed.slice(1) : trimmed)
|
|
172
|
+
.replace(/[A-Z]/g, (letter) => letter.toLowerCase());
|
|
173
|
+
return /^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/.test(token) || token === '?' ? token : '';
|
|
174
|
+
}
|
|
175
|
+
export function resolveClientPreFlightTrigger(input) {
|
|
176
|
+
const trimmed = input.trim();
|
|
177
|
+
if (/^@?epic-[a-z0-9][a-z0-9._-]*$/i.test(trimmed))
|
|
178
|
+
return 'epic';
|
|
179
|
+
// P179.02: local pre-flight mirrors invoke's leading-token command contract
|
|
180
|
+
// so Free/Pro users are gated before remote invocation for `58 plan` and
|
|
181
|
+
// Solyd alias-with-mode forms. Only the first public token is considered.
|
|
182
|
+
const leadingToken = trimmed.split(/\s+/, 1)[0] ?? '';
|
|
183
|
+
const numericToken = leadingToken.trim().replace(/^\*/, '');
|
|
184
|
+
if (/^\d+$/.test(numericToken)) {
|
|
185
|
+
return CLIENT_COMMAND_BY_NUMBER.get(Number.parseInt(numericToken, 10))?.id ?? null;
|
|
186
|
+
}
|
|
187
|
+
const token = normalizeCommandToken(leadingToken);
|
|
188
|
+
if (!token)
|
|
189
|
+
return null;
|
|
190
|
+
if (token === 'goal-tick')
|
|
191
|
+
return 'goal';
|
|
192
|
+
if (token === 'loop-tick')
|
|
193
|
+
return 'loop';
|
|
194
|
+
if (CLIENT_COMMAND_BY_ID.has(token))
|
|
195
|
+
return token;
|
|
196
|
+
return CLIENT_COMMAND_ALIAS_MAP.get(token) ?? null;
|
|
197
|
+
}
|
|
198
|
+
const TIER_HIERARCHY = {
|
|
199
|
+
free: 0,
|
|
200
|
+
pro: 1,
|
|
201
|
+
enterprise: 2,
|
|
202
|
+
};
|
|
203
|
+
// ── TierAwareClient ──────────────────────────────────────────────────────
|
|
204
|
+
export class TierAwareClient {
|
|
205
|
+
cache;
|
|
206
|
+
licenseClient;
|
|
207
|
+
cachedTier = null;
|
|
208
|
+
constructor(options) {
|
|
209
|
+
this.cache = options.cacheProvider;
|
|
210
|
+
this.licenseClient = options.licenseClient;
|
|
211
|
+
}
|
|
212
|
+
// ── Story 60.1: Tier Extraction from JWT + Cache ────────────────────
|
|
213
|
+
/**
|
|
214
|
+
* Get the current tier. Checks in-memory, then cache, then JWT token.
|
|
215
|
+
* NEVER throws - returns 'free' on failure (fail-open).
|
|
216
|
+
*/
|
|
217
|
+
async getCachedTier() {
|
|
218
|
+
try {
|
|
219
|
+
// 1. In-memory
|
|
220
|
+
if (this.cachedTier)
|
|
221
|
+
return this.cachedTier;
|
|
222
|
+
// 2. EncryptedCache
|
|
223
|
+
const cached = await this.cache.get(TIER_CACHE_KEY);
|
|
224
|
+
if (cached && VALID_TIERS.has(cached)) {
|
|
225
|
+
this.cachedTier = cached;
|
|
226
|
+
return this.cachedTier;
|
|
227
|
+
}
|
|
228
|
+
// 3. Extract from JWT
|
|
229
|
+
const token = await this.licenseClient.getToken();
|
|
230
|
+
if (token) {
|
|
231
|
+
const tier = this.extractTierFromJwt(token);
|
|
232
|
+
this.cachedTier = tier;
|
|
233
|
+
await this.cache.set(TIER_CACHE_KEY, tier, TIER_CACHE_TTL_MS).catch(() => { });
|
|
234
|
+
return tier;
|
|
235
|
+
}
|
|
236
|
+
return DEFAULT_TIER;
|
|
237
|
+
}
|
|
238
|
+
catch {
|
|
239
|
+
return DEFAULT_TIER;
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
/**
|
|
243
|
+
* Update cached tier (called when server returns tier info).
|
|
244
|
+
*/
|
|
245
|
+
async updateTier(tier) {
|
|
246
|
+
try {
|
|
247
|
+
if (!VALID_TIERS.has(tier))
|
|
248
|
+
return;
|
|
249
|
+
this.cachedTier = tier;
|
|
250
|
+
await this.cache.set(TIER_CACHE_KEY, tier, TIER_CACHE_TTL_MS).catch(() => { });
|
|
251
|
+
}
|
|
252
|
+
catch {
|
|
253
|
+
// Non-critical
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
// ── Story 18.8: Tier Cache Invalidation ──────────────────────────────
|
|
257
|
+
/**
|
|
258
|
+
* Invalidate all tier and quota caches.
|
|
259
|
+
* Called when a tier change is detected to ensure fresh data.
|
|
260
|
+
* NEVER throws.
|
|
261
|
+
*/
|
|
262
|
+
async invalidateTierCache() {
|
|
263
|
+
try {
|
|
264
|
+
this.cachedTier = null;
|
|
265
|
+
await this.cache.clear().catch(() => { });
|
|
266
|
+
}
|
|
267
|
+
catch {
|
|
268
|
+
// Non-critical
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
// ── Story 60.2: Pre-flight Trigger Check ────────────────────────────
|
|
272
|
+
/**
|
|
273
|
+
* Check if a trigger is allowed for the current tier WITHOUT calling the server.
|
|
274
|
+
* Returns immediately (in-memory lookup).
|
|
275
|
+
* NEVER throws - returns { allowed: true } on failure (fail-open).
|
|
276
|
+
*/
|
|
277
|
+
async preFlightCheck(trigger, tier) {
|
|
278
|
+
try {
|
|
279
|
+
const userTier = tier ?? await this.getCachedTier();
|
|
280
|
+
const canonicalTrigger = resolveClientPreFlightTrigger(trigger) ?? trigger;
|
|
281
|
+
const requiredTier = TRIGGER_GATES[canonicalTrigger] ?? 'free';
|
|
282
|
+
if (TIER_HIERARCHY[userTier] >= TIER_HIERARCHY[requiredTier]) {
|
|
283
|
+
return { allowed: true };
|
|
284
|
+
}
|
|
285
|
+
const message = this.buildUpgradeMessage(canonicalTrigger, userTier, requiredTier);
|
|
286
|
+
return { allowed: false, message };
|
|
287
|
+
}
|
|
288
|
+
catch {
|
|
289
|
+
// Fail-open: allow on error
|
|
290
|
+
return { allowed: true };
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
// ── Story 60.3: Quota Cache from Response ───────────────────────────
|
|
294
|
+
/**
|
|
295
|
+
* Update cached quota from server response metadata.
|
|
296
|
+
* Called after each successful invoke.
|
|
297
|
+
*/
|
|
298
|
+
async updateQuotaFromResponse(metadata) {
|
|
299
|
+
try {
|
|
300
|
+
const quotaRemaining = metadata.quotaRemaining;
|
|
301
|
+
if (!quotaRemaining)
|
|
302
|
+
return;
|
|
303
|
+
const snapshot = {
|
|
304
|
+
stepsRemaining: quotaRemaining.stepsRemaining ?? 0,
|
|
305
|
+
invocationsRemaining: quotaRemaining.invocationsRemaining ?? 0,
|
|
306
|
+
stepsLimit: quotaRemaining.stepsLimit ?? 0,
|
|
307
|
+
invocationsLimit: quotaRemaining.invocationsLimit ?? 0,
|
|
308
|
+
cachedAt: Date.now(),
|
|
309
|
+
};
|
|
310
|
+
const dateKey = this.getQuotaCacheKey();
|
|
311
|
+
await this.cache.set(dateKey, JSON.stringify(snapshot), QUOTA_TTL_MS).catch(() => { });
|
|
312
|
+
}
|
|
313
|
+
catch {
|
|
314
|
+
// Non-critical
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
/**
|
|
318
|
+
* Get cached quota for today.
|
|
319
|
+
* NEVER throws - returns null if cache empty or expired.
|
|
320
|
+
*/
|
|
321
|
+
async getCachedQuota() {
|
|
322
|
+
try {
|
|
323
|
+
const dateKey = this.getQuotaCacheKey();
|
|
324
|
+
const raw = await this.cache.get(dateKey);
|
|
325
|
+
if (!raw)
|
|
326
|
+
return null;
|
|
327
|
+
const snapshot = JSON.parse(raw);
|
|
328
|
+
// Validate TTL (EncryptedCache already handles this, but double-check)
|
|
329
|
+
if (Date.now() - snapshot.cachedAt > QUOTA_TTL_MS)
|
|
330
|
+
return null;
|
|
331
|
+
return snapshot;
|
|
332
|
+
}
|
|
333
|
+
catch {
|
|
334
|
+
return null;
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
// ── Story 60.4: Offline Enforcement ─────────────────────────────────
|
|
338
|
+
/**
|
|
339
|
+
* Check quota in offline mode using cached data.
|
|
340
|
+
* NEVER throws - returns { allowed: true } on failure (fail-open).
|
|
341
|
+
*
|
|
342
|
+
* @param isOffline - Whether the circuit breaker is in L2+ degradation
|
|
343
|
+
*/
|
|
344
|
+
async offlineQuotaCheck(isOffline = false) {
|
|
345
|
+
try {
|
|
346
|
+
if (!isOffline)
|
|
347
|
+
return { allowed: true };
|
|
348
|
+
const quota = await this.getCachedQuota();
|
|
349
|
+
// Fail-open: if no cached quota, allow
|
|
350
|
+
if (!quota)
|
|
351
|
+
return { allowed: true };
|
|
352
|
+
// Check steps
|
|
353
|
+
if (quota.stepsRemaining <= 0 && quota.stepsLimit > 0) {
|
|
354
|
+
return {
|
|
355
|
+
allowed: false,
|
|
356
|
+
message: `Daily step limit reached (${quota.stepsLimit}/${quota.stepsLimit}). Resets at 00:00 UTC.`,
|
|
357
|
+
};
|
|
358
|
+
}
|
|
359
|
+
// Check invocations
|
|
360
|
+
if (quota.invocationsRemaining <= 0 && quota.invocationsLimit > 0) {
|
|
361
|
+
return {
|
|
362
|
+
allowed: false,
|
|
363
|
+
message: `Daily invocation limit reached (${quota.invocationsLimit}/${quota.invocationsLimit}). Resets at 00:00 UTC.`,
|
|
364
|
+
};
|
|
365
|
+
}
|
|
366
|
+
return { allowed: true };
|
|
367
|
+
}
|
|
368
|
+
catch {
|
|
369
|
+
// Fail-open
|
|
370
|
+
return { allowed: true };
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
// ── Private Helpers ─────────────────────────────────────────────────
|
|
374
|
+
/**
|
|
375
|
+
* Extract tier from JWT payload via base64url decode.
|
|
376
|
+
* No cryptographic verification - client-side is UX only.
|
|
377
|
+
*/
|
|
378
|
+
extractTierFromJwt(token) {
|
|
379
|
+
try {
|
|
380
|
+
const parts = token.split('.');
|
|
381
|
+
if (parts.length !== 3)
|
|
382
|
+
return DEFAULT_TIER;
|
|
383
|
+
// Decode base64url payload
|
|
384
|
+
const payload = parts[1];
|
|
385
|
+
const decoded = Buffer.from(payload, 'base64url').toString('utf8');
|
|
386
|
+
const claims = JSON.parse(decoded);
|
|
387
|
+
const tier = claims.tier;
|
|
388
|
+
if (tier && VALID_TIERS.has(tier)) {
|
|
389
|
+
return tier;
|
|
390
|
+
}
|
|
391
|
+
return DEFAULT_TIER;
|
|
392
|
+
}
|
|
393
|
+
catch {
|
|
394
|
+
return DEFAULT_TIER;
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
buildUpgradeMessage(trigger, currentTier, requiredTier) {
|
|
398
|
+
return `The *${trigger} command requires ${requiredTier.toUpperCase()} plan. Your current plan: ${currentTier.toUpperCase()}. Upgrade: https://neocortex.sh/portal/dashboard/plans`;
|
|
399
|
+
}
|
|
400
|
+
getQuotaCacheKey() {
|
|
401
|
+
const now = new Date();
|
|
402
|
+
const dateStr = now.toISOString().slice(0, 10); // YYYY-MM-DD UTC
|
|
403
|
+
return `${QUOTA_CACHE_KEY_PREFIX}${dateStr}`;
|
|
404
|
+
}
|
|
405
|
+
}
|
|
@@ -1 +1,38 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* @license FSL-1.1
|
|
3
|
+
* Copyright (c) 2026 OrNexus AI
|
|
4
|
+
*
|
|
5
|
+
* This file is part of Neocortex CLI, licensed under the
|
|
6
|
+
* Functional Source License, Version 1.1 (FSL-1.1).
|
|
7
|
+
*
|
|
8
|
+
* Change Date: February 20, 2029
|
|
9
|
+
* Change License: MIT
|
|
10
|
+
*
|
|
11
|
+
* See the LICENSE file in the project root for full license text.
|
|
12
|
+
*/
|
|
13
|
+
/**
|
|
14
|
+
* @neocortex/client - Type Definitions
|
|
15
|
+
*
|
|
16
|
+
* All types for the asset resolution abstraction layer.
|
|
17
|
+
*/
|
|
18
|
+
// ── Resolver Mode ────────────────────────────────────────────────────────
|
|
19
|
+
/** Mode of asset resolution */
|
|
20
|
+
export var ResolverMode;
|
|
21
|
+
(function (ResolverMode) {
|
|
22
|
+
/** Read assets from local filesystem (development) */
|
|
23
|
+
ResolverMode["LOCAL"] = "local";
|
|
24
|
+
/** Fetch assets from remote IP Protection Server (production) */
|
|
25
|
+
ResolverMode["REMOTE"] = "remote";
|
|
26
|
+
})(ResolverMode || (ResolverMode = {}));
|
|
27
|
+
/** No-op cache implementation for development/fallback */
|
|
28
|
+
export class NoOpCache {
|
|
29
|
+
async get() {
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
async set() {
|
|
33
|
+
// No-op: cache disabled
|
|
34
|
+
}
|
|
35
|
+
async clear() {
|
|
36
|
+
// No-op: nothing to clear
|
|
37
|
+
}
|
|
38
|
+
}
|
|
@@ -1 +1,27 @@
|
|
|
1
|
-
import{readFileSync
|
|
1
|
+
import { readFileSync } from 'node:fs';
|
|
2
|
+
import { fileURLToPath } from 'node:url';
|
|
3
|
+
import { dirname, join } from 'node:path';
|
|
4
|
+
/** Resolve the installed package version for both source and packed runtimes. */
|
|
5
|
+
export function getClientVersion(fromUrl = import.meta.url) {
|
|
6
|
+
try {
|
|
7
|
+
let directory = dirname(fileURLToPath(fromUrl));
|
|
8
|
+
for (let depth = 0; depth < 6; depth += 1) {
|
|
9
|
+
try {
|
|
10
|
+
const pkg = JSON.parse(readFileSync(join(directory, 'package.json'), 'utf8'));
|
|
11
|
+
if ((pkg.name === '@ornexus/neocortex' || pkg.name === '@neocortex/client') &&
|
|
12
|
+
typeof pkg.version === 'string' &&
|
|
13
|
+
/^\d+\.\d+\.\d+(?:[-+][A-Za-z0-9.-]+)?$/.test(pkg.version))
|
|
14
|
+
return pkg.version;
|
|
15
|
+
}
|
|
16
|
+
catch {
|
|
17
|
+
// Continue toward the package root.
|
|
18
|
+
}
|
|
19
|
+
directory = dirname(directory);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
catch {
|
|
23
|
+
// Fall through to the explicit unavailable value.
|
|
24
|
+
}
|
|
25
|
+
return '0.0.0';
|
|
26
|
+
}
|
|
27
|
+
export const CLIENT_VERSION = getClientVersion();
|
|
@@ -1 +1,126 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { execFileSync } from 'node:child_process';
|
|
2
|
+
import { realpathSync } from 'node:fs';
|
|
3
|
+
import { createYoloChangeEvidence } from '../../../shared/dist/yolo/change-evidence.js';
|
|
4
|
+
import { readGitLifecycleRuntimeSync } from '../git/git-lifecycle-store.js';
|
|
5
|
+
/** Reacquire only an expired setup lease for this exact story through P207's CAS boundary. */
|
|
6
|
+
export async function reconcileYoloChangeEvidenceLease(options) {
|
|
7
|
+
let lease;
|
|
8
|
+
try {
|
|
9
|
+
lease = readGitLifecycleRuntimeSync(options.projectRoot, { required: true })
|
|
10
|
+
.epics[options.epicId]?.branch_lease;
|
|
11
|
+
}
|
|
12
|
+
catch (error) {
|
|
13
|
+
// C01 can legitimately precede first-use sidecar materialization. Only
|
|
14
|
+
// that exact absence falls through to the existing remote/base evidence.
|
|
15
|
+
if (error instanceof Error && error.message === 'git-lifecycle-runtime-missing')
|
|
16
|
+
return;
|
|
17
|
+
throw new Error('yolo-change-evidence-unavailable');
|
|
18
|
+
}
|
|
19
|
+
if (lease === null || lease === undefined)
|
|
20
|
+
return;
|
|
21
|
+
if (typeof lease !== 'object' || Array.isArray(lease)
|
|
22
|
+
|| lease.ownerStoryId !== options.storyId
|
|
23
|
+
|| typeof lease.expiresAt !== 'string') {
|
|
24
|
+
throw new Error('yolo-change-evidence-unavailable');
|
|
25
|
+
}
|
|
26
|
+
const expiry = Date.parse(lease.expiresAt);
|
|
27
|
+
if (!Number.isFinite(expiry))
|
|
28
|
+
throw new Error('yolo-change-evidence-unavailable');
|
|
29
|
+
if (expiry > Date.now())
|
|
30
|
+
return;
|
|
31
|
+
if (typeof lease.sessionId !== 'string'
|
|
32
|
+
|| !/^setup-[a-f0-9]{64}$/.test(lease.sessionId)
|
|
33
|
+
|| lease.idempotencyKey !== lease.sessionId) {
|
|
34
|
+
throw new Error('yolo-change-evidence-unavailable');
|
|
35
|
+
}
|
|
36
|
+
const { prepareDirectYoloSetup } = await import('../git/direct-yolo-checkpoint.js');
|
|
37
|
+
const result = await prepareDirectYoloSetup(options);
|
|
38
|
+
if (!result.ok || result.value.storyId !== options.storyId
|
|
39
|
+
|| result.value.epicId !== options.epicId
|
|
40
|
+
|| Date.parse(result.value.leaseExpiresAt) <= Date.now()) {
|
|
41
|
+
throw new Error('yolo-change-evidence-unavailable');
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
function git(root, args) {
|
|
45
|
+
try {
|
|
46
|
+
return execFileSync('git', ['-C', root, ...args], {
|
|
47
|
+
encoding: 'utf8', timeout: 3_000, maxBuffer: 1024 * 1024, stdio: ['ignore', 'pipe', 'ignore'],
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
catch {
|
|
51
|
+
throw new Error('yolo-change-evidence-unavailable');
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
export function collectYoloChangeEvidence(options) {
|
|
55
|
+
if (!/^[A-Za-z0-9][A-Za-z0-9_./-]{0,119}$/.test(options.defaultBranch)
|
|
56
|
+
|| options.defaultBranch.includes('..'))
|
|
57
|
+
throw new Error('yolo-change-evidence-unavailable');
|
|
58
|
+
const repositoryRoot = git(options.projectRoot, ['rev-parse', '--show-toplevel']).trim();
|
|
59
|
+
if (realpathSync(repositoryRoot) !== realpathSync(options.projectRoot))
|
|
60
|
+
throw new Error('yolo-change-evidence-unavailable');
|
|
61
|
+
const headSha = git(options.projectRoot, ['rev-parse', 'HEAD']).trim();
|
|
62
|
+
if (headSha !== options.expectedHeadSha)
|
|
63
|
+
throw new Error('yolo-change-evidence-stale');
|
|
64
|
+
let baseSha;
|
|
65
|
+
let activeStoryLease = false;
|
|
66
|
+
let executionBranch = null;
|
|
67
|
+
if (options.storyId && options.epicId) {
|
|
68
|
+
try {
|
|
69
|
+
const runtime = readGitLifecycleRuntimeSync(options.projectRoot);
|
|
70
|
+
const epic = runtime.epics[options.epicId];
|
|
71
|
+
const lease = epic?.branch_lease;
|
|
72
|
+
const currentBranch = git(options.projectRoot, ['symbolic-ref', '--quiet', '--short', 'HEAD']).trim();
|
|
73
|
+
if (epic?.branch_mode === 'epic' && epic.execution_branch === currentBranch) {
|
|
74
|
+
executionBranch = currentBranch;
|
|
75
|
+
}
|
|
76
|
+
if (lease && typeof lease === 'object' && !Array.isArray(lease)) {
|
|
77
|
+
const item = lease;
|
|
78
|
+
if (item.ownerStoryId !== options.storyId
|
|
79
|
+
|| typeof item.expiresAt !== 'string' || Date.parse(item.expiresAt) <= Date.now()
|
|
80
|
+
|| executionBranch === null) {
|
|
81
|
+
throw new Error('yolo-change-evidence-unavailable');
|
|
82
|
+
}
|
|
83
|
+
activeStoryLease = true;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
catch {
|
|
87
|
+
throw new Error('yolo-change-evidence-unavailable');
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
if (activeStoryLease) {
|
|
91
|
+
// Before the root C08 commit, the setup lease owns the current checkout.
|
|
92
|
+
// Earlier epic commits are not part of this story's implementation diff.
|
|
93
|
+
// A manually pre-committed change cannot satisfy the staged C08 checkpoint.
|
|
94
|
+
baseSha = headSha;
|
|
95
|
+
}
|
|
96
|
+
else {
|
|
97
|
+
// Before C01 has acquired a story lease, compare this epic checkout with
|
|
98
|
+
// its published tip. Historical epic commits are not new story changes,
|
|
99
|
+
// while local unpushed commits must remain visible to the evidence gate.
|
|
100
|
+
const remoteLine = executionBranch === null ? '' : git(options.projectRoot, [
|
|
101
|
+
'ls-remote', '--heads', 'origin', `refs/heads/${executionBranch}`,
|
|
102
|
+
]).trim();
|
|
103
|
+
if (remoteLine) {
|
|
104
|
+
const match = /^([a-f0-9]{40})\trefs\/heads\/([^\n]+)$/.exec(remoteLine);
|
|
105
|
+
if (!match || match[2] !== executionBranch
|
|
106
|
+
|| git(options.projectRoot, ['merge-base', 'HEAD', match[1]]).trim() !== match[1]) {
|
|
107
|
+
throw new Error('yolo-change-evidence-unavailable');
|
|
108
|
+
}
|
|
109
|
+
baseSha = match[1];
|
|
110
|
+
}
|
|
111
|
+
else {
|
|
112
|
+
try {
|
|
113
|
+
baseSha = git(options.projectRoot, ['merge-base', 'HEAD', options.defaultBranch]).trim();
|
|
114
|
+
}
|
|
115
|
+
catch {
|
|
116
|
+
baseSha = git(options.projectRoot, ['merge-base', 'HEAD', `refs/remotes/origin/${options.defaultBranch}`]).trim();
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
const tracked = git(options.projectRoot, ['diff', '--name-only', '-z', baseSha, '--']).split('\0').filter(Boolean);
|
|
121
|
+
const untracked = git(options.projectRoot, ['ls-files', '--others', '--exclude-standard', '-z']).split('\0').filter(Boolean);
|
|
122
|
+
const evidence = createYoloChangeEvidence({ baseSha, headSha, changedPaths: [...tracked, ...untracked] });
|
|
123
|
+
if (git(options.projectRoot, ['rev-parse', 'HEAD']).trim() !== headSha)
|
|
124
|
+
throw new Error('yolo-change-evidence-stale');
|
|
125
|
+
return evidence;
|
|
126
|
+
}
|