aiden-runtime 4.1.5 → 4.6.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 (181) hide show
  1. package/README.md +265 -847
  2. package/dist/api/server.js +32 -5
  3. package/dist/cli/v4/aidenCLI.js +536 -152
  4. package/dist/cli/v4/callbacks.js +170 -0
  5. package/dist/cli/v4/chatSession.js +245 -3
  6. package/dist/cli/v4/commands/_runtimeToggleHelpers.js +94 -0
  7. package/dist/cli/v4/commands/browserDepth.js +45 -0
  8. package/dist/cli/v4/commands/cron.js +264 -0
  9. package/dist/cli/v4/commands/daemon.js +541 -0
  10. package/dist/cli/v4/commands/daemonStatus.js +253 -0
  11. package/dist/cli/v4/commands/fanout.js +42 -59
  12. package/dist/cli/v4/commands/help.js +13 -0
  13. package/dist/cli/v4/commands/index.js +35 -1
  14. package/dist/cli/v4/commands/mcp.js +80 -54
  15. package/dist/cli/v4/commands/plannerGuard.js +53 -0
  16. package/dist/cli/v4/commands/recovery.js +122 -0
  17. package/dist/cli/v4/commands/runs.js +223 -0
  18. package/dist/cli/v4/commands/sandbox.js +48 -0
  19. package/dist/cli/v4/commands/spawnPause.js +93 -0
  20. package/dist/cli/v4/commands/suggestions.js +68 -0
  21. package/dist/cli/v4/commands/tce.js +41 -0
  22. package/dist/cli/v4/commands/trigger.js +378 -0
  23. package/dist/cli/v4/commands/update.js +95 -3
  24. package/dist/cli/v4/daemonAgentBuilder.js +145 -0
  25. package/dist/cli/v4/defaultSoul.js +1 -1
  26. package/dist/cli/v4/display/capabilityCard.js +26 -0
  27. package/dist/cli/v4/display.js +18 -8
  28. package/dist/cli/v4/replyRenderer.js +31 -23
  29. package/dist/cli/v4/updateBootPrompt.js +170 -0
  30. package/dist/core/playwrightBridge.js +129 -0
  31. package/dist/core/v4/aidenAgent.js +527 -5
  32. package/dist/core/v4/browserState.js +436 -0
  33. package/dist/core/v4/checkpoint.js +79 -0
  34. package/dist/core/v4/daemon/bootstrap.js +651 -0
  35. package/dist/core/v4/daemon/cleanShutdown.js +154 -0
  36. package/dist/core/v4/daemon/cron/cronBridge.js +126 -0
  37. package/dist/core/v4/daemon/cron/cronEmitter.js +173 -0
  38. package/dist/core/v4/daemon/cron/migration.js +199 -0
  39. package/dist/core/v4/daemon/cron/misfirePolicy.js +115 -0
  40. package/dist/core/v4/daemon/daemonConfig.js +90 -0
  41. package/dist/core/v4/daemon/db/connection.js +106 -0
  42. package/dist/core/v4/daemon/db/migrations.js +362 -0
  43. package/dist/core/v4/daemon/db/schema/v1.spec.js +18 -0
  44. package/dist/core/v4/daemon/dispatcher/agentRunner.js +98 -0
  45. package/dist/core/v4/daemon/dispatcher/budgetGate.js +127 -0
  46. package/dist/core/v4/daemon/dispatcher/daemonApproval.js +113 -0
  47. package/dist/core/v4/daemon/dispatcher/dailyBudgetTracker.js +120 -0
  48. package/dist/core/v4/daemon/dispatcher/dispatcher.js +389 -0
  49. package/dist/core/v4/daemon/dispatcher/fireRateLimiter.js +113 -0
  50. package/dist/core/v4/daemon/dispatcher/index.js +53 -0
  51. package/dist/core/v4/daemon/dispatcher/promptTemplate.js +95 -0
  52. package/dist/core/v4/daemon/dispatcher/realAgentRunner.js +356 -0
  53. package/dist/core/v4/daemon/dispatcher/resolveModel.js +93 -0
  54. package/dist/core/v4/daemon/dispatcher/sessionId.js +93 -0
  55. package/dist/core/v4/daemon/drain.js +156 -0
  56. package/dist/core/v4/daemon/eventLoopLag.js +73 -0
  57. package/dist/core/v4/daemon/health.js +159 -0
  58. package/dist/core/v4/daemon/idempotencyStore.js +204 -0
  59. package/dist/core/v4/daemon/index.js +179 -0
  60. package/dist/core/v4/daemon/instanceTracker.js +99 -0
  61. package/dist/core/v4/daemon/resourceRegistry.js +150 -0
  62. package/dist/core/v4/daemon/restartCode.js +32 -0
  63. package/dist/core/v4/daemon/restartFailureCounter.js +77 -0
  64. package/dist/core/v4/daemon/runStore.js +144 -0
  65. package/dist/core/v4/daemon/runtimeLock.js +167 -0
  66. package/dist/core/v4/daemon/signals.js +50 -0
  67. package/dist/core/v4/daemon/supervisor.js +272 -0
  68. package/dist/core/v4/daemon/triggerBus.js +279 -0
  69. package/dist/core/v4/daemon/triggers/email/allowlist.js +70 -0
  70. package/dist/core/v4/daemon/triggers/email/automatedSender.js +78 -0
  71. package/dist/core/v4/daemon/triggers/email/bodyExtractor.js +0 -0
  72. package/dist/core/v4/daemon/triggers/email/emailSeenStore.js +99 -0
  73. package/dist/core/v4/daemon/triggers/email/emailSpec.js +107 -0
  74. package/dist/core/v4/daemon/triggers/email/imapConnection.js +211 -0
  75. package/dist/core/v4/daemon/triggers/email/index.js +332 -0
  76. package/dist/core/v4/daemon/triggers/email/seenUids.js +60 -0
  77. package/dist/core/v4/daemon/triggers/fileObservationsStore.js +93 -0
  78. package/dist/core/v4/daemon/triggers/fileWatcher.js +253 -0
  79. package/dist/core/v4/daemon/triggers/fileWatcherSpec.js +88 -0
  80. package/dist/core/v4/daemon/triggers/fsIdentity.js +42 -0
  81. package/dist/core/v4/daemon/triggers/globMatcher.js +100 -0
  82. package/dist/core/v4/daemon/triggers/reconcile.js +206 -0
  83. package/dist/core/v4/daemon/triggers/settleStat.js +81 -0
  84. package/dist/core/v4/daemon/triggers/webhook.js +376 -0
  85. package/dist/core/v4/daemon/triggers/webhookDeliveriesStore.js +109 -0
  86. package/dist/core/v4/daemon/triggers/webhookIdempotency.js +72 -0
  87. package/dist/core/v4/daemon/triggers/webhookRateLimit.js +56 -0
  88. package/dist/core/v4/daemon/triggers/webhookSpec.js +76 -0
  89. package/dist/core/v4/daemon/triggers/webhookVerifier.js +128 -0
  90. package/dist/core/v4/daemon/types.js +15 -0
  91. package/dist/core/v4/dockerSession.js +461 -0
  92. package/dist/core/v4/dryRun.js +117 -0
  93. package/dist/core/v4/failureClassifier.js +779 -0
  94. package/dist/core/v4/providerFallback.js +35 -2
  95. package/dist/core/v4/recoveryReport.js +449 -0
  96. package/dist/core/v4/runtimeToggles.js +214 -0
  97. package/dist/core/v4/sandboxConfig.js +285 -0
  98. package/dist/core/v4/sandboxFs.js +316 -0
  99. package/dist/core/v4/selfimprovement/recoveryStore.js +307 -0
  100. package/dist/core/v4/selfimprovement/signatureBuilder.js +158 -0
  101. package/dist/core/v4/subagent/childBuilder.js +391 -0
  102. package/dist/core/v4/subagent/fanout.js +75 -51
  103. package/dist/core/v4/subagent/spawnPause.js +191 -0
  104. package/dist/core/v4/subagent/spawnSubAgent.js +310 -0
  105. package/dist/core/v4/suggestionCatalog.js +41 -0
  106. package/dist/core/v4/suggestionEngine.js +210 -0
  107. package/dist/core/v4/toolRegistry.js +37 -3
  108. package/dist/core/v4/turnState.js +587 -0
  109. package/dist/core/v4/update/checkUpdate.js +63 -3
  110. package/dist/core/v4/update/installMethodDetect.js +115 -0
  111. package/dist/core/v4/update/registryClient.js +121 -0
  112. package/dist/core/v4/update/skipState.js +75 -0
  113. package/dist/core/v4/verifier.js +448 -0
  114. package/dist/core/version.js +1 -1
  115. package/dist/moat/plannerGuard.js +29 -0
  116. package/dist/providers/v4/anthropicAdapter.js +31 -3
  117. package/dist/providers/v4/chatCompletionsAdapter.js +26 -3
  118. package/dist/providers/v4/codexResponsesAdapter.js +25 -2
  119. package/dist/providers/v4/ollamaPromptToolsAdapter.js +57 -2
  120. package/dist/tools/v4/browser/_observer.js +224 -0
  121. package/dist/tools/v4/browser/browserBlocker.js +396 -0
  122. package/dist/tools/v4/browser/browserClick.js +18 -1
  123. package/dist/tools/v4/browser/browserClose.js +18 -1
  124. package/dist/tools/v4/browser/browserExtract.js +5 -1
  125. package/dist/tools/v4/browser/browserFill.js +17 -1
  126. package/dist/tools/v4/browser/browserGetUrl.js +5 -1
  127. package/dist/tools/v4/browser/browserNavigate.js +16 -1
  128. package/dist/tools/v4/browser/browserScreenshot.js +5 -1
  129. package/dist/tools/v4/browser/browserScroll.js +18 -1
  130. package/dist/tools/v4/browser/browserType.js +17 -1
  131. package/dist/tools/v4/browser/captchaCheck.js +5 -1
  132. package/dist/tools/v4/executeCode.js +1 -0
  133. package/dist/tools/v4/files/fileCopy.js +56 -2
  134. package/dist/tools/v4/files/fileDelete.js +38 -1
  135. package/dist/tools/v4/files/fileList.js +12 -1
  136. package/dist/tools/v4/files/fileMove.js +59 -2
  137. package/dist/tools/v4/files/filePatch.js +43 -1
  138. package/dist/tools/v4/files/fileRead.js +12 -1
  139. package/dist/tools/v4/files/fileWrite.js +41 -1
  140. package/dist/tools/v4/index.js +88 -61
  141. package/dist/tools/v4/memory/memoryAdd.js +14 -0
  142. package/dist/tools/v4/memory/memoryRemove.js +14 -0
  143. package/dist/tools/v4/memory/memoryReplace.js +15 -0
  144. package/dist/tools/v4/memory/sessionSummary.js +12 -0
  145. package/dist/tools/v4/process/processKill.js +19 -0
  146. package/dist/tools/v4/process/processList.js +1 -0
  147. package/dist/tools/v4/process/processLogRead.js +1 -0
  148. package/dist/tools/v4/process/processSpawn.js +13 -0
  149. package/dist/tools/v4/process/processWait.js +1 -0
  150. package/dist/tools/v4/sessions/recallSession.js +1 -0
  151. package/dist/tools/v4/sessions/sessionList.js +1 -0
  152. package/dist/tools/v4/sessions/sessionSearch.js +1 -0
  153. package/dist/tools/v4/skills/lookupToolSchema.js +7 -0
  154. package/dist/tools/v4/skills/skillManage.js +13 -0
  155. package/dist/tools/v4/skills/skillView.js +1 -0
  156. package/dist/tools/v4/skills/skillsList.js +1 -0
  157. package/dist/tools/v4/subagent/spawnSubAgentTool.js +334 -0
  158. package/dist/tools/v4/subagent/subagentFanout.js +54 -1
  159. package/dist/tools/v4/system/aidenSelfUpdate.js +16 -0
  160. package/dist/tools/v4/system/appClose.js +13 -0
  161. package/dist/tools/v4/system/appInput.js +13 -0
  162. package/dist/tools/v4/system/appLaunch.js +13 -0
  163. package/dist/tools/v4/system/clipboardRead.js +1 -0
  164. package/dist/tools/v4/system/clipboardWrite.js +14 -0
  165. package/dist/tools/v4/system/mediaKey.js +12 -0
  166. package/dist/tools/v4/system/mediaSessions.js +1 -0
  167. package/dist/tools/v4/system/mediaTransport.js +13 -0
  168. package/dist/tools/v4/system/naturalEvents.js +1 -0
  169. package/dist/tools/v4/system/nowPlaying.js +1 -0
  170. package/dist/tools/v4/system/osProcessList.js +1 -0
  171. package/dist/tools/v4/system/screenshot.js +1 -0
  172. package/dist/tools/v4/system/systemInfo.js +1 -0
  173. package/dist/tools/v4/system/volumeSet.js +17 -0
  174. package/dist/tools/v4/terminal/shellExec.js +81 -9
  175. package/dist/tools/v4/web/deepResearch.js +1 -0
  176. package/dist/tools/v4/web/openUrl.js +1 -0
  177. package/dist/tools/v4/web/webFetch.js +1 -0
  178. package/dist/tools/v4/web/webPage.js +1 -0
  179. package/dist/tools/v4/web/webSearch.js +1 -0
  180. package/dist/tools/v4/web/youtubeSearch.js +1 -0
  181. package/package.json +13 -3
