devworkspace 0.5.0 → 0.5.2
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/CHANGELOG.md +44 -0
- package/README.md +57 -509
- package/dist/agents/claude/adapter.js +0 -1
- package/dist/agents/claude/content.js +0 -1
- package/dist/agents/codex/adapter.js +0 -1
- package/dist/agents/copilot/adapter.js +0 -1
- package/dist/agents/cursor/adapter.js +0 -1
- package/dist/agents/index.js +0 -1
- package/dist/agents/shared.js +0 -1
- package/dist/agents/types.js +0 -1
- package/dist/cli/args.d.ts +16 -0
- package/dist/cli/args.js +5 -1
- package/dist/cli/help.js +59 -17
- package/dist/cli/main.js +0 -1
- package/dist/cli/prompt.d.ts +15 -0
- package/dist/cli/prompt.js +113 -0
- package/dist/cli/render.d.ts +10 -0
- package/dist/cli/render.js +174 -4
- package/dist/cli/run.d.ts +3 -0
- package/dist/cli/run.js +366 -17
- package/dist/config/feature-gate.d.ts +15 -0
- package/dist/config/feature-gate.js +77 -0
- package/dist/config/feature-registry.d.ts +49 -0
- package/dist/config/feature-registry.js +451 -0
- package/dist/config/schemas.js +0 -1
- package/dist/config/settings.d.ts +54 -0
- package/dist/config/settings.js +293 -0
- package/dist/config/validate.js +0 -1
- package/dist/core/artifacts.js +0 -1
- package/dist/core/contracts.js +0 -1
- package/dist/core/migrations.js +0 -1
- package/dist/core/version.js +0 -1
- package/dist/core/versioned.js +0 -1
- package/dist/core/workspace.d.ts +1 -0
- package/dist/core/workspace.js +1 -1
- package/dist/decisions/decision.js +0 -1
- package/dist/discovery/cache.js +0 -1
- package/dist/discovery/commands.js +0 -1
- package/dist/discovery/detect.js +0 -1
- package/dist/discovery/docs.js +0 -1
- package/dist/discovery/entrypoints.js +0 -1
- package/dist/discovery/ignore.js +0 -1
- package/dist/discovery/scan.js +0 -1
- package/dist/discovery/types.js +0 -1
- package/dist/dx/dashboard.js +2 -1
- package/dist/dx/guidance.js +0 -1
- package/dist/dx/guided-setup.d.ts +102 -0
- package/dist/dx/guided-setup.js +508 -0
- package/dist/dx/index.js +0 -1
- package/dist/dx/onboarding.js +0 -1
- package/dist/dx/types.js +0 -1
- package/dist/errors/index.js +0 -1
- package/dist/features/schema.js +0 -1
- package/dist/features/types.js +0 -1
- package/dist/features/validate.js +0 -1
- package/dist/git/git.js +0 -1
- package/dist/index.d.ts +15 -5
- package/dist/index.js +10 -2
- package/dist/integrations/adapters/agent-skills.js +0 -1
- package/dist/integrations/adapters/claudePlugin.js +0 -1
- package/dist/integrations/adapters/graphify.js +0 -1
- package/dist/integrations/adapters/omniroute.js +0 -1
- package/dist/integrations/adapters/pluginSkill.js +0 -1
- package/dist/integrations/adapters/ponytail.js +0 -1
- package/dist/integrations/exec.js +0 -1
- package/dist/integrations/index.js +0 -1
- package/dist/integrations/manager.d.ts +2 -1
- package/dist/integrations/manager.js +22 -3
- package/dist/integrations/notices.js +0 -1
- package/dist/integrations/persistentPath.js +0 -1
- package/dist/integrations/protect.js +0 -1
- package/dist/integrations/state.js +0 -1
- package/dist/integrations/types.d.ts +1 -1
- package/dist/integrations/types.js +1 -1
- package/dist/intelligence/agents/profiles.js +0 -1
- package/dist/intelligence/agents/registry.js +0 -1
- package/dist/intelligence/agents/types.js +0 -1
- package/dist/intelligence/observability/tracer.js +0 -1
- package/dist/intelligence/observability/types.js +0 -1
- package/dist/intelligence/orchestration/engine.d.ts +21 -3
- package/dist/intelligence/orchestration/engine.js +486 -48
- package/dist/intelligence/orchestration/lock-manager.js +0 -1
- package/dist/intelligence/orchestration/store.js +0 -1
- package/dist/intelligence/orchestration/types.d.ts +40 -2
- package/dist/intelligence/orchestration/types.js +2 -3
- package/dist/intelligence/routing/matcher.js +0 -1
- package/dist/intelligence/routing/router.js +0 -1
- package/dist/intelligence/routing/types.js +0 -1
- package/dist/intelligence/runtime/adk/adapter.js +21 -33
- package/dist/intelligence/runtime/adk/detector.js +0 -1
- package/dist/intelligence/runtime/auth-provider.d.ts +63 -0
- package/dist/intelligence/runtime/auth-provider.js +201 -0
- package/dist/intelligence/runtime/boundary.d.ts +142 -0
- package/dist/intelligence/runtime/boundary.js +845 -0
- package/dist/intelligence/runtime/changes.d.ts +59 -0
- package/dist/intelligence/runtime/changes.js +362 -0
- package/dist/intelligence/runtime/external.d.ts +1 -0
- package/dist/intelligence/runtime/external.js +38 -61
- package/dist/intelligence/runtime/native.js +23 -56
- package/dist/intelligence/runtime/types.d.ts +91 -1
- package/dist/intelligence/runtime/types.js +11 -2
- package/dist/intelligence/security/audit.js +8 -2
- package/dist/intelligence/security/policy.js +0 -1
- package/dist/intelligence/security/types.d.ts +8 -0
- package/dist/intelligence/security/types.js +0 -1
- package/dist/intelligence/skills/builtins.js +0 -1
- package/dist/intelligence/skills/loader.js +0 -1
- package/dist/intelligence/skills/registry.js +0 -1
- package/dist/intelligence/skills/types.js +0 -1
- package/dist/intelligence/verification/engine.d.ts +30 -8
- package/dist/intelligence/verification/engine.js +126 -21
- package/dist/intelligence/verification/reviewer.d.ts +18 -2
- package/dist/intelligence/verification/reviewer.js +356 -4
- package/dist/intelligence/verification/types.d.ts +71 -0
- package/dist/intelligence/verification/types.js +0 -1
- package/dist/knowledge/facts.js +0 -1
- package/dist/mcp/protocol.js +0 -1
- package/dist/mcp/server.js +38 -2
- package/dist/mcp/setup.js +5 -2
- package/dist/mcp/tools.js +0 -1
- package/dist/mcp/types.js +0 -1
- package/dist/mcp/verify.js +0 -1
- package/dist/portability/bundle.js +0 -1
- package/dist/prompts/onboarding.js +0 -1
- package/dist/prompts/refresh.js +0 -1
- package/dist/prompts/requirements.js +0 -1
- package/dist/security/files.js +0 -1
- package/dist/security/redact.js +0 -1
- package/dist/services/agent.js +2 -1
- package/dist/services/analysis.js +0 -1
- package/dist/services/common.js +0 -1
- package/dist/services/doctor.js +13 -2
- package/dist/services/drift.js +0 -1
- package/dist/services/features.js +5 -1
- package/dist/services/graph.js +4 -1
- package/dist/services/init.js +0 -1
- package/dist/services/integrations.d.ts +2 -1
- package/dist/services/integrations.js +29 -6
- package/dist/services/intelligence.d.ts +2 -2
- package/dist/services/intelligence.js +38 -36
- package/dist/services/knowledge.js +0 -1
- package/dist/services/migrate.js +0 -1
- package/dist/services/modules.d.ts +85 -0
- package/dist/services/modules.js +313 -0
- package/dist/services/portability.js +0 -1
- package/dist/services/records.js +5 -1
- package/dist/services/refresh.js +0 -1
- package/dist/services/reset.js +0 -1
- package/dist/services/settings.d.ts +36 -0
- package/dist/services/settings.js +102 -0
- package/dist/services/setup.d.ts +4 -5
- package/dist/services/setup.js +40 -28
- package/dist/services/standards.js +10 -1
- package/dist/services/status.js +0 -1
- package/dist/services/taskContext.js +0 -1
- package/dist/services/tasks.js +9 -1
- package/dist/services/verify.js +7 -2
- package/dist/sessions/session.js +0 -1
- package/dist/standards/acquisition/ingest.js +0 -1
- package/dist/standards/applicability/engine.js +0 -1
- package/dist/standards/builtin/code-quality.js +0 -1
- package/dist/standards/builtin/database-safety.js +0 -1
- package/dist/standards/builtin/index.js +0 -1
- package/dist/standards/builtin/security-baseline.js +0 -1
- package/dist/standards/builtin/testing-contracts.js +0 -1
- package/dist/standards/builtin/undo-kit.js +0 -1
- package/dist/standards/config/config.js +0 -1
- package/dist/standards/distribution/cache.d.ts +1 -0
- package/dist/standards/distribution/cache.js +199 -186
- package/dist/standards/distribution/index.js +0 -1
- package/dist/standards/distribution/keys.js +0 -1
- package/dist/standards/distribution/package.js +6 -1
- package/dist/standards/distribution/server.js +0 -1
- package/dist/standards/distribution/sync.d.ts +7 -2
- package/dist/standards/distribution/sync.js +41 -9
- package/dist/standards/distribution/types.js +0 -1
- package/dist/standards/engine/compliance.js +0 -1
- package/dist/standards/engine/engine.js +0 -1
- package/dist/standards/engine/reporter.js +0 -1
- package/dist/standards/index.js +0 -1
- package/dist/standards/registry/registry.js +0 -1
- package/dist/standards/schema/types.js +0 -1
- package/dist/standards/schema/validate.js +0 -1
- package/dist/standards/templates/index.js +0 -1
- package/dist/standards/validators/database.js +0 -1
- package/dist/standards/validators/quality.js +0 -1
- package/dist/standards/validators/registry.js +0 -1
- package/dist/standards/validators/security.js +0 -1
- package/dist/standards/validators/testing.js +0 -1
- package/dist/standards/validators/types.js +0 -1
- package/dist/standards/validators/undo-kit.js +0 -1
- package/dist/tasks/routing.js +0 -1
- package/dist/tasks/task.js +0 -1
- package/dist/utils/cleanup.js +0 -1
- package/dist/utils/fs.js +0 -1
- package/dist/utils/lock.js +92 -49
- package/dist/utils/logger.js +0 -1
- package/dist/utils/paths.js +0 -1
- package/dist/utils/proc.d.ts +12 -0
- package/dist/utils/proc.js +106 -44
- package/dist/verification/safety.js +0 -1
- package/dist/verification/scope.js +0 -1
- package/docs/agents.md +15 -0
- package/docs/architecture/global-standards-architecture.md +287 -0
- package/docs/archive/global-standards/GLOBAL_STANDARDS_AUDIT.md +99 -0
- package/docs/archive/global-standards/GLOBAL_STANDARDS_FINAL_STATUS.md +138 -0
- package/docs/archive/global-standards/GLOBAL_STANDARDS_IMPLEMENTATION_PLAN.md +100 -0
- package/docs/archive/global-standards/GLOBAL_STANDARDS_INDEPENDENT_AUDIT.md +219 -0
- package/docs/archive/global-standards/GLOBAL_STANDARDS_SECURITY_REPORT.md +184 -0
- package/docs/configuration.md +67 -0
- package/docs/contributing.md +15 -5
- package/docs/development/EXECUTION_STATE.md +50 -0
- package/docs/features.md +80 -0
- package/docs/getting-started.md +69 -111
- package/docs/guides/global-standards-migration.md +100 -0
- package/docs/integrations.md +7 -0
- package/docs/mcp.md +13 -0
- package/docs/security/THIRD_PARTY_LICENSES.md +41 -0
- package/docs/security.md +8 -2
- package/docs/testing/FINAL_CORRECTION_AND_CLEANUP_REPORT.md +92 -0
- package/docs/testing/global-standards-real-project-tests.md +218 -0
- package/docs/testing/global-standards-test-report.md +89 -0
- package/docs/testing/global-standards-verification-matrix.md +174 -0
- package/docs/troubleshooting.md +3 -0
- package/package.json +1 -1
- package/dist/agents/claude/adapter.js.map +0 -1
- package/dist/agents/claude/content.js.map +0 -1
- package/dist/agents/codex/adapter.js.map +0 -1
- package/dist/agents/copilot/adapter.js.map +0 -1
- package/dist/agents/cursor/adapter.js.map +0 -1
- package/dist/agents/index.js.map +0 -1
- package/dist/agents/shared.js.map +0 -1
- package/dist/agents/types.js.map +0 -1
- package/dist/cli/args.js.map +0 -1
- package/dist/cli/help.js.map +0 -1
- package/dist/cli/main.js.map +0 -1
- package/dist/cli/render.js.map +0 -1
- package/dist/cli/run.js.map +0 -1
- package/dist/config/schemas.js.map +0 -1
- package/dist/config/validate.js.map +0 -1
- package/dist/core/artifacts.js.map +0 -1
- package/dist/core/contracts.js.map +0 -1
- package/dist/core/migrations.js.map +0 -1
- package/dist/core/version.js.map +0 -1
- package/dist/core/versioned.js.map +0 -1
- package/dist/core/workspace.js.map +0 -1
- package/dist/decisions/decision.js.map +0 -1
- package/dist/discovery/cache.js.map +0 -1
- package/dist/discovery/commands.js.map +0 -1
- package/dist/discovery/detect.js.map +0 -1
- package/dist/discovery/docs.js.map +0 -1
- package/dist/discovery/entrypoints.js.map +0 -1
- package/dist/discovery/ignore.js.map +0 -1
- package/dist/discovery/scan.js.map +0 -1
- package/dist/discovery/types.js.map +0 -1
- package/dist/dx/dashboard.js.map +0 -1
- package/dist/dx/guidance.js.map +0 -1
- package/dist/dx/index.js.map +0 -1
- package/dist/dx/onboarding.js.map +0 -1
- package/dist/dx/types.js.map +0 -1
- package/dist/errors/index.js.map +0 -1
- package/dist/features/schema.js.map +0 -1
- package/dist/features/types.js.map +0 -1
- package/dist/features/validate.js.map +0 -1
- package/dist/git/git.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/integrations/adapters/agent-skills.js.map +0 -1
- package/dist/integrations/adapters/claudePlugin.js.map +0 -1
- package/dist/integrations/adapters/graphify.js.map +0 -1
- package/dist/integrations/adapters/omniroute.js.map +0 -1
- package/dist/integrations/adapters/pluginSkill.js.map +0 -1
- package/dist/integrations/adapters/ponytail.js.map +0 -1
- package/dist/integrations/exec.js.map +0 -1
- package/dist/integrations/index.js.map +0 -1
- package/dist/integrations/manager.js.map +0 -1
- package/dist/integrations/notices.js.map +0 -1
- package/dist/integrations/persistentPath.js.map +0 -1
- package/dist/integrations/protect.js.map +0 -1
- package/dist/integrations/state.js.map +0 -1
- package/dist/integrations/types.js.map +0 -1
- package/dist/intelligence/agents/profiles.js.map +0 -1
- package/dist/intelligence/agents/registry.js.map +0 -1
- package/dist/intelligence/agents/types.js.map +0 -1
- package/dist/intelligence/observability/tracer.js.map +0 -1
- package/dist/intelligence/observability/types.js.map +0 -1
- package/dist/intelligence/orchestration/engine.js.map +0 -1
- package/dist/intelligence/orchestration/lock-manager.js.map +0 -1
- package/dist/intelligence/orchestration/store.js.map +0 -1
- package/dist/intelligence/orchestration/types.js.map +0 -1
- package/dist/intelligence/routing/matcher.js.map +0 -1
- package/dist/intelligence/routing/router.js.map +0 -1
- package/dist/intelligence/routing/types.js.map +0 -1
- package/dist/intelligence/runtime/adk/adapter.js.map +0 -1
- package/dist/intelligence/runtime/adk/detector.js.map +0 -1
- package/dist/intelligence/runtime/external.js.map +0 -1
- package/dist/intelligence/runtime/native.js.map +0 -1
- package/dist/intelligence/runtime/types.js.map +0 -1
- package/dist/intelligence/security/audit.js.map +0 -1
- package/dist/intelligence/security/policy.js.map +0 -1
- package/dist/intelligence/security/types.js.map +0 -1
- package/dist/intelligence/skills/builtins.js.map +0 -1
- package/dist/intelligence/skills/loader.js.map +0 -1
- package/dist/intelligence/skills/registry.js.map +0 -1
- package/dist/intelligence/skills/types.js.map +0 -1
- package/dist/intelligence/verification/engine.js.map +0 -1
- package/dist/intelligence/verification/reviewer.js.map +0 -1
- package/dist/intelligence/verification/types.js.map +0 -1
- package/dist/knowledge/facts.js.map +0 -1
- package/dist/mcp/protocol.js.map +0 -1
- package/dist/mcp/server.js.map +0 -1
- package/dist/mcp/setup.js.map +0 -1
- package/dist/mcp/tools.js.map +0 -1
- package/dist/mcp/types.js.map +0 -1
- package/dist/mcp/verify.js.map +0 -1
- package/dist/portability/bundle.js.map +0 -1
- package/dist/prompts/onboarding.js.map +0 -1
- package/dist/prompts/refresh.js.map +0 -1
- package/dist/prompts/requirements.js.map +0 -1
- package/dist/security/files.js.map +0 -1
- package/dist/security/redact.js.map +0 -1
- package/dist/services/agent.js.map +0 -1
- package/dist/services/analysis.js.map +0 -1
- package/dist/services/common.js.map +0 -1
- package/dist/services/doctor.js.map +0 -1
- package/dist/services/drift.js.map +0 -1
- package/dist/services/features.js.map +0 -1
- package/dist/services/graph.js.map +0 -1
- package/dist/services/init.js.map +0 -1
- package/dist/services/integrations.js.map +0 -1
- package/dist/services/intelligence.js.map +0 -1
- package/dist/services/knowledge.js.map +0 -1
- package/dist/services/migrate.js.map +0 -1
- package/dist/services/portability.js.map +0 -1
- package/dist/services/records.js.map +0 -1
- package/dist/services/refresh.js.map +0 -1
- package/dist/services/reset.js.map +0 -1
- package/dist/services/setup.js.map +0 -1
- package/dist/services/standards.js.map +0 -1
- package/dist/services/status.js.map +0 -1
- package/dist/services/taskContext.js.map +0 -1
- package/dist/services/tasks.js.map +0 -1
- package/dist/services/verify.js.map +0 -1
- package/dist/sessions/session.js.map +0 -1
- package/dist/standards/acquisition/ingest.js.map +0 -1
- package/dist/standards/applicability/engine.js.map +0 -1
- package/dist/standards/builtin/code-quality.js.map +0 -1
- package/dist/standards/builtin/database-safety.js.map +0 -1
- package/dist/standards/builtin/index.js.map +0 -1
- package/dist/standards/builtin/security-baseline.js.map +0 -1
- package/dist/standards/builtin/testing-contracts.js.map +0 -1
- package/dist/standards/builtin/undo-kit.js.map +0 -1
- package/dist/standards/config/config.js.map +0 -1
- package/dist/standards/distribution/cache.js.map +0 -1
- package/dist/standards/distribution/index.js.map +0 -1
- package/dist/standards/distribution/keys.js.map +0 -1
- package/dist/standards/distribution/package.js.map +0 -1
- package/dist/standards/distribution/server.js.map +0 -1
- package/dist/standards/distribution/sync.js.map +0 -1
- package/dist/standards/distribution/types.js.map +0 -1
- package/dist/standards/engine/compliance.js.map +0 -1
- package/dist/standards/engine/engine.js.map +0 -1
- package/dist/standards/engine/reporter.js.map +0 -1
- package/dist/standards/index.js.map +0 -1
- package/dist/standards/registry/registry.js.map +0 -1
- package/dist/standards/schema/types.js.map +0 -1
- package/dist/standards/schema/validate.js.map +0 -1
- package/dist/standards/templates/index.js.map +0 -1
- package/dist/standards/validators/database.js.map +0 -1
- package/dist/standards/validators/quality.js.map +0 -1
- package/dist/standards/validators/registry.js.map +0 -1
- package/dist/standards/validators/security.js.map +0 -1
- package/dist/standards/validators/testing.js.map +0 -1
- package/dist/standards/validators/types.js.map +0 -1
- package/dist/standards/validators/undo-kit.js.map +0 -1
- package/dist/tasks/routing.js.map +0 -1
- package/dist/tasks/task.js.map +0 -1
- package/dist/utils/cleanup.js.map +0 -1
- package/dist/utils/fs.js.map +0 -1
- package/dist/utils/lock.js.map +0 -1
- package/dist/utils/logger.js.map +0 -1
- package/dist/utils/paths.js.map +0 -1
- package/dist/utils/proc.js.map +0 -1
- package/dist/verification/safety.js.map +0 -1
- package/dist/verification/scope.js.map +0 -1
|
@@ -1,16 +1,110 @@
|
|
|
1
|
+
import crypto from 'node:crypto';
|
|
2
|
+
import path from 'node:path';
|
|
1
3
|
import { StageLockManager } from './lock-manager.js';
|
|
2
4
|
import { NativeRuntimeAdapter } from '../runtime/native.js';
|
|
5
|
+
import { createExecutionId, evaluateApprovalGrants, evaluateStageScope, readRevokedGrantState, recordApprovalAuditEvent, revokeApprovalGrant, verifyGrantSecurity, withRevocationAuthLock, } from '../runtime/boundary.js';
|
|
6
|
+
import { captureWorkspaceSnapshotDetailed, detectGitRenames, diffWorkspaceSnapshots, hashWorkspaceSnapshot, } from '../runtime/changes.js';
|
|
3
7
|
import { isValidStateTransition } from './types.js';
|
|
4
8
|
import { DevWorkspaceError } from '../../errors/index.js';
|
|
5
9
|
import { redact } from '../../security/redact.js';
|
|
10
|
+
import { isSensitiveFile } from '../../security/files.js';
|
|
11
|
+
import { readTextBounded } from '../../utils/fs.js';
|
|
12
|
+
import { resolveInside } from '../../utils/paths.js';
|
|
13
|
+
import { run as runProc } from '../../utils/proc.js';
|
|
6
14
|
export class OrchestrationEngine {
|
|
7
15
|
router;
|
|
8
16
|
store;
|
|
9
17
|
lockManager;
|
|
10
|
-
|
|
18
|
+
authProvider;
|
|
19
|
+
constructor(router, store, authProvider) {
|
|
11
20
|
this.router = router;
|
|
12
21
|
this.store = store;
|
|
13
22
|
this.lockManager = new StageLockManager();
|
|
23
|
+
this.authProvider = authProvider;
|
|
24
|
+
}
|
|
25
|
+
/** Compute a workspace SHA-256 fingerprint across git HEAD and all non-ignored workspace files, plus completeness metadata. */
|
|
26
|
+
async computeWorkspaceFingerprintDetailed(workspaceRoot, filePaths) {
|
|
27
|
+
const hash = crypto.createHash('sha256');
|
|
28
|
+
if (workspaceRoot) {
|
|
29
|
+
try {
|
|
30
|
+
const gitRes = await runProc('git', ['rev-parse', 'HEAD'], { cwd: workspaceRoot, timeoutMs: 2_000 });
|
|
31
|
+
hash.update(`head:${gitRes.ok ? gitRes.stdout.trim() : 'nogit'}\n`);
|
|
32
|
+
}
|
|
33
|
+
catch {
|
|
34
|
+
hash.update('head:nogit\n');
|
|
35
|
+
}
|
|
36
|
+
const snapshot = await captureWorkspaceSnapshotDetailed(workspaceRoot);
|
|
37
|
+
hash.update(`snapshot:${hashWorkspaceSnapshot(snapshot)}\n`);
|
|
38
|
+
return {
|
|
39
|
+
fingerprint: hash.digest('hex'),
|
|
40
|
+
complete: snapshot.complete,
|
|
41
|
+
incompleteReasons: snapshot.incompleteReasons,
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
hash.update(`files:${[...filePaths].sort().join(',')}`);
|
|
45
|
+
return {
|
|
46
|
+
fingerprint: hash.digest('hex'),
|
|
47
|
+
complete: false,
|
|
48
|
+
incompleteReasons: ['Workspace root not supplied for fingerprint computation.'],
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
/** Compute a workspace SHA-256 fingerprint across git HEAD and all non-ignored workspace files. */
|
|
52
|
+
async computeWorkspaceFingerprint(workspaceRoot, filePaths) {
|
|
53
|
+
const res = await this.computeWorkspaceFingerprintDetailed(workspaceRoot, filePaths);
|
|
54
|
+
return res.fingerprint;
|
|
55
|
+
}
|
|
56
|
+
/** Safely load bounded contents of modified files for independent verification without leaking secrets. */
|
|
57
|
+
async loadModifiedFileContents(workspaceRoot, filePaths) {
|
|
58
|
+
const out = [];
|
|
59
|
+
for (const rel of filePaths) {
|
|
60
|
+
if (!workspaceRoot || isSensitiveFile(rel)) {
|
|
61
|
+
out.push({ path: rel, content: '' });
|
|
62
|
+
continue;
|
|
63
|
+
}
|
|
64
|
+
try {
|
|
65
|
+
const full = resolveInside(workspaceRoot, rel);
|
|
66
|
+
const content = await readTextBounded(full, 256 * 1024);
|
|
67
|
+
out.push({ path: rel, content: content ?? '' });
|
|
68
|
+
}
|
|
69
|
+
catch {
|
|
70
|
+
out.push({ path: rel, content: '' });
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
return out;
|
|
74
|
+
}
|
|
75
|
+
/** Reject and invalidate any stage verification receipt whose workspace files changed since verification. */
|
|
76
|
+
async invalidateStaleReceipts(runId, workspaceRoot) {
|
|
77
|
+
const loaded = await this.store.getRun(runId);
|
|
78
|
+
if (!loaded) {
|
|
79
|
+
throw new DevWorkspaceError('NOT_FOUND', `Orchestration run "${runId}" not found.`);
|
|
80
|
+
}
|
|
81
|
+
const invalidatedStages = [];
|
|
82
|
+
for (const stage of loaded.stages) {
|
|
83
|
+
if (!stage.receipt || !stage.receipt.verified)
|
|
84
|
+
continue;
|
|
85
|
+
const root = workspaceRoot ?? stage.receipt.cwd;
|
|
86
|
+
const fpRes = await this.computeWorkspaceFingerprintDetailed(root, stage.receipt.filesModified);
|
|
87
|
+
if (!fpRes.complete || (stage.receipt.workspaceFingerprint && fpRes.fingerprint !== stage.receipt.workspaceFingerprint)) {
|
|
88
|
+
stage.receipt.verified = false;
|
|
89
|
+
stage.receipt.stale = true;
|
|
90
|
+
stage.receipt.verificationStatus = fpRes.complete ? 'NOT_TESTED' : 'BLOCKED';
|
|
91
|
+
stage.status = 'VERIFYING';
|
|
92
|
+
stage.outputs = { ...(stage.outputs ?? {}), verified: false, stale: true, receipt: stage.receipt };
|
|
93
|
+
invalidatedStages.push(stage.id);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
if (invalidatedStages.length > 0) {
|
|
97
|
+
if (loaded.state === 'COMPLETED' || loaded.state === 'SUCCEEDED') {
|
|
98
|
+
loaded.state = 'VERIFYING';
|
|
99
|
+
}
|
|
100
|
+
loaded.checkpoints.push({
|
|
101
|
+
at: new Date().toISOString(),
|
|
102
|
+
state: loaded.state,
|
|
103
|
+
note: `Invalidated stale verification receipt(s) due to workspace changes: ${invalidatedStages.join(', ')}.`,
|
|
104
|
+
});
|
|
105
|
+
await this.store.saveRun(loaded);
|
|
106
|
+
}
|
|
107
|
+
return { run: loaded, invalidatedStages };
|
|
14
108
|
}
|
|
15
109
|
/**
|
|
16
110
|
* Detects potentially destructive operations in stage inputs or prompt.
|
|
@@ -165,17 +259,98 @@ export class OrchestrationEngine {
|
|
|
165
259
|
await this.store.saveRun(run);
|
|
166
260
|
return run;
|
|
167
261
|
}
|
|
168
|
-
async approve(runId,
|
|
262
|
+
async approve(runId, options) {
|
|
169
263
|
const run = await this.store.getRun(runId);
|
|
170
264
|
if (!run) {
|
|
171
265
|
throw new DevWorkspaceError('NOT_FOUND', `Orchestration run "${runId}" not found.`);
|
|
172
266
|
}
|
|
173
|
-
|
|
267
|
+
const provider = options?.authProvider ?? this.authProvider;
|
|
268
|
+
if (!provider) {
|
|
269
|
+
throw new DevWorkspaceError('SECURITY', 'ApprovalAuthProvider is required to authenticate approval (fail-closed).');
|
|
270
|
+
}
|
|
271
|
+
const session = await provider.authenticate(options?.credentials);
|
|
272
|
+
const grants = options?.grants ?? [];
|
|
273
|
+
const workspaceRoot = options?.workspaceRoot;
|
|
274
|
+
if (run.state !== 'AWAITING_APPROVAL' && run.state !== 'WAITING_APPROVAL' && grants.length === 0) {
|
|
174
275
|
throw new DevWorkspaceError('USAGE', `Run "${runId}" is in state "${run.state}", not AWAITING_APPROVAL.`);
|
|
175
276
|
}
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
277
|
+
if (grants.length > 0) {
|
|
278
|
+
for (const g of grants) {
|
|
279
|
+
if (!g.approverIdentity ||
|
|
280
|
+
g.approverIdentity.principalId !== session.principalId ||
|
|
281
|
+
g.approverIdentity.sessionId !== session.sessionId ||
|
|
282
|
+
g.approverIdentity.authMethod !== session.authMethod) {
|
|
283
|
+
throw new DevWorkspaceError('SECURITY', `Grant "${g.grantId}" identity/session does not match authenticated session "${session.principalId}" (${session.sessionId}).`);
|
|
284
|
+
}
|
|
285
|
+
await withRevocationAuthLock(workspaceRoot ?? g.workspaceRoot, async () => {
|
|
286
|
+
const revState = await readRevokedGrantState(workspaceRoot ?? g.workspaceRoot);
|
|
287
|
+
if (!revState.trustworthy) {
|
|
288
|
+
throw new DevWorkspaceError('IO', `Cannot verify revocation state before attaching grant "${g.grantId}": ${revState.reason}`);
|
|
289
|
+
}
|
|
290
|
+
const secCheck = await verifyGrantSecurity(g, {
|
|
291
|
+
authProvider: provider,
|
|
292
|
+
revokedGrantIds: revState.revokedIds,
|
|
293
|
+
});
|
|
294
|
+
if (!secCheck.ok) {
|
|
295
|
+
throw new DevWorkspaceError('SECURITY', `Grant "${g.grantId}" failed verification: ${secCheck.reason}`);
|
|
296
|
+
}
|
|
297
|
+
await recordApprovalAuditEvent(workspaceRoot ?? g.workspaceRoot, {
|
|
298
|
+
timestamp: new Date().toISOString(),
|
|
299
|
+
agentId: session.principalId,
|
|
300
|
+
scope: 'terminal:exec',
|
|
301
|
+
target: `${g.executable} ${g.args.join(' ')}`.trim(),
|
|
302
|
+
allowed: true,
|
|
303
|
+
requiresApproval: true,
|
|
304
|
+
eventType: 'grant-issued',
|
|
305
|
+
grantId: g.grantId,
|
|
306
|
+
approvedBy: session.principalId,
|
|
307
|
+
principalId: session.principalId,
|
|
308
|
+
sessionId: session.sessionId,
|
|
309
|
+
authMethod: session.authMethod,
|
|
310
|
+
stageId: g.stageId,
|
|
311
|
+
operation: g.operation,
|
|
312
|
+
});
|
|
313
|
+
});
|
|
314
|
+
}
|
|
315
|
+
run.approvalGrants = [...(run.approvalGrants ?? []), ...grants];
|
|
316
|
+
}
|
|
317
|
+
run.approvedBy = session.principalId;
|
|
318
|
+
run.approvedAt = session.authenticatedAt;
|
|
319
|
+
run.approvedSessionId = session.sessionId;
|
|
320
|
+
run.approvedAuthMethod = session.authMethod;
|
|
321
|
+
run.approvedAuthProviderId = provider.id;
|
|
322
|
+
if (run.state === 'AWAITING_APPROVAL' || run.state === 'WAITING_APPROVAL') {
|
|
323
|
+
this.transitionState(run, 'READY', grants.length > 0
|
|
324
|
+
? `Plan approved by ${session.principalId} (session ${session.sessionId}) with ${grants.length} signed approval grant(s). Ready for execution.`
|
|
325
|
+
: `Plan approved by ${session.principalId} (session ${session.sessionId}; no scoped command/destructive grants attached).`);
|
|
326
|
+
}
|
|
327
|
+
else {
|
|
328
|
+
run.updatedAt = new Date().toISOString();
|
|
329
|
+
run.checkpoints.push({
|
|
330
|
+
at: run.updatedAt,
|
|
331
|
+
state: run.state,
|
|
332
|
+
note: `Attached ${grants.length} signed approval grant(s) from ${session.principalId} (session ${session.sessionId}).`,
|
|
333
|
+
});
|
|
334
|
+
}
|
|
335
|
+
await this.store.saveRun(run);
|
|
336
|
+
return run;
|
|
337
|
+
}
|
|
338
|
+
async revokeApproval(runId, grantId, revokedBy, reason = 'Revoked by operator', workspaceRoot) {
|
|
339
|
+
const run = await this.store.getRun(runId);
|
|
340
|
+
if (!run) {
|
|
341
|
+
throw new DevWorkspaceError('NOT_FOUND', `Orchestration run "${runId}" not found.`);
|
|
342
|
+
}
|
|
343
|
+
const target = run.approvalGrants?.find((g) => g.grantId === grantId);
|
|
344
|
+
if (!target) {
|
|
345
|
+
throw new DevWorkspaceError('NOT_FOUND', `Approval grant "${grantId}" not found on run "${runId}".`);
|
|
346
|
+
}
|
|
347
|
+
await revokeApprovalGrant(target, revokedBy, reason, workspaceRoot ?? target.workspaceRoot);
|
|
348
|
+
run.updatedAt = new Date().toISOString();
|
|
349
|
+
run.checkpoints.push({
|
|
350
|
+
at: run.updatedAt,
|
|
351
|
+
state: run.state,
|
|
352
|
+
note: `Approval grant "${grantId}" revoked by ${revokedBy}: ${reason}`,
|
|
353
|
+
});
|
|
179
354
|
await this.store.saveRun(run);
|
|
180
355
|
return run;
|
|
181
356
|
}
|
|
@@ -219,15 +394,40 @@ export class OrchestrationEngine {
|
|
|
219
394
|
if (run.state === 'CANCELLED' || run.state === 'TIMED_OUT') {
|
|
220
395
|
throw new DevWorkspaceError('USAGE', `Cannot run "${run.runId}" in terminal state "${run.state}".`);
|
|
221
396
|
}
|
|
222
|
-
|
|
397
|
+
const allGrants = [...(run.approvalGrants ?? []), ...(options.approvalGrants ?? [])];
|
|
398
|
+
const activeAuthProvider = options.authProvider ?? this.authProvider;
|
|
399
|
+
// Approval gating: require cryptographically verified scoped approval grants; fail closed if authentication is unavailable
|
|
223
400
|
if (run.state === 'AWAITING_APPROVAL' || run.state === 'WAITING_APPROVAL') {
|
|
224
|
-
if (options.
|
|
225
|
-
|
|
401
|
+
if (options.approvalGrants && options.approvalGrants.length > 0) {
|
|
402
|
+
if (!activeAuthProvider) {
|
|
403
|
+
throw new DevWorkspaceError('SECURITY', 'ApprovalAuthProvider is required to verify supplied approval grants (fail-closed).');
|
|
404
|
+
}
|
|
405
|
+
for (const g of options.approvalGrants) {
|
|
406
|
+
await withRevocationAuthLock(options.workspaceRoot ?? g.workspaceRoot, async () => {
|
|
407
|
+
const revState = await readRevokedGrantState(options.workspaceRoot ?? g.workspaceRoot);
|
|
408
|
+
if (!revState.trustworthy) {
|
|
409
|
+
throw new DevWorkspaceError('IO', `Cannot verify revocation state: ${revState.reason}`);
|
|
410
|
+
}
|
|
411
|
+
const secCheck = await verifyGrantSecurity(g, {
|
|
412
|
+
authProvider: activeAuthProvider,
|
|
413
|
+
revokedGrantIds: revState.revokedIds,
|
|
414
|
+
});
|
|
415
|
+
if (!secCheck.ok) {
|
|
416
|
+
throw new DevWorkspaceError('SECURITY', `Grant "${g.grantId}" rejected: ${secCheck.reason}`);
|
|
417
|
+
}
|
|
418
|
+
});
|
|
419
|
+
}
|
|
420
|
+
const leadGrant = options.approvalGrants[0];
|
|
421
|
+
run.approvedBy = run.approvedBy ?? leadGrant.approvedBy;
|
|
226
422
|
run.approvedAt = new Date().toISOString();
|
|
227
|
-
|
|
423
|
+
run.approvedSessionId = run.approvedSessionId ?? leadGrant.approverIdentity.sessionId;
|
|
424
|
+
run.approvedAuthMethod = run.approvedAuthMethod ?? leadGrant.approverIdentity.authMethod;
|
|
425
|
+
run.approvedAuthProviderId = run.approvedAuthProviderId ?? activeAuthProvider.id;
|
|
426
|
+
run.approvalGrants = allGrants;
|
|
427
|
+
this.transitionState(run, 'READY', `Execution unlocked with ${options.approvalGrants.length} verified signed approval grant(s).`);
|
|
228
428
|
}
|
|
229
429
|
else {
|
|
230
|
-
throw new DevWorkspaceError('USAGE', `Run "${run.runId}" requires developer approval before execution.`);
|
|
430
|
+
throw new DevWorkspaceError('USAGE', `Run "${run.runId}" requires scoped developer approval before execution (authenticated via ApprovalAuthProvider).`);
|
|
231
431
|
}
|
|
232
432
|
}
|
|
233
433
|
if (run.state !== 'READY' && run.state !== 'PAUSED' && run.state !== 'BLOCKED') {
|
|
@@ -263,12 +463,123 @@ export class OrchestrationEngine {
|
|
|
263
463
|
await this.store.saveRun(run);
|
|
264
464
|
return run;
|
|
265
465
|
}
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
466
|
+
const stageExternalCfg = stage.inputs.externalExecution ?? options.externalExecution;
|
|
467
|
+
const stageCommand = stage.inputs.command ?? stageExternalCfg?.command;
|
|
468
|
+
const rootForStage = options.workspaceRoot ?? stageExternalCfg?.sandboxPath;
|
|
469
|
+
// Destructive operations safety gate: serialized against concurrent revocations via shared revocation-auth lock
|
|
470
|
+
if (stage.isDestructive) {
|
|
471
|
+
const gateResult = await withRevocationAuthLock(rootForStage, async () => {
|
|
472
|
+
const revState = await readRevokedGrantState(rootForStage);
|
|
473
|
+
if (!revState.trustworthy) {
|
|
474
|
+
if (rootForStage) {
|
|
475
|
+
try {
|
|
476
|
+
await recordApprovalAuditEvent(rootForStage, {
|
|
477
|
+
timestamp: new Date().toISOString(),
|
|
478
|
+
agentId: stage.agentId,
|
|
479
|
+
scope: 'terminal:exec',
|
|
480
|
+
target: stageCommand?.join(' ') ?? stage.name,
|
|
481
|
+
allowed: false,
|
|
482
|
+
requiresApproval: true,
|
|
483
|
+
eventType: 'grant-rejected',
|
|
484
|
+
stageId: stage.id,
|
|
485
|
+
operation: 'destructive-op',
|
|
486
|
+
reason: revState.reason,
|
|
487
|
+
});
|
|
488
|
+
}
|
|
489
|
+
catch {
|
|
490
|
+
// Already blocking execution due to untrustworthy revocation store
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
return {
|
|
494
|
+
allowed: false,
|
|
495
|
+
nextState: 'BLOCKED',
|
|
496
|
+
reason: revState.reason ?? 'Untrustworthy revocation store.',
|
|
497
|
+
untrustedRevocation: true,
|
|
498
|
+
};
|
|
499
|
+
}
|
|
500
|
+
const revokedIds = revState.revokedIds;
|
|
501
|
+
const normalizedRoot = rootForStage ? path.resolve(rootForStage).replace(/[\\/]+$/, '') : undefined;
|
|
502
|
+
let hasDestructiveGrant = false;
|
|
503
|
+
let destructiveRejectionReason = 'Missing, expired, or revoked destructive-op ApprovalGrant.';
|
|
504
|
+
if (!activeAuthProvider) {
|
|
505
|
+
destructiveRejectionReason = 'Approval authentication provider is unavailable; destructive execution fails closed.';
|
|
506
|
+
}
|
|
507
|
+
else if (stageCommand && stageCommand.length > 0 && rootForStage) {
|
|
508
|
+
const evalRes = await evaluateApprovalGrants(allGrants, ['destructive-op'], stageCommand, rootForStage, {
|
|
509
|
+
stageId: stage.id,
|
|
510
|
+
revokedGrantIds: revokedIds,
|
|
511
|
+
authProvider: activeAuthProvider,
|
|
512
|
+
allowStageIndependent: options.allowStageIndependent,
|
|
513
|
+
});
|
|
514
|
+
hasDestructiveGrant = evalRes.matched;
|
|
515
|
+
if (!evalRes.matched && evalRes.reason)
|
|
516
|
+
destructiveRejectionReason = evalRes.reason;
|
|
517
|
+
}
|
|
518
|
+
else {
|
|
519
|
+
for (const g of allGrants) {
|
|
520
|
+
if (g.operation !== 'destructive-op')
|
|
521
|
+
continue;
|
|
522
|
+
if (normalizedRoot) {
|
|
523
|
+
const gRoot = path.resolve(g.workspaceRoot).replace(/[\\/]+$/, '');
|
|
524
|
+
const rootMatch = process.platform === 'win32'
|
|
525
|
+
? gRoot.toLowerCase() === normalizedRoot.toLowerCase()
|
|
526
|
+
: gRoot === normalizedRoot;
|
|
527
|
+
if (!rootMatch)
|
|
528
|
+
continue;
|
|
529
|
+
}
|
|
530
|
+
const stageCheck = evaluateStageScope(g, stage.id, Boolean(options.allowStageIndependent));
|
|
531
|
+
if (!stageCheck.ok) {
|
|
532
|
+
destructiveRejectionReason = stageCheck.reason;
|
|
533
|
+
continue;
|
|
534
|
+
}
|
|
535
|
+
const secCheck = await verifyGrantSecurity(g, {
|
|
536
|
+
authProvider: activeAuthProvider,
|
|
537
|
+
revokedGrantIds: revokedIds,
|
|
538
|
+
});
|
|
539
|
+
if (!secCheck.ok) {
|
|
540
|
+
destructiveRejectionReason = secCheck.reason;
|
|
541
|
+
continue;
|
|
542
|
+
}
|
|
543
|
+
hasDestructiveGrant = true;
|
|
544
|
+
break;
|
|
545
|
+
}
|
|
546
|
+
}
|
|
547
|
+
if (!hasDestructiveGrant) {
|
|
548
|
+
if (rootForStage) {
|
|
549
|
+
await recordApprovalAuditEvent(rootForStage, {
|
|
550
|
+
timestamp: new Date().toISOString(),
|
|
551
|
+
agentId: stage.agentId,
|
|
552
|
+
scope: 'terminal:exec',
|
|
553
|
+
target: stageCommand?.join(' ') ?? stage.name,
|
|
554
|
+
allowed: false,
|
|
555
|
+
requiresApproval: true,
|
|
556
|
+
eventType: 'grant-rejected',
|
|
557
|
+
stageId: stage.id,
|
|
558
|
+
operation: 'destructive-op',
|
|
559
|
+
reason: destructiveRejectionReason,
|
|
560
|
+
});
|
|
561
|
+
}
|
|
562
|
+
const nextState = !activeAuthProvider && allGrants.length > 0 ? 'BLOCKED' : 'WAITING_APPROVAL';
|
|
563
|
+
return {
|
|
564
|
+
allowed: false,
|
|
565
|
+
nextState,
|
|
566
|
+
reason: destructiveRejectionReason,
|
|
567
|
+
untrustedRevocation: false,
|
|
568
|
+
};
|
|
569
|
+
}
|
|
570
|
+
return { allowed: true };
|
|
571
|
+
});
|
|
572
|
+
if (!gateResult.allowed) {
|
|
573
|
+
stage.status = gateResult.nextState;
|
|
574
|
+
if (gateResult.nextState === 'BLOCKED') {
|
|
575
|
+
stage.error = gateResult.reason;
|
|
576
|
+
run.error = gateResult.reason;
|
|
577
|
+
}
|
|
578
|
+
const prefix = gateResult.untrustedRevocation ? 'Execution blocked' : 'Execution halted';
|
|
579
|
+
this.transitionState(run, gateResult.nextState, `${prefix}: ${gateResult.reason}`, stage.id);
|
|
580
|
+
await this.store.saveRun(run);
|
|
581
|
+
return run;
|
|
582
|
+
}
|
|
272
583
|
}
|
|
273
584
|
// Single-writer lock acquisition for claimed files
|
|
274
585
|
if (stage.claimedFiles.length > 0) {
|
|
@@ -287,53 +598,168 @@ export class OrchestrationEngine {
|
|
|
287
598
|
let stageSuccess = false;
|
|
288
599
|
let lastError;
|
|
289
600
|
let receipt;
|
|
601
|
+
let haltState = null;
|
|
290
602
|
while (!stageSuccess && stage.retryCount <= run.maxRetries) {
|
|
291
603
|
try {
|
|
604
|
+
const preExecSnapshot = rootForStage ? await captureWorkspaceSnapshotDetailed(rootForStage) : null;
|
|
292
605
|
const execRes = await adapter.execute({
|
|
293
606
|
agentId: stage.agentId,
|
|
294
607
|
role: stage.name,
|
|
295
608
|
prompt: run.request,
|
|
296
609
|
skills: stage.skillIds,
|
|
297
610
|
contextFiles: stage.claimedFiles,
|
|
611
|
+
stageId: stage.id,
|
|
298
612
|
timeoutMs: timeoutMs > 0 ? Math.max(1000, timeoutMs - (Date.now() - startTs)) : undefined,
|
|
299
613
|
signal: options.signal,
|
|
300
|
-
command:
|
|
301
|
-
cwd:
|
|
614
|
+
command: stageCommand,
|
|
615
|
+
cwd: rootForStage,
|
|
616
|
+
workspaceRoot: rootForStage,
|
|
617
|
+
approvalGrants: allGrants,
|
|
618
|
+
authProvider: activeAuthProvider,
|
|
619
|
+
allowStageIndependent: options.allowStageIndependent,
|
|
620
|
+
allowExternalExecution: stageExternalCfg?.allowed,
|
|
621
|
+
sandboxPath: stageExternalCfg?.sandboxPath ?? rootForStage,
|
|
622
|
+
allowlistedEnvKeys: stageExternalCfg?.allowlistedEnvKeys,
|
|
302
623
|
});
|
|
303
|
-
|
|
304
|
-
|
|
624
|
+
const postExecSnapshot = rootForStage ? await captureWorkspaceSnapshotDetailed(rootForStage) : null;
|
|
625
|
+
let changeManifest;
|
|
626
|
+
if (preExecSnapshot && postExecSnapshot && rootForStage) {
|
|
627
|
+
const gitRenames = await detectGitRenames(rootForStage);
|
|
628
|
+
changeManifest = diffWorkspaceSnapshots(preExecSnapshot, postExecSnapshot, gitRenames);
|
|
305
629
|
}
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
}
|
|
630
|
+
else {
|
|
631
|
+
changeManifest = execRes.changeManifest ?? {
|
|
632
|
+
created: [],
|
|
633
|
+
modified: [],
|
|
634
|
+
deleted: [],
|
|
635
|
+
renamed: [],
|
|
636
|
+
changedFiles: [],
|
|
637
|
+
snapshotComplete: false,
|
|
638
|
+
snapshotIncompleteReasons: ['No workspace root was supplied for execution change capture.'],
|
|
639
|
+
};
|
|
316
640
|
}
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
641
|
+
const execId = execRes.executionId ?? createExecutionId('exec');
|
|
642
|
+
const execStatus = execRes.status ?? (execRes.ok ? 'SUCCEEDED' : 'FAILED');
|
|
643
|
+
const execFiles = changeManifest.changedFiles;
|
|
644
|
+
const inspectableFiles = [...new Set([
|
|
645
|
+
...changeManifest.created,
|
|
646
|
+
...changeManifest.modified,
|
|
647
|
+
...changeManifest.renamed.map((r) => r.to),
|
|
648
|
+
])];
|
|
649
|
+
stage.modifiedFiles = execFiles;
|
|
650
|
+
stage.changeManifest = changeManifest;
|
|
651
|
+
const baseReceipt = (verified, verificationStatus, fp, report) => ({
|
|
652
|
+
executionId: execId,
|
|
653
|
+
stageId: stage.id,
|
|
654
|
+
executionStatus: execStatus,
|
|
655
|
+
verificationStatus,
|
|
656
|
+
verifierId: report?.verifierId,
|
|
657
|
+
verifierVersion: report?.verifierVersion,
|
|
658
|
+
workspaceFingerprint: fp,
|
|
659
|
+
verifiedAt: report?.verifiedAt,
|
|
660
|
+
checksPerformed: report?.checksPerformed ?? [],
|
|
661
|
+
evidenceRefs: report?.evidenceRefs ?? execFiles,
|
|
662
|
+
command: execRes.command ?? stageCommand,
|
|
663
|
+
cwd: execRes.cwd ?? rootForStage,
|
|
664
|
+
exitCode: execRes.exitCode,
|
|
322
665
|
durationMs: execRes.durationMs,
|
|
323
666
|
stdout: execRes.stdout,
|
|
324
667
|
stderr: execRes.stderr,
|
|
325
668
|
timedOut: execRes.timedOut,
|
|
326
669
|
aborted: execRes.aborted,
|
|
327
|
-
filesModified:
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
670
|
+
filesModified: execFiles,
|
|
671
|
+
changeManifest,
|
|
672
|
+
executedAt: execRes.endedAt ?? new Date().toISOString(),
|
|
673
|
+
verified,
|
|
674
|
+
verificationReport: report,
|
|
675
|
+
});
|
|
676
|
+
if (execRes.isPlaceholder) {
|
|
677
|
+
throw new Error(execRes.error || 'Placeholder runtime cannot execute stages.');
|
|
678
|
+
}
|
|
679
|
+
if (execStatus === 'TIMED_OUT' || execRes.timedOut || (timeoutMs > 0 && Date.now() - startTs > timeoutMs)) {
|
|
680
|
+
stage.receipt = baseReceipt(false, 'NOT_TESTED');
|
|
681
|
+
lastError = execRes.error || `Stage execution timed out${timeoutMs > 0 ? ` after ${timeoutMs}ms` : ''}.`;
|
|
682
|
+
haltState = 'TIMED_OUT';
|
|
683
|
+
break;
|
|
684
|
+
}
|
|
685
|
+
if (execStatus === 'CANCELLED' || execRes.aborted) {
|
|
686
|
+
stage.receipt = baseReceipt(false, 'NOT_TESTED');
|
|
687
|
+
lastError = execRes.error || 'Stage execution cancelled.';
|
|
688
|
+
haltState = 'CANCELLED';
|
|
689
|
+
break;
|
|
690
|
+
}
|
|
691
|
+
if (execStatus === 'PREPARED' || execStatus === 'NOT_EXECUTED' || execStatus === 'UNSUPPORTED' || execStatus === 'BLOCKED') {
|
|
692
|
+
stage.receipt = baseReceipt(false, 'NOT_TESTED');
|
|
693
|
+
lastError = execRes.reason || execRes.error || `Stage did not execute (${execStatus}).`;
|
|
694
|
+
haltState = 'BLOCKED';
|
|
695
|
+
break;
|
|
696
|
+
}
|
|
697
|
+
if (execStatus !== 'SUCCEEDED' || !execRes.ok) {
|
|
698
|
+
throw new Error(execRes.error || 'Stage execution failed in runtime adapter.');
|
|
699
|
+
}
|
|
700
|
+
// Fail closed if workspace snapshot inspection was incomplete (truncation, unreadable dirs/files)
|
|
701
|
+
const rootForVerify = rootForStage ?? execRes.cwd;
|
|
702
|
+
const fpResult = await this.computeWorkspaceFingerprintDetailed(rootForVerify, execFiles);
|
|
703
|
+
const preVerifyFingerprint = fpResult.fingerprint;
|
|
704
|
+
const snapshotComplete = changeManifest.snapshotComplete && fpResult.complete;
|
|
705
|
+
const incompleteReasons = [...new Set([
|
|
706
|
+
...changeManifest.snapshotIncompleteReasons,
|
|
707
|
+
...fpResult.incompleteReasons,
|
|
708
|
+
])];
|
|
709
|
+
if (!snapshotComplete) {
|
|
710
|
+
const incompleteReceipt = baseReceipt(false, 'BLOCKED', preVerifyFingerprint);
|
|
711
|
+
stage.receipt = incompleteReceipt;
|
|
712
|
+
stage.outputs = { outcome: 'blocked', verified: false, snapshotComplete: false, incompleteReasons, receipt: incompleteReceipt };
|
|
713
|
+
lastError = `Workspace snapshot incomplete; cannot verify completion: ${incompleteReasons.join('; ')}`;
|
|
714
|
+
haltState = 'BLOCKED';
|
|
715
|
+
break;
|
|
716
|
+
}
|
|
717
|
+
if (!options.verificationEngine) {
|
|
718
|
+
const unverifiedReceipt = baseReceipt(false, 'NOT_TESTED', preVerifyFingerprint);
|
|
719
|
+
stage.receipt = unverifiedReceipt;
|
|
720
|
+
stage.outputs = { outcome: 'unverified', verified: false, receipt: unverifiedReceipt };
|
|
721
|
+
lastError = 'Independent verification engine is required before verified completion; execution finished unverified.';
|
|
722
|
+
haltState = 'BLOCKED';
|
|
723
|
+
break;
|
|
724
|
+
}
|
|
725
|
+
this.transitionState(run, 'VERIFYING', `Running independent verification for stage "${stage.name}".`, stage.id);
|
|
726
|
+
const checks = stage.inputs.contractChecks ?? [];
|
|
727
|
+
const acceptanceCriteria = stage.inputs.acceptanceCriteria ?? [];
|
|
728
|
+
const criteriaMappings = stage.inputs.criteriaEvidenceMap ?? [];
|
|
729
|
+
const modified = await this.loadModifiedFileContents(rootForVerify, inspectableFiles);
|
|
730
|
+
const verificationReport = await options.verificationEngine.verify(checks, modified, acceptanceCriteria, stage.retryCount, run.maxRetries, {
|
|
731
|
+
executionId: execId,
|
|
732
|
+
stageId: stage.id,
|
|
733
|
+
workspaceFingerprint: preVerifyFingerprint,
|
|
734
|
+
evidenceRefs: execFiles,
|
|
735
|
+
changeManifest,
|
|
736
|
+
criteriaMappings,
|
|
737
|
+
snapshotComplete,
|
|
738
|
+
snapshotIncompleteReasons: incompleteReasons,
|
|
739
|
+
});
|
|
740
|
+
if (verificationReport.executionId && verificationReport.executionId !== execId) {
|
|
741
|
+
throw new Error(`Stale verification receipt rejected: bound to "${verificationReport.executionId}", expected "${execId}".`);
|
|
742
|
+
}
|
|
743
|
+
if (verificationReport.workspaceFingerprint && verificationReport.workspaceFingerprint !== preVerifyFingerprint) {
|
|
744
|
+
throw new Error('Stale verification receipt rejected: workspace fingerprint mismatch.');
|
|
745
|
+
}
|
|
746
|
+
const postFpResult = await this.computeWorkspaceFingerprintDetailed(rootForVerify, execFiles);
|
|
747
|
+
if (!postFpResult.complete) {
|
|
748
|
+
throw new Error(`Verification invalidated: post-verify snapshot incomplete (${postFpResult.incompleteReasons.join('; ')}).`);
|
|
749
|
+
}
|
|
750
|
+
if (postFpResult.fingerprint !== preVerifyFingerprint) {
|
|
751
|
+
throw new Error('Verification invalidated: workspace files changed during verification.');
|
|
752
|
+
}
|
|
753
|
+
if (!verificationReport.canComplete || !verificationReport.mandatoryGatesPassed || verificationReport.verificationStatus !== 'PASS') {
|
|
754
|
+
throw new Error(`Verification failed (${verificationReport.verificationStatus}): ${verificationReport.summary}`);
|
|
755
|
+
}
|
|
756
|
+
receipt = baseReceipt(true, 'PASS', preVerifyFingerprint, verificationReport);
|
|
332
757
|
stage.status = 'COMPLETED';
|
|
333
758
|
stage.completedAt = new Date().toISOString();
|
|
334
759
|
stage.outputs = { outcome: 'success', verified: true, receipt };
|
|
335
760
|
stage.receipt = receipt;
|
|
336
761
|
run.metrics.stagesCompleted += 1;
|
|
762
|
+
run.metrics.filesModifiedCount = new Set(run.stages.flatMap((s) => s.modifiedFiles)).size;
|
|
337
763
|
stageSuccess = true;
|
|
338
764
|
}
|
|
339
765
|
catch (err) {
|
|
@@ -350,6 +776,14 @@ export class OrchestrationEngine {
|
|
|
350
776
|
}
|
|
351
777
|
}
|
|
352
778
|
this.lockManager.releaseAllForStage(stage.id);
|
|
779
|
+
if (haltState) {
|
|
780
|
+
stage.status = haltState;
|
|
781
|
+
stage.error = redact(lastError ?? `Execution halted (${haltState}).`);
|
|
782
|
+
run.error = stage.error;
|
|
783
|
+
this.transitionState(run, haltState, stage.error, stage.id);
|
|
784
|
+
await this.store.saveRun(run);
|
|
785
|
+
return run;
|
|
786
|
+
}
|
|
353
787
|
if (timeoutMs > 0 && Date.now() - startTs > timeoutMs) {
|
|
354
788
|
stage.status = 'TIMED_OUT';
|
|
355
789
|
this.transitionState(run, 'TIMED_OUT', `Execution timed out after ${timeoutMs}ms.`, stage.id);
|
|
@@ -361,14 +795,19 @@ export class OrchestrationEngine {
|
|
|
361
795
|
stage.error = lastError;
|
|
362
796
|
throw new Error(lastError || `Stage "${stage.name}" failed after ${run.maxRetries} retries.`);
|
|
363
797
|
}
|
|
364
|
-
this.transitionState(run, 'RUNNING', `Stage "${stage.name}" completed successfully.`, stage.id);
|
|
798
|
+
this.transitionState(run, 'RUNNING', `Stage "${stage.name}" completed and verified successfully.`, stage.id);
|
|
365
799
|
await this.store.saveRun(run);
|
|
366
800
|
}
|
|
367
|
-
//
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
801
|
+
// Final Completion: only reachable when every stage executed and passed independent verification
|
|
802
|
+
const allStagesVerified = run.stages.every((s) => s.status === 'COMPLETED' && s.receipt?.verified === true && s.receipt.verificationStatus === 'PASS');
|
|
803
|
+
if (!allStagesVerified) {
|
|
804
|
+
this.transitionState(run, 'BLOCKED', 'Run cannot complete because one or more stages lack verified completion.');
|
|
805
|
+
run.error = 'One or more stages lack verified completion.';
|
|
806
|
+
run.metrics.durationMs = Date.now() - startTs;
|
|
807
|
+
await this.store.saveRun(run);
|
|
808
|
+
return run;
|
|
809
|
+
}
|
|
810
|
+
this.transitionState(run, 'COMPLETED', 'Workflow executed and independently verified.');
|
|
372
811
|
run.metrics.durationMs = Date.now() - startTs;
|
|
373
812
|
await this.store.saveRun(run);
|
|
374
813
|
return run;
|
|
@@ -415,4 +854,3 @@ export class OrchestrationEngine {
|
|
|
415
854
|
return run;
|
|
416
855
|
}
|
|
417
856
|
}
|
|
418
|
-
//# sourceMappingURL=engine.js.map
|