@dsh-cc/permission-rules 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.
Files changed (65) hide show
  1. package/LICENSE +201 -0
  2. package/README.i18n.yaml +6 -0
  3. package/README.md +86 -0
  4. package/README.zh.md +86 -0
  5. package/lib/approval-listener.d.ts +50 -0
  6. package/lib/approval-listener.d.ts.map +1 -0
  7. package/lib/approval-listener.js +58 -0
  8. package/lib/approval-listener.js.map +1 -0
  9. package/lib/auto-stage.d.ts +138 -0
  10. package/lib/auto-stage.d.ts.map +1 -0
  11. package/lib/auto-stage.js +284 -0
  12. package/lib/auto-stage.js.map +1 -0
  13. package/lib/classifier.d.ts +57 -0
  14. package/lib/classifier.d.ts.map +1 -0
  15. package/lib/classifier.js +129 -0
  16. package/lib/classifier.js.map +1 -0
  17. package/lib/decide.d.ts +80 -0
  18. package/lib/decide.d.ts.map +1 -0
  19. package/lib/decide.js +127 -0
  20. package/lib/decide.js.map +1 -0
  21. package/lib/domain.d.ts +46 -0
  22. package/lib/domain.d.ts.map +1 -0
  23. package/lib/domain.js +103 -0
  24. package/lib/domain.js.map +1 -0
  25. package/lib/evaluate.d.ts +32 -0
  26. package/lib/evaluate.d.ts.map +1 -0
  27. package/lib/evaluate.js +176 -0
  28. package/lib/evaluate.js.map +1 -0
  29. package/lib/index.d.ts +123 -0
  30. package/lib/index.d.ts.map +1 -0
  31. package/lib/index.js +380 -0
  32. package/lib/index.js.map +1 -0
  33. package/lib/invariant.d.ts +28 -0
  34. package/lib/invariant.d.ts.map +1 -0
  35. package/lib/invariant.js +54 -0
  36. package/lib/invariant.js.map +1 -0
  37. package/lib/llm-classifier.d.ts +107 -0
  38. package/lib/llm-classifier.d.ts.map +1 -0
  39. package/lib/llm-classifier.js +231 -0
  40. package/lib/llm-classifier.js.map +1 -0
  41. package/lib/matchers.d.ts +18 -0
  42. package/lib/matchers.d.ts.map +1 -0
  43. package/lib/matchers.js +43 -0
  44. package/lib/matchers.js.map +1 -0
  45. package/lib/mode.d.ts +91 -0
  46. package/lib/mode.d.ts.map +1 -0
  47. package/lib/mode.js +133 -0
  48. package/lib/mode.js.map +1 -0
  49. package/lib/parser.d.ts +91 -0
  50. package/lib/parser.d.ts.map +1 -0
  51. package/lib/parser.js +282 -0
  52. package/lib/parser.js.map +1 -0
  53. package/lib/session-allowlist.d.ts +76 -0
  54. package/lib/session-allowlist.d.ts.map +1 -0
  55. package/lib/session-allowlist.js +122 -0
  56. package/lib/session-allowlist.js.map +1 -0
  57. package/lib/settings-schema.d.ts +99 -0
  58. package/lib/settings-schema.d.ts.map +1 -0
  59. package/lib/settings-schema.js +64 -0
  60. package/lib/settings-schema.js.map +1 -0
  61. package/lib/types.d.ts +150 -0
  62. package/lib/types.d.ts.map +1 -0
  63. package/lib/types.js +33 -0
  64. package/lib/types.js.map +1 -0
  65. package/package.json +71 -0
