devworkspace 0.4.5 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +57 -0
- package/README.md +7 -0
- package/dist/cli/args.d.ts +30 -0
- package/dist/cli/args.js +10 -0
- package/dist/cli/args.js.map +1 -1
- package/dist/cli/help.js +134 -0
- package/dist/cli/help.js.map +1 -1
- package/dist/cli/render.d.ts +6 -0
- package/dist/cli/render.js +106 -0
- package/dist/cli/render.js.map +1 -1
- package/dist/cli/run.js +351 -1
- package/dist/cli/run.js.map +1 -1
- package/dist/core/contracts.d.ts +70 -0
- package/dist/core/contracts.js +88 -0
- package/dist/core/contracts.js.map +1 -0
- package/dist/discovery/commands.d.ts +1 -1
- package/dist/discovery/commands.js.map +1 -1
- package/dist/discovery/detect.d.ts +2 -70
- package/dist/discovery/detect.js.map +1 -1
- package/dist/discovery/entrypoints.d.ts +2 -11
- package/dist/discovery/entrypoints.js.map +1 -1
- package/dist/discovery/types.d.ts +79 -0
- package/dist/discovery/types.js +2 -0
- package/dist/discovery/types.js.map +1 -0
- package/dist/dx/dashboard.d.ts +21 -0
- package/dist/dx/dashboard.js +274 -0
- package/dist/dx/dashboard.js.map +1 -0
- package/dist/dx/guidance.d.ts +21 -0
- package/dist/dx/guidance.js +266 -0
- package/dist/dx/guidance.js.map +1 -0
- package/dist/dx/index.d.ts +4 -0
- package/dist/dx/index.js +5 -0
- package/dist/dx/index.js.map +1 -0
- package/dist/dx/onboarding.d.ts +23 -0
- package/dist/dx/onboarding.js +155 -0
- package/dist/dx/onboarding.js.map +1 -0
- package/dist/dx/types.d.ts +70 -0
- package/dist/dx/types.js +3 -0
- package/dist/dx/types.js.map +1 -0
- package/dist/index.d.ts +35 -0
- package/dist/index.js +28 -0
- package/dist/index.js.map +1 -1
- package/dist/integrations/persistentPath.d.ts +2 -9
- package/dist/integrations/persistentPath.js.map +1 -1
- package/dist/integrations/types.d.ts +4 -1
- package/dist/integrations/types.js.map +1 -1
- package/dist/intelligence/agents/profiles.d.ts +2 -0
- package/dist/intelligence/agents/profiles.js +326 -0
- package/dist/intelligence/agents/profiles.js.map +1 -0
- package/dist/intelligence/agents/registry.d.ts +15 -0
- package/dist/intelligence/agents/registry.js +108 -0
- package/dist/intelligence/agents/registry.js.map +1 -0
- package/dist/intelligence/agents/types.d.ts +43 -0
- package/dist/intelligence/agents/types.js +2 -0
- package/dist/intelligence/agents/types.js.map +1 -0
- package/dist/intelligence/observability/tracer.d.ts +13 -0
- package/dist/intelligence/observability/tracer.js +129 -0
- package/dist/intelligence/observability/tracer.js.map +1 -0
- package/dist/intelligence/observability/types.d.ts +38 -0
- package/dist/intelligence/observability/types.js +2 -0
- package/dist/intelligence/observability/types.js.map +1 -0
- package/dist/intelligence/orchestration/engine.d.ts +42 -0
- package/dist/intelligence/orchestration/engine.js +418 -0
- package/dist/intelligence/orchestration/engine.js.map +1 -0
- package/dist/intelligence/orchestration/lock-manager.d.ts +21 -0
- package/dist/intelligence/orchestration/lock-manager.js +70 -0
- package/dist/intelligence/orchestration/lock-manager.js.map +1 -0
- package/dist/intelligence/orchestration/store.d.ts +11 -0
- package/dist/intelligence/orchestration/store.js +73 -0
- package/dist/intelligence/orchestration/store.js.map +1 -0
- package/dist/intelligence/orchestration/types.d.ts +100 -0
- package/dist/intelligence/orchestration/types.js +48 -0
- package/dist/intelligence/orchestration/types.js.map +1 -0
- package/dist/intelligence/routing/matcher.d.ts +7 -0
- package/dist/intelligence/routing/matcher.js +96 -0
- package/dist/intelligence/routing/matcher.js.map +1 -0
- package/dist/intelligence/routing/router.d.ts +9 -0
- package/dist/intelligence/routing/router.js +198 -0
- package/dist/intelligence/routing/router.js.map +1 -0
- package/dist/intelligence/routing/types.d.ts +64 -0
- package/dist/intelligence/routing/types.js +2 -0
- package/dist/intelligence/routing/types.js.map +1 -0
- package/dist/intelligence/runtime/adk/adapter.d.ts +7 -0
- package/dist/intelligence/runtime/adk/adapter.js +60 -0
- package/dist/intelligence/runtime/adk/adapter.js.map +1 -0
- package/dist/intelligence/runtime/adk/detector.d.ts +7 -0
- package/dist/intelligence/runtime/adk/detector.js +28 -0
- package/dist/intelligence/runtime/adk/detector.js.map +1 -0
- package/dist/intelligence/runtime/external.d.ts +9 -0
- package/dist/intelligence/runtime/external.js +102 -0
- package/dist/intelligence/runtime/external.js.map +1 -0
- package/dist/intelligence/runtime/native.d.ts +19 -0
- package/dist/intelligence/runtime/native.js +99 -0
- package/dist/intelligence/runtime/native.js.map +1 -0
- package/dist/intelligence/runtime/types.d.ts +49 -0
- package/dist/intelligence/runtime/types.js +2 -0
- package/dist/intelligence/runtime/types.js.map +1 -0
- package/dist/intelligence/security/audit.d.ts +8 -0
- package/dist/intelligence/security/audit.js +43 -0
- package/dist/intelligence/security/audit.js.map +1 -0
- package/dist/intelligence/security/policy.d.ts +12 -0
- package/dist/intelligence/security/policy.js +153 -0
- package/dist/intelligence/security/policy.js.map +1 -0
- package/dist/intelligence/security/types.d.ts +25 -0
- package/dist/intelligence/security/types.js +2 -0
- package/dist/intelligence/security/types.js.map +1 -0
- package/dist/intelligence/skills/builtins.d.ts +2 -0
- package/dist/intelligence/skills/builtins.js +379 -0
- package/dist/intelligence/skills/builtins.js.map +1 -0
- package/dist/intelligence/skills/loader.d.ts +4 -0
- package/dist/intelligence/skills/loader.js +84 -0
- package/dist/intelligence/skills/loader.js.map +1 -0
- package/dist/intelligence/skills/registry.d.ts +15 -0
- package/dist/intelligence/skills/registry.js +134 -0
- package/dist/intelligence/skills/registry.js.map +1 -0
- package/dist/intelligence/skills/types.d.ts +35 -0
- package/dist/intelligence/skills/types.js +2 -0
- package/dist/intelligence/skills/types.js.map +1 -0
- package/dist/intelligence/verification/engine.d.ts +23 -0
- package/dist/intelligence/verification/engine.js +66 -0
- package/dist/intelligence/verification/engine.js.map +1 -0
- package/dist/intelligence/verification/reviewer.d.ts +8 -0
- package/dist/intelligence/verification/reviewer.js +55 -0
- package/dist/intelligence/verification/reviewer.js.map +1 -0
- package/dist/intelligence/verification/types.d.ts +32 -0
- package/dist/intelligence/verification/types.js +2 -0
- package/dist/intelligence/verification/types.js.map +1 -0
- package/dist/mcp/setup.d.ts +2 -4
- package/dist/mcp/setup.js.map +1 -1
- package/dist/mcp/tools.js +6 -6
- package/dist/mcp/tools.js.map +1 -1
- package/dist/mcp/types.d.ts +4 -0
- package/dist/mcp/types.js.map +1 -1
- package/dist/mcp/verify.d.ts +1 -1
- package/dist/mcp/verify.js.map +1 -1
- package/dist/security/redact.js +3 -2
- package/dist/security/redact.js.map +1 -1
- package/dist/services/doctor.js +4 -0
- package/dist/services/doctor.js.map +1 -1
- package/dist/services/intelligence.d.ts +44 -0
- package/dist/services/intelligence.js +119 -0
- package/dist/services/intelligence.js.map +1 -0
- package/dist/services/standards.d.ts +85 -0
- package/dist/services/standards.js +230 -0
- package/dist/services/standards.js.map +1 -0
- package/dist/services/taskContext.js +4 -0
- package/dist/services/taskContext.js.map +1 -1
- package/dist/standards/acquisition/ingest.d.ts +12 -0
- package/dist/standards/acquisition/ingest.js +98 -0
- package/dist/standards/acquisition/ingest.js.map +1 -0
- package/dist/standards/applicability/engine.d.ts +38 -0
- package/dist/standards/applicability/engine.js +250 -0
- package/dist/standards/applicability/engine.js.map +1 -0
- package/dist/standards/builtin/code-quality.d.ts +2 -0
- package/dist/standards/builtin/code-quality.js +53 -0
- package/dist/standards/builtin/code-quality.js.map +1 -0
- package/dist/standards/builtin/database-safety.d.ts +2 -0
- package/dist/standards/builtin/database-safety.js +56 -0
- package/dist/standards/builtin/database-safety.js.map +1 -0
- package/dist/standards/builtin/index.d.ts +8 -0
- package/dist/standards/builtin/index.js +14 -0
- package/dist/standards/builtin/index.js.map +1 -0
- package/dist/standards/builtin/security-baseline.d.ts +2 -0
- package/dist/standards/builtin/security-baseline.js +64 -0
- package/dist/standards/builtin/security-baseline.js.map +1 -0
- package/dist/standards/builtin/testing-contracts.d.ts +2 -0
- package/dist/standards/builtin/testing-contracts.js +54 -0
- package/dist/standards/builtin/testing-contracts.js.map +1 -0
- package/dist/standards/builtin/undo-kit.d.ts +8 -0
- package/dist/standards/builtin/undo-kit.js +106 -0
- package/dist/standards/builtin/undo-kit.js.map +1 -0
- package/dist/standards/config/config.d.ts +12 -0
- package/dist/standards/config/config.js +110 -0
- package/dist/standards/config/config.js.map +1 -0
- package/dist/standards/distribution/cache.d.ts +57 -0
- package/dist/standards/distribution/cache.js +411 -0
- package/dist/standards/distribution/cache.js.map +1 -0
- package/dist/standards/distribution/index.d.ts +6 -0
- package/dist/standards/distribution/index.js +7 -0
- package/dist/standards/distribution/index.js.map +1 -0
- package/dist/standards/distribution/keys.d.ts +53 -0
- package/dist/standards/distribution/keys.js +269 -0
- package/dist/standards/distribution/keys.js.map +1 -0
- package/dist/standards/distribution/package.d.ts +25 -0
- package/dist/standards/distribution/package.js +248 -0
- package/dist/standards/distribution/package.js.map +1 -0
- package/dist/standards/distribution/server.d.ts +38 -0
- package/dist/standards/distribution/server.js +204 -0
- package/dist/standards/distribution/server.js.map +1 -0
- package/dist/standards/distribution/sync.d.ts +51 -0
- package/dist/standards/distribution/sync.js +212 -0
- package/dist/standards/distribution/sync.js.map +1 -0
- package/dist/standards/distribution/types.d.ts +140 -0
- package/dist/standards/distribution/types.js +26 -0
- package/dist/standards/distribution/types.js.map +1 -0
- package/dist/standards/engine/compliance.d.ts +2 -0
- package/dist/standards/engine/compliance.js +45 -0
- package/dist/standards/engine/compliance.js.map +1 -0
- package/dist/standards/engine/engine.d.ts +14 -0
- package/dist/standards/engine/engine.js +114 -0
- package/dist/standards/engine/engine.js.map +1 -0
- package/dist/standards/engine/reporter.d.ts +2 -0
- package/dist/standards/engine/reporter.js +42 -0
- package/dist/standards/engine/reporter.js.map +1 -0
- package/dist/standards/index.d.ts +18 -0
- package/dist/standards/index.js +19 -0
- package/dist/standards/index.js.map +1 -0
- package/dist/standards/registry/registry.d.ts +29 -0
- package/dist/standards/registry/registry.js +210 -0
- package/dist/standards/registry/registry.js.map +1 -0
- package/dist/standards/schema/types.d.ts +133 -0
- package/dist/standards/schema/types.js +33 -0
- package/dist/standards/schema/types.js.map +1 -0
- package/dist/standards/schema/validate.d.ts +6 -0
- package/dist/standards/schema/validate.js +131 -0
- package/dist/standards/schema/validate.js.map +1 -0
- package/dist/standards/templates/index.d.ts +11 -0
- package/dist/standards/templates/index.js +176 -0
- package/dist/standards/templates/index.js.map +1 -0
- package/dist/standards/validators/database.d.ts +5 -0
- package/dist/standards/validators/database.js +122 -0
- package/dist/standards/validators/database.js.map +1 -0
- package/dist/standards/validators/quality.d.ts +6 -0
- package/dist/standards/validators/quality.js +91 -0
- package/dist/standards/validators/quality.js.map +1 -0
- package/dist/standards/validators/registry.d.ts +11 -0
- package/dist/standards/validators/registry.js +83 -0
- package/dist/standards/validators/registry.js.map +1 -0
- package/dist/standards/validators/security.d.ts +7 -0
- package/dist/standards/validators/security.js +182 -0
- package/dist/standards/validators/security.js.map +1 -0
- package/dist/standards/validators/testing.d.ts +6 -0
- package/dist/standards/validators/testing.js +142 -0
- package/dist/standards/validators/testing.js.map +1 -0
- package/dist/standards/validators/types.d.ts +11 -0
- package/dist/standards/validators/types.js +2 -0
- package/dist/standards/validators/types.js.map +1 -0
- package/dist/standards/validators/undo-kit.d.ts +7 -0
- package/dist/standards/validators/undo-kit.js +334 -0
- package/dist/standards/validators/undo-kit.js.map +1 -0
- package/dist/tasks/routing.js +5 -3
- package/dist/tasks/routing.js.map +1 -1
- package/dist/utils/fs.d.ts +1 -1
- package/dist/utils/fs.js.map +1 -1
- package/dist/utils/lock.js +11 -3
- package/dist/utils/lock.js.map +1 -1
- package/dist/utils/paths.js +29 -0
- package/dist/utils/paths.js.map +1 -1
- package/dist/utils/proc.js +2 -0
- package/dist/utils/proc.js.map +1 -1
- package/docs/contributing.md +9 -0
- package/docs/getting-started.md +7 -0
- package/docs/security/HOME_SERVER_THREAT_MODEL.md +72 -0
- package/docs/security/THREAT_MODEL.md +101 -0
- package/docs/standards.md +143 -0
- package/package.json +1 -1
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { run } from '../../utils/proc.js';
|
|
2
|
+
import { redact } from '../../security/redact.js';
|
|
3
|
+
const MAX_OUTPUT_CHARS = 50_000;
|
|
4
|
+
export class NativeRuntimeAdapter {
|
|
5
|
+
id = 'native';
|
|
6
|
+
name = 'DevWorkspace Native Deterministic Runtime';
|
|
7
|
+
isPlaceholder = false;
|
|
8
|
+
async checkAvailability() {
|
|
9
|
+
return {
|
|
10
|
+
available: true,
|
|
11
|
+
provider: 'native',
|
|
12
|
+
version: '0.5.0',
|
|
13
|
+
supportsStreaming: false,
|
|
14
|
+
supportsNativeSubagents: true,
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
async execute(request) {
|
|
18
|
+
const start = Date.now();
|
|
19
|
+
// Reject simulated placeholder runtime execution
|
|
20
|
+
if (request.isPlaceholder) {
|
|
21
|
+
return {
|
|
22
|
+
ok: false,
|
|
23
|
+
output: '',
|
|
24
|
+
error: 'Placeholder runtime cannot return a successful execution.',
|
|
25
|
+
durationMs: 0,
|
|
26
|
+
filesModified: [],
|
|
27
|
+
isPlaceholder: true,
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
// Execute real deterministic command if provided
|
|
31
|
+
if (request.command && request.command.length > 0) {
|
|
32
|
+
const [cmd, ...args] = request.command;
|
|
33
|
+
const result = await run(cmd, args, {
|
|
34
|
+
cwd: request.cwd,
|
|
35
|
+
timeoutMs: request.timeoutMs ?? 30_000,
|
|
36
|
+
signal: request.signal,
|
|
37
|
+
maxBytes: request.maxBytes ?? MAX_OUTPUT_CHARS,
|
|
38
|
+
env: request.env,
|
|
39
|
+
});
|
|
40
|
+
const boundedStdout = result.stdout.slice(0, MAX_OUTPUT_CHARS);
|
|
41
|
+
const boundedStderr = result.stderr.slice(0, MAX_OUTPUT_CHARS);
|
|
42
|
+
const outputText = boundedStdout || boundedStderr;
|
|
43
|
+
return {
|
|
44
|
+
ok: result.ok,
|
|
45
|
+
output: redact(outputText),
|
|
46
|
+
error: result.ok ? undefined : redact(result.stderr || result.error || `Command exited with code ${result.code}`),
|
|
47
|
+
durationMs: Date.now() - start,
|
|
48
|
+
tokensUsed: 0,
|
|
49
|
+
filesModified: request.contextFiles ?? [],
|
|
50
|
+
exitCode: result.code ?? (result.ok ? 0 : 1),
|
|
51
|
+
stdout: redact(boundedStdout),
|
|
52
|
+
stderr: redact(boundedStderr),
|
|
53
|
+
timedOut: result.timedOut,
|
|
54
|
+
aborted: result.aborted,
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
// Deterministic task inspection within local workspace boundaries
|
|
58
|
+
const summary = `[Native Runtime] Executed stage for ${request.role} (${request.agentId}). Handled deterministically within project boundaries.`;
|
|
59
|
+
return {
|
|
60
|
+
ok: true,
|
|
61
|
+
output: redact(summary),
|
|
62
|
+
durationMs: Date.now() - start,
|
|
63
|
+
tokensUsed: 0,
|
|
64
|
+
filesModified: request.contextFiles ?? [],
|
|
65
|
+
exitCode: 0,
|
|
66
|
+
stdout: redact(summary),
|
|
67
|
+
stderr: '',
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Placeholder runtime adapter explicitly defined to certify that placeholder
|
|
73
|
+
* runtimes cannot return a successful execution under any circumstances.
|
|
74
|
+
*/
|
|
75
|
+
export class PlaceholderRuntimeAdapter {
|
|
76
|
+
id = 'placeholder';
|
|
77
|
+
name = 'Placeholder Runtime';
|
|
78
|
+
isPlaceholder = true;
|
|
79
|
+
async checkAvailability() {
|
|
80
|
+
return {
|
|
81
|
+
available: false,
|
|
82
|
+
provider: 'placeholder',
|
|
83
|
+
reason: 'Placeholder runtimes cannot execute tasks.',
|
|
84
|
+
supportsStreaming: false,
|
|
85
|
+
supportsNativeSubagents: false,
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
async execute(_request) {
|
|
89
|
+
return {
|
|
90
|
+
ok: false,
|
|
91
|
+
output: '',
|
|
92
|
+
error: 'Placeholder runtime cannot return a successful execution.',
|
|
93
|
+
durationMs: 0,
|
|
94
|
+
filesModified: [],
|
|
95
|
+
isPlaceholder: true,
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
//# sourceMappingURL=native.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"native.js","sourceRoot":"","sources":["../../../src/intelligence/runtime/native.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,GAAG,EAAE,MAAM,qBAAqB,CAAC;AAC1C,OAAO,EAAE,MAAM,EAAE,MAAM,0BAA0B,CAAC;AAElD,MAAM,gBAAgB,GAAG,MAAM,CAAC;AAEhC,MAAM,OAAO,oBAAoB;IACtB,EAAE,GAAG,QAAQ,CAAC;IACd,IAAI,GAAG,2CAA2C,CAAC;IACnD,aAAa,GAAG,KAAK,CAAC;IAE/B,KAAK,CAAC,iBAAiB;QACrB,OAAO;YACL,SAAS,EAAE,IAAI;YACf,QAAQ,EAAE,QAAQ;YAClB,OAAO,EAAE,OAAO;YAChB,iBAAiB,EAAE,KAAK;YACxB,uBAAuB,EAAE,IAAI;SAC9B,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,OAAO,CAAC,OAA8B;QAC1C,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;QAEzB,iDAAiD;QACjD,IAAI,OAAO,CAAC,aAAa,EAAE,CAAC;YAC1B,OAAO;gBACL,EAAE,EAAE,KAAK;gBACT,MAAM,EAAE,EAAE;gBACV,KAAK,EAAE,2DAA2D;gBAClE,UAAU,EAAE,CAAC;gBACb,aAAa,EAAE,EAAE;gBACjB,aAAa,EAAE,IAAI;aACpB,CAAC;QACJ,CAAC;QAED,iDAAiD;QACjD,IAAI,OAAO,CAAC,OAAO,IAAI,OAAO,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAClD,MAAM,CAAC,GAAG,EAAE,G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Q;gBACzB,OAAO,EAAE,MAAM,CAAC,OAAO;aACxB,CAAC;QACJ,CAAC;QAED,kEAAkE;QAClE,MAAM,OAAO,GAAG,uCAAuC,OAAO,CAAC,IAAI,KAAK,OAAO,CAAC,OAAO,yDAAyD,CAAC;QACjJ,OAAO;YACL,EAAE,EAAE,IAAI;YACR,MAAM,EAAE,MAAM,CAAC,OAAO,CAAC;YACvB,UAAU,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,KAAK;YAC9B,UAAU,EAAE,CAAC;YACb,aAAa,EAAE,OAAO,CAAC,YAAY,IAAI,EAAE;YACzC,QAAQ,EAAE,CAAC;YACX,MAAM,EAAE,MAAM,CAAC,OAAO,CAAC;YACvB,MAAM,EAAE,EAAE;SACX,CAAC;IACJ,CAAC;CACF;AAED;;;GAGG;AACH,MAAM,OAAO,yBAAyB;IAC3B,EAAE,GAAG,aAAa,CAAC;IACnB,IAAI,GAAG,qBAAqB,CAAC;IAC7B,aAAa,GAAG,IAAI,CAAC;IAE9B,KAAK,CAAC,iBAAiB;QACrB,OAAO;YACL,SAAS,EAAE,KAAK;YAChB,QAAQ,EAAE,aAAa;YACvB,MAAM,EAAE,4CAA4C;YACpD,iBAAiB,EAAE,KAAK;YACxB,uBAAuB,EAAE,KAAK;SAC/B,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,OAAO,CAAC,QAA+B;QAC3C,OAAO;YACL,EAAE,EAAE,KAAK;YACT,MAAM,EAAE,EAAE;YACV,KAAK,EAAE,2DAA2D;YAClE,UAAU,EAAE,CAAC;YACb,aAAa,EAAE,EAAE;YACjB,aAAa,EAAE,IAAI;SACpB,CAAC;IACJ,CAAC;CACF","sourcesContent":["import type {\n AgentExecutionRequest,\n AgentExecutionResponse,\n AgentRuntimeAdapter,\n RuntimeAvailability,\n} from './types.js';\nimport { run } from '../../utils/proc.js';\nimport { redact } from '../../security/redact.js';\n\nconst MAX_OUTPUT_CHARS = 50_000;\n\nexport class NativeRuntimeAdapter implements AgentRuntimeAdapter {\n readonly id = 'native';\n readonly name = 'DevWorkspace Native Deterministic Runtime';\n readonly isPlaceholder = false;\n\n async checkAvailability(): Promise<RuntimeAvailability> {\n return {\n available: true,\n provider: 'native',\n version: '0.5.0',\n supportsStreaming: false,\n supportsNativeSubagents: true,\n };\n }\n\n async execute(request: AgentExecutionRequest): Promise<AgentExecutionResponse> {\n const start = Date.now();\n\n // Reject simulated placeholder runtime execution\n if (request.isPlaceholder) {\n return {\n ok: false,\n output: '',\n error: 'Placeholder runtime cannot return a successful execution.',\n durationMs: 0,\n filesModified: [],\n isPlaceholder: true,\n };\n }\n\n // Execute real deterministic command if provided\n if (request.command && request.command.length > 0) {\n const [cmd, ...args] = request.command;\n const result = await run(cmd!, args, {\n cwd: request.cwd,\n timeoutMs: request.timeoutMs ?? 30_000,\n signal: request.signal,\n maxBytes: request.maxBytes ?? MAX_OUTPUT_CHARS,\n env: request.env,\n });\n\n const boundedStdout = result.stdout.slice(0, MAX_OUTPUT_CHARS);\n const boundedStderr = result.stderr.slice(0, MAX_OUTPUT_CHARS);\n const outputText = boundedStdout || boundedStderr;\n\n return {\n ok: result.ok,\n output: redact(outputText),\n error: result.ok ? undefined : redact(result.stderr || result.error || `Command exited with code ${result.code}`),\n durationMs: Date.now() - start,\n tokensUsed: 0,\n filesModified: request.contextFiles ?? [],\n exitCode: result.code ?? (result.ok ? 0 : 1),\n stdout: redact(boundedStdout),\n stderr: redact(boundedStderr),\n timedOut: result.timedOut,\n aborted: result.aborted,\n };\n }\n\n // Deterministic task inspection within local workspace boundaries\n const summary = `[Native Runtime] Executed stage for ${request.role} (${request.agentId}). Handled deterministically within project boundaries.`;\n return {\n ok: true,\n output: redact(summary),\n durationMs: Date.now() - start,\n tokensUsed: 0,\n filesModified: request.contextFiles ?? [],\n exitCode: 0,\n stdout: redact(summary),\n stderr: '',\n };\n }\n}\n\n/**\n * Placeholder runtime adapter explicitly defined to certify that placeholder\n * runtimes cannot return a successful execution under any circumstances.\n */\nexport class PlaceholderRuntimeAdapter implements AgentRuntimeAdapter {\n readonly id = 'placeholder';\n readonly name = 'Placeholder Runtime';\n readonly isPlaceholder = true;\n\n async checkAvailability(): Promise<RuntimeAvailability> {\n return {\n available: false,\n provider: 'placeholder',\n reason: 'Placeholder runtimes cannot execute tasks.',\n supportsStreaming: false,\n supportsNativeSubagents: false,\n };\n }\n\n async execute(_request: AgentExecutionRequest): Promise<AgentExecutionResponse> {\n return {\n ok: false,\n output: '',\n error: 'Placeholder runtime cannot return a successful execution.',\n durationMs: 0,\n filesModified: [],\n isPlaceholder: true,\n };\n }\n}\n"]}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
export interface AgentExecutionRequest {
|
|
2
|
+
agentId: string;
|
|
3
|
+
role: string;
|
|
4
|
+
prompt: string;
|
|
5
|
+
skills?: string[];
|
|
6
|
+
toolPermissions?: any[];
|
|
7
|
+
contextFiles?: string[];
|
|
8
|
+
tools?: string[];
|
|
9
|
+
timeoutMs?: number;
|
|
10
|
+
signal?: AbortSignal;
|
|
11
|
+
command?: string[];
|
|
12
|
+
cwd?: string;
|
|
13
|
+
env?: Record<string, string>;
|
|
14
|
+
maxBytes?: number;
|
|
15
|
+
allowExternalExecution?: boolean;
|
|
16
|
+
sandboxPath?: string;
|
|
17
|
+
isDeterministic?: boolean;
|
|
18
|
+
isPlaceholder?: boolean;
|
|
19
|
+
}
|
|
20
|
+
export interface AgentExecutionResponse {
|
|
21
|
+
ok: boolean;
|
|
22
|
+
output: string;
|
|
23
|
+
error?: string;
|
|
24
|
+
tokensUsed?: number;
|
|
25
|
+
durationMs: number;
|
|
26
|
+
filesModified: string[];
|
|
27
|
+
exitCode?: number;
|
|
28
|
+
stdout?: string;
|
|
29
|
+
stderr?: string;
|
|
30
|
+
timedOut?: boolean;
|
|
31
|
+
aborted?: boolean;
|
|
32
|
+
isPlaceholder?: boolean;
|
|
33
|
+
evidence?: Record<string, unknown>;
|
|
34
|
+
}
|
|
35
|
+
export interface RuntimeAvailability {
|
|
36
|
+
available: boolean;
|
|
37
|
+
provider: string;
|
|
38
|
+
version?: string;
|
|
39
|
+
reason?: string;
|
|
40
|
+
supportsStreaming: boolean;
|
|
41
|
+
supportsNativeSubagents: boolean;
|
|
42
|
+
}
|
|
43
|
+
export interface AgentRuntimeAdapter {
|
|
44
|
+
readonly id: string;
|
|
45
|
+
readonly name: string;
|
|
46
|
+
readonly isPlaceholder?: boolean;
|
|
47
|
+
checkAvailability(): Promise<RuntimeAvailability>;
|
|
48
|
+
execute(request: AgentExecutionRequest): Promise<AgentExecutionResponse>;
|
|
49
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/intelligence/runtime/types.ts"],"names":[],"mappings":"","sourcesContent":["export interface AgentExecutionRequest {\n agentId: string;\n role: string;\n prompt: string;\n skills?: string[];\n toolPermissions?: any[];\n contextFiles?: string[];\n tools?: string[];\n timeoutMs?: number;\n signal?: AbortSignal;\n command?: string[];\n cwd?: string;\n env?: Record<string, string>;\n maxBytes?: number;\n allowExternalExecution?: boolean;\n sandboxPath?: string;\n isDeterministic?: boolean;\n isPlaceholder?: boolean;\n}\n\nexport interface AgentExecutionResponse {\n ok: boolean;\n output: string;\n error?: string;\n tokensUsed?: number;\n durationMs: number;\n filesModified: string[];\n exitCode?: number;\n stdout?: string;\n stderr?: string;\n timedOut?: boolean;\n aborted?: boolean;\n isPlaceholder?: boolean;\n evidence?: Record<string, unknown>;\n}\n\nexport interface RuntimeAvailability {\n available: boolean;\n provider: string;\n version?: string;\n reason?: string;\n supportsStreaming: boolean;\n supportsNativeSubagents: boolean;\n}\n\nexport interface AgentRuntimeAdapter {\n readonly id: string;\n readonly name: string;\n readonly isPlaceholder?: boolean;\n checkAvailability(): Promise<RuntimeAvailability>;\n execute(request: AgentExecutionRequest): Promise<AgentExecutionResponse>;\n}\n"]}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { SecurityAuditEntry } from './types.js';
|
|
2
|
+
export declare class SecurityAuditLogger {
|
|
3
|
+
private workspaceRoot;
|
|
4
|
+
constructor(workspaceRoot: string);
|
|
5
|
+
private auditLogPath;
|
|
6
|
+
record(entry: SecurityAuditEntry): Promise<void>;
|
|
7
|
+
getRecentEntries(limit?: number): Promise<SecurityAuditEntry[]>;
|
|
8
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import { promises as fs } from 'node:fs';
|
|
3
|
+
import { ensureDir, pathExists } from '../../utils/fs.js';
|
|
4
|
+
const AUDIT_LOG_REL = '.devworkspace/orchestration/security-audit.jsonl';
|
|
5
|
+
export class SecurityAuditLogger {
|
|
6
|
+
workspaceRoot;
|
|
7
|
+
constructor(workspaceRoot) {
|
|
8
|
+
this.workspaceRoot = workspaceRoot;
|
|
9
|
+
}
|
|
10
|
+
auditLogPath() {
|
|
11
|
+
return path.join(this.workspaceRoot, AUDIT_LOG_REL);
|
|
12
|
+
}
|
|
13
|
+
async record(entry) {
|
|
14
|
+
const filePath = this.auditLogPath();
|
|
15
|
+
await ensureDir(path.dirname(filePath));
|
|
16
|
+
const line = JSON.stringify(entry) + '\n';
|
|
17
|
+
await fs.appendFile(filePath, line, 'utf8');
|
|
18
|
+
}
|
|
19
|
+
async getRecentEntries(limit = 100) {
|
|
20
|
+
const filePath = this.auditLogPath();
|
|
21
|
+
if (!(await pathExists(filePath))) {
|
|
22
|
+
return [];
|
|
23
|
+
}
|
|
24
|
+
try {
|
|
25
|
+
const content = await fs.readFile(filePath, 'utf8');
|
|
26
|
+
const lines = content.trim().split('\n').filter(Boolean);
|
|
27
|
+
const entries = [];
|
|
28
|
+
for (const line of lines.slice(-limit)) {
|
|
29
|
+
try {
|
|
30
|
+
entries.push(JSON.parse(line));
|
|
31
|
+
}
|
|
32
|
+
catch {
|
|
33
|
+
// ignore corrupted lines
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return entries;
|
|
37
|
+
}
|
|
38
|
+
catch {
|
|
39
|
+
return [];
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=audit.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"audit.js","sourceRoot":"","sources":["../../../src/intelligence/security/audit.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,QAAQ,IAAI,EAAE,EAAE,MAAM,SAAS,CAAC;AAEzC,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAE1D,MAAM,aAAa,GAAG,kDAAkD,CAAC;AAEzE,MAAM,OAAO,mBAAmB;IACtB,aAAa,CAAS;IAE9B,YAAY,aAAqB;QAC/B,IAAI,CAAC,aAAa,GAAG,aAAa,CAAC;IACrC,CAAC;IAEO,YAAY;QAClB,OAAO,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,aAAa,EAAE,aAAa,CAAC,CAAC;IACtD,CAAC;IAED,KAAK,CAAC,MAAM,CAAC,KAAyB;QACpC,MAAM,QAAQ,GAAG,IAAI,CAAC,YAAY,EAAE,CAAC;QACrC,MAAM,SAAS,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC;QACxC,MAAM,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC;QAC1C,MAAM,EAAE,CAAC,UAAU,CAAC,QAAQ,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC;IAC9C,CAAC;IAED,KAAK,CAAC,gBAAgB,CAAC,KAAK,GAAG,GAAG;QAChC,MAAM,QAAQ,GAAG,IAAI,CAAC,YAAY,EAAE,CAAC;QACrC,IAAI,CAAC,CAAC,MAAM,UAAU,CAAC,QAAQ,CAAC,CAAC,EAAE,CAAC;YAClC,OAAO,EAAE,CAAC;QACZ,CAAC;QAED,IAAI,CAAC;YACH,MAAM,OAAO,GAAG,MAAM,EAAE,CAAC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;YACpD,MAAM,KAAK,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;YACzD,MAAM,OAAO,GAAyB,EAAE,CAAC;YACzC,KAAK,MAAM,IAAI,IAAI,KAAK,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,EAAE,CAAC;gBACvC,IAAI,CAAC;oBACH,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC;gBACjC,CAAC;gBAAC,MAAM,CAAC;oBACP,yBAAyB;gBAC3B,CAAC;YACH,CAAC;YACD,OAAO,OAAO,CAAC;QACjB,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,EAAE,CAAC;QACZ,CAAC;IACH,CAAC;CACF","sourcesContent":["import path from 'node:path';\nimport { promises as fs } from 'node:fs';\nimport type { SecurityAuditEntry } from './types.js';\nimport { ensureDir, pathExists } from '../../utils/fs.js';\n\nconst AUDIT_LOG_REL = '.devworkspace/orchestration/security-audit.jsonl';\n\nexport class SecurityAuditLogger {\n private workspaceRoot: string;\n\n constructor(workspaceRoot: string) {\n this.workspaceRoot = workspaceRoot;\n }\n\n private auditLogPath(): string {\n return path.join(this.workspaceRoot, AUDIT_LOG_REL);\n }\n\n async record(entry: SecurityAuditEntry): Promise<void> {\n const filePath = this.auditLogPath();\n await ensureDir(path.dirname(filePath));\n const line = JSON.stringify(entry) + '\\n';\n await fs.appendFile(filePath, line, 'utf8');\n }\n\n async getRecentEntries(limit = 100): Promise<SecurityAuditEntry[]> {\n const filePath = this.auditLogPath();\n if (!(await pathExists(filePath))) {\n return [];\n }\n\n try {\n const content = await fs.readFile(filePath, 'utf8');\n const lines = content.trim().split('\\n').filter(Boolean);\n const entries: SecurityAuditEntry[] = [];\n for (const line of lines.slice(-limit)) {\n try {\n entries.push(JSON.parse(line));\n } catch {\n // ignore corrupted lines\n }\n }\n return entries;\n } catch {\n return [];\n }\n }\n}\n"]}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { PermissionScope, SecurityCheckResult, SecurityPolicy } from './types.js';
|
|
2
|
+
export declare const DEFAULT_SECURITY_POLICY: SecurityPolicy;
|
|
3
|
+
export declare class SecurityPolicyEvaluator {
|
|
4
|
+
private workspaceRoot;
|
|
5
|
+
private policy;
|
|
6
|
+
constructor(workspaceRoot: string, policy?: SecurityPolicy);
|
|
7
|
+
checkScope(scope: PermissionScope): SecurityCheckResult;
|
|
8
|
+
checkFileRead(targetPath: string): SecurityCheckResult;
|
|
9
|
+
checkFileWrite(targetPath: string): SecurityCheckResult;
|
|
10
|
+
checkCommandExec(command: string): SecurityCheckResult;
|
|
11
|
+
private matchesPattern;
|
|
12
|
+
}
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import { isInside, looksAbsolute, toPosix } from '../../utils/paths.js';
|
|
3
|
+
export const DEFAULT_SECURITY_POLICY = {
|
|
4
|
+
allowedScopes: ['fs:read', 'fs:write', 'terminal:exec', 'skill:install', 'agent:delegate'],
|
|
5
|
+
allowedReadDirectories: ['**/*'],
|
|
6
|
+
allowedWriteDirectories: ['src/**', 'lib/**', 'tests/**', 'docs/**', 'package.json', '.devworkspace/**'],
|
|
7
|
+
deniedFilePatterns: [
|
|
8
|
+
'.env',
|
|
9
|
+
'.env.*',
|
|
10
|
+
'**/.env',
|
|
11
|
+
'**/.env.*',
|
|
12
|
+
'**/*.pem',
|
|
13
|
+
'**/*.key',
|
|
14
|
+
'**/*id_rsa*',
|
|
15
|
+
'.git/**',
|
|
16
|
+
],
|
|
17
|
+
allowedCommandPrefixes: [
|
|
18
|
+
'npm test',
|
|
19
|
+
'npm run',
|
|
20
|
+
'npx tsc',
|
|
21
|
+
'npx vitest',
|
|
22
|
+
'npx jest',
|
|
23
|
+
'npx eslint',
|
|
24
|
+
'git status',
|
|
25
|
+
'git diff',
|
|
26
|
+
'git log',
|
|
27
|
+
'node',
|
|
28
|
+
],
|
|
29
|
+
deniedCommandPatterns: [
|
|
30
|
+
'rm -rf /',
|
|
31
|
+
'rm -rf ~',
|
|
32
|
+
'mkfs',
|
|
33
|
+
'format c:',
|
|
34
|
+
'del /s /q c:',
|
|
35
|
+
'shutdown',
|
|
36
|
+
'curl | bash',
|
|
37
|
+
'wget | bash',
|
|
38
|
+
],
|
|
39
|
+
maxExecutionTimeoutSeconds: 300,
|
|
40
|
+
requireApprovalForMutations: false,
|
|
41
|
+
};
|
|
42
|
+
export class SecurityPolicyEvaluator {
|
|
43
|
+
workspaceRoot;
|
|
44
|
+
policy;
|
|
45
|
+
constructor(workspaceRoot, policy = DEFAULT_SECURITY_POLICY) {
|
|
46
|
+
this.workspaceRoot = path.resolve(workspaceRoot);
|
|
47
|
+
this.policy = policy;
|
|
48
|
+
}
|
|
49
|
+
checkScope(scope) {
|
|
50
|
+
if (!this.policy.allowedScopes.includes(scope)) {
|
|
51
|
+
return {
|
|
52
|
+
allowed: false,
|
|
53
|
+
requiresApproval: true,
|
|
54
|
+
reason: `Scope "${scope}" is not granted under current security policy.`,
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
return { allowed: true, requiresApproval: false };
|
|
58
|
+
}
|
|
59
|
+
checkFileRead(targetPath) {
|
|
60
|
+
const scopeCheck = this.checkScope('fs:read');
|
|
61
|
+
if (!scopeCheck.allowed)
|
|
62
|
+
return scopeCheck;
|
|
63
|
+
const normalized = toPosix(targetPath).trim();
|
|
64
|
+
// 1. Path traversal check
|
|
65
|
+
if (normalized.split('/').includes('..')) {
|
|
66
|
+
return {
|
|
67
|
+
allowed: false,
|
|
68
|
+
requiresApproval: false,
|
|
69
|
+
reason: `Parent path traversal blocked: "${targetPath}".`,
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
if ((path.isAbsolute(targetPath) || looksAbsolute(targetPath)) && !(path.isAbsolute(targetPath) && isInside(this.workspaceRoot, targetPath))) {
|
|
73
|
+
return {
|
|
74
|
+
allowed: false,
|
|
75
|
+
requiresApproval: false,
|
|
76
|
+
reason: `Access outside workspace root blocked: "${targetPath}".`,
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
// 2. Sensitive file patterns check
|
|
80
|
+
for (const pat of this.policy.deniedFilePatterns) {
|
|
81
|
+
if (this.matchesPattern(normalized, pat)) {
|
|
82
|
+
return {
|
|
83
|
+
allowed: false,
|
|
84
|
+
requiresApproval: false,
|
|
85
|
+
reason: `Security Policy Refusal: File "${targetPath}" is quarantined as credential/secret material.`,
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
return { allowed: true, requiresApproval: false };
|
|
90
|
+
}
|
|
91
|
+
checkFileWrite(targetPath) {
|
|
92
|
+
const scopeCheck = this.checkScope('fs:write');
|
|
93
|
+
if (!scopeCheck.allowed)
|
|
94
|
+
return scopeCheck;
|
|
95
|
+
const readCheck = this.checkFileRead(targetPath);
|
|
96
|
+
if (!readCheck.allowed)
|
|
97
|
+
return readCheck;
|
|
98
|
+
if (this.policy.requireApprovalForMutations) {
|
|
99
|
+
return {
|
|
100
|
+
allowed: false,
|
|
101
|
+
requiresApproval: true,
|
|
102
|
+
reason: 'Policy requires developer approval prior to file modifications.',
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
return { allowed: true, requiresApproval: false };
|
|
106
|
+
}
|
|
107
|
+
checkCommandExec(command) {
|
|
108
|
+
const scopeCheck = this.checkScope('terminal:exec');
|
|
109
|
+
if (!scopeCheck.allowed)
|
|
110
|
+
return scopeCheck;
|
|
111
|
+
const trimmed = command.trim();
|
|
112
|
+
// Check against dangerous denylist
|
|
113
|
+
for (const den of this.policy.deniedCommandPatterns) {
|
|
114
|
+
if (trimmed.toLowerCase().includes(den.toLowerCase())) {
|
|
115
|
+
return {
|
|
116
|
+
allowed: false,
|
|
117
|
+
requiresApproval: false,
|
|
118
|
+
reason: `Forbidden dangerous command pattern detected: "${den}".`,
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
// Check allowlist
|
|
123
|
+
const allowed = this.policy.allowedCommandPrefixes.some((p) => trimmed.startsWith(p));
|
|
124
|
+
if (!allowed) {
|
|
125
|
+
return {
|
|
126
|
+
allowed: false,
|
|
127
|
+
requiresApproval: true,
|
|
128
|
+
reason: `Command "${trimmed}" is not in the pre-approved allowlist and requires approval.`,
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
return { allowed: true, requiresApproval: false };
|
|
132
|
+
}
|
|
133
|
+
matchesPattern(filePath, pattern) {
|
|
134
|
+
const cleanPath = filePath.replace(/^\/+/, '');
|
|
135
|
+
const cleanPat = pattern.replace(/^\/+/, '');
|
|
136
|
+
if (cleanPat.endsWith('/**')) {
|
|
137
|
+
const prefix = cleanPat.slice(0, -3);
|
|
138
|
+
return cleanPath.startsWith(prefix) || cleanPath === prefix;
|
|
139
|
+
}
|
|
140
|
+
if (cleanPat.startsWith('**/')) {
|
|
141
|
+
const sub = cleanPat.slice(3);
|
|
142
|
+
if (this.matchesPattern(cleanPath, sub))
|
|
143
|
+
return true;
|
|
144
|
+
const parts = cleanPath.split('/');
|
|
145
|
+
return parts.some((_, idx) => this.matchesPattern(parts.slice(idx).join('/'), sub));
|
|
146
|
+
}
|
|
147
|
+
const regexStr = '^' + cleanPat
|
|
148
|
+
.replace(/[.+^${}()|[\]\\]/g, '\\$&')
|
|
149
|
+
.replace(/\*/g, '.*') + '$';
|
|
150
|
+
return new RegExp(regexStr, 'i').test(cleanPath);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
//# sourceMappingURL=policy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"policy.js","sourceRoot":"","sources":["../../../src/intelligence/security/policy.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,OAAO,EAAE,QA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C;QAED,MAAM,QAAQ,GAAG,GAAG,GAAG,QAAQ;aAC5B,OAAO,CAAC,mBAAmB,EAAE,MAAM,CAAC;aACpC,OAAO,CAAC,KAAK,EAAE,IAAI,CAAC,GAAG,GAAG,CAAC;QAC9B,OAAO,IAAI,MAAM,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;IACnD,CAAC;CACF","sourcesContent":["import path from 'node:path';\nimport type { PermissionScope, SecurityCheckResult, SecurityPolicy } from './types.js';\nimport { isInside, looksAbsolute, toPosix } from '../../utils/paths.js';\n\nexport const DEFAULT_SECURITY_POLICY: SecurityPolicy = {\n allowedScopes: ['fs:read', 'fs:write', 'terminal:exec', 'skill:install', 'agent:delegate'],\n allowedReadDirectories: ['**/*'],\n allowedWriteDirectories: ['src/**', 'lib/**', 'tests/**', 'docs/**', 'package.json', '.devworkspace/**'],\n deniedFilePatterns: [\n '.env',\n '.env.*',\n '**/.env',\n '**/.env.*',\n '**/*.pem',\n '**/*.key',\n '**/*id_rsa*',\n '.git/**',\n ],\n allowedCommandPrefixes: [\n 'npm test',\n 'npm run',\n 'npx tsc',\n 'npx vitest',\n 'npx jest',\n 'npx eslint',\n 'git status',\n 'git diff',\n 'git log',\n 'node',\n ],\n deniedCommandPatterns: [\n 'rm -rf /',\n 'rm -rf ~',\n 'mkfs',\n 'format c:',\n 'del /s /q c:',\n 'shutdown',\n 'curl | bash',\n 'wget | bash',\n ],\n maxExecutionTimeoutSeconds: 300,\n requireApprovalForMutations: false,\n};\n\nexport class SecurityPolicyEvaluator {\n private workspaceRoot: string;\n private policy: SecurityPolicy;\n\n constructor(workspaceRoot: string, policy: SecurityPolicy = DEFAULT_SECURITY_POLICY) {\n this.workspaceRoot = path.resolve(workspaceRoot);\n this.policy = policy;\n }\n\n checkScope(scope: PermissionScope): SecurityCheckResult {\n if (!this.policy.allowedScopes.includes(scope)) {\n return {\n allowed: false,\n requiresApproval: true,\n reason: `Scope \"${scope}\" is not granted under current security policy.`,\n };\n }\n return { allowed: true, requiresApproval: false };\n }\n\n checkFileRead(targetPath: string): SecurityCheckResult {\n const scopeCheck = this.checkScope('fs:read');\n if (!scopeCheck.allowed) return scopeCheck;\n\n const normalized = toPosix(targetPath).trim();\n\n // 1. Path traversal check\n if (normalized.split('/').includes('..')) {\n return {\n allowed: false,\n requiresApproval: false,\n reason: `Parent path traversal blocked: \"${targetPath}\".`,\n };\n }\n\n if ((path.isAbsolute(targetPath) || looksAbsolute(targetPath)) && !(path.isAbsolute(targetPath) && isInside(this.workspaceRoot, targetPath))) {\n return {\n allowed: false,\n requiresApproval: false,\n reason: `Access outside workspace root blocked: \"${targetPath}\".`,\n };\n }\n\n // 2. Sensitive file patterns check\n for (const pat of this.policy.deniedFilePatterns) {\n if (this.matchesPattern(normalized, pat)) {\n return {\n allowed: false,\n requiresApproval: false,\n reason: `Security Policy Refusal: File \"${targetPath}\" is quarantined as credential/secret material.`,\n };\n }\n }\n\n return { allowed: true, requiresApproval: false };\n }\n\n checkFileWrite(targetPath: string): SecurityCheckResult {\n const scopeCheck = this.checkScope('fs:write');\n if (!scopeCheck.allowed) return scopeCheck;\n\n const readCheck = this.checkFileRead(targetPath);\n if (!readCheck.allowed) return readCheck;\n\n if (this.policy.requireApprovalForMutations) {\n return {\n allowed: false,\n requiresApproval: true,\n reason: 'Policy requires developer approval prior to file modifications.',\n };\n }\n\n return { allowed: true, requiresApproval: false };\n }\n\n checkCommandExec(command: string): SecurityCheckResult {\n const scopeCheck = this.checkScope('terminal:exec');\n if (!scopeCheck.allowed) return scopeCheck;\n\n const trimmed = command.trim();\n\n // Check against dangerous denylist\n for (const den of this.policy.deniedCommandPatterns) {\n if (trimmed.toLowerCase().includes(den.toLowerCase())) {\n return {\n allowed: false,\n requiresApproval: false,\n reason: `Forbidden dangerous command pattern detected: \"${den}\".`,\n };\n }\n }\n\n // Check allowlist\n const allowed = this.policy.allowedCommandPrefixes.some((p) => trimmed.startsWith(p));\n if (!allowed) {\n return {\n allowed: false,\n requiresApproval: true,\n reason: `Command \"${trimmed}\" is not in the pre-approved allowlist and requires approval.`,\n };\n }\n\n return { allowed: true, requiresApproval: false };\n }\n\n private matchesPattern(filePath: string, pattern: string): boolean {\n const cleanPath = filePath.replace(/^\\/+/, '');\n const cleanPat = pattern.replace(/^\\/+/, '');\n\n if (cleanPat.endsWith('/**')) {\n const prefix = cleanPat.slice(0, -3);\n return cleanPath.startsWith(prefix) || cleanPath === prefix;\n }\n if (cleanPat.startsWith('**/')) {\n const sub = cleanPat.slice(3);\n if (this.matchesPattern(cleanPath, sub)) return true;\n const parts = cleanPath.split('/');\n return parts.some((_, idx) => this.matchesPattern(parts.slice(idx).join('/'), sub));\n }\n\n const regexStr = '^' + cleanPat\n .replace(/[.+^${}()|[\\]\\\\]/g, '\\\\$&')\n .replace(/\\*/g, '.*') + '$';\n return new RegExp(regexStr, 'i').test(cleanPath);\n }\n}\n"]}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export type PermissionScope = 'fs:read' | 'fs:write' | 'terminal:exec' | 'network:outbound' | 'git:modify' | 'deps:install' | 'skill:install' | 'agent:delegate';
|
|
2
|
+
export interface SecurityPolicy {
|
|
3
|
+
allowedScopes: PermissionScope[];
|
|
4
|
+
allowedReadDirectories: string[];
|
|
5
|
+
allowedWriteDirectories: string[];
|
|
6
|
+
deniedFilePatterns: string[];
|
|
7
|
+
allowedCommandPrefixes: string[];
|
|
8
|
+
deniedCommandPatterns: string[];
|
|
9
|
+
maxExecutionTimeoutSeconds: number;
|
|
10
|
+
requireApprovalForMutations: boolean;
|
|
11
|
+
}
|
|
12
|
+
export interface SecurityCheckResult {
|
|
13
|
+
allowed: boolean;
|
|
14
|
+
reason?: string;
|
|
15
|
+
requiresApproval: boolean;
|
|
16
|
+
}
|
|
17
|
+
export interface SecurityAuditEntry {
|
|
18
|
+
timestamp: string;
|
|
19
|
+
agentId: string;
|
|
20
|
+
scope: PermissionScope;
|
|
21
|
+
target: string;
|
|
22
|
+
allowed: boolean;
|
|
23
|
+
requiresApproval: boolean;
|
|
24
|
+
reason?: string;
|
|
25
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/intelligence/security/types.ts"],"names":[],"mappings":"","sourcesContent":["export type PermissionScope =\n | 'fs:read'\n | 'fs:write'\n | 'terminal:exec'\n | 'network:outbound'\n | 'git:modify'\n | 'deps:install'\n | 'skill:install'\n | 'agent:delegate';\n\nexport interface SecurityPolicy {\n allowedScopes: PermissionScope[];\n allowedReadDirectories: string[];\n allowedWriteDirectories: string[];\n deniedFilePatterns: string[];\n allowedCommandPrefixes: string[];\n deniedCommandPatterns: string[];\n maxExecutionTimeoutSeconds: number;\n requireApprovalForMutations: boolean;\n}\n\nexport interface SecurityCheckResult {\n allowed: boolean;\n reason?: string;\n requiresApproval: boolean;\n}\n\nexport interface SecurityAuditEntry {\n timestamp: string;\n agentId: string;\n scope: PermissionScope;\n target: string;\n allowed: boolean;\n requiresApproval: boolean;\n reason?: string;\n}\n"]}
|