@octopi-agent/engine 0.90.11 → 0.98.4

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 (246) hide show
  1. package/dist/config-admin/agent-presets.d.ts +70 -0
  2. package/dist/config-admin/agent-presets.js +243 -0
  3. package/dist/config-admin/discover.d.ts +30 -0
  4. package/dist/config-admin/discover.js +48 -0
  5. package/dist/config-admin/env.d.ts +22 -0
  6. package/dist/config-admin/env.js +41 -0
  7. package/dist/config-admin/index.d.ts +20 -0
  8. package/dist/config-admin/index.js +15 -0
  9. package/dist/config-admin/model-presets.d.ts +75 -0
  10. package/dist/config-admin/model-presets.js +249 -0
  11. package/dist/config-admin/name-guard.d.ts +14 -0
  12. package/dist/config-admin/name-guard.js +24 -0
  13. package/dist/config-admin/patch.d.ts +56 -0
  14. package/dist/config-admin/patch.js +201 -0
  15. package/dist/config-admin/port.d.ts +68 -0
  16. package/dist/config-admin/port.js +21 -0
  17. package/dist/config-admin/redact.d.ts +39 -0
  18. package/dist/config-admin/redact.js +42 -0
  19. package/dist/config-schema/agent.d.ts +45 -1
  20. package/dist/config-schema/context.d.ts +6 -1
  21. package/dist/config-schema/context.js +8 -0
  22. package/dist/config-schema/engine.d.ts +110 -4
  23. package/dist/config-schema/governance.d.ts +45 -1
  24. package/dist/config-schema/governance.js +187 -0
  25. package/dist/config-schema/models.d.ts +5 -2
  26. package/dist/config-schema/models.js +4 -1
  27. package/dist/config-schema/observability.d.ts +9 -0
  28. package/dist/config-schema/observability.js +29 -0
  29. package/dist/config-schema/run.d.ts +3 -0
  30. package/dist/config-schema/run.js +14 -0
  31. package/dist/config.d.ts +29 -4
  32. package/dist/config.js +15 -4
  33. package/dist/harness/activation/dispatcher.d.ts +8 -2
  34. package/dist/harness/activation/dispatcher.js +33 -5
  35. package/dist/harness/activation/inbox.d.ts +87 -0
  36. package/dist/harness/activation/inbox.js +169 -0
  37. package/dist/harness/activation/runtime.d.ts +9 -8
  38. package/dist/harness/activation/runtime.js +100 -8
  39. package/dist/harness/activation/types.d.ts +19 -0
  40. package/dist/harness/activation/types.js +2 -0
  41. package/dist/harness/agent/builder.d.ts +26 -1
  42. package/dist/harness/agent/builder.js +85 -37
  43. package/dist/harness/agent/config-bridge.d.ts +5 -0
  44. package/dist/harness/agent/config-bridge.js +3 -0
  45. package/dist/harness/agent/config-integrity.d.ts +138 -0
  46. package/dist/harness/agent/config-integrity.js +235 -0
  47. package/dist/harness/agent/wire-agent-builder.js +7 -1
  48. package/dist/harness/collaboration/autonomous-subsystem/index.d.ts +2 -2
  49. package/dist/harness/collaboration/autonomous-subsystem/index.js +1 -1
  50. package/dist/harness/collaboration/autonomous-subsystem/loader.js +3 -0
  51. package/dist/harness/collaboration/autonomous-subsystem/sense/engine.js +19 -2
  52. package/dist/harness/collaboration/autonomous-subsystem/think/completion-guard.d.ts +40 -0
  53. package/dist/harness/collaboration/autonomous-subsystem/think/completion-guard.js +59 -0
  54. package/dist/harness/collaboration/autonomous-subsystem/think/executor.js +3 -1
  55. package/dist/harness/collaboration/autonomous-subsystem/think/index.d.ts +2 -0
  56. package/dist/harness/collaboration/autonomous-subsystem/think/index.js +1 -0
  57. package/dist/harness/collaboration/autonomous-subsystem/think/model-resolver.js +1 -1
  58. package/dist/harness/collaboration/autonomous-subsystem/types.d.ts +9 -0
  59. package/dist/harness/collaboration/delegation/child-run.js +21 -5
  60. package/dist/harness/collaboration/delegation/notifier.js +4 -3
  61. package/dist/harness/collaboration/delegation/service.js +2 -3
  62. package/dist/harness/collaboration/delegation/wiring.js +6 -5
  63. package/dist/harness/collaboration/orchestration/reflector/llm-reflector.d.ts +1 -1
  64. package/dist/harness/collaboration/orchestration/reflector/llm-reflector.js +1 -1
  65. package/dist/harness/context/capabilities/compact/engine.d.ts +30 -0
  66. package/dist/harness/context/capabilities/compact/engine.js +198 -46
  67. package/dist/harness/context/capabilities/compact/handover.d.ts +78 -0
  68. package/dist/harness/context/capabilities/compact/handover.js +107 -0
  69. package/dist/harness/context/capabilities/compact/index.d.ts +3 -1
  70. package/dist/harness/context/capabilities/compact/index.js +2 -1
  71. package/dist/harness/context/capabilities/compact/types.d.ts +30 -1
  72. package/dist/harness/context/capabilities/summary/executor.js +2 -1
  73. package/dist/harness/context/capabilities/summary/policies.js +8 -5
  74. package/dist/harness/context/capabilities/summary/resolver.d.ts +1 -1
  75. package/dist/harness/context/capabilities/summary/resolver.js +4 -4
  76. package/dist/harness/context/capabilities/summary/types.d.ts +2 -2
  77. package/dist/harness/context/constitution/default-agents.md +11 -10
  78. package/dist/harness/context/default-context-engine.d.ts +34 -4
  79. package/dist/harness/context/default-context-engine.js +194 -49
  80. package/dist/harness/context/hybrid-compressor.js +6 -0
  81. package/dist/harness/context/layers.d.ts +2 -4
  82. package/dist/harness/context/layers.js +9 -11
  83. package/dist/harness/context/llm-summarizer.d.ts +2 -8
  84. package/dist/harness/context/llm-summarizer.js +69 -91
  85. package/dist/harness/context/message-selector.js +4 -3
  86. package/dist/harness/context/summarize.d.ts +3 -1
  87. package/dist/harness/context/summarize.js +9 -4
  88. package/dist/harness/context/system-prompt-assembler.d.ts +2 -0
  89. package/dist/harness/context/system-prompt-assembler.js +1 -0
  90. package/dist/harness/context/truncate-compressor.js +7 -0
  91. package/dist/harness/context/turn-envelope.d.ts +3 -2
  92. package/dist/harness/context/turn-envelope.js +3 -2
  93. package/dist/harness/context/types.d.ts +33 -1
  94. package/dist/harness/extension/execution-environment/dangerous-commands.d.ts +28 -0
  95. package/dist/harness/extension/execution-environment/dangerous-commands.js +129 -0
  96. package/dist/harness/extension/execution-environment/effect-policy.d.ts +149 -8
  97. package/dist/harness/extension/execution-environment/effect-policy.js +274 -19
  98. package/dist/harness/extension/execution-environment/index.d.ts +4 -2
  99. package/dist/harness/extension/execution-environment/index.js +2 -1
  100. package/dist/harness/extension/execution-environment/kill-switch.d.ts +34 -0
  101. package/dist/harness/extension/execution-environment/kill-switch.js +46 -0
  102. package/dist/harness/extension/execution-environment/ops-audit.d.ts +204 -0
  103. package/dist/harness/extension/execution-environment/ops-audit.js +337 -0
  104. package/dist/harness/extension/execution-environment/privileged-exec.d.ts +158 -0
  105. package/dist/harness/extension/execution-environment/privileged-exec.js +418 -0
  106. package/dist/harness/extension/execution-environment/process-info.d.ts +180 -0
  107. package/dist/harness/extension/execution-environment/process-info.js +466 -0
  108. package/dist/harness/extension/execution-environment/process-isolation.d.ts +7 -0
  109. package/dist/harness/extension/execution-environment/process-isolation.js +9 -0
  110. package/dist/harness/extension/execution-environment/sandbox.d.ts +109 -0
  111. package/dist/harness/extension/execution-environment/sandbox.js +228 -21
  112. package/dist/harness/extension/execution-environment/tool-capabilities.d.ts +1 -1
  113. package/dist/harness/extension/execution-environment/tool-capabilities.js +6 -0
  114. package/dist/harness/extension/execution-environment/types.d.ts +19 -0
  115. package/dist/harness/extension/execution-environment/undo-log.d.ts +6 -2
  116. package/dist/harness/extension/execution-environment/undo-log.js +31 -10
  117. package/dist/harness/extension/plugin-ecosystem/channel-types.d.ts +5 -0
  118. package/dist/harness/extension/plugin-ecosystem/tools/allowlisted-run.js +33 -0
  119. package/dist/harness/extension/plugin-ecosystem/tools/ask-user.d.ts +4 -5
  120. package/dist/harness/extension/plugin-ecosystem/tools/ask-user.js +5 -15
  121. package/dist/harness/extension/plugin-ecosystem/tools/builtin.d.ts +3 -0
  122. package/dist/harness/extension/plugin-ecosystem/tools/builtin.js +70 -26
  123. package/dist/harness/extension/plugin-ecosystem/tools/document-tools.js +3 -9
  124. package/dist/harness/extension/plugin-ecosystem/tools/file-edit.js +3 -6
  125. package/dist/harness/extension/plugin-ecosystem/tools/file-ops.js +9 -5
  126. package/dist/harness/extension/plugin-ecosystem/tools/file-search.js +9 -130
  127. package/dist/harness/extension/plugin-ecosystem/tools/git-tools.js +122 -14
  128. package/dist/harness/extension/plugin-ecosystem/tools/index.d.ts +2 -0
  129. package/dist/harness/extension/plugin-ecosystem/tools/index.js +2 -0
  130. package/dist/harness/extension/plugin-ecosystem/tools/package-tools.js +4 -13
  131. package/dist/harness/extension/plugin-ecosystem/tools/platform.d.ts +25 -11
  132. package/dist/harness/extension/plugin-ecosystem/tools/platform.js +168 -62
  133. package/dist/harness/extension/plugin-ecosystem/tools/privileged-tool.d.ts +43 -0
  134. package/dist/harness/extension/plugin-ecosystem/tools/privileged-tool.js +350 -0
  135. package/dist/harness/extension/plugin-ecosystem/tools/process-tools.d.ts +30 -0
  136. package/dist/harness/extension/plugin-ecosystem/tools/process-tools.js +137 -0
  137. package/dist/harness/governance/human-in-the-loop/decision-cache.d.ts +54 -4
  138. package/dist/harness/governance/human-in-the-loop/decision-cache.js +42 -16
  139. package/dist/harness/governance/security/default-risk-policy.d.ts +1 -0
  140. package/dist/harness/governance/security/default-risk-policy.js +1 -0
  141. package/dist/harness/governance/security/default-security-guard.js +9 -0
  142. package/dist/harness/governance/security/index.d.ts +1 -0
  143. package/dist/harness/governance/security/index.js +2 -0
  144. package/dist/harness/governance/security/risk-evaluator.js +13 -0
  145. package/dist/harness/governance/security/risk-types.d.ts +12 -0
  146. package/dist/harness/governance/security/shell-parser-fallback.d.ts +29 -0
  147. package/dist/harness/governance/security/shell-parser-fallback.js +410 -0
  148. package/dist/harness/governance/security/shell-parser-shared.d.ts +83 -0
  149. package/dist/harness/governance/security/shell-parser-shared.js +188 -0
  150. package/dist/harness/governance/security/shell-parser-treesitter.d.ts +52 -0
  151. package/dist/harness/governance/security/shell-parser-treesitter.js +370 -0
  152. package/dist/harness/governance/security/shell-parser.d.ts +23 -10
  153. package/dist/harness/governance/security/shell-parser.js +37 -496
  154. package/dist/harness/governance/security/temp-path.d.ts +9 -0
  155. package/dist/harness/governance/security/temp-path.js +13 -2
  156. package/dist/harness/governance/security/vendor/README.md +24 -0
  157. package/dist/harness/governance/security/vendor/tree-sitter-bash.LICENSE.txt +21 -0
  158. package/dist/harness/governance/security/vendor/tree-sitter-bash.wasm +0 -0
  159. package/dist/harness/governance/session-acl/seed-roles.js +14 -0
  160. package/dist/harness/index.d.ts +2 -0
  161. package/dist/harness/index.js +2 -0
  162. package/dist/harness/knowledge/fts.js +1 -2
  163. package/dist/harness/knowledge/index-store.js +59 -9
  164. package/dist/harness/memory/index.d.ts +6 -2
  165. package/dist/harness/memory/index.js +4 -1
  166. package/dist/harness/memory/memory-events.d.ts +25 -0
  167. package/dist/harness/memory/memory-events.js +38 -0
  168. package/dist/harness/memory/sqlite/agent-db.js +15 -0
  169. package/dist/harness/memory/sqlite/keyword-search.d.ts +1 -0
  170. package/dist/harness/memory/sqlite/keyword-search.js +4 -3
  171. package/dist/harness/memory/sqlite/wisdom-store.d.ts +7 -2
  172. package/dist/harness/memory/sqlite/wisdom-store.js +51 -2
  173. package/dist/harness/memory/steward-policy.d.ts +3 -0
  174. package/dist/harness/memory/steward-policy.js +1 -1
  175. package/dist/harness/memory/types.d.ts +41 -3
  176. package/dist/harness/memory/wisdom-attribution.d.ts +136 -0
  177. package/dist/harness/memory/wisdom-attribution.js +287 -0
  178. package/dist/harness/memory/wisdom-events.d.ts +37 -0
  179. package/dist/harness/memory/wisdom-events.js +61 -0
  180. package/dist/harness/memory/wisdom-formation.d.ts +20 -1
  181. package/dist/harness/memory/wisdom-formation.js +55 -21
  182. package/dist/harness/memory/wisdom.d.ts +7 -2
  183. package/dist/harness/memory/wisdom.js +40 -2
  184. package/dist/harness/observability/observer/hub.js +8 -0
  185. package/dist/harness/observability/observer/run-snapshot.js +1 -0
  186. package/dist/harness/observability/observer/types.d.ts +4 -0
  187. package/dist/harness/run/agent/agent.d.ts +7 -0
  188. package/dist/harness/run/agent/agent.js +23 -1
  189. package/dist/harness/run/reliability/fallback-provider.d.ts +117 -5
  190. package/dist/harness/run/reliability/fallback-provider.js +262 -22
  191. package/dist/harness/run/reliability/harness-events.d.ts +24 -1
  192. package/dist/harness/run/reliability/model-error-policy.d.ts +32 -0
  193. package/dist/harness/run/reliability/model-error-policy.js +42 -0
  194. package/dist/harness/run/reliability/provider-wrapper.js +29 -2
  195. package/dist/harness/run/reliability/refusal-guard.d.ts +20 -0
  196. package/dist/harness/run/reliability/refusal-guard.js +102 -0
  197. package/dist/harness/run/reliability/run-agent.js +231 -33
  198. package/dist/harness/run/run-guard/default-run-guard.js +1 -1
  199. package/dist/harness/run/run-scope.d.ts +35 -0
  200. package/dist/harness/run/runner.d.ts +141 -2
  201. package/dist/harness/run/runner.js +592 -42
  202. package/dist/harness/session/attachments/llm-intent.js +2 -1
  203. package/dist/harness/session/tasks/render.d.ts +4 -1
  204. package/dist/harness/session/tasks/render.js +10 -7
  205. package/dist/harness/shared/events/agent-event-map.d.ts +66 -0
  206. package/dist/harness/shared/events/agent-event-map.js +5 -0
  207. package/dist/harness/shared/paths/glob.d.ts +52 -0
  208. package/dist/harness/shared/paths/glob.js +218 -0
  209. package/dist/harness/shared/paths/index.d.ts +84 -0
  210. package/dist/harness/shared/paths/index.js +179 -0
  211. package/dist/index.d.ts +3 -3
  212. package/dist/index.js +2 -2
  213. package/dist/integration/agent-runtime/channel-message-source.js +19 -1
  214. package/dist/integration/index.d.ts +2 -0
  215. package/dist/integration/index.js +1 -0
  216. package/dist/integration/observability/loop-watchdog.d.ts +56 -0
  217. package/dist/integration/observability/loop-watchdog.js +177 -0
  218. package/dist/integration/observability/metrics.d.ts +3 -0
  219. package/dist/integration/observability/metrics.js +18 -7
  220. package/dist/integration/providers/anthropic.d.ts +23 -0
  221. package/dist/integration/providers/anthropic.js +97 -12
  222. package/dist/integration/providers/fetch-timeout.d.ts +42 -0
  223. package/dist/integration/providers/fetch-timeout.js +51 -0
  224. package/dist/integration/providers/openai.d.ts +10 -0
  225. package/dist/integration/providers/openai.js +58 -11
  226. package/dist/integration/providers/provider-diagnostics.d.ts +80 -0
  227. package/dist/integration/providers/provider-diagnostics.js +89 -0
  228. package/dist/integration/providers/timeout-coherence.d.ts +52 -0
  229. package/dist/integration/providers/timeout-coherence.js +68 -0
  230. package/dist/integration/providers/wire-dump.d.ts +62 -0
  231. package/dist/integration/providers/wire-dump.js +111 -2
  232. package/dist/integration/storage/jsonl.js +4 -1
  233. package/dist/subsystems/cognition-steward/conceptualize/config.yaml +4 -2
  234. package/dist/subsystems/cognition-steward/conceptualize/handler.js +12 -20
  235. package/dist/subsystems/memory-steward/backfill/config.yaml +4 -2
  236. package/dist/subsystems/memory-steward/backfill/handler.js +44 -52
  237. package/dist/subsystems/wisdom-steward/attribute/SUBSYSTEM.md +24 -0
  238. package/dist/subsystems/wisdom-steward/attribute/config.yaml +60 -0
  239. package/dist/subsystems/wisdom-steward/attribute/handler.d.ts +23 -0
  240. package/dist/subsystems/wisdom-steward/attribute/handler.js +167 -0
  241. package/dist/subsystems/wisdom-steward/evaluate/handler.js +3 -1
  242. package/dist/subsystems/wisdom-steward/formation/config.yaml +12 -5
  243. package/dist/subsystems/wisdom-steward/formation/handler.js +12 -18
  244. package/dist/subsystems/wisdom-steward/govern/config.yaml +1 -1
  245. package/dist/subsystems/wisdom-steward/govern/handler.js +4 -0
  246. package/package.json +8 -2