@@ -0,0 +1,64 @@
1
+ /**
2
+ * Plugin-facing settings/config shapes for the permission-rule engine: the
3
+ * local `permissions` section schema (hand-mirroring the shared cascade
4
+ * schemas — no cross-package dependency), the Config-provided rule set, and
5
+ * the plugin Config schema. Kept separate from the service so the plugin
6
+ * entry stays under the file-size gate.
7
+ *
8
+ * @module @dsh-cc/permission-rules/settings-schema
9
+ */
10
+ import z from '@deepseek-ai/schemastery';
11
+ import { PERMISSION_MODES, SOURCE_PRIORITY } from "./types.js";
12
+ /** The standard file-edit tool set, applied when {@link Config.fileEditTools} is omitted. */
13
+ export const DEFAULT_FILE_EDIT_TOOLS = ['edit', 'write', 'multi_edit', 'notebook_edit', 'str_replace_editor'];
14
+ /** The standard read-only tool set, applied when {@link Config.readOnlyTools} is omitted. */
15
+ export const DEFAULT_READ_ONLY_TOOLS = ['read', 'glob', 'grep', 'search', 'web_fetch', 'web_search'];
16
+ /** The classifier sub-object schema: defaults apply only when the object is present. */
17
+ const autoModeClassifierSchema = z.object({
18
+ enabled: z.boolean().default(false),
19
+ route: z.string().default('haiku'),
20
+ timeoutMs: z.number().default(8000),
21
+ cacheMaxEntries: z.number().default(256),
22
+ });
23
+ /** The shared settings schema (Config-facing and settings-provider-facing). */
24
+ export function permissionSettingsSchema() {
25
+ return z.object({
26
+ allow: z.array(z.string()),
27
+ deny: z.array(z.string()),
28
+ ask: z.array(z.string()),
29
+ defaultMode: z.union(PERMISSION_MODES),
30
+ disableBypassPermissionsMode: z.union(['disable']),
31
+ additionalDirectories: z.array(z.string()),
32
+ protectedFiles: z.array(z.string()),
33
+ dangerousPatterns: z.array(z.string()),
34
+ // Union with `undefined` keeps an absent `autoMode` key absent — no
35
+ // defaults materialized, the classifier stays disarmed (mirrors the
36
+ // shared AutoModeSchema union-with-undefined idiom).
37
+ autoMode: z.union([
38
+ z.object({
39
+ soft_deny: z.union([z.array(z.string()), z.const(undefined)]),
40
+ classifier: z.union([autoModeClassifierSchema, z.const(undefined)]),
41
+ }),
42
+ z.const(undefined),
43
+ ]),
44
+ });
45
+ }
46
+ /** The plugin Config schema (defaults applied by schemastery). */
47
+ export const ConfigSchema = z.object({
48
+ rules: z.object({
49
+ allow: z.array(z.string()),
50
+ deny: z.array(z.string()),
51
+ ask: z.array(z.string()),
52
+ bypassImmune: z.array(z.string()),
53
+ }),
54
+ settingsNamespace: z.string().default('permissions'),
55
+ settingsSource: z.union(SOURCE_PRIORITY).default('userSettings'),
56
+ defaultMode: z.union(PERMISSION_MODES).default('default'),
57
+ bashToolName: z.string().default('Bash'),
58
+ fileEditTools: z.array(z.string()).default(DEFAULT_FILE_EDIT_TOOLS),
59
+ readOnlyTools: z.array(z.string()).default(DEFAULT_READ_ONLY_TOOLS),
60
+ exemptSandboxedBashFromToolAsk: z.boolean().default(false),
61
+ disableBypassPermissionsMode: z.boolean().default(false),
62
+ classifierEnabled: z.boolean().default(true),
63
+ });
64
+ //# sourceMappingURL=settings-schema.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"settings-schema.js","sourceRoot":"","sources":["../src/settings-schema.ts"],"names":[],"mapp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Ac,CAAC;IAC1F,WAAW,EAAE,CAAC,CAAC,KAAK,CAAC,gBAAoC,CAAC,CAAC,OAAO,CAAC,SAAS,CAAC;IAC7E,YAAY,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,OAAO,CAAC,MAAM,CAAC;IACxC,aAAa,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC,OAAO,CAAC,uBAAuB,CAAC;IACnE,aAAa,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC,OAAO,CAAC,uBAAuB,CAAC;IACnE,8BAA8B,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC;IAC1D,4BAA4B,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC;IACxD,iBAAiB,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC;CAC7C,CAAC,CAAA"}
package/lib/types.d.ts ADDED
@@ -0,0 +1,150 @@
1
+ /**
2
+ * Shared types for the permission-rule engine: rule, source, mode, and the
3
+ * pure evaluation decision. Browser-safe — no Cordis/session imports, so the
4
+ * host UI (which previews what a rule hits) can import this subpath directly.
5
+ * @module @dsh-cc/permission-rules/types
6
+ */
7
+ /** Where a {@link PermissionRule} came from, in descending evaluation priority. */
8
+ export type PermissionRuleSource =
9
+ /** Highest priority — a rule imposed by the delegation/session layer. */
10
+ 'session'
11
+ /** A rule passed on the command line at launch. */
12
+ | 'cliArg'
13
+ /** A rule imposed by an external policy document. */
14
+ | 'policySettings'
15
+ /** A rule from a feature-flag or launch-flag settings layer. */
16
+ | 'flagSettings'
17
+ /** A rule from the local (machine-scoped) settings layer. */
18
+ | 'localSettings'
19
+ /** A rule from the project/workspace-scoped settings layer. */
20
+ | 'projectSettings'
21
+ /** A rule from the user settings layer. */
22
+ | 'userSettings'
23
+ /** Lowest priority — a rule from the plugin's composition `Config`. */
24
+ | 'config';
25
+ /**
26
+ * Every {@link PermissionRuleSource} ordered highest-priority first. Content
27
+ * rules are consulted in this order; the first source with a matching rule
28
+ * decides. Ties within one source fall back to declaration order.
29
+ */
30
+ export declare const SOURCE_PRIORITY: readonly PermissionRuleSource[];
31
+ /** The behavior a rule prescribes when its tool (and content, when present) matches. */
32
+ export type PermissionBehavior = 'allow' | 'deny' | 'ask';
33
+ /** The engine's permission mode, controlling tool-class and safe-mode short-circuits. */
34
+ export type PermissionMode = 'default' | 'acceptEdits' | 'plan' | 'bypassPermissions' | 'auto';
35
+ /** Every {@link PermissionMode}, for option advertisement and runtime validation of untrusted strings. */
36
+ export declare const PERMISSION_MODES: readonly PermissionMode[];
37
+ /** Modes that may be written to a `permission/mode` event. `plan` is owned by plan-mode. */
38
+ export type SwitchablePermissionMode = Exclude<PermissionMode, 'plan'>;
39
+ export declare const SWITCHABLE_PERMISSION_MODES: readonly SwitchablePermissionMode[];
40
+ /**
41
+ * Reason attached to a plan-mode denial of a non-read-only call. Lives here
42
+ * (not in `mode.ts`) so the browser-safe `evaluate` module can import it
43
+ * without pulling in the session-vocabulary side effect.
44
+ */
45
+ export declare const PLAN_READONLY_REASON = "plan mode is read-only; submit via exit_plan_mode";
46
+ /**
47
+ * One parsed permission rule. `toolName` is the exact tool the rule governs;
48
+ * `content` makes it a content-level rule (matched against the tool's subject
49
+ * string, e.g. a shell command or a file path) rather than a whole-tool rule.
50
+ */
51
+ export interface PermissionRule {
52
+ /** The exact tool name this rule governs. */
53
+ readonly toolName: string;
54
+ /**
55
+ * The content subject, when present: matched against the tool call's
56
+ * subject string with the rule's {@link ContentMatcher}. Absent means the
57
+ * rule is whole-tool.
58
+ */
59
+ readonly content?: string;
60
+ /** How to compare a call's subject against {@link PermissionRule.content}. */
61
+ readonly matcher?: ContentMatcher;
62
+ /** The behavior this rule prescribes on a match. */
63
+ readonly behavior: PermissionBehavior;
64
+ /** Where this rule came from, used for priority when several match. */
65
+ readonly source: PermissionRuleSource;
66
+ }
67
+ /**
68
+ * How a content rule compares a call's subject against its declared content.
69
+ * A `wildcard` pattern uses `*` to match any run of characters (`\*` is a
70
+ * literal asterisk); a `prefix` rule matches any subject starting with the
71
+ * string; a `domain` rule (WebFetch only) matches the call's canonicalized
72
+ * URL hostname against a domain pattern (exact, `*.suffix` subdomain-tree, or
73
+ * single-label `*` wildcards).
74
+ */
75
+ export type ContentMatcher = {
76
+ kind: 'wildcard';
77
+ pattern: string;
78
+ } | {
79
+ kind: 'prefix';
80
+ prefix: string;
81
+ } | {
82
+ kind: 'domain';
83
+ hostname: string;
84
+ };
85
+ /** A group of rules by behavior, used as the engine's rule input. */
86
+ export interface PermissionRuleSet {
87
+ /** Rules that allow matching calls. */
88
+ readonly allow: readonly PermissionRule[];
89
+ /** Rules that deny matching calls. */
90
+ readonly deny: readonly PermissionRule[];
91
+ /** Rules that route matching calls to an approval question. */
92
+ readonly ask: readonly PermissionRule[];
93
+ /**
94
+ * Bypass-immune deny rules, consulted BEFORE any mode logic and enforced
95
+ * through the monotonic guard layer so neither a mode switch nor
96
+ * `bypassPermissions` can override them (e.g. dotfiles, shell config paths,
97
+ * `.git` internals).
98
+ */
99
+ readonly bypassImmune: readonly PermissionRule[];
100
+ }
101
+ /** A rule set with empty arrays (the no-rules input). */
102
+ export declare const EMPTY_RULE_SET: PermissionRuleSet;
103
+ /**
104
+ * The engine's decision for one call, consumed by the `tools/pre-execute`
105
+ * listener. `passthrough` falls through to downstream listeners (ultimately
106
+ * the approval seam).
107
+ */
108
+ export type PermissionDecision = {
109
+ kind: 'allow';
110
+ } | {
111
+ kind: 'deny';
112
+ reason: string;
113
+ } | {
114
+ kind: 'ask';
115
+ reason?: string;
116
+ } | {
117
+ kind: 'passthrough';
118
+ };
119
+ /** The input the pure {@link evaluatePermission} folds a decision from. */
120
+ export interface EvaluationInput {
121
+ /** The tool being called. */
122
+ readonly toolName: string;
123
+ /** The call's subject string (shell command, file path), when it has one. */
124
+ readonly subject?: string;
125
+ /** The rules to evaluate, already parsed and source-labelled. */
126
+ readonly rules: PermissionRuleSet;
127
+ /** The active permission mode. */
128
+ readonly mode: PermissionMode;
129
+ /** Whether `bypassPermissions` mode is disabled (fall back to `default`). */
130
+ readonly bypassDisabled?: boolean;
131
+ /**
132
+ * Whether the call is a file-edit tool (auto-allowed under `acceptEdits`).
133
+ * Resolved from a configured tool-name set by the plugin, or provided
134
+ * directly by a host UI caller.
135
+ */
136
+ readonly isFileEdit?: boolean;
137
+ /**
138
+ * Whether a sandboxed bash call should skip a whole-tool `ask` (allowed
139
+ * instead). The plugin resolves this from the shell's confining sandbox;
140
+ * host callers may compute it directly.
141
+ */
142
+ readonly sandboxedBashExempt?: boolean;
143
+ /**
144
+ * Whether the call is read-only (auto-allowed under `plan` mode). Resolved
145
+ * from a configured tool-name set by the plugin.
146
+ */
147
+ readonly isReadOnly?: boolean;
148
+ }
149
+ export default PermissionRule;
150
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,mFAAmF;AACnF,MAAM,MAAM,oBAAoB;AAC9B,yEAAyE;AACvE,SAAS;AACX,mDAAmD;GACjD,QAAQ;AACV,qDAAqD;GACnD,gBAAgB;AAClB,gEAAgE;GAC9D,cAAc;AAChB,6DAA6D;GAC3D,eAAe;AACjB,+DAA+D;GAC7D,iBAAiB;AACnB,2CAA2C;GACzC,cAAc;AAChB,uEAAuE;GACrE,QAAQ,CAAA;AAEZ;;;;GAIG;AACH,eAAO,MAAM,eAAe,EAAE,SAAS,oBAAoB,EAS1D,CAAA;AAED,wFAAwF;AACxF,MAAM,MAAM,kBAAkB,GAAG,OAAO,GAAG,MAAM,GAAG,KAAK,CAAA;AAEzD,yFAAyF;AACzF,MAAM,MAAM,cAAc,GAAG,SAAS,GAAG,aAAa,GAAG,MAAM,GAAG,mBAAmB,GAAG,MAAM,CAAA;AA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;AAED,yDAAyD;AACzD,eAAO,MAAM,cAAc,EAAE,iBAAsE,CAAA;AAEnG;;;;GAIG;AACH,MAAM,MAAM,kBAAkB,GAC1B;IAAE,IAAI,EAAE,OAAO,CAAA;CAAE,GACjB;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,GAChC;IAAE,IAAI,EAAE,KAAK,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAA;CAAE,GAChC;IAAE,IAAI,EAAE,aAAa,CAAA;CAAE,CAAA;AAE3B,2EAA2E;AAC3E,MAAM,WAAW,eAAe;IAC9B,6BAA6B;IAC7B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAA;IACzB,6EAA6E;IAC7E,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAA;IACzB,iEAAiE;IACjE,QAAQ,CAAC,KAAK,EAAE,iBAAiB,CAAA;IACjC,kCAAkC;IAClC,QAAQ,CAAC,IAAI,EAAE,cAAc,CAAA;IAC7B,6EAA6E;IAC7E,QAAQ,CAAC,cAAc,CAAC,EAAE,OAAO,CAAA;IACjC;;;;OAIG;IACH,QAAQ,CAAC,UAAU,CAAC,EAAE,OAAO,CAAA;IAC7B;;;;OAIG;IACH,QAAQ,CAAC,mBAAmB,CAAC,EAAE,OAAO,CAAA;IACtC;;;OAGG;IACH,QAAQ,CAAC,UAAU,CAAC,EAAE,OAAO,CAAA;CAC9B;AAED,eAAe,cAAc,CAAA"}
package/lib/types.js ADDED
@@ -0,0 +1,33 @@
1
+ /**
2
+ * Shared types for the permission-rule engine: rule, source, mode, and the
3
+ * pure evaluation decision. Browser-safe — no Cordis/session imports, so the
4
+ * host UI (which previews what a rule hits) can import this subpath directly.
5
+ * @module @dsh-cc/permission-rules/types
6
+ */
7
+ /**
8
+ * Every {@link PermissionRuleSource} ordered highest-priority first. Content
9
+ * rules are consulted in this order; the first source with a matching rule
10
+ * decides. Ties within one source fall back to declaration order.
11
+ */
12
+ export const SOURCE_PRIORITY = [
13
+ 'session',
14
+ 'cliArg',
15
+ 'policySettings',
16
+ 'flagSettings',
17
+ 'localSettings',
18
+ 'projectSettings',
19
+ 'userSettings',
20
+ 'config',
21
+ ];
22
+ /** Every {@link PermissionMode}, for option advertisement and runtime validation of untrusted strings. */
23
+ export const PERMISSION_MODES = ['default', 'acceptEdits', 'plan', 'bypassPermissions', 'auto'];
24
+ export const SWITCHABLE_PERMISSION_MODES = ['default', 'acceptEdits', 'bypassPermissions', 'auto'];
25
+ /**
26
+ * Reason attached to a plan-mode denial of a non-read-only call. Lives here
27
+ * (not in `mode.ts`) so the browser-safe `evaluate` module can import it
28
+ * without pulling in the session-vocabulary side effect.
29
+ */
30
+ export const PLAN_READONLY_REASON = 'plan mode is read-only; submit via exit_plan_mode';
31
+ /** A rule set with empty arrays (the no-rules input). */
32
+ export const EMPTY_RULE_SET = { allow: [], deny: [], ask: [], bypassImmune: [] };
33
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAqBH;;;;GAIG;AACH,MAAM,CAAC,MAAM,eAAe,GAAoC;IAC9D,SAAS;IACT,QAAQ;IACR,gBAAgB;IAChB,cAAc;IACd,eAAe;IACf,iBAAiB;IACjB,cAAc;IACd,QAAQ;CACT,CAAA;AAQD,0GAA0G;AAC1G,MAAM,CAAC,MAAM,gBAAgB,GAA8B,CAAC,SAAS,EAAE,aAAa,EAAE,MAAM,EAAE,mBAAmB,EAAE,MAAM,CAAC,CAAA;AAI1H,MAAM,CAAC,MAAM,2BAA2B,GAAwC,CAAC,SAAS,EAAE,aAAa,EAAE,mBAAmB,EAAE,MAAM,CAAC,CAAA;AAEvI;;;;GAIG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG,mDAAmD,CAAA;AAsDvF,yDAAyD;AACzD,MAAM,CAAC,MAAM,cAAc,GAAsB,EAAE,KAAK,EAAE,EAAE,EAAE,IAAI,EAAE,EAAE,EAAE,GAAG,EAAE,EAAE,EAAE,YAAY,EAAE,EAAE,EAAE,CAAA"}
package/package.json ADDED
@@ -0,0 +1,71 @@
1
+ {
2
+ "name": "@dsh-cc/permission-rules",
3
+ "description": "Claude Code-compatible permission rule engine for DeepSeek Harness: rule parsing, mode-aware pre-execute evaluation, monotonic bypass-immune guards, and optional settings config",
4
+ "version": "0.5.0",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "git+https://github.com/dsh-cc/dsh-cc.git",
8
+ "directory": "packages/interaction/permission-rules"
9
+ },
10
+ "type": "module",
11
+ "exports": {
12
+ ".": {
13
+ "types": "./lib/index.d.ts",
14
+ "default": "./lib/index.js"
15
+ },
16
+ "./invariant": {
17
+ "types": "./lib/invariant.d.ts",
18
+ "default": "./lib/invariant.js"
19
+ },
20
+ "./types": {
21
+ "types": "./lib/types.d.ts",
22
+ "default": "./lib/types.js"
23
+ },
24
+ "./src/*": "./src/*",
25
+ "./package.json": "./package.json"
26
+ },
27
+ "files": [
28
+ "lib"
29
+ ],
30
+ "license": "Apache-2.0",
31
+ "peerDependencies": {
32
+ "@deepseek-ai/dsh-agent": ">=0.1.1-rc.2",
33
+ "@deepseek-ai/dsh-invariants": ">=0.1.1-rc.2",
34
+ "@deepseek-ai/dsh-llm": ">=0.1.1-rc.2",
35
+ "@deepseek-ai/dsh-plan-mode": ">=0.1.1-rc.2",
36
+ "@deepseek-ai/dsh-sandbox": ">=0.1.1-rc.2",
37
+ "@deepseek-ai/dsh-sandbox-policy": ">=0.1.1-rc.2",
38
+ "@deepseek-ai/dsh-scope": ">=0.1.1-rc.2",
39
+ "@deepseek-ai/dsh-session": ">=0.1.1-rc.2",
40
+ "@deepseek-ai/dsh-shell": ">=0.1.1-rc.2",
41
+ "@deepseek-ai/dsh-settings": ">=0.1.1-rc.2",
42
+ "@deepseek-ai/dsh-user-approval": ">=0.1.1-rc.2",
43
+ "@deepseek-ai/cordis": ">=0.1.1-rc.2",
44
+ "@deepseek-ai/schemastery": "^3.18.1",
45
+ "@dsh-cc/model-aliases": "^0.5.0",
46
+ "@dsh-cc/session-cwd": "^0.5.0",
47
+ "@dsh-cc/tools": "^0.5.0"
48
+ },
49
+ "devDependencies": {
50
+ "@deepseek-ai/dsh-agent": "link:../../../../deepseek-harness/packages/core/agent",
51
+ "@deepseek-ai/dsh-invariants": "link:../../../../deepseek-harness/packages/runtime-diagnostics/invariants",
52
+ "@deepseek-ai/dsh-plan-mode": "link:../../../../deepseek-harness/packages/plan/plan-mode",
53
+ "@deepseek-ai/dsh-sandbox": "link:../../../../deepseek-harness/packages/sandbox/sandbox",
54
+ "@deepseek-ai/dsh-sandbox-policy": "link:../../../../deepseek-harness/packages/sandbox/sandbox-policy",
55
+ "@deepseek-ai/dsh-scope": "link:../../../../deepseek-harness/packages/core/scope",
56
+ "@deepseek-ai/dsh-session": "link:../../../../deepseek-harness/packages/core/session",
57
+ "@deepseek-ai/dsh-shell": "link:../../../../deepseek-harness/packages/shell/shell",
58
+ "@deepseek-ai/dsh-settings": "link:../../../../deepseek-harness/packages/settings/settings",
59
+ "@dsh-cc/session-cwd": "link:../../workspace/session-cwd",
60
+ "@deepseek-ai/dsh-user-approval": "link:../../../../deepseek-harness/packages/interaction/user-approval",
61
+ "@deepseek-ai/cordis": "link:../../../../deepseek-harness/vendor/cordis",
62
+ "@deepseek-ai/schemastery": "link:../../../../deepseek-harness/vendor/schemastery",
63
+ "@deepseek-ai/dsh-llm": "link:../../../../deepseek-harness/packages/llm/llm",
64
+ "@deepseek-ai/dsh-system-prompt": "link:../../../../deepseek-harness/packages/core/system-prompt",
65
+ "@dsh-cc/tools": "^0.5.0",
66
+ "@dsh-cc/model-aliases": "^0.5.0"
67
+ },
68
+ "publishConfig": {
69
+ "access": "public"
70
+ }
71
+ }