@@ -57,10 +57,14 @@ exports.CAPTCHA_MARKERS = [
57
57
  'request unsuccessful',
58
58
  'reference number',
59
59
  'this website is using a security service',
60
- // hCaptcha / reCAPTCHA explicit
60
+ // hCaptcha / reCAPTCHA / Turnstile explicit
61
61
  'hcaptcha.com',
62
62
  'recaptcha',
63
63
  'g-recaptcha',
64
+ // v4.3 Phase 3 — Cloudflare Turnstile (newer than Cloudflare's
65
+ // older "Just a moment" interstitial; uses its own widget).
66
+ 'cf-turnstile',
67
+ 'turnstile',
64
68
  // PerimeterX
65
69
  'press and hold',
66
70
  'human verification',
@@ -71,6 +71,7 @@ exports.executeCodeTool = {
71
71
  category: 'execute',
72
72
  mutates: false,
73
73
  toolset: 'execute',
74
+ riskTier: 'caution', // v4.4 Phase 1
74
75
  async execute(args) {
75
76
  const code = String(args.code ?? '');
76
77
  if (!code.trim()) {
@@ -21,6 +21,7 @@ exports.fileCopyTool = void 0;
21
21
  const node_fs_1 = require("node:fs");
22
22
  const node_path_1 = __importDefault(require("node:path"));
23
23
  const paths_1 = require("../utils/paths");
24
+ const sandboxFs_1 = require("../../../core/v4/sandboxFs");
24
25
  exports.fileCopyTool = {
25
26
  schema: {
26
27
  name: 'file_copy',
@@ -37,6 +38,42 @@ exports.fileCopyTool = {
37
38
  category: 'write',
38
39
  mutates: true,
39
40
  toolset: 'files',
41
+ riskTier: 'caution', // v4.4 Phase 1
42
+ // v4.4 Phase 4 — dry-run preview.
43
+ async buildPreview(args, ctx) {
44
+ const fromRaw = String(args.from ?? args.source ?? '').trim();
45
+ const toRaw = String(args.to ?? args.dest ?? args.destination ?? '').trim();
46
+ const src = (0, sandboxFs_1.isPathAllowed)(fromRaw, 'read', ctx.cwd);
47
+ const dst = (0, sandboxFs_1.isPathAllowed)(toRaw, 'write', ctx.cwd);
48
+ let srcExists = false;
49
+ try {
50
+ await node_fs_1.promises.stat(src.resolvedPath);
51
+ srcExists = true;
52
+ }
53
+ catch { /* missing */ }
54
+ if (!src.allowed) {
55
+ return {
56
+ tool: 'file_copy', args, riskTier: 'caution', detectedRisks: [],
57
+ sideEffects: [{ type: 'refuse', reason: src.violation.message }],
58
+ summary: `Refused (source): ${src.violation.code}`,
59
+ };
60
+ }
61
+ if (!dst.allowed) {
62
+ return {
63
+ tool: 'file_copy', args, riskTier: 'caution', detectedRisks: [],
64
+ sideEffects: [{ type: 'refuse', reason: dst.violation.message }],
65
+ summary: `Refused (dest): ${dst.violation.code}`,
66
+ };
67
+ }
68
+ return {
69
+ tool: 'file_copy',
70
+ args,
71
+ riskTier: 'caution',
72
+ sideEffects: [{ type: 'copy_path', from: src.resolvedPath, to: dst.resolvedPath, src_exists: srcExists }],
73
+ detectedRisks: [],
74
+ summary: `Would copy ${src.resolvedPath} → ${dst.resolvedPath}${srcExists ? '' : ' (source missing)'}`,
75
+ };
76
+ },
40
77
  async execute(args, ctx) {
41
78
  const fromRaw = String(args.from ?? args.source ?? '').trim();
42
79
  const toRaw = String(args.to ?? args.dest ?? args.destination ?? '').trim();
@@ -46,8 +83,25 @@ exports.fileCopyTool = {
46
83
  if ((0, paths_1.isProtectedPath)(fromRaw) || (0, paths_1.isProtectedPath)(toRaw)) {
47
84
  return { success: false, error: 'Access denied: protected path' };
48
85
  }
49
- const from = (0, paths_1.expandPath)(fromRaw, ctx.cwd);
50
- const to = (0, paths_1.expandPath)(toRaw, ctx.cwd);
86
+ // v4.4 Phase 2 — sandbox preflight (source = read, dest = write).
87
+ const srcPolicy = (0, sandboxFs_1.isPathAllowed)(fromRaw, 'read', ctx.cwd);
88
+ if (!srcPolicy.allowed) {
89
+ return {
90
+ success: false,
91
+ error: srcPolicy.violation.message,
92
+ sandbox_violation: (0, sandboxFs_1.violationEnvelope)(srcPolicy),
93
+ };
94
+ }
95
+ const dstPolicy = (0, sandboxFs_1.isPathAllowed)(toRaw, 'write', ctx.cwd);
96
+ if (!dstPolicy.allowed) {
97
+ return {
98
+ success: false,
99
+ error: dstPolicy.violation.message,
100
+ sandbox_violation: (0, sandboxFs_1.violationEnvelope)(dstPolicy),
101
+ };
102
+ }
103
+ const from = srcPolicy.resolvedPath;
104
+ const to = dstPolicy.resolvedPath;
51
105
  try {
52
106
  await node_fs_1.promises.mkdir(node_path_1.default.dirname(to), { recursive: true });
53
107
  await node_fs_1.promises.cp(from, to, { recursive: true });
@@ -19,6 +19,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
19
19
  exports.fileDeleteTool = void 0;
20
20
  const node_fs_1 = require("node:fs");
21
21
  const paths_1 = require("../utils/paths");
22
+ const sandboxFs_1 = require("../../../core/v4/sandboxFs");
22
23
  exports.fileDeleteTool = {
23
24
  schema: {
24
25
  name: 'file_delete',
@@ -38,6 +39,33 @@ exports.fileDeleteTool = {
38
39
  category: 'write',
39
40
  mutates: true,
40
41
  toolset: 'files',
42
+ riskTier: 'dangerous', // v4.4 Phase 1 — irreversible filesystem mutation
43
+ // v4.4 Phase 4 — dry-run preview.
44
+ async buildPreview(args, ctx) {
45
+ const raw = String(args.path ?? args.file ?? '').trim();
46
+ const recursive = args.recursive === true;
47
+ const policy = (0, sandboxFs_1.isPathAllowed)(raw, 'delete', ctx.cwd);
48
+ const resolved = policy.resolvedPath;
49
+ let exists = false;
50
+ try {
51
+ await node_fs_1.promises.stat(resolved);
52
+ exists = true;
53
+ }
54
+ catch { /* missing */ }
55
+ const sideEffects = policy.allowed
56
+ ? [{ type: 'delete_file', path: resolved, exists, recursive }]
57
+ : [{ type: 'refuse', reason: policy.violation.message }];
58
+ return {
59
+ tool: 'file_delete',
60
+ args,
61
+ riskTier: 'dangerous',
62
+ sideEffects,
63
+ detectedRisks: policy.allowed && recursive ? ['recursive_delete'] : [],
64
+ summary: policy.allowed
65
+ ? `Would ${recursive ? 'recursively ' : ''}delete ${resolved}${exists ? '' : ' (does not exist)'}`
66
+ : `Refused: ${policy.violation.code}`,
67
+ };
68
+ },
41
69
  async execute(args, ctx) {
42
70
  const raw = String(args.path ?? args.file ?? '').trim();
43
71
  if (!raw)
@@ -45,7 +73,16 @@ exports.fileDeleteTool = {
45
73
  if ((0, paths_1.isProtectedPath)(raw)) {
46
74
  return { success: false, error: 'Access denied: protected path' };
47
75
  }
48
- const resolved = (0, paths_1.expandPath)(raw, ctx.cwd);
76
+ // v4.4 Phase 2 — sandbox preflight (no-op when AIDEN_SANDBOX!=1).
77
+ const policy = (0, sandboxFs_1.isPathAllowed)(raw, 'delete', ctx.cwd);
78
+ if (!policy.allowed) {
79
+ return {
80
+ success: false,
81
+ error: policy.violation.message,
82
+ sandbox_violation: (0, sandboxFs_1.violationEnvelope)(policy),
83
+ };
84
+ }
85
+ const resolved = policy.resolvedPath;
49
86
  if ((0, paths_1.isFilesystemRoot)(resolved)) {
50
87
  return { success: false, error: 'Refusing to delete filesystem root' };
51
88
  }
@@ -22,6 +22,7 @@ exports.fileListTool = void 0;
22
22
  const node_fs_1 = require("node:fs");
23
23
  const node_path_1 = __importDefault(require("node:path"));
24
24
  const node_os_1 = __importDefault(require("node:os"));
25
+ const sandboxFs_1 = require("../../../core/v4/sandboxFs");
25
26
  function expandPath(input, cwd) {
26
27
  const home = node_os_1.default.homedir();
27
28
  let p = input;
@@ -54,9 +55,19 @@ exports.fileListTool = {
54
55
  category: 'read',
55
56
  mutates: false,
56
57
  toolset: 'files',
58
+ riskTier: 'safe', // v4.4 Phase 1
57
59
  async execute(args, ctx) {
58
60
  const raw = String(args.path ?? args.dir ?? ctx.cwd).trim();
59
- const resolved = expandPath(raw || ctx.cwd, ctx.cwd);
61
+ // v4.4 Phase 2 — sandbox preflight (no-op when AIDEN_SANDBOX!=1).
62
+ const policy = (0, sandboxFs_1.isPathAllowed)(raw || ctx.cwd, 'read', ctx.cwd);
63
+ if (!policy.allowed) {
64
+ return {
65
+ success: false,
66
+ error: policy.violation.message,
67
+ sandbox_violation: (0, sandboxFs_1.violationEnvelope)(policy),
68
+ };
69
+ }
70
+ const resolved = policy.resolvedPath;
60
71
  try {
61
72
  const entries = await node_fs_1.promises.readdir(resolved, { withFileTypes: true });
62
73
  const items = entries.map((e) => ({
@@ -22,6 +22,7 @@ exports.fileMoveTool = void 0;
22
22
  const node_fs_1 = require("node:fs");
23
23
  const node_path_1 = __importDefault(require("node:path"));
24
24
  const paths_1 = require("../utils/paths");
25
+ const sandboxFs_1 = require("../../../core/v4/sandboxFs");
25
26
  exports.fileMoveTool = {
26
27
  schema: {
27
28
  name: 'file_move',
@@ -38,6 +39,42 @@ exports.fileMoveTool = {
38
39
  category: 'write',
39
40
  mutates: true,
40
41
  toolset: 'files',
42
+ riskTier: 'caution', // v4.4 Phase 1
43
+ // v4.4 Phase 4 — dry-run preview.
44
+ async buildPreview(args, ctx) {
45
+ const fromRaw = String(args.from ?? args.source ?? '').trim();
46
+ const toRaw = String(args.to ?? args.dest ?? args.destination ?? '').trim();
47
+ const src = (0, sandboxFs_1.isPathAllowed)(fromRaw, 'write', ctx.cwd);
48
+ const dst = (0, sandboxFs_1.isPathAllowed)(toRaw, 'write', ctx.cwd);
49
+ let srcExists = false;
50
+ try {
51
+ await node_fs_1.promises.stat(src.resolvedPath);
52
+ srcExists = true;
53
+ }
54
+ catch { /* missing */ }
55
+ if (!src.allowed) {
56
+ return {
57
+ tool: 'file_move', args, riskTier: 'caution', detectedRisks: [],
58
+ sideEffects: [{ type: 'refuse', reason: src.violation.message }],
59
+ summary: `Refused (source): ${src.violation.code}`,
60
+ };
61
+ }
62
+ if (!dst.allowed) {
63
+ return {
64
+ tool: 'file_move', args, riskTier: 'caution', detectedRisks: [],
65
+ sideEffects: [{ type: 'refuse', reason: dst.violation.message }],
66
+ summary: `Refused (dest): ${dst.violation.code}`,
67
+ };
68
+ }
69
+ return {
70
+ tool: 'file_move',
71
+ args,
72
+ riskTier: 'caution',
73
+ sideEffects: [{ type: 'move_path', from: src.resolvedPath, to: dst.resolvedPath, src_exists: srcExists }],
74
+ detectedRisks: [],
75
+ summary: `Would move ${src.resolvedPath} → ${dst.resolvedPath}${srcExists ? '' : ' (source missing)'}`,
76
+ };
77
+ },
41
78
  async execute(args, ctx) {
42
79
  const fromRaw = String(args.from ?? args.source ?? '').trim();
43
80
  const toRaw = String(args.to ?? args.dest ?? args.destination ?? '').trim();
@@ -47,8 +84,28 @@ exports.fileMoveTool = {
47
84
  if ((0, paths_1.isProtectedPath)(fromRaw) || (0, paths_1.isProtectedPath)(toRaw)) {
48
85
  return { success: false, error: 'Access denied: protected path' };
49
86
  }
50
- const from = (0, paths_1.expandPath)(fromRaw, ctx.cwd);
51
- const to = (0, paths_1.expandPath)(toRaw, ctx.cwd);
87
+ // v4.4 Phase 2 — sandbox preflight. Move = read source + write dest;
88
+ // since the source is also being deleted, this could arguably be
89
+ // 'delete' on source — but delete and write share the same allowlist
90
+ // semantics in the policy. 'read' on source matches copy's shape.
91
+ const srcPolicy = (0, sandboxFs_1.isPathAllowed)(fromRaw, 'write', ctx.cwd);
92
+ if (!srcPolicy.allowed) {
93
+ return {
94
+ success: false,
95
+ error: srcPolicy.violation.message,
96
+ sandbox_violation: (0, sandboxFs_1.violationEnvelope)(srcPolicy),
97
+ };
98
+ }
99
+ const dstPolicy = (0, sandboxFs_1.isPathAllowed)(toRaw, 'write', ctx.cwd);
100
+ if (!dstPolicy.allowed) {
101
+ return {
102
+ success: false,
103
+ error: dstPolicy.violation.message,
104
+ sandbox_violation: (0, sandboxFs_1.violationEnvelope)(dstPolicy),
105
+ };
106
+ }
107
+ const from = srcPolicy.resolvedPath;
108
+ const to = dstPolicy.resolvedPath;
52
109
  try {
53
110
  await node_fs_1.promises.mkdir(node_path_1.default.dirname(to), { recursive: true });
54
111
  try {
@@ -19,6 +19,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
19
19
  exports.filePatchTool = void 0;
20
20
  const node_fs_1 = require("node:fs");
21
21
  const paths_1 = require("../utils/paths");
22
+ const sandboxFs_1 = require("../../../core/v4/sandboxFs");
22
23
  exports.filePatchTool = {
23
24
  schema: {
24
25
  name: 'file_patch',
@@ -40,6 +41,38 @@ exports.filePatchTool = {
40
41
  category: 'write',
41
42
  mutates: true,
42
43
  toolset: 'files',
44
+ riskTier: 'caution', // v4.4 Phase 1
45
+ // v4.4 Phase 4 — dry-run preview.
46
+ async buildPreview(args, ctx) {
47
+ const raw = String(args.path ?? args.file ?? '').trim();
48
+ const find = typeof args.find === 'string' ? args.find : '';
49
+ const replace = typeof args.replace === 'string' ? args.replace : '';
50
+ const policy = (0, sandboxFs_1.isPathAllowed)(raw, 'write', ctx.cwd);
51
+ const resolved = policy.resolvedPath;
52
+ let matches = 0;
53
+ let bytesDelta = 0;
54
+ if (policy.allowed && find) {
55
+ try {
56
+ const txt = await node_fs_1.promises.readFile(resolved, 'utf-8');
57
+ matches = txt.split(find).length - 1;
58
+ bytesDelta = matches * (Buffer.byteLength(replace, 'utf-8') - Buffer.byteLength(find, 'utf-8'));
59
+ }
60
+ catch { /* file may not exist — surfaced as 0 matches */ }
61
+ }
62
+ const sideEffects = policy.allowed
63
+ ? [{ type: 'patch_file', path: resolved, matches, bytes_delta: bytesDelta }]
64
+ : [{ type: 'refuse', reason: policy.violation.message }];
65
+ return {
66
+ tool: 'file_patch',
67
+ args,
68
+ riskTier: 'caution',
69
+ sideEffects,
70
+ detectedRisks: [],
71
+ summary: policy.allowed
72
+ ? `Would patch ${resolved} (${matches} match${matches === 1 ? '' : 'es'}, Δ ${bytesDelta} bytes)`
73
+ : `Refused: ${policy.violation.code}`,
74
+ };
75
+ },
43
76
  async execute(args, ctx) {
44
77
  const raw = String(args.path ?? args.file ?? '').trim();
45
78
  if (!raw)
@@ -47,12 +80,21 @@ exports.filePatchTool = {
47
80
  if ((0, paths_1.isProtectedPath)(raw)) {
48
81
  return { success: false, error: 'Access denied: protected path' };
49
82
  }
83
+ // v4.4 Phase 2 — sandbox preflight (no-op when AIDEN_SANDBOX!=1).
84
+ const policy = (0, sandboxFs_1.isPathAllowed)(raw, 'write', ctx.cwd);
85
+ if (!policy.allowed) {
86
+ return {
87
+ success: false,
88
+ error: policy.violation.message,
89
+ sandbox_violation: (0, sandboxFs_1.violationEnvelope)(policy),
90
+ };
91
+ }
50
92
  const find = typeof args.find === 'string' ? args.find : '';
51
93
  const replace = typeof args.replace === 'string' ? args.replace : '';
52
94
  if (!find)
53
95
  return { success: false, error: 'Empty find string' };
54
96
  const replaceAll = args.replace_all === true;
55
- const resolved = (0, paths_1.expandPath)(raw, ctx.cwd);
97
+ const resolved = policy.resolvedPath;
56
98
  try {
57
99
  const original = await node_fs_1.promises.readFile(resolved, 'utf-8');
58
100
  const occurrences = original.split(find).length - 1;
@@ -24,6 +24,7 @@ exports.fileReadTool = void 0;
24
24
  const node_fs_1 = require("node:fs");
25
25
  const node_path_1 = __importDefault(require("node:path"));
26
26
  const node_os_1 = __importDefault(require("node:os"));
27
+ const sandboxFs_1 = require("../../../core/v4/sandboxFs");
27
28
  const MAX_OUTPUT = 5000;
28
29
  const DENY_PATTERNS = [
29
30
  /[\\/]\.ssh[\\/]/i,
@@ -73,6 +74,7 @@ exports.fileReadTool = {
73
74
  category: 'read',
74
75
  mutates: false,
75
76
  toolset: 'files',
77
+ riskTier: 'safe', // v4.4 Phase 1
76
78
  async execute(args, ctx) {
77
79
  const raw = String(args.path ?? args.file ?? '').trim();
78
80
  if (!raw)
@@ -83,7 +85,16 @@ exports.fileReadTool = {
83
85
  error: 'Access denied: protected path (credentials/keys/.env)',
84
86
  };
85
87
  }
86
- const resolved = expandPath(raw, ctx.cwd);
88
+ // v4.4 Phase 2 — sandbox preflight (no-op when AIDEN_SANDBOX!=1).
89
+ const policy = (0, sandboxFs_1.isPathAllowed)(raw, 'read', ctx.cwd);
90
+ if (!policy.allowed) {
91
+ return {
92
+ success: false,
93
+ error: policy.violation.message,
94
+ sandbox_violation: (0, sandboxFs_1.violationEnvelope)(policy),
95
+ };
96
+ }
97
+ const resolved = policy.resolvedPath;
87
98
  try {
88
99
  const content = await node_fs_1.promises.readFile(resolved, 'utf-8');
89
100
  return {
@@ -23,6 +23,8 @@ exports.fileWriteTool = void 0;
23
23
  const node_fs_1 = require("node:fs");
24
24
  const node_path_1 = __importDefault(require("node:path"));
25
25
  const paths_1 = require("../utils/paths");
26
+ const sandboxFs_1 = require("../../../core/v4/sandboxFs");
27
+ const dryRun_1 = require("../../../core/v4/dryRun");
26
28
  exports.fileWriteTool = {
27
29
  schema: {
28
30
  name: 'file_write',
@@ -39,6 +41,35 @@ exports.fileWriteTool = {
39
41
  category: 'write',
40
42
  mutates: true,
41
43
  toolset: 'files',
44
+ riskTier: 'caution', // v4.4 Phase 1
45
+ // v4.4 Phase 4 — dry-run preview.
46
+ async buildPreview(args, ctx) {
47
+ const raw = String(args.path ?? args.file ?? '').trim();
48
+ const content = typeof args.content === 'string' ? args.content : '';
49
+ const policy = (0, sandboxFs_1.isPathAllowed)(raw, 'write', ctx.cwd);
50
+ const resolved = policy.resolvedPath;
51
+ let prevBytes;
52
+ try {
53
+ prevBytes = (await node_fs_1.promises.stat(resolved)).size;
54
+ }
55
+ catch { /* didn't exist */ }
56
+ const newBytes = Buffer.byteLength(content, 'utf-8');
57
+ const sideEffects = policy.allowed
58
+ ? [prevBytes !== undefined
59
+ ? { type: 'overwrite_file', path: resolved, prev_bytes: prevBytes, new_bytes: newBytes, preview: (0, dryRun_1.truncatePreview)(content) }
60
+ : { type: 'create_file', path: resolved, bytes: newBytes, preview: (0, dryRun_1.truncatePreview)(content) }]
61
+ : [{ type: 'refuse', reason: policy.violation.message }];
62
+ return {
63
+ tool: 'file_write',
64
+ args,
65
+ riskTier: 'caution',
66
+ sideEffects,
67
+ detectedRisks: [],
68
+ summary: policy.allowed
69
+ ? `Would write ${newBytes} bytes to ${resolved}`
70
+ : `Refused: ${policy.violation.code}`,
71
+ };
72
+ },
42
73
  async execute(args, ctx) {
43
74
  const raw = String(args.path ?? args.file ?? '').trim();
44
75
  if (!raw)
@@ -46,8 +77,17 @@ exports.fileWriteTool = {
46
77
  if ((0, paths_1.isProtectedPath)(raw)) {
47
78
  return { success: false, error: 'Access denied: protected path' };
48
79
  }
80
+ // v4.4 Phase 2 — sandbox preflight (no-op when AIDEN_SANDBOX!=1).
81
+ const policy = (0, sandboxFs_1.isPathAllowed)(raw, 'write', ctx.cwd);
82
+ if (!policy.allowed) {
83
+ return {
84
+ success: false,
85
+ error: policy.violation.message,
86
+ sandbox_violation: (0, sandboxFs_1.violationEnvelope)(policy),
87
+ };
88
+ }
49
89
  const content = typeof args.content === 'string' ? args.content : '';
50
- const resolved = (0, paths_1.expandPath)(raw, ctx.cwd);
90
+ const resolved = policy.resolvedPath;
51
91
  try {
52
92
  await node_fs_1.promises.mkdir(node_path_1.default.dirname(resolved), { recursive: true });
53
93
  await node_fs_1.promises.writeFile(resolved, content, 'utf-8');