@@ -1,14 +1,12 @@
1
1
  import { gateEffect } from '../../execution-environment/effect-policy.js';
2
- import { resolveToolPath, isUnderAttachmentRoot, isUnderSessionUndoRoot } from './platform.js';
2
+ import { containmentOptions, isUnderAttachmentRoot, isUnderSessionUndoRoot, resolveToolPath, } from './platform.js';
3
3
  import { detectEol, toEol } from './eol.js';
4
4
  import { assertSafeRef } from './allowlisted-run.js';
5
+ import { matchesDenyPattern } from '../../../shared/paths/glob.js';
5
6
  import { runGit } from './git-runner.js';
6
7
  function resolveCwd(context, raw) {
7
8
  const cwd = raw ?? context?.cwd ?? process.cwd();
8
- const abs = resolveToolPath(cwd, context?.cwd, {
9
- allowRoots: context?.pathRoots,
10
- containment: context?.pathContainment,
11
- });
9
+ const abs = resolveToolPath(cwd, context?.cwd, containmentOptions(context));
12
10
  if (isUnderAttachmentRoot(abs, context?.attachmentRoots)) {
13
11
  throw new Error('session attachments are read-only; cannot run git under attachments root');
14
12
  }
@@ -18,10 +16,7 @@ function resolveCwd(context, raw) {
18
16
  return abs;
19
17
  }
20
18
  function assertPathSafe(raw, context, label) {
21
- const abs = resolveToolPath(raw, context?.cwd, {
22
- allowRoots: context?.pathRoots,
23
- containment: context?.pathContainment,
24
- });
19
+ const abs = resolveToolPath(raw, context?.cwd, containmentOptions(context));
25
20
  if (isUnderAttachmentRoot(abs, context?.attachmentRoots)) {
26
21
  throw new Error(`session attachments are read-only; cannot ${label} under attachments root`);
27
22
  }
@@ -43,6 +38,12 @@ function toGitPathspec(raw, context, label) {
43
38
  if (!isMagic) {
44
39
  return assertPathSafe(raw, context, label);
45
40
  }
41
+ const denylist = context?.pathDenylist ?? [];
42
+ // A glob pathspec is matched by git, not by us, so we cannot prove it excludes
43
+ // denied paths. Fail closed instead of shipping an unverifiable allow.
44
+ if (denylist.length > 0) {
45
+ throw new Error(`pathspec_glob_forbidden: glob pathspec "${raw}" cannot be checked against pathDenylist; pass explicit paths`);
46
+ }
46
47
  if (raw.startsWith('/') ||
47
48
  raw.startsWith('\\\\') ||
48
49
  (process.platform === 'win32' && /^[A-Za-z]:[\\/]/.test(raw))) {
@@ -56,9 +57,116 @@ function toGitPathspec(raw, context, label) {
56
57
  }
57
58
  return raw;
58
59
  }
59
- function toText(result) {
60
+ /**
61
+ * Decode a git-quoted path (`"a\tb"`) into its literal spelling.
62
+ *
63
+ * @param token - path token straight from git output
64
+ * @returns the path git meant, without the a/ or b/ side prefix
65
+ */
66
+ function unquoteGitPath(token) {
67
+ const body = token.startsWith('"') && token.endsWith('"')
68
+ ? token.slice(1, -1).replace(/\\(.)/g, '$1')
69
+ : token;
70
+ return body.replace(/^[ab]\//, '');
71
+ }
72
+ /**
73
+ * Split the arguments of a `diff --git a/<path> b/<path>` header.
74
+ *
75
+ * @param rest - header text after `diff --git `
76
+ * @returns path tokens, still quoted when git quoted them
77
+ */
78
+ function splitDiffHeader(rest) {
79
+ const tokens = [];
80
+ let index = 0;
81
+ while (index < rest.length) {
82
+ if (rest[index] === ' ') {
83
+ index += 1;
84
+ continue;
85
+ }
86
+ let token = '';
87
+ while (index < rest.length && rest[index] !== ' ') {
88
+ if (rest[index] === '"') {
89
+ token += '"';
90
+ index += 1;
91
+ while (index < rest.length) {
92
+ if (rest[index] === '\\' && index + 1 < rest.length) {
93
+ token += rest[index] + rest[index + 1];
94
+ index += 2;
95
+ continue;
96
+ }
97
+ token += rest[index];
98
+ if (rest[index] === '"') {
99
+ index += 1;
100
+ break;
101
+ }
102
+ index += 1;
103
+ }
104
+ continue;
105
+ }
106
+ token += rest[index];
107
+ index += 1;
108
+ }
109
+ tokens.push(token);
110
+ }
111
+ return tokens;
112
+ }
113
+ /**
114
+ * Drop git output that names or contains denied paths.
115
+ *
116
+ * `git_diff` / `git_show` emit file *contents* keyed by section headers, and
117
+ * `git_status` emits bare paths, so path arguments alone are not enough: a
118
+ * deployment that denies `.env*` must not get that content back through VCS.
119
+ * Truncated diffs cannot be verified section by section, so they are refused
120
+ * rather than returned unverified.
121
+ *
122
+ * @param text - raw git stdout
123
+ * @param truncated - whether the runner cut the output
124
+ * @param patterns - denylist globs
125
+ * @param kind - output shape
126
+ * @returns filtered stdout
127
+ */
128
+ function filterGitOutput(text, truncated, patterns, kind) {
129
+ if (patterns.length === 0)
130
+ return text;
131
+ const lines = text.split('\n');
132
+ if (kind === 'status') {
133
+ return lines
134
+ .filter((line) => {
135
+ if (line.startsWith('##') || line.length < 4)
136
+ return true;
137
+ const raw = line.slice(3);
138
+ const target = raw.includes(' -> ') ? raw.slice(raw.lastIndexOf(' -> ') + 4) : raw;
139
+ return !matchesDenyPattern(unquoteGitPath(target.trim()), patterns);
140
+ })
141
+ .join('\n');
142
+ }
143
+ if (truncated) {
144
+ throw new Error('path_forbidden: git output was truncated, so pathDenylist could not be verified; narrow the request');
145
+ }
146
+ let dropping = false;
147
+ const kept = [];
148
+ for (const line of lines) {
149
+ if (line.startsWith('diff --git ')) {
150
+ const paths = splitDiffHeader(line.slice('diff --git '.length)).map(unquoteGitPath);
151
+ dropping = paths.some((path) => matchesDenyPattern(path, patterns));
152
+ }
153
+ else if (/^ .+?\s+\|\s+\d+/.test(line)) {
154
+ // `--stat` rows are single lines, not sections; test the named path.
155
+ const path = unquoteGitPath(line.trim().split(/\s+\|\s+/)[0].trim());
156
+ if (matchesDenyPattern(path, patterns))
157
+ continue;
158
+ }
159
+ if (!dropping)
160
+ kept.push(line);
161
+ }
162
+ return kept.join('\n');
163
+ }
164
+ function toText(result, context, contentKind) {
165
+ const stdout = contentKind
166
+ ? filterGitOutput(result.stdout, result.truncated, context?.pathDenylist ?? [], contentKind)
167
+ : result.stdout;
60
168
  return {
61
- stdout: result.stdout,
169
+ stdout,
62
170
  stderr: result.stderr,
63
171
  exitCode: result.exitCode,
64
172
  durationMs: result.durationMs,
@@ -95,7 +203,7 @@ export function createGitStatusTool() {
95
203
  '--untracked-files=all',
96
204
  ...pathArgs,
97
205
  ]);
98
- return { ...toText(result), cwd };
206
+ return { ...toText(result, context, 'status'), cwd };
99
207
  },
100
208
  };
101
209
  }
@@ -147,7 +255,7 @@ export function createGitDiffTool() {
147
255
  gitArgs.push('--', ...paths.map((p) => toGitPathspec(p, context, 'diff')));
148
256
  }
149
257
  const result = await runGit(context, cwd, gitArgs, { timeoutMs: 120_000 });
150
- return { ...toText(result), cwd, mode };
258
+ return { ...toText(result, context, 'diff'), cwd, mode };
151
259
  },
152
260
  };
153
261
  }
