dvalincode 0.12.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/LICENSE +22 -0
- package/README.md +649 -0
- package/README.zh-CN.md +623 -0
- package/THIRD_PARTY_NOTICES.md +432 -0
- package/dist/agent/compact.d.ts +4 -0
- package/dist/agent/compact.js +40 -0
- package/dist/agent/compact.js.map +1 -0
- package/dist/agent/loop.d.ts +44 -0
- package/dist/agent/loop.js +262 -0
- package/dist/agent/loop.js.map +1 -0
- package/dist/agent/modes.d.ts +13 -0
- package/dist/agent/modes.js +44 -0
- package/dist/agent/modes.js.map +1 -0
- package/dist/agent/runner.d.ts +37 -0
- package/dist/agent/runner.js +171 -0
- package/dist/agent/runner.js.map +1 -0
- package/dist/agent/session.d.ts +73 -0
- package/dist/agent/session.js +282 -0
- package/dist/agent/session.js.map +1 -0
- package/dist/agent/types.d.ts +86 -0
- package/dist/agent/types.js +26 -0
- package/dist/agent/types.js.map +1 -0
- package/dist/audit/diffStat.d.ts +8 -0
- package/dist/audit/diffStat.js +17 -0
- package/dist/audit/diffStat.js.map +1 -0
- package/dist/audit/hash.d.ts +10 -0
- package/dist/audit/hash.js +33 -0
- package/dist/audit/hash.js.map +1 -0
- package/dist/audit/log.d.ts +147 -0
- package/dist/audit/log.js +163 -0
- package/dist/audit/log.js.map +1 -0
- package/dist/audit/minimize.d.ts +10 -0
- package/dist/audit/minimize.js +61 -0
- package/dist/audit/minimize.js.map +1 -0
- package/dist/audit/report.d.ts +8 -0
- package/dist/audit/report.js +113 -0
- package/dist/audit/report.js.map +1 -0
- package/dist/audit/taps.d.ts +8 -0
- package/dist/audit/taps.js +67 -0
- package/dist/audit/taps.js.map +1 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.js +56 -0
- package/dist/cli.js.map +1 -0
- package/dist/commands/ask.d.ts +3 -0
- package/dist/commands/ask.js +14 -0
- package/dist/commands/ask.js.map +1 -0
- package/dist/commands/chat.d.ts +3 -0
- package/dist/commands/chat.js +148 -0
- package/dist/commands/chat.js.map +1 -0
- package/dist/commands/data.d.ts +2 -0
- package/dist/commands/data.js +65 -0
- package/dist/commands/data.js.map +1 -0
- package/dist/commands/evidence.d.ts +2 -0
- package/dist/commands/evidence.js +50 -0
- package/dist/commands/evidence.js.map +1 -0
- package/dist/commands/init.d.ts +2 -0
- package/dist/commands/init.js +18 -0
- package/dist/commands/init.js.map +1 -0
- package/dist/commands/memory.d.ts +2 -0
- package/dist/commands/memory.js +74 -0
- package/dist/commands/memory.js.map +1 -0
- package/dist/commands/policy.d.ts +2 -0
- package/dist/commands/policy.js +95 -0
- package/dist/commands/policy.js.map +1 -0
- package/dist/commands/provider.d.ts +2 -0
- package/dist/commands/provider.js +130 -0
- package/dist/commands/provider.js.map +1 -0
- package/dist/commands/report.d.ts +2 -0
- package/dist/commands/report.js +47 -0
- package/dist/commands/report.js.map +1 -0
- package/dist/commands/runTool.d.ts +3 -0
- package/dist/commands/runTool.js +41 -0
- package/dist/commands/runTool.js.map +1 -0
- package/dist/commands/scan.d.ts +2 -0
- package/dist/commands/scan.js +15 -0
- package/dist/commands/scan.js.map +1 -0
- package/dist/commands/serve.d.ts +2 -0
- package/dist/commands/serve.js +18 -0
- package/dist/commands/serve.js.map +1 -0
- package/dist/commands/tools.d.ts +3 -0
- package/dist/commands/tools.js +11 -0
- package/dist/commands/tools.js.map +1 -0
- package/dist/commands/trust.d.ts +2 -0
- package/dist/commands/trust.js +16 -0
- package/dist/commands/trust.js.map +1 -0
- package/dist/commands/tui.d.ts +2 -0
- package/dist/commands/tui.js +13 -0
- package/dist/commands/tui.js.map +1 -0
- package/dist/core/context.d.ts +28 -0
- package/dist/core/context.js +29 -0
- package/dist/core/context.js.map +1 -0
- package/dist/core/diffPreview.d.ts +6 -0
- package/dist/core/diffPreview.js +37 -0
- package/dist/core/diffPreview.js.map +1 -0
- package/dist/core/ignorefile.d.ts +1 -0
- package/dist/core/ignorefile.js +14 -0
- package/dist/core/ignorefile.js.map +1 -0
- package/dist/core/permissions.d.ts +3 -0
- package/dist/core/permissions.js +9 -0
- package/dist/core/permissions.js.map +1 -0
- package/dist/core/policy.d.ts +182 -0
- package/dist/core/policy.js +358 -0
- package/dist/core/policy.js.map +1 -0
- package/dist/core/projectScanner.d.ts +12 -0
- package/dist/core/projectScanner.js +85 -0
- package/dist/core/projectScanner.js.map +1 -0
- package/dist/core/subprocessSandbox.d.ts +42 -0
- package/dist/core/subprocessSandbox.js +132 -0
- package/dist/core/subprocessSandbox.js.map +1 -0
- package/dist/core/trust.d.ts +50 -0
- package/dist/core/trust.js +191 -0
- package/dist/core/trust.js.map +1 -0
- package/dist/core/workspace.d.ts +9 -0
- package/dist/core/workspace.js +55 -0
- package/dist/core/workspace.js.map +1 -0
- package/dist/data/archive.d.ts +39 -0
- package/dist/data/archive.js +127 -0
- package/dist/data/archive.js.map +1 -0
- package/dist/evidence/compliance.d.ts +22 -0
- package/dist/evidence/compliance.js +57 -0
- package/dist/evidence/compliance.js.map +1 -0
- package/dist/evidence/pack.d.ts +56 -0
- package/dist/evidence/pack.js +123 -0
- package/dist/evidence/pack.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +8 -0
- package/dist/index.js.map +1 -0
- package/dist/mcp/client.d.ts +45 -0
- package/dist/mcp/client.js +111 -0
- package/dist/mcp/client.js.map +1 -0
- package/dist/mcp/config.d.ts +10 -0
- package/dist/mcp/config.js +18 -0
- package/dist/mcp/config.js.map +1 -0
- package/dist/mcp/governedFetch.d.ts +16 -0
- package/dist/mcp/governedFetch.js +44 -0
- package/dist/mcp/governedFetch.js.map +1 -0
- package/dist/mcp/register.d.ts +26 -0
- package/dist/mcp/register.js +77 -0
- package/dist/mcp/register.js.map +1 -0
- package/dist/memory/importers.d.ts +17 -0
- package/dist/memory/importers.js +186 -0
- package/dist/memory/importers.js.map +1 -0
- package/dist/memory/store.d.ts +71 -0
- package/dist/memory/store.js +251 -0
- package/dist/memory/store.js.map +1 -0
- package/dist/providers/egress.d.ts +2 -0
- package/dist/providers/egress.js +172 -0
- package/dist/providers/egress.js.map +1 -0
- package/dist/providers/localPlanner.d.ts +3 -0
- package/dist/providers/localPlanner.js +21 -0
- package/dist/providers/localPlanner.js.map +1 -0
- package/dist/providers/manager.d.ts +30 -0
- package/dist/providers/manager.js +48 -0
- package/dist/providers/manager.js.map +1 -0
- package/dist/providers/openaiCompatible.d.ts +5 -0
- package/dist/providers/openaiCompatible.js +176 -0
- package/dist/providers/openaiCompatible.js.map +1 -0
- package/dist/providers/pool.d.ts +14 -0
- package/dist/providers/pool.js +59 -0
- package/dist/providers/pool.js.map +1 -0
- package/dist/providers/secrets.d.ts +8 -0
- package/dist/providers/secrets.js +17 -0
- package/dist/providers/secrets.js.map +1 -0
- package/dist/providers/trustedBaseUrls.d.ts +1 -0
- package/dist/providers/trustedBaseUrls.js +49 -0
- package/dist/providers/trustedBaseUrls.js.map +1 -0
- package/dist/providers/types.d.ts +59 -0
- package/dist/providers/types.js +2 -0
- package/dist/providers/types.js.map +1 -0
- package/dist/remediation/cases.d.ts +37 -0
- package/dist/remediation/cases.js +90 -0
- package/dist/remediation/cases.js.map +1 -0
- package/dist/remediation/localScan.d.ts +2 -0
- package/dist/remediation/localScan.js +212 -0
- package/dist/remediation/localScan.js.map +1 -0
- package/dist/remediation/sarif.d.ts +26 -0
- package/dist/remediation/sarif.js +150 -0
- package/dist/remediation/sarif.js.map +1 -0
- package/dist/remediation/worktree.d.ts +11 -0
- package/dist/remediation/worktree.js +90 -0
- package/dist/remediation/worktree.js.map +1 -0
- package/dist/server/configStore.d.ts +59 -0
- package/dist/server/configStore.js +73 -0
- package/dist/server/configStore.js.map +1 -0
- package/dist/server/index.d.ts +17 -0
- package/dist/server/index.js +120 -0
- package/dist/server/index.js.map +1 -0
- package/dist/server/playbookHandler.d.ts +3 -0
- package/dist/server/playbookHandler.js +44 -0
- package/dist/server/playbookHandler.js.map +1 -0
- package/dist/server/routes/config.d.ts +1 -0
- package/dist/server/routes/config.js +184 -0
- package/dist/server/routes/config.js.map +1 -0
- package/dist/server/routes/data.d.ts +1 -0
- package/dist/server/routes/data.js +29 -0
- package/dist/server/routes/data.js.map +1 -0
- package/dist/server/routes/files.d.ts +1 -0
- package/dist/server/routes/files.js +20 -0
- package/dist/server/routes/files.js.map +1 -0
- package/dist/server/routes/git.d.ts +1 -0
- package/dist/server/routes/git.js +29 -0
- package/dist/server/routes/git.js.map +1 -0
- package/dist/server/routes/projects.d.ts +3 -0
- package/dist/server/routes/projects.js +178 -0
- package/dist/server/routes/projects.js.map +1 -0
- package/dist/server/routes/remediation.d.ts +1 -0
- package/dist/server/routes/remediation.js +99 -0
- package/dist/server/routes/remediation.js.map +1 -0
- package/dist/server/routes/sessions.d.ts +1 -0
- package/dist/server/routes/sessions.js +46 -0
- package/dist/server/routes/sessions.js.map +1 -0
- package/dist/server/routes/skills.d.ts +1 -0
- package/dist/server/routes/skills.js +48 -0
- package/dist/server/routes/skills.js.map +1 -0
- package/dist/server/routes/tools.d.ts +1 -0
- package/dist/server/routes/tools.js +12 -0
- package/dist/server/routes/tools.js.map +1 -0
- package/dist/server/security.d.ts +7 -0
- package/dist/server/security.js +128 -0
- package/dist/server/security.js.map +1 -0
- package/dist/server/wsHandler.d.ts +2 -0
- package/dist/server/wsHandler.js +212 -0
- package/dist/server/wsHandler.js.map +1 -0
- package/dist/sessions/journal.d.ts +65 -0
- package/dist/sessions/journal.js +98 -0
- package/dist/sessions/journal.js.map +1 -0
- package/dist/sessions/markdown.d.ts +8 -0
- package/dist/sessions/markdown.js +69 -0
- package/dist/sessions/markdown.js.map +1 -0
- package/dist/sessions/store.d.ts +26 -0
- package/dist/sessions/store.js +136 -0
- package/dist/sessions/store.js.map +1 -0
- package/dist/skills/store.d.ts +24 -0
- package/dist/skills/store.js +215 -0
- package/dist/skills/store.js.map +1 -0
- package/dist/tools/deleteFile.d.ts +8 -0
- package/dist/tools/deleteFile.js +37 -0
- package/dist/tools/deleteFile.js.map +1 -0
- package/dist/tools/editFile.d.ts +10 -0
- package/dist/tools/editFile.js +66 -0
- package/dist/tools/editFile.js.map +1 -0
- package/dist/tools/gitDiff.d.ts +10 -0
- package/dist/tools/gitDiff.js +59 -0
- package/dist/tools/gitDiff.js.map +1 -0
- package/dist/tools/gitStatus.d.ts +5 -0
- package/dist/tools/gitStatus.js +45 -0
- package/dist/tools/gitStatus.js.map +1 -0
- package/dist/tools/listFiles.d.ts +9 -0
- package/dist/tools/listFiles.js +36 -0
- package/dist/tools/listFiles.js.map +1 -0
- package/dist/tools/listRemediationCases.d.ts +8 -0
- package/dist/tools/listRemediationCases.js +23 -0
- package/dist/tools/listRemediationCases.js.map +1 -0
- package/dist/tools/listSkills.d.ts +6 -0
- package/dist/tools/listSkills.js +21 -0
- package/dist/tools/listSkills.js.map +1 -0
- package/dist/tools/memoryDelete.d.ts +8 -0
- package/dist/tools/memoryDelete.js +24 -0
- package/dist/tools/memoryDelete.js.map +1 -0
- package/dist/tools/memoryImport.d.ts +18 -0
- package/dist/tools/memoryImport.js +64 -0
- package/dist/tools/memoryImport.js.map +1 -0
- package/dist/tools/memorySearch.d.ts +13 -0
- package/dist/tools/memorySearch.js +40 -0
- package/dist/tools/memorySearch.js.map +1 -0
- package/dist/tools/memoryUpdate.d.ts +19 -0
- package/dist/tools/memoryUpdate.js +38 -0
- package/dist/tools/memoryUpdate.js.map +1 -0
- package/dist/tools/memoryWrite.d.ts +22 -0
- package/dist/tools/memoryWrite.js +36 -0
- package/dist/tools/memoryWrite.js.map +1 -0
- package/dist/tools/prepareRemediationWorktree.d.ts +8 -0
- package/dist/tools/prepareRemediationWorktree.js +48 -0
- package/dist/tools/prepareRemediationWorktree.js.map +1 -0
- package/dist/tools/projectScripts.d.ts +11 -0
- package/dist/tools/projectScripts.js +64 -0
- package/dist/tools/projectScripts.js.map +1 -0
- package/dist/tools/readFile.d.ts +10 -0
- package/dist/tools/readFile.js +57 -0
- package/dist/tools/readFile.js.map +1 -0
- package/dist/tools/readSkill.d.ts +8 -0
- package/dist/tools/readSkill.js +25 -0
- package/dist/tools/readSkill.js.map +1 -0
- package/dist/tools/registry.d.ts +15 -0
- package/dist/tools/registry.js +121 -0
- package/dist/tools/registry.js.map +1 -0
- package/dist/tools/runCheck.d.ts +17 -0
- package/dist/tools/runCheck.js +125 -0
- package/dist/tools/runCheck.js.map +1 -0
- package/dist/tools/runSecurityScan.d.ts +8 -0
- package/dist/tools/runSecurityScan.js +36 -0
- package/dist/tools/runSecurityScan.js.map +1 -0
- package/dist/tools/searchText.d.ts +11 -0
- package/dist/tools/searchText.js +67 -0
- package/dist/tools/searchText.js.map +1 -0
- package/dist/tools/shell.d.ts +16 -0
- package/dist/tools/shell.js +114 -0
- package/dist/tools/shell.js.map +1 -0
- package/dist/tools/types.d.ts +57 -0
- package/dist/tools/types.js +2 -0
- package/dist/tools/types.js.map +1 -0
- package/dist/tools/writeFile.d.ts +9 -0
- package/dist/tools/writeFile.js +89 -0
- package/dist/tools/writeFile.js.map +1 -0
- package/dist/tui/app.d.ts +8 -0
- package/dist/tui/app.js +178 -0
- package/dist/tui/app.js.map +1 -0
- package/dist/tui/presets.d.ts +13 -0
- package/dist/tui/presets.js +11 -0
- package/dist/tui/presets.js.map +1 -0
- package/dist/tui/render.d.ts +14 -0
- package/dist/tui/render.js +83 -0
- package/dist/tui/render.js.map +1 -0
- package/dist/ui/output.d.ts +4 -0
- package/dist/ui/output.js +21 -0
- package/dist/ui/output.js.map +1 -0
- package/package.json +77 -0
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
/**
|
|
3
|
+
* Org policy — the "可控 / controllable" pillar (see docs/APPROVABILITY-PLAN.md, Epic A1).
|
|
4
|
+
*
|
|
5
|
+
* A company, not the developer, bounds the agent's blast radius. Policy is discovered
|
|
6
|
+
* from two layers and resolved by **narrowing (intersection)**: a repo-committed policy
|
|
7
|
+
* can only ever make the machine-level policy *stricter*, never wider. This is the
|
|
8
|
+
* keystone everyone else reads — `dvalincode trust` reports the resolved policy, the
|
|
9
|
+
* Approval Pack snapshots it, and the tool layer enforces it.
|
|
10
|
+
*
|
|
11
|
+
* Threat model: the agent runs on the developer's own machine, so policy is
|
|
12
|
+
* default-enforced and tamper-*evident* (its hash is recorded in the audit log at
|
|
13
|
+
* run_start), not tamper-*proof* against a hostile local admin. Hard enforcement is the
|
|
14
|
+
* job of the future server-mediated mode (A5).
|
|
15
|
+
*/
|
|
16
|
+
export declare const networkLevels: readonly ["off", "endpoint-only", "on"];
|
|
17
|
+
export type NetworkLevel = (typeof networkLevels)[number];
|
|
18
|
+
export declare const agentModes: readonly ["chat", "cowork", "code"];
|
|
19
|
+
export type AgentMode = (typeof agentModes)[number];
|
|
20
|
+
/** The shape of a policy file as authored. Every field is optional; absent = unrestricted. */
|
|
21
|
+
export declare const orgPolicySchema: z.ZodObject<{
|
|
22
|
+
modes: z.ZodOptional<z.ZodArray<z.ZodEnum<{
|
|
23
|
+
chat: "chat";
|
|
24
|
+
cowork: "cowork";
|
|
25
|
+
code: "code";
|
|
26
|
+
}>>>;
|
|
27
|
+
providers: z.ZodOptional<z.ZodObject<{
|
|
28
|
+
allow: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
29
|
+
}, z.core.$strict>>;
|
|
30
|
+
models: z.ZodOptional<z.ZodObject<{
|
|
31
|
+
allow: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
32
|
+
}, z.core.$strict>>;
|
|
33
|
+
commands: z.ZodOptional<z.ZodObject<{
|
|
34
|
+
allow: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
35
|
+
deny: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
36
|
+
defaultDeny: z.ZodOptional<z.ZodBoolean>;
|
|
37
|
+
}, z.core.$strict>>;
|
|
38
|
+
paths: z.ZodOptional<z.ZodObject<{
|
|
39
|
+
allow: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
40
|
+
deny: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
41
|
+
}, z.core.$strict>>;
|
|
42
|
+
tools: z.ZodOptional<z.ZodObject<{
|
|
43
|
+
deny: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
44
|
+
}, z.core.$strict>>;
|
|
45
|
+
mcp: z.ZodOptional<z.ZodObject<{
|
|
46
|
+
allow: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
47
|
+
}, z.core.$strict>>;
|
|
48
|
+
network: z.ZodOptional<z.ZodEnum<{
|
|
49
|
+
off: "off";
|
|
50
|
+
"endpoint-only": "endpoint-only";
|
|
51
|
+
on: "on";
|
|
52
|
+
}>>;
|
|
53
|
+
maxToolCalls: z.ZodOptional<z.ZodNumber>;
|
|
54
|
+
}, z.core.$strict>;
|
|
55
|
+
export type OrgPolicyInput = z.infer<typeof orgPolicySchema>;
|
|
56
|
+
/** A fully-resolved policy: defaults applied, all sources narrowed together. */
|
|
57
|
+
export type ResolvedPolicy = {
|
|
58
|
+
/** Modes the agent may run in (default: all). */
|
|
59
|
+
modes: AgentMode[];
|
|
60
|
+
/** Provider id allowlist; undefined = any provider. */
|
|
61
|
+
providers: {
|
|
62
|
+
allow?: string[];
|
|
63
|
+
};
|
|
64
|
+
/** Model id allowlist; undefined = any model. */
|
|
65
|
+
models: {
|
|
66
|
+
allow?: string[];
|
|
67
|
+
};
|
|
68
|
+
/** Shell command policy. `allow` (if set) is an allowlist; `deny` always blocks. */
|
|
69
|
+
commands: {
|
|
70
|
+
allow?: string[];
|
|
71
|
+
deny: string[];
|
|
72
|
+
defaultDeny: boolean;
|
|
73
|
+
};
|
|
74
|
+
/** Filesystem path policy, layered on top of .dvalincodeignore. Globs. */
|
|
75
|
+
paths: {
|
|
76
|
+
allow?: string[];
|
|
77
|
+
deny: string[];
|
|
78
|
+
};
|
|
79
|
+
/** Tool-name denylist. */
|
|
80
|
+
tools: {
|
|
81
|
+
deny: string[];
|
|
82
|
+
};
|
|
83
|
+
/** MCP server-id allowlist; undefined = any configured server is permitted. */
|
|
84
|
+
mcp: {
|
|
85
|
+
allow?: string[];
|
|
86
|
+
};
|
|
87
|
+
/** Outbound network posture. */
|
|
88
|
+
network: NetworkLevel;
|
|
89
|
+
/** Hard cap on tool calls per run; undefined = unlimited. */
|
|
90
|
+
maxToolCalls?: number;
|
|
91
|
+
};
|
|
92
|
+
/** The most permissive policy — equivalent to having no policy file at all. */
|
|
93
|
+
export declare function permissivePolicy(): ResolvedPolicy;
|
|
94
|
+
/** A policy decision. When denied, `rule` names the constraint that blocked it. */
|
|
95
|
+
export type Decision = {
|
|
96
|
+
allowed: true;
|
|
97
|
+
} | {
|
|
98
|
+
allowed: false;
|
|
99
|
+
rule: string;
|
|
100
|
+
};
|
|
101
|
+
/**
|
|
102
|
+
* Thrown when the tool layer blocks a call by policy. Carries structured fields so a
|
|
103
|
+
* frontend can render it as a native inline denial (e.g. `⛔ Blocked by policy: …`)
|
|
104
|
+
* rather than a raw error, keeping the UX on par with mainstream coding agents.
|
|
105
|
+
*/
|
|
106
|
+
export declare class PolicyViolationError extends Error {
|
|
107
|
+
readonly tool: string;
|
|
108
|
+
readonly rule: string;
|
|
109
|
+
readonly target: string;
|
|
110
|
+
constructor(tool: string, rule: string, target: string);
|
|
111
|
+
}
|
|
112
|
+
/** Resolve a set of authored policies into one effective policy by narrowing. */
|
|
113
|
+
export declare function resolvePolicy(sources: OrgPolicyInput[]): ResolvedPolicy;
|
|
114
|
+
export declare function checkMode(p: ResolvedPolicy, mode: AgentMode): Decision;
|
|
115
|
+
export declare function checkProvider(p: ResolvedPolicy, provider: string): Decision;
|
|
116
|
+
export declare function checkModel(p: ResolvedPolicy, model: string): Decision;
|
|
117
|
+
export declare function checkTool(p: ResolvedPolicy, toolName: string): Decision;
|
|
118
|
+
export declare function checkMcpServer(p: ResolvedPolicy, serverId: string): Decision;
|
|
119
|
+
/** Is an outbound connection permitted? `isModelEndpoint` flags the configured LLM host. */
|
|
120
|
+
export declare function checkEgress(p: ResolvedPolicy, isModelEndpoint: boolean): Decision;
|
|
121
|
+
export declare function checkCommand(p: ResolvedPolicy, commandLine: string): Decision;
|
|
122
|
+
export declare function checkPath(p: ResolvedPolicy, filePath: string): Decision;
|
|
123
|
+
/** A policy source on disk, with its integrity hash for tamper-evidence. */
|
|
124
|
+
export type PolicySource = {
|
|
125
|
+
/** Layer: machine-level (IT-pushed) or repo-level (team-committed). */
|
|
126
|
+
layer: 'machine' | 'repo';
|
|
127
|
+
path: string;
|
|
128
|
+
present: boolean;
|
|
129
|
+
/** SHA-256 of the raw file content; null when absent. */
|
|
130
|
+
hash: string | null;
|
|
131
|
+
/** Parse/validation error, if the file existed but could not be applied. */
|
|
132
|
+
error?: string;
|
|
133
|
+
};
|
|
134
|
+
/** Resolved policy plus provenance: which files contributed and their hashes. */
|
|
135
|
+
export type LoadedPolicy = {
|
|
136
|
+
policy: ResolvedPolicy;
|
|
137
|
+
sources: PolicySource[];
|
|
138
|
+
/** SHA-256 of the canonicalized resolved policy — recorded at run_start. */
|
|
139
|
+
hash: string;
|
|
140
|
+
};
|
|
141
|
+
/** Machine-level policy path (IT-pushed). Overridable for tests. */
|
|
142
|
+
export declare function machinePolicyPath(): string;
|
|
143
|
+
/** Repo-level policy path (team-committed, narrowing only). */
|
|
144
|
+
export declare function repoPolicyPath(cwd: string): string;
|
|
145
|
+
/** Hash of a resolved policy, for the audit run_start record and `trust`. */
|
|
146
|
+
export declare function policyHash(policy: ResolvedPolicy): string;
|
|
147
|
+
/**
|
|
148
|
+
* Discover and resolve the effective policy for a workspace.
|
|
149
|
+
* Reads the machine layer then the repo layer; narrows them together.
|
|
150
|
+
*/
|
|
151
|
+
export declare function loadPolicy(cwd?: string): LoadedPolicy;
|
|
152
|
+
/** One Zod issue per line — used by `dvalincode policy check` for readable authoring feedback. */
|
|
153
|
+
export declare function formatZodIssues(err: z.ZodError): string[];
|
|
154
|
+
export type PolicyValidationFailure = {
|
|
155
|
+
ok: false;
|
|
156
|
+
kind: 'missing' | 'read' | 'json' | 'schema';
|
|
157
|
+
path: string;
|
|
158
|
+
errors: string[];
|
|
159
|
+
};
|
|
160
|
+
export type PolicyValidationSuccess = {
|
|
161
|
+
ok: true;
|
|
162
|
+
path: string;
|
|
163
|
+
fileHash: string;
|
|
164
|
+
parsed: OrgPolicyInput;
|
|
165
|
+
};
|
|
166
|
+
/** Validate a policy file against `orgPolicySchema` without loading other layers. */
|
|
167
|
+
export declare function validatePolicyFile(file: string): PolicyValidationSuccess | PolicyValidationFailure;
|
|
168
|
+
export type PolicyCheckSuccess = {
|
|
169
|
+
ok: true;
|
|
170
|
+
path: string;
|
|
171
|
+
policy: ResolvedPolicy;
|
|
172
|
+
hash: string;
|
|
173
|
+
sources: PolicySource[];
|
|
174
|
+
/** Set when the machine layer exists but could not be applied (mirrors runtime). */
|
|
175
|
+
machineWarning?: string;
|
|
176
|
+
};
|
|
177
|
+
export type PolicyCheckFailure = PolicyValidationFailure;
|
|
178
|
+
/**
|
|
179
|
+
* Validate `file` and resolve the effective policy after narrowing with the machine layer.
|
|
180
|
+
* The checked file must be valid; a malformed machine policy is skipped with `machineWarning`.
|
|
181
|
+
*/
|
|
182
|
+
export declare function resolveCheckedPolicy(file: string, cwd?: string): PolicyCheckSuccess | PolicyCheckFailure;
|
|
@@ -0,0 +1,358 @@
|
|
|
1
|
+
import { readFileSync, existsSync } from 'node:fs';
|
|
2
|
+
import os from 'node:os';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import { z } from 'zod';
|
|
5
|
+
import { sha256, canonicalJSON } from '../audit/hash.js';
|
|
6
|
+
/**
|
|
7
|
+
* Org policy — the "可控 / controllable" pillar (see docs/APPROVABILITY-PLAN.md, Epic A1).
|
|
8
|
+
*
|
|
9
|
+
* A company, not the developer, bounds the agent's blast radius. Policy is discovered
|
|
10
|
+
* from two layers and resolved by **narrowing (intersection)**: a repo-committed policy
|
|
11
|
+
* can only ever make the machine-level policy *stricter*, never wider. This is the
|
|
12
|
+
* keystone everyone else reads — `dvalincode trust` reports the resolved policy, the
|
|
13
|
+
* Approval Pack snapshots it, and the tool layer enforces it.
|
|
14
|
+
*
|
|
15
|
+
* Threat model: the agent runs on the developer's own machine, so policy is
|
|
16
|
+
* default-enforced and tamper-*evident* (its hash is recorded in the audit log at
|
|
17
|
+
* run_start), not tamper-*proof* against a hostile local admin. Hard enforcement is the
|
|
18
|
+
* job of the future server-mediated mode (A5).
|
|
19
|
+
*/
|
|
20
|
+
export const networkLevels = ['off', 'endpoint-only', 'on'];
|
|
21
|
+
export const agentModes = ['chat', 'cowork', 'code'];
|
|
22
|
+
/** Restrictiveness rank — lower is stricter. Used to pick the most restrictive level. */
|
|
23
|
+
const NETWORK_RANK = { off: 0, 'endpoint-only': 1, on: 2 };
|
|
24
|
+
/** The shape of a policy file as authored. Every field is optional; absent = unrestricted. */
|
|
25
|
+
export const orgPolicySchema = z
|
|
26
|
+
.object({
|
|
27
|
+
modes: z.array(z.enum(agentModes)).optional(),
|
|
28
|
+
providers: z.object({ allow: z.array(z.string()).optional() }).strict().optional(),
|
|
29
|
+
models: z.object({ allow: z.array(z.string()).optional() }).strict().optional(),
|
|
30
|
+
commands: z
|
|
31
|
+
.object({
|
|
32
|
+
allow: z.array(z.string()).optional(),
|
|
33
|
+
deny: z.array(z.string()).optional(),
|
|
34
|
+
defaultDeny: z.boolean().optional(),
|
|
35
|
+
})
|
|
36
|
+
.strict()
|
|
37
|
+
.optional(),
|
|
38
|
+
paths: z
|
|
39
|
+
.object({
|
|
40
|
+
allow: z.array(z.string()).optional(),
|
|
41
|
+
deny: z.array(z.string()).optional(),
|
|
42
|
+
})
|
|
43
|
+
.strict()
|
|
44
|
+
.optional(),
|
|
45
|
+
tools: z.object({ deny: z.array(z.string()).optional() }).strict().optional(),
|
|
46
|
+
mcp: z.object({ allow: z.array(z.string()).optional() }).strict().optional(),
|
|
47
|
+
network: z.enum(networkLevels).optional(),
|
|
48
|
+
maxToolCalls: z.number().int().positive().optional(),
|
|
49
|
+
})
|
|
50
|
+
.strict();
|
|
51
|
+
/** The most permissive policy — equivalent to having no policy file at all. */
|
|
52
|
+
export function permissivePolicy() {
|
|
53
|
+
return {
|
|
54
|
+
modes: [...agentModes],
|
|
55
|
+
providers: {},
|
|
56
|
+
models: {},
|
|
57
|
+
commands: { deny: [], defaultDeny: false },
|
|
58
|
+
paths: { deny: [] },
|
|
59
|
+
tools: { deny: [] },
|
|
60
|
+
mcp: {},
|
|
61
|
+
network: 'on',
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Thrown when the tool layer blocks a call by policy. Carries structured fields so a
|
|
66
|
+
* frontend can render it as a native inline denial (e.g. `⛔ Blocked by policy: …`)
|
|
67
|
+
* rather than a raw error, keeping the UX on par with mainstream coding agents.
|
|
68
|
+
*/
|
|
69
|
+
export class PolicyViolationError extends Error {
|
|
70
|
+
tool;
|
|
71
|
+
rule;
|
|
72
|
+
target;
|
|
73
|
+
constructor(tool, rule, target) {
|
|
74
|
+
super(`Blocked by policy: ${rule}`);
|
|
75
|
+
this.name = 'PolicyViolationError';
|
|
76
|
+
this.tool = tool;
|
|
77
|
+
this.rule = rule;
|
|
78
|
+
this.target = target;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
const ALLOW = { allowed: true };
|
|
82
|
+
const deny = (rule) => ({ allowed: false, rule });
|
|
83
|
+
// ── Resolution (narrowing) ────────────────────────────────────────────────────
|
|
84
|
+
// Every combinator only ever *restricts*. Order of sources is therefore irrelevant
|
|
85
|
+
// to safety: a developer-supplied source can never widen an IT-supplied one.
|
|
86
|
+
// List-valued fields carry set semantics, so every combinator returns a sorted result.
|
|
87
|
+
// This makes the resolved policy canonical: its hash is independent of source order,
|
|
88
|
+
// which is exactly what a tamper-evidence hash needs.
|
|
89
|
+
function intersectList(a, b) {
|
|
90
|
+
const set = new Set(b);
|
|
91
|
+
return a.filter(x => set.has(x)).sort();
|
|
92
|
+
}
|
|
93
|
+
/** Intersect two allowlists where "undefined" means "no restriction (all)". */
|
|
94
|
+
function intersectAllow(a, b) {
|
|
95
|
+
if (a === undefined)
|
|
96
|
+
return b ? [...b].sort() : undefined;
|
|
97
|
+
if (b === undefined)
|
|
98
|
+
return [...a].sort();
|
|
99
|
+
return intersectList(a, b);
|
|
100
|
+
}
|
|
101
|
+
function union(a, b) {
|
|
102
|
+
return [...new Set([...a, ...(b ?? [])])].sort();
|
|
103
|
+
}
|
|
104
|
+
function moreRestrictiveNetwork(a, b) {
|
|
105
|
+
return NETWORK_RANK[a] <= NETWORK_RANK[b] ? a : b;
|
|
106
|
+
}
|
|
107
|
+
function minDefined(a, b) {
|
|
108
|
+
if (a === undefined)
|
|
109
|
+
return b;
|
|
110
|
+
if (b === undefined)
|
|
111
|
+
return a;
|
|
112
|
+
return Math.min(a, b);
|
|
113
|
+
}
|
|
114
|
+
/** Narrow a resolved policy by one authored source. Result is never wider than `base`. */
|
|
115
|
+
function narrow(base, next) {
|
|
116
|
+
return {
|
|
117
|
+
modes: next.modes ? intersectList(base.modes, next.modes) : base.modes,
|
|
118
|
+
providers: { allow: intersectAllow(base.providers.allow, next.providers?.allow) },
|
|
119
|
+
models: { allow: intersectAllow(base.models.allow, next.models?.allow) },
|
|
120
|
+
commands: {
|
|
121
|
+
allow: intersectAllow(base.commands.allow, next.commands?.allow),
|
|
122
|
+
deny: union(base.commands.deny, next.commands?.deny),
|
|
123
|
+
defaultDeny: base.commands.defaultDeny || (next.commands?.defaultDeny ?? false),
|
|
124
|
+
},
|
|
125
|
+
paths: {
|
|
126
|
+
allow: intersectAllow(base.paths.allow, next.paths?.allow),
|
|
127
|
+
deny: union(base.paths.deny, next.paths?.deny),
|
|
128
|
+
},
|
|
129
|
+
tools: { deny: union(base.tools.deny, next.tools?.deny) },
|
|
130
|
+
mcp: { allow: intersectAllow(base.mcp.allow, next.mcp?.allow) },
|
|
131
|
+
network: next.network ? moreRestrictiveNetwork(base.network, next.network) : base.network,
|
|
132
|
+
maxToolCalls: minDefined(base.maxToolCalls, next.maxToolCalls),
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
/** Resolve a set of authored policies into one effective policy by narrowing. */
|
|
136
|
+
export function resolvePolicy(sources) {
|
|
137
|
+
return sources.reduce(narrow, permissivePolicy());
|
|
138
|
+
}
|
|
139
|
+
// ── Decision functions (enforced by the tool layer in A2) ───────────────────────
|
|
140
|
+
export function checkMode(p, mode) {
|
|
141
|
+
return p.modes.includes(mode) ? ALLOW : deny(`mode "${mode}" is not permitted by policy`);
|
|
142
|
+
}
|
|
143
|
+
export function checkProvider(p, provider) {
|
|
144
|
+
if (!p.providers.allow)
|
|
145
|
+
return ALLOW;
|
|
146
|
+
return p.providers.allow.includes(provider) ? ALLOW : deny(`provider "${provider}" is not in the allowlist`);
|
|
147
|
+
}
|
|
148
|
+
export function checkModel(p, model) {
|
|
149
|
+
if (!p.models.allow)
|
|
150
|
+
return ALLOW;
|
|
151
|
+
return p.models.allow.includes(model) ? ALLOW : deny(`model "${model}" is not in the allowlist`);
|
|
152
|
+
}
|
|
153
|
+
export function checkTool(p, toolName) {
|
|
154
|
+
return p.tools.deny.includes(toolName) ? deny(`tool "${toolName}" is denied by policy`) : ALLOW;
|
|
155
|
+
}
|
|
156
|
+
export function checkMcpServer(p, serverId) {
|
|
157
|
+
if (!p.mcp.allow)
|
|
158
|
+
return ALLOW;
|
|
159
|
+
return p.mcp.allow.includes(serverId) ? ALLOW : deny(`MCP server "${serverId}" is not in the allowlist`);
|
|
160
|
+
}
|
|
161
|
+
/** Is an outbound connection permitted? `isModelEndpoint` flags the configured LLM host. */
|
|
162
|
+
export function checkEgress(p, isModelEndpoint) {
|
|
163
|
+
if (p.network === 'on')
|
|
164
|
+
return ALLOW;
|
|
165
|
+
if (p.network === 'off')
|
|
166
|
+
return deny('network egress is disabled by policy (network: off)');
|
|
167
|
+
return isModelEndpoint ? ALLOW : deny('only the configured model endpoint is reachable (network: endpoint-only)');
|
|
168
|
+
}
|
|
169
|
+
export function checkCommand(p, commandLine) {
|
|
170
|
+
for (const pattern of p.commands.deny) {
|
|
171
|
+
if (safeMatch(pattern, commandLine))
|
|
172
|
+
return deny(`command matches denylist: /${pattern}/`);
|
|
173
|
+
}
|
|
174
|
+
if (p.commands.allow) {
|
|
175
|
+
const ok = p.commands.allow.some(pattern => safeMatch(pattern, commandLine));
|
|
176
|
+
if (!ok)
|
|
177
|
+
return deny('command is not in the allowlist');
|
|
178
|
+
}
|
|
179
|
+
else if (p.commands.defaultDeny) {
|
|
180
|
+
return deny('command blocked by default-deny (no allowlist match)');
|
|
181
|
+
}
|
|
182
|
+
return ALLOW;
|
|
183
|
+
}
|
|
184
|
+
export function checkPath(p, filePath) {
|
|
185
|
+
const norm = filePath.replace(/\\/g, '/');
|
|
186
|
+
for (const glob of p.paths.deny) {
|
|
187
|
+
if (globToRegExp(glob).test(norm))
|
|
188
|
+
return deny(`path is denied by policy: ${glob}`);
|
|
189
|
+
}
|
|
190
|
+
if (p.paths.allow) {
|
|
191
|
+
const ok = p.paths.allow.some(glob => globToRegExp(glob).test(norm));
|
|
192
|
+
if (!ok)
|
|
193
|
+
return deny('path is outside the policy allowlist');
|
|
194
|
+
}
|
|
195
|
+
return ALLOW;
|
|
196
|
+
}
|
|
197
|
+
/** Compile a command pattern to a RegExp; a malformed pattern never matches. */
|
|
198
|
+
function safeMatch(pattern, value) {
|
|
199
|
+
try {
|
|
200
|
+
return new RegExp(pattern).test(value);
|
|
201
|
+
}
|
|
202
|
+
catch {
|
|
203
|
+
return false;
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
/** Minimal glob → RegExp supporting `**`, `*`, and `?`. Anchored full-string match. */
|
|
207
|
+
function globToRegExp(glob) {
|
|
208
|
+
let re = '';
|
|
209
|
+
for (let i = 0; i < glob.length; i++) {
|
|
210
|
+
const c = glob[i];
|
|
211
|
+
if (c === '*') {
|
|
212
|
+
if (glob[i + 1] === '*') {
|
|
213
|
+
re += '.*';
|
|
214
|
+
i++;
|
|
215
|
+
}
|
|
216
|
+
else {
|
|
217
|
+
re += '[^/]*';
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
else if (c === '?') {
|
|
221
|
+
re += '[^/]';
|
|
222
|
+
}
|
|
223
|
+
else {
|
|
224
|
+
re += c.replace(/[.+^${}()|[\]\\]/g, '\\$&');
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
return new RegExp(`^${re}$`);
|
|
228
|
+
}
|
|
229
|
+
/** Machine-level policy path (IT-pushed). Overridable for tests. */
|
|
230
|
+
export function machinePolicyPath() {
|
|
231
|
+
return process.env.DVALINCODE_POLICY_FILE ?? path.join(os.homedir(), '.dvalincode', 'policy.json');
|
|
232
|
+
}
|
|
233
|
+
/** Repo-level policy path (team-committed, narrowing only). */
|
|
234
|
+
export function repoPolicyPath(cwd) {
|
|
235
|
+
return path.join(cwd, 'dvalin.policy.json');
|
|
236
|
+
}
|
|
237
|
+
/** Hash of a resolved policy, for the audit run_start record and `trust`. */
|
|
238
|
+
export function policyHash(policy) {
|
|
239
|
+
return sha256(canonicalJSON(policy));
|
|
240
|
+
}
|
|
241
|
+
function readSource(layer, file) {
|
|
242
|
+
if (!existsSync(file)) {
|
|
243
|
+
return { source: { layer, path: file, present: false, hash: null } };
|
|
244
|
+
}
|
|
245
|
+
let raw;
|
|
246
|
+
try {
|
|
247
|
+
raw = readFileSync(file, 'utf8');
|
|
248
|
+
}
|
|
249
|
+
catch (err) {
|
|
250
|
+
return { source: { layer, path: file, present: true, hash: null, error: errMsg(err) } };
|
|
251
|
+
}
|
|
252
|
+
const hash = sha256(raw);
|
|
253
|
+
try {
|
|
254
|
+
const parsed = orgPolicySchema.parse(JSON.parse(raw));
|
|
255
|
+
return { source: { layer, path: file, present: true, hash }, parsed };
|
|
256
|
+
}
|
|
257
|
+
catch (err) {
|
|
258
|
+
// Fail-safe: a malformed policy is NOT silently treated as "allow everything".
|
|
259
|
+
// It is skipped and the error surfaced loudly via run_start / `trust` so the
|
|
260
|
+
// gatekeeper sees that a policy was intended but did not apply.
|
|
261
|
+
return { source: { layer, path: file, present: true, hash, error: errMsg(err) } };
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
/**
|
|
265
|
+
* Discover and resolve the effective policy for a workspace.
|
|
266
|
+
* Reads the machine layer then the repo layer; narrows them together.
|
|
267
|
+
*/
|
|
268
|
+
export function loadPolicy(cwd = process.cwd()) {
|
|
269
|
+
const results = [
|
|
270
|
+
readSource('machine', machinePolicyPath()),
|
|
271
|
+
readSource('repo', repoPolicyPath(cwd)),
|
|
272
|
+
];
|
|
273
|
+
const inputs = results.flatMap(r => (r.parsed ? [r.parsed] : []));
|
|
274
|
+
const policy = resolvePolicy(inputs);
|
|
275
|
+
return {
|
|
276
|
+
policy,
|
|
277
|
+
sources: results.map(r => r.source),
|
|
278
|
+
hash: policyHash(policy),
|
|
279
|
+
};
|
|
280
|
+
}
|
|
281
|
+
/** One Zod issue per line — used by `dvalincode policy check` for readable authoring feedback. */
|
|
282
|
+
export function formatZodIssues(err) {
|
|
283
|
+
return err.issues.map(i => {
|
|
284
|
+
const field = i.path.length ? i.path.join('.') : '(root)';
|
|
285
|
+
return `${field}: ${i.message}`;
|
|
286
|
+
});
|
|
287
|
+
}
|
|
288
|
+
/** Validate a policy file against `orgPolicySchema` without loading other layers. */
|
|
289
|
+
export function validatePolicyFile(file) {
|
|
290
|
+
const resolved = path.resolve(file);
|
|
291
|
+
if (!existsSync(resolved)) {
|
|
292
|
+
return { ok: false, kind: 'missing', path: resolved, errors: ['file does not exist'] };
|
|
293
|
+
}
|
|
294
|
+
let raw;
|
|
295
|
+
try {
|
|
296
|
+
raw = readFileSync(resolved, 'utf8');
|
|
297
|
+
}
|
|
298
|
+
catch (err) {
|
|
299
|
+
return { ok: false, kind: 'read', path: resolved, errors: [errMsg(err)] };
|
|
300
|
+
}
|
|
301
|
+
let json;
|
|
302
|
+
try {
|
|
303
|
+
json = JSON.parse(raw);
|
|
304
|
+
}
|
|
305
|
+
catch (err) {
|
|
306
|
+
return {
|
|
307
|
+
ok: false,
|
|
308
|
+
kind: 'json',
|
|
309
|
+
path: resolved,
|
|
310
|
+
errors: [err instanceof Error ? err.message : String(err)],
|
|
311
|
+
};
|
|
312
|
+
}
|
|
313
|
+
const parsed = orgPolicySchema.safeParse(json);
|
|
314
|
+
if (!parsed.success) {
|
|
315
|
+
return { ok: false, kind: 'schema', path: resolved, errors: formatZodIssues(parsed.error) };
|
|
316
|
+
}
|
|
317
|
+
return { ok: true, path: resolved, fileHash: sha256(raw), parsed: parsed.data };
|
|
318
|
+
}
|
|
319
|
+
/**
|
|
320
|
+
* Validate `file` and resolve the effective policy after narrowing with the machine layer.
|
|
321
|
+
* The checked file must be valid; a malformed machine policy is skipped with `machineWarning`.
|
|
322
|
+
*/
|
|
323
|
+
export function resolveCheckedPolicy(file, cwd = process.cwd()) {
|
|
324
|
+
const resolved = path.resolve(cwd, file);
|
|
325
|
+
const validation = validatePolicyFile(resolved);
|
|
326
|
+
if (!validation.ok)
|
|
327
|
+
return validation;
|
|
328
|
+
const machinePath = path.resolve(machinePolicyPath());
|
|
329
|
+
const machine = readSource('machine', machinePath);
|
|
330
|
+
const inputs = [];
|
|
331
|
+
if (machine.parsed && resolved !== machinePath)
|
|
332
|
+
inputs.push(machine.parsed);
|
|
333
|
+
inputs.push(validation.parsed);
|
|
334
|
+
const policy = resolvePolicy(inputs);
|
|
335
|
+
const sources = [];
|
|
336
|
+
if (resolved !== machinePath)
|
|
337
|
+
sources.push(machine.source);
|
|
338
|
+
sources.push({
|
|
339
|
+
layer: resolved === machinePath ? 'machine' : 'repo',
|
|
340
|
+
path: resolved,
|
|
341
|
+
present: true,
|
|
342
|
+
hash: validation.fileHash,
|
|
343
|
+
});
|
|
344
|
+
return {
|
|
345
|
+
ok: true,
|
|
346
|
+
path: resolved,
|
|
347
|
+
policy,
|
|
348
|
+
hash: policyHash(policy),
|
|
349
|
+
sources,
|
|
350
|
+
machineWarning: machine.source.error,
|
|
351
|
+
};
|
|
352
|
+
}
|
|
353
|
+
function errMsg(err) {
|
|
354
|
+
if (err instanceof z.ZodError)
|
|
355
|
+
return formatZodIssues(err).join('; ');
|
|
356
|
+
return err instanceof Error ? err.message : String(err);
|
|
357
|
+
}
|
|
358
|
+
//# sourceMappingURL=policy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"policy.js","sourceRoot":"","sources":["../../src/core/policy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACnD,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAEzD;;;;;;;;;;;;;GAaG;AAEH,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,KAAK,EAAE,eAAe,EAAE,IAAI,CAAU,CAAC;AAGrE,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,MAAM,EAAE,QAAQ,EAAE,MAAM,CAAU,CAAC;AAG9D,yFAAyF;AACzF,MAAM,YAAY,GAAiC,EAAE,GAAG,EAAE,CAAC,EAAE,eAAe,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC;AAEzF,8FAA8F;AAC9F,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC;KAC7B,MAAM,CAAC;IACN,KAAK,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,QAAQ,EAAE;IAC7C,SAAS,EAAE,CAAC,CAAC,MAAM,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAClF,MAAM,EAAE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C,CAAC;AAC1D,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export type ProjectSummary = {
|
|
2
|
+
root: string;
|
|
3
|
+
fileCount: number;
|
|
4
|
+
directories: string[];
|
|
5
|
+
topExtensions: Array<{
|
|
6
|
+
extension: string;
|
|
7
|
+
count: number;
|
|
8
|
+
}>;
|
|
9
|
+
packageManagers: string[];
|
|
10
|
+
signals: string[];
|
|
11
|
+
};
|
|
12
|
+
export declare function scanProject(root: string): Promise<ProjectSummary>;
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { readFile } from 'node:fs/promises';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import fg from 'fast-glob';
|
|
4
|
+
const DEFAULT_IGNORES = [
|
|
5
|
+
'**/.git/**',
|
|
6
|
+
'**/node_modules/**',
|
|
7
|
+
'**/dist/**',
|
|
8
|
+
'**/build/**',
|
|
9
|
+
'**/coverage/**',
|
|
10
|
+
'**/.next/**',
|
|
11
|
+
'**/.cache/**',
|
|
12
|
+
];
|
|
13
|
+
export async function scanProject(root) {
|
|
14
|
+
const cwd = path.resolve(root);
|
|
15
|
+
const files = await fg('**/*', {
|
|
16
|
+
cwd,
|
|
17
|
+
dot: true,
|
|
18
|
+
onlyFiles: true,
|
|
19
|
+
ignore: DEFAULT_IGNORES,
|
|
20
|
+
followSymbolicLinks: false,
|
|
21
|
+
});
|
|
22
|
+
const directories = [...new Set(files.map(file => path.dirname(file)).filter(dir => dir !== '.'))]
|
|
23
|
+
.sort()
|
|
24
|
+
.slice(0, 20);
|
|
25
|
+
const extensionCounts = new Map();
|
|
26
|
+
for (const file of files) {
|
|
27
|
+
const extension = path.extname(file).replace(/^\./, '') || '[none]';
|
|
28
|
+
extensionCounts.set(extension, (extensionCounts.get(extension) ?? 0) + 1);
|
|
29
|
+
}
|
|
30
|
+
const topExtensions = [...extensionCounts.entries()]
|
|
31
|
+
.map(([extension, count]) => ({ extension, count }))
|
|
32
|
+
.sort((a, b) => b.count - a.count || a.extension.localeCompare(b.extension))
|
|
33
|
+
.slice(0, 10);
|
|
34
|
+
return {
|
|
35
|
+
root: cwd,
|
|
36
|
+
fileCount: files.length,
|
|
37
|
+
directories,
|
|
38
|
+
topExtensions,
|
|
39
|
+
packageManagers: detectPackageManagers(files),
|
|
40
|
+
signals: await detectProjectSignals(cwd, files),
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
function detectPackageManagers(files) {
|
|
44
|
+
const managers = [];
|
|
45
|
+
if (files.includes('package-lock.json'))
|
|
46
|
+
managers.push('npm');
|
|
47
|
+
if (files.includes('pnpm-lock.yaml'))
|
|
48
|
+
managers.push('pnpm');
|
|
49
|
+
if (files.includes('yarn.lock'))
|
|
50
|
+
managers.push('yarn');
|
|
51
|
+
if (files.includes('bun.lockb') || files.includes('bun.lock'))
|
|
52
|
+
managers.push('bun');
|
|
53
|
+
return managers;
|
|
54
|
+
}
|
|
55
|
+
async function detectProjectSignals(cwd, files) {
|
|
56
|
+
const signals = [];
|
|
57
|
+
if (files.includes('package.json')) {
|
|
58
|
+
signals.push('Node.js package');
|
|
59
|
+
const packageJson = await readTextFile(path.join(cwd, 'package.json'));
|
|
60
|
+
if (packageJson?.includes('"typescript"'))
|
|
61
|
+
signals.push('TypeScript');
|
|
62
|
+
if (packageJson?.includes('"vitest"'))
|
|
63
|
+
signals.push('Vitest tests');
|
|
64
|
+
if (packageJson?.includes('"react"'))
|
|
65
|
+
signals.push('React');
|
|
66
|
+
}
|
|
67
|
+
if (files.includes('tsconfig.json'))
|
|
68
|
+
signals.push('TypeScript config');
|
|
69
|
+
if (files.includes('Cargo.toml'))
|
|
70
|
+
signals.push('Rust package');
|
|
71
|
+
if (files.includes('pyproject.toml'))
|
|
72
|
+
signals.push('Python package');
|
|
73
|
+
if (files.includes('go.mod'))
|
|
74
|
+
signals.push('Go module');
|
|
75
|
+
return signals;
|
|
76
|
+
}
|
|
77
|
+
async function readTextFile(filePath) {
|
|
78
|
+
try {
|
|
79
|
+
return await readFile(filePath, 'utf8');
|
|
80
|
+
}
|
|
81
|
+
catch {
|
|
82
|
+
return null;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
//# sourceMappingURL=projectScanner.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"projectScanner.js","sourceRoot":"","sources":["../../src/core/projectScanner.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,MAAM,WAAW,CAAC;AAE3B,MAAM,eAAe,GAAG;IACtB,YAAY;IACZ,oBAAoB;IACpB,YAAY;IACZ,aAAa;IACb,gBAAgB;IAChB,aAAa;IACb,cAAc;CACf,CAAC;AAWF,MAAM,CAAC,KAAK,UAAU,WAAW,CAAC,IAAY;IAC5C,MAAM,GAAG,GAAG,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IAC/B,MAAM,KAAK,GAAG,MAAM,EAAE,CAAC,MAAM,EAAE;QAC7B,GAAG;QACH,GAAG,EAAE,IAAI;QACT,SAAS,EAAE,IAAI;QACf,MAAM,EAAE,eAAe;QACvB,mBAAmB,EAAE,KAAK;KAC3B,CAAC,CAAC;IAEH,MAAM,WAAW,GAAG,CAAC,GAAG,IAAI,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,GAAG,CAAC,CAAC,CAAC;SAC/F,IAAI,EAAE;SACN,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;IAEhB,MAAM,eAAe,GAAG,IAAI,GAAG,EAAkB,CAAC;IAClD,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,MAAM,SAAS,GAAG,IAAI,CAAC,OAAO,CAAC,IAAI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