@@ -215,7 +323,7 @@ export function createGitShowTool() {
215
323
  gitArgs.push('--stat');
216
324
  gitArgs.push(rev);
217
325
  const result = await runGit(context, cwd, gitArgs, { timeoutMs: 120_000 });
218
- return { ...toText(result), cwd, revision: rev };
326
+ return { ...toText(result, context, 'diff'), cwd, revision: rev };
219
327
  },
220
328
  };
221
329
  }
@@ -10,6 +10,8 @@ export { createFileEditTool } from './file-edit.js';
10
10
  export { createFileSearchTool } from './file-search.js';
11
11
  export { createHttpRequestTool } from './http.js';
12
12
  export { createEnvInfoTool } from './env-info.js';
13
+ export { createProcessListTool } from './process-tools.js';
14
+ export { createPrivExecTool } from './privileged-tool.js';
13
15
  export { commandExists, defaultPathEnv, findExecutable, resetPlatformShellCache, resolvePlatformShell, resolveToolPath, type PlatformShell, type ShellKind, } from './platform.js';
14
16
  export { createToolSet } from './tool-set.js';
15
17
  export type { ToolSet, ToolSetConfig } from './tool-set.js';
@@ -8,6 +8,8 @@ export { createFileEditTool } from './file-edit.js';
8
8
  export { createFileSearchTool } from './file-search.js';
9
9
  export { createHttpRequestTool } from './http.js';
10
10
  export { createEnvInfoTool } from './env-info.js';
11
+ export { createProcessListTool } from './process-tools.js';
12
+ export { createPrivExecTool } from './privileged-tool.js';
11
13
  export { commandExists, defaultPathEnv, findExecutable, resetPlatformShellCache, resolvePlatformShell, resolveToolPath, } from './platform.js';
12
14
  export { createToolSet } from './tool-set.js';
13
15
  export { createAskUserTool } from './ask-user.js';
@@ -11,15 +11,12 @@
11
11
  import { tmpdir } from 'node:os';
12
12
  import { join } from 'node:path';
13
13
  import { gateEffect } from '../../execution-environment/effect-policy.js';
14
- import { isUnderAttachmentRoot, isUnderSessionUndoRoot, resolveToolPath, findExecutable, } from './platform.js';
14
+ import { containmentOptions, findExecutable, isUnderAttachmentRoot, isUnderSessionUndoRoot, resolveToolPath, } from './platform.js';
15
15
  import { runAllowlistedArgv } from './allowlisted-run.js';
16
16
  import { resolveNodeToolCommand } from './platform.js';
17
17
  function resolveCwd(context, raw) {
18
18
  const cwd = raw ?? context?.cwd ?? process.cwd();
19
- const abs = resolveToolPath(cwd, context?.cwd, {
20
- allowRoots: context?.pathRoots,
21
- containment: context?.pathContainment,
22
- });
19
+ const abs = resolveToolPath(cwd, context?.cwd, containmentOptions(context));
23
20
  if (isUnderAttachmentRoot(abs, context?.attachmentRoots)) {
24
21
  throw new Error('session attachments are read-only; cannot run package tools under attachments root');
25
22
  }
@@ -29,10 +26,7 @@ function resolveCwd(context, raw) {
29
26
  return abs;
30
27
  }
31
28
  function assertPathSafe(raw, context, label) {
32
- const abs = resolveToolPath(raw, context?.cwd, {
33
- allowRoots: context?.pathRoots,
34
- containment: context?.pathContainment,
35
- });
29
+ const abs = resolveToolPath(raw, context?.cwd, containmentOptions(context));
36
30
  if (isUnderAttachmentRoot(abs, context?.attachmentRoots)) {
37
31
  throw new Error(`session attachments are read-only; cannot ${label} under attachments root`);
38
32
  }
@@ -235,10 +229,7 @@ export function createProjectRunTool() {
235
229
  if (!script || !/^[A-Za-z0-9][A-Za-z0-9:._-]*$/.test(script)) {
236
230
  throw new Error(`project_run: invalid script name "${script}"`);
237
231
  }
238
- const pkgPath = resolveToolPath('package.json', cwd, {
239
- allowRoots: context?.pathRoots,
240
- containment: context?.pathContainment,
241
- });
232
+ const pkgPath = resolveToolPath('package.json', cwd, containmentOptions(context));
242
233
  const { pkg } = await readPackageJson(pkgPath);
243
234
  const scripts = (pkg.scripts ?? {});
244
235
  if (typeof scripts[script] !== 'string') {
@@ -4,6 +4,8 @@
4
4
  * 文件/Shell 工具统一走这里,避免在各工具内手写 `startsWith('/')`
5
5
  * 或硬编码 `/bin/bash` 导致 Windows 行为分裂。
6
6
  */
7
+ import { isPathUnderRoots } from '../../../shared/paths/index.js';
8
+ export { isPathUnderRoots };
7
9
  /** 平台 shell 方言 */
8
10
  export type ShellKind = 'bash' | 'powershell' | 'cmd';
9
11
  /** 已解析的平台 shell */
@@ -17,20 +19,34 @@ export interface PlatformShell {
17
19
  label: string;
18
20
  }
19
21
  /**
20
- * 解析工具入参路径:绝对路径原样返回,相对路径相对 cwd
22
+ * Build containment options from a tool context.
21
23
  *
22
- * 使用 `path.isAbsolute`,同时覆盖 POSIX `/foo`、Windows 盘符
23
- * `C:\` / `C:/` 与 UNC `\\server\share`。
24
+ * Every tool used to spell these fields out by hand, which is how a newly added
25
+ * policy field gets silently dropped (the same failure that hid
26
+ * `refuseFinalSymlink` from the tool surface). One constructor, one place to add
27
+ * the next field.
24
28
  *
25
- * @param rawPath - 工具入参路径
26
- * @param cwd - 工作目录;缺省为 `process.cwd()`
27
- * @returns 规范化后的绝对路径
29
+ * @param context - tool execution context
30
+ * @returns options for {@link resolveToolPath}
28
31
  */
32
+ export declare function containmentOptions(context?: {
33
+ pathRoots?: readonly string[];
34
+ pathContainment?: 'strict' | 'soft' | 'none';
35
+ pathDenylist?: readonly string[];
36
+ } | null): ResolveToolPathOptions;
37
+ /** L2 路径约束选项(由 {@link containmentOptions} 从工具上下文构造) */
29
38
  export interface ResolveToolPathOptions {
30
39
  /** L2 允许根;containment 非 none 时必须落在其下 */
31
- allowRoots?: string[];
40
+ allowRoots?: readonly string[];
32
41
  /** L2 级别;省略 = 不限制 */
33
42
  containment?: 'strict' | 'soft' | 'none';
43
+ /**
44
+ * L2 拒绝清单(glob,匹配允许根内相对路径与文件名)。
45
+ *
46
+ * 独立于 containment:声明即拒绝,任何级别都生效。默认空 = 不拒绝任何路径,
47
+ * 因为「agent 读写自己 workspace 里的 `.env`」是合法且常见的用法。
48
+ */
49
+ denyPatterns?: readonly string[];
34
50
  }
35
51
  /**
36
52
  * 解析工具入参路径:绝对路径原样返回,相对路径相对 cwd
@@ -38,13 +54,11 @@ export interface ResolveToolPathOptions {
38
54
  * 使用 path.isAbsolute,同时覆盖 POSIX /foo、Windows 盘符与 UNC。
39
55
  *
40
56
  * @param rawPath - 工具入参路径
41
- * @param cwd - 工作目录;缺省为 process.cwd()
57
+ * @param cwd - 工具 cwd;缺省为 process.cwd()
42
58
  * @param options - L2 路径包含(ToolEffectPolicy)
43
- * @returns 规范化后的绝对路径
59
+ * @returns 规范化后的绝对路径;containment 生效时为符号链接解析后的真实路径
44
60
  */
45
61
  export declare function resolveToolPath(rawPath: string, cwd?: string, options?: ResolveToolPathOptions): string;
46
- /** 路径是否落在任一 root 之下(含 root 本身) */
47
- export declare function isPathUnderRoots(absPath: string, roots: string[]): boolean;
48
62
  /**
49
63
  * 只读附件根内解析(OP-15):相对名优先贴到 attachmentRoots
50
64
  *
@@ -5,50 +5,146 @@
5
5
  * 或硬编码 `/bin/bash` 导致 Windows 行为分裂。
6
6
  */
7
7
  import { accessSync, constants, existsSync, statSync } from 'node:fs';
8
- import { delimiter, dirname, isAbsolute, join, resolve, sep } from 'node:path';
8
+ import { delimiter, dirname, isAbsolute, join, relative, resolve, sep } from 'node:path';
9
+ import { isPathUnderRoots, lexicalUnderRoots, realpathAllowMissing, } from '../../../shared/paths/index.js';
10
+ import { matchesDenyPattern } from '../../../shared/paths/glob.js';
11
+ export { isPathUnderRoots };
12
+ /**
13
+ * Build containment options from a tool context.
14
+ *
15
+ * Every tool used to spell these fields out by hand, which is how a newly added
16
+ * policy field gets silently dropped (the same failure that hid
17
+ * `refuseFinalSymlink` from the tool surface). One constructor, one place to add
18
+ * the next field.
19
+ *
20
+ * @param context - tool execution context
21
+ * @returns options for {@link resolveToolPath}
22
+ */
23
+ export function containmentOptions(context) {
24
+ return {
25
+ allowRoots: context?.pathRoots,
26
+ containment: context?.pathContainment,
27
+ denyPatterns: context?.pathDenylist,
28
+ };
29
+ }
30
+ /**
31
+ * Apply L2 path containment against real (symlink-resolved) paths.
32
+ *
33
+ * Both sides are resolved: comparing a resolved target against an unresolved
34
+ * root would deny legitimate paths whenever the root is itself an alias
35
+ * (macOS `/var` → `/private/var`). The resolved target is returned so callers
36
+ * act on the same path that was checked; otherwise a link swapped between the
37
+ * check and the following fs call would still escape.
38
+ *
39
+ * @param absPath - absolute, lexically normalized candidate
40
+ * @param rawPath - original caller-supplied path, for error messages
41
+ * @param options - containment level and allowed roots
42
+ * @returns path to operate on
43
+ */
44
+ function containPath(absPath, rawPath, options) {
45
+ const containment = options?.containment ?? 'none';
46
+ const denyPatterns = options?.denyPatterns ?? [];
47
+ const roots = options?.allowRoots ?? [];
48
+ // The denylist is an independent deny layer: if a deployment declares these
49
+ // patterns forbidden, they are forbidden at every containment level. The
50
+ // lexical spelling is checked first because it needs no syscalls.
51
+ if (denyPatterns.length > 0) {
52
+ denyPath(absPath, rawPath, options, denyPatterns);
53
+ }
54
+ // `none` stays syscall-free unless a denylist is declared: then the resolved
55
+ // target must be checked too, or an innocuously named link reads a denied file.
56
+ if (containment === 'none') {
57
+ if (denyPatterns.length > 0)
58
+ denyResolvedTarget(absPath, rawPath, options, denyPatterns);
59
+ return absPath;
60
+ }
61
+ if (roots.length === 0) {
62
+ // strict 无 root = fail-closed(与 isPathAllowed 一致);soft 仅审计
63
+ if (containment === 'strict') {
64
+ throw new Error(`path_forbidden: "${rawPath}" effect roots not configured`);
65
+ }
66
+ if (denyPatterns.length > 0)
67
+ denyResolvedTarget(absPath, rawPath, options, denyPatterns);
68
+ return absPath;
69
+ }
70
+ const realRoots = roots
71
+ .map((root) => realpathAllowMissing(resolve(root)))
72
+ .filter((root) => root !== null);
73
+ const realTarget = realpathAllowMissing(absPath);
74
+ // Re-check the resolved path *before* the root verdict: the caller's spelling
75
+ // may be innocuous while the link target is denied, and that must also hold for
76
+ // paths that end up escaping the roots (soft mode passes those through).
77
+ if (denyPatterns.length > 0 && realTarget !== null && realTarget !== absPath) {
78
+ denyPath(realTarget, rawPath, options, denyPatterns);
79
+ }
80
+ // An unresolvable target or a set of vanished roots is a denial, not a pass.
81
+ // Both sides are already real here, so compare them lexically: re-resolving
82
+ // them would only repeat the syscalls.
83
+ if (realTarget === null || realRoots.length === 0 || !lexicalUnderRoots(realTarget, realRoots)) {
84
+ if (containment === 'strict') {
85
+ throw new Error(`path_forbidden: "${rawPath}" escapes effect roots`);
86
+ }
87
+ // soft:放行(审计由调用方/Observer 负责),保留词法答案以免改变既有语义
88
+ return absPath;
89
+ }
90
+ return realTarget;
91
+ }
92
+ /**
93
+ * Apply the denylist to the symlink-resolved target of a path.
94
+ *
95
+ * Only the resolved spelling is tested: the lexical one was already checked by
96
+ * the caller, and this exists for the "harmless name → denied target" case.
97
+ *
98
+ * @param absPath - absolute, lexically normalized candidate
99
+ * @param rawPath - caller spelling, for the error message
100
+ * @param options - containment options (roots)
101
+ * @param denyPatterns - denylist globs
102
+ */
103
+ function denyResolvedTarget(absPath, rawPath, options, denyPatterns) {
104
+ const realTarget = realpathAllowMissing(absPath);
105
+ if (realTarget !== null && realTarget !== absPath)
106
+ denyPath(realTarget, rawPath, options, denyPatterns);
107
+ }
108
+ /**
109
+ * Throw when the path matches the denylist.
110
+ *
111
+ * Matching happens against the path relative to the containing root, so a
112
+ * pattern like `.git/**` means "inside a root", not "anywhere on the host".
113
+ * When no root contains it the absolute path is used, which still catches
114
+ * name-based patterns such as `*.pem`.
115
+ *
116
+ * @param absPath - absolute path to test
117
+ * @param rawPath - caller spelling, for the error message
118
+ * @param options - containment options (roots)
119
+ * @param denyPatterns - denylist globs
120
+ */
121
+ function denyPath(absPath, rawPath, options, denyPatterns) {
122
+ const roots = options?.allowRoots ?? [];
123
+ const candidates = [];
124
+ for (const root of roots) {
125
+ const realRoot = realpathAllowMissing(resolve(root)) ?? resolve(root);
126
+ if (lexicalUnderRoots(absPath, [realRoot])) {
127
+ candidates.push(relative(realRoot, absPath).split(sep).join('/'));
128
+ }
129
+ }
130
+ candidates.push(absPath.split(sep).join('/'));
131
+ if (candidates.some((candidate) => matchesDenyPattern(candidate, denyPatterns))) {
132
+ throw new Error(`path_forbidden: "${rawPath}" matches pathDenylist`);
133
+ }
134
+ }
9
135
  /**
10
136
  * 解析工具入参路径:绝对路径原样返回,相对路径相对 cwd
11
137
  *
12
138
  * 使用 path.isAbsolute,同时覆盖 POSIX /foo、Windows 盘符与 UNC。
13
139
  *
14
140
  * @param rawPath - 工具入参路径
15
- * @param cwd - 工作目录;缺省为 process.cwd()
141
+ * @param cwd - 工具 cwd;缺省为 process.cwd()
16
142
  * @param options - L2 路径包含(ToolEffectPolicy)
17
- * @returns 规范化后的绝对路径
143
+ * @returns 规范化后的绝对路径;containment 生效时为符号链接解析后的真实路径
18
144
  */
19
145
  export function resolveToolPath(rawPath, cwd, options) {
20
146
  const abs = isAbsolute(rawPath) ? resolve(rawPath) : resolve(cwd ?? process.cwd(), rawPath);
21
- const containment = options?.containment ?? 'none';
22
- if (containment !== 'none') {
23
- const roots = options?.allowRoots ?? [];
24
- if (roots.length === 0) {
25
- // strict 无 root = fail-closed(与 isPathAllowed 一致);soft 仅审计
26
- if (containment === 'strict') {
27
- throw new Error(`path_forbidden: "${rawPath}" effect roots not configured`);
28
- }
29
- return abs;
30
- }
31
- if (!isPathUnderRoots(abs, roots)) {
32
- if (containment === 'strict') {
33
- throw new Error(`path_forbidden: "${rawPath}" escapes effect roots`);
34
- }
35
- // soft:放行(审计由调用方/Observer 负责)
36
- }
37
- }
38
- return abs;
39
- }
40
- /** 路径是否落在任一 root 之下(含 root 本身) */
41
- export function isPathUnderRoots(absPath, roots) {
42
- const win = process.platform === 'win32';
43
- const norm = (s) => {
44
- const r = resolve(s);
45
- return win ? r.toLowerCase() : r;
46
- };
47
- const p = norm(absPath);
48
- return roots.some((root) => {
49
- const r = norm(root);
50
- return p === r || p.startsWith(r.endsWith(sep) ? r : r + sep);
51
- });
147
+ return containPath(abs, rawPath, options);
52
148
  }
53
149
  /**
54
150
  * 只读附件根内解析(OP-15):相对名优先贴到 attachmentRoots
@@ -64,13 +160,31 @@ export function resolveReadableToolPath(rawPath, cwd, attachmentRoots, options)
64
160
  if (!isAbsolute(rawPath) && roots.length > 0) {
65
161
  const cleaned = rawPath.replace(/^[/\\]+/, '');
66
162
  for (const root of roots) {
67
- const candidate = resolve(root, cleaned);
68
163
  const rootResolved = resolve(root);
69
- const prefix = rootResolved.endsWith(sep) ? rootResolved : rootResolved + sep;
70
- if (candidate === rootResolved || candidate.startsWith(prefix)) {
71
- if (existsSync(candidate))
72
- return candidate;
164
+ const candidate = resolve(rootResolved, cleaned);
165
+ // Lexical guard against `cleaned` climbing out of the root; shares the
166
+ // win32 case-folding rule with every other containment check.
167
+ if (candidate !== rootResolved && !lexicalUnderRoots(candidate, [rootResolved]))
168
+ continue;
169
+ if (!existsSync(candidate))
170
+ continue;
171
+ // Attachment roots sit outside the effect roots by design, so they carry
172
+ // their own containment: a link planted in the attachment tree would
173
+ // otherwise be a straight read out of the read-only sandbox.
174
+ // Both sides are resolved here, so compare lexically rather than making
175
+ // isPathUnderRoots resolve them a second time.
176
+ const realRoot = realpathAllowMissing(rootResolved);
177
+ const realCandidate = realpathAllowMissing(candidate);
178
+ if (realRoot === null || realCandidate === null)
179
+ continue;
180
+ if (!lexicalUnderRoots(realCandidate, [realRoot]))
181
+ continue;
182
+ // Attachment roots are outside the effect roots, so they would otherwise
183
+ // skip the denylist entirely: "read-only" is not "allowed to read".
184
+ if (options?.denyPatterns && options.denyPatterns.length > 0) {
185
+ denyPath(realCandidate, rawPath, options, options.denyPatterns);
73
186
  }
187
+ return realCandidate;
74
188
  }
75
189
  }
76
190
  // attachments 命中后返回;其余走 L2
@@ -85,17 +199,11 @@ export function resolveReadableToolPath(rawPath, cwd, attachmentRoots, options)
85
199
  export function isUnderAttachmentRoot(path, attachmentRoots) {
86
200
  if (!attachmentRoots?.length)
87
201
  return false;
88
- // Windows 路径比较须大小写不敏感,否则可绕过 startsWith 写保护
89
- const win = process.platform === 'win32';
90
- const norm = (s) => (win ? resolve(s).toLowerCase() : resolve(s));
91
- const p = norm(path);
92
- for (const root of attachmentRoots) {
93
- const r = norm(root);
94
- const prefix = r.endsWith(sep) ? r : r + sep;
95
- if (p === r || p.startsWith(prefix))
96
- return true;
97
- }
98
- return false;
202
+ // `path` now arrives resolved (`resolveToolPath` returns the real path), so a
203
+ // purely lexical comparison against a configured root would report false
204
+ // whenever the root is an alias (macOS /var, symlinked HOME) — turning a
205
+ // write-protection guard into a fail-open. Resolve both sides.
206
+ return isPathUnderRoots(path, attachmentRoots);
99
207
  }
100
208
  function isExecutableFile(filePath) {
101
209
  try {
@@ -374,17 +482,15 @@ export function defaultPathEnv() {
374
482
  * @returns whether the path is protected undo ledger
375
483
  */
376
484
  export function isUnderSessionUndoRoot(target, undoRoots) {
377
- const resolved = resolve(target);
378
485
  const roots = (undoRoots ?? []).map((r) => r?.trim()).filter(Boolean);
379
- const fold = (p) => process.platform === 'win32' ? p.toLowerCase() : p;
380
- if (roots.length > 0) {
381
- const norm = (p) => fold(resolve(p).replace(/\\/g, '/'));
382
- const tNorm = norm(resolved);
383
- return roots.some((root) => {
384
- const r = norm(root);
385
- return tNorm === r || tNorm.startsWith(r.endsWith('/') ? r : r + '/');
386
- });
387
- }
388
- const norm = fold(resolved.replace(/\\/g, '/'));
389
- return /\/sessions\/[^/]+\/undo(\/|$)/i.test(norm);
486
+ // Same coordinate problem as isUnderAttachmentRoot: the target arrives as a
487
+ // real path while the configured roots keep their lexical spelling.
488
+ if (roots.length > 0)
489
+ return isPathUnderRoots(target, roots);
490
+ // No configured roots: recognise the default layout instead. Resolve first so
491
+ // a symlinked sessions directory still matches the same rule.
492
+ const resolved = realpathAllowMissing(resolve(target)) ?? resolve(target);
493
+ const converted = resolved.replace(/\\/g, '/');
494
+ const folded = process.platform === 'win32' ? converted.toLowerCase() : converted;
495
+ return /\/sessions\/[^/]+\/undo(\/|$)/i.test(folded);
390
496
  }
@@ -0,0 +1,43 @@
1
+ /**
2
+ * priv_exec 工具 — 白名单提权执行(ops P3,§5 P3 / §8)
3
+ *
4
+ * 独立 privileged 通道:引擎侧 execFile 执行完整 argv,不经 shell、不包 jail、
5
+ * env 消毒、**cwd 钉住**(规则显式或 `/`,绝不取 agent 的 cwd)、超时真树杀。
6
+ * shell 工具保持原牢笼语义不动(原则 6:提权不与牢笼抢轴)。
7
+ *
8
+ * 安全闸门(全 fail-closed):
9
+ * 1. **匹配面**(effect-policy `matchEscalationRule`):`allowlist` 档 cmd 绝对路径 +
10
+ * args 逐项全等;`full` 档(P4,需 privilegedAck + jail=none + mode=host)无
11
+ * allowlist 面,但 `via: sudo` 仍必须显式 `sudo -n` 形态(裸跑 = 非特权通道假象)。
12
+ * 未命中/形态非法 → 拒绝 + `ops.escalation.denied` 留痕(不留痕的拒绝等于没拒)。
13
+ * 2. **确认闸门**:规则 `confirm: true`(allowlist)或 §6 危险分类命中(full 档)走
14
+ * HitlDecision 单模型(§8.2),缓存 key 含**完整 argv 全等**(§5 P3:防一次批准
15
+ * 放行整类);特权通道把 `approve_always` 降格为 `approve_session`。
16
+ * **确认超时一律 deny**(T1 硬约束,outcome 不可配)。
17
+ * 3. **请求者授权**(§8.6 拍板):由 SEC-2 `toolRights.deny('priv_exec')` 表达——
18
+ * 缺权参与者在 toolRights 层即拒,连确认闸都到不了。
19
+ * 4. **审计**(§7):`ops.escalation.requested` → `ops.privileged.exec` / `denied`。
20
+ *
21
+ * `full` 档的 §6 分类是**减速带不是安全边界**(只拦事故不拦攻击):未命中自动放行,
22
+ * 不做「未知即危险」;真正的边界是 privilegedAck + 常驻 PRIVILEGED 标记 + 审计。
23
+ */
24
+ import type { RegisteredTool } from '@octopi-agent/core/types.js';
25
+ import { type HitlDecisionCache } from '../../../governance/human-in-the-loop/decision-cache.js';
26
+ /** 创建选项 */
27
+ export interface CreatePrivExecToolOptions {
28
+ /** HITL 决策缓存(缺省全局 defaultHitlCache;测试/宿主可注入独立实例) */
29
+ cache?: HitlDecisionCache;
30
+ }
31
+ /**
32
+ * 创建 priv_exec 工具
33
+ *
34
+ * 参数:
35
+ * - cmd (string, required):可执行文件**绝对路径**(与规则逐字相同)
36
+ * - args (string[], optional):argv 尾部(与规则逐项全等)
37
+ *
38
+ * 返回:ruleId / exitCode / stdout / stderr / durationMs / confirmDecision。
39
+ *
40
+ * @param options - 可注入 HITL 缓存
41
+ * @returns 注册好的提权工具
42
+ */
43
+ export declare function createPrivExecTool(options?: CreatePrivExecToolOptions): RegisteredTool;