claude-code-session-manager 0.140.0 → 0.142.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 (204) hide show
  1. package/README.md +80 -70
  2. package/bin/cli.cjs +11 -0
  3. package/dist/assets/AppSettings-BcZgIvvY.js +2 -0
  4. package/dist/assets/{History--JwsFnbn.js → History-DpZuJXi1.js} +1 -1
  5. package/dist/assets/HomeClaudeConfig-D32ZJtU-.js +3 -0
  6. package/dist/assets/{Panel-CALyU0pe.js → Panel-BjdJjhqt.js} +1 -1
  7. package/dist/assets/{ProjectClaudeConfig-sdlA-fUb.js → ProjectClaudeConfig-BTClYV6i.js} +7 -7
  8. package/dist/assets/Scheduler-DPobKx1Z.js +16 -0
  9. package/dist/assets/{SkillReferenceGraph-CxAuwhNN.js → SkillReferenceGraph-Cqyu4mef.js} +1 -1
  10. package/dist/assets/{Skills-DtRzghn5.js → Skills-vv0noNVI.js} +5 -5
  11. package/dist/assets/{TiptapBody-DApeu7x8.js → TiptapBody-CXi8Pvut.js} +1 -1
  12. package/dist/assets/Toggle-CiYCWLjh.js +1 -0
  13. package/dist/assets/{VoiceButton-DtStfv1H.js → VoiceButton-4NKKd1sC.js} +1 -1
  14. package/dist/assets/{historyTotals-ydfnwepc.js → historyTotals-DDunb8Ch.js} +1 -1
  15. package/dist/assets/index-Cn5E9958.js +3133 -0
  16. package/dist/assets/{index-DKXdXfka.css → index-DVHIHoJf.css} +1 -1
  17. package/dist/index.html +2 -2
  18. package/dist-web/app.css +1 -1
  19. package/dist-web/app.js +496 -484
  20. package/package.json +4 -2
  21. package/plugins/AGENTS.md +4 -3
  22. package/plugins/session-manager-dev/hooks/hooks.json +15 -0
  23. package/plugins/session-manager-dev/hooks/residue-check.cjs +241 -0
  24. package/plugins/session-manager-dev/skills/builder/SKILL.md +4 -2
  25. package/plugins/session-manager-dev/skills/develop/SKILL.md +55 -18
  26. package/plugins/session-manager-dev/skills/develop/standards.md +3 -2
  27. package/scripts/README.md +1 -0
  28. package/scripts/hooks/guard-tool-risk.cjs +5 -1
  29. package/scripts/hooks/lib/guard-tool-risk-policy.cjs +158 -1
  30. package/scripts/scheduler-mcp-server.cjs +737 -110
  31. package/src/main/adminRouteRegistry.cjs +59 -0
  32. package/src/main/agentLibrary.cjs +72 -4
  33. package/src/main/agentsIpc.cjs +3 -2
  34. package/src/main/build-info.json +4 -4
  35. package/src/main/chatRunner.cjs +231 -16
  36. package/src/main/config.cjs +30 -0
  37. package/src/main/docEdit.cjs +4 -2
  38. package/src/main/health.cjs +91 -0
  39. package/src/main/index.cjs +98 -48
  40. package/src/main/ipcSchemas.cjs +171 -8
  41. package/src/main/lib/AGENTS.md +1 -1
  42. package/src/main/lib/chatBootRecovery.cjs +2 -0
  43. package/src/main/lib/claude/agentModelResolve.cjs +51 -25
  44. package/src/main/lib/claude/agentSnapshot.cjs +186 -0
  45. package/src/main/lib/claude/environmentProfiles.cjs +242 -0
  46. package/src/main/lib/claude/jobSandboxPolicy.cjs +241 -33
  47. package/src/main/lib/claude/personaToolScope.cjs +82 -31
  48. package/src/main/lib/claude/runClaudeP.cjs +4 -2
  49. package/src/main/lib/claude/toolRiskMarks.cjs +41 -1
  50. package/src/main/lib/claude/usageCircuit.cjs +49 -21
  51. package/src/main/lib/claude/vaultRefs.cjs +277 -0
  52. package/src/main/lib/demo-video-kit/capture.cjs +282 -12
  53. package/src/main/lib/demo-video-kit/cast.md +43 -0
  54. package/src/main/lib/demo-video-kit/character.cjs +722 -30
  55. package/src/main/lib/demo-video-kit/checks.cjs +120 -1
  56. package/src/main/lib/demo-video-kit/export.cjs +218 -0
  57. package/src/main/lib/demo-video-kit/frames.cjs +104 -9
  58. package/src/main/lib/demo-video-kit/kind-marketing.md +121 -0
  59. package/src/main/lib/demo-video-kit/kind-tiktok.md +99 -0
  60. package/src/main/lib/demo-video-kit/kokoroSay.cjs +205 -0
  61. package/src/main/lib/demo-video-kit/project-home-html.md +43 -0
  62. package/src/main/lib/demo-video-kit/resumableRun.cjs +298 -0
  63. package/src/main/lib/demo-video-kit/seedKit.cjs +3 -3
  64. package/src/main/lib/demo-video-kit/voiceLane.cjs +233 -0
  65. package/src/main/lib/demo-video-kit/voiceLibrary.cjs +312 -0
  66. package/src/main/lib/epic/artifactAdminRoutes.cjs +211 -0
  67. package/src/main/lib/epic/artifactIpc.cjs +153 -0
  68. package/src/main/lib/epic/artifactNotice.cjs +72 -0
  69. package/src/main/lib/epic/artifactRetention.cjs +310 -0
  70. package/src/main/lib/epic/artifactStore.cjs +392 -0
  71. package/src/main/lib/epic/delegationReadiness.cjs +76 -2
  72. package/src/main/lib/epic/epicAgentRefresh.cjs +97 -0
  73. package/src/main/lib/epic/epicEventLog.cjs +214 -0
  74. package/src/main/lib/epic/epicMint.cjs +43 -1
  75. package/src/main/lib/epic/epicOutsideRead.cjs +1 -0
  76. package/src/main/lib/epic/epicOutsideState.cjs +18 -4
  77. package/src/main/lib/epic/epicPurge.cjs +347 -0
  78. package/src/main/lib/epic/epicReopen.cjs +5 -2
  79. package/src/main/lib/epic/epicSettle.cjs +4 -13
  80. package/src/main/lib/epic/epicSpawnPlan.cjs +57 -4
  81. package/src/main/lib/epic/epicStatusMirror.cjs +34 -1
  82. package/src/main/lib/epic/epicTransitions.cjs +139 -0
  83. package/src/main/lib/epic/epicValidationHook.cjs +81 -2
  84. package/src/main/lib/epic/guardSpawnSettings.cjs +3 -2
  85. package/src/main/lib/externalContract.cjs +37 -4
  86. package/src/main/lib/feedback-remote/crossProjectReply.cjs +389 -126
  87. package/src/main/lib/feedback-remote/customerFeedbackAdminRoutes.cjs +16 -3
  88. package/src/main/lib/feedback-remote/customerFeedbackClient.cjs +11 -6
  89. package/src/main/lib/feedback-remote/customerFeedbackInbox.cjs +26 -1
  90. package/src/main/lib/feedback-remote/customerFeedbackIpc.cjs +5 -2
  91. package/src/main/lib/feedback-remote/feedbackBoxDrain.cjs +409 -0
  92. package/src/main/lib/feedback-remote/feedbackBoxKeys.cjs +218 -0
  93. package/src/main/lib/feedback-remote/feedbackEnvelope.cjs +163 -0
  94. package/src/main/lib/feedback-remote/feedbackRelayClient.cjs +164 -0
  95. package/src/main/lib/feedback-remote/feedbackReport.cjs +234 -0
  96. package/src/main/lib/feedback-remote/feedbackSeal.cjs +217 -0
  97. package/src/main/lib/feedback-remote/localAdminHttp.cjs +108 -2
  98. package/src/main/lib/feedback-remote/macroAdminRoutes.cjs +2 -1
  99. package/src/main/lib/feedback-remote/needsYouIpc.cjs +17 -0
  100. package/src/main/lib/feedback-remote/needsYouStore.cjs +177 -6
  101. package/src/main/lib/feedback-remote/pendingReplies.cjs +189 -0
  102. package/src/main/lib/feedback-remote/projectHomeAdminRoutes.cjs +188 -10
  103. package/src/main/lib/feedback-remote/serviceClient.cjs +429 -0
  104. package/src/main/lib/feedback-remote/serviceMcpSession.cjs +252 -0
  105. package/src/main/lib/feedback-remote/serviceMcpTools.cjs +284 -0
  106. package/src/main/lib/feedback-remote/servicePairings.cjs +313 -0
  107. package/src/main/lib/feedback-remote/serviceStdioBridge.cjs +290 -0
  108. package/src/main/lib/feedback-remote/siteFeedbackAdminRoutes.cjs +295 -0
  109. package/src/main/lib/feedback-remote/siteFeedbackInbox.cjs +598 -0
  110. package/src/main/lib/feedback-remote/siteFeedbackIpc.cjs +86 -0
  111. package/src/main/lib/feedback-remote/siteFeedbackService.cjs +477 -0
  112. package/src/main/lib/git/worktreeDeps.cjs +77 -2
  113. package/src/main/lib/mcpToolCatalog.cjs +315 -30
  114. package/src/main/lib/opsOwnership.cjs +29 -1
  115. package/src/main/lib/opsRetentionSettings.cjs +27 -5
  116. package/src/main/lib/persona-macro/builtinMacros.cjs +7 -2
  117. package/src/main/lib/persona-macro/macroJobDispatch.cjs +52 -8
  118. package/src/main/lib/persona-macro/macroJobIpc.cjs +16 -6
  119. package/src/main/lib/persona-macro/macroLibrary.cjs +49 -7
  120. package/src/main/lib/persona-macro/personaFrontmatterSchema.cjs +83 -0
  121. package/src/main/lib/persona-macro/projectVideoToolCheck.cjs +3 -0
  122. package/src/main/lib/persona-macro/shippedPersonaSeeds.cjs +263 -0
  123. package/src/main/lib/phaseProjection.cjs +103 -0
  124. package/src/main/lib/prd/depSlugResolve.cjs +4 -13
  125. package/src/main/lib/prd/prdBodyPatch.cjs +12 -17
  126. package/src/main/lib/prd/prdCreate.cjs +67 -5
  127. package/src/main/lib/prd/prdCriteria.cjs +225 -0
  128. package/src/main/lib/prd/prdFrontmatter.cjs +68 -3
  129. package/src/main/lib/prd/prdGateFiles.cjs +125 -49
  130. package/src/main/lib/prd/prdSizing.cjs +3 -1
  131. package/src/main/lib/process/cleanEnv.cjs +52 -1
  132. package/src/main/lib/process/leftoverRenice.cjs +178 -0
  133. package/src/main/lib/process/memoryScope.cjs +31 -3
  134. package/src/main/lib/project-pages/pagesLibrary.cjs +72 -6
  135. package/src/main/lib/project-pages/videoReviewIpc.cjs +3 -2
  136. package/src/main/lib/project-pages/voiceAdminRoutes.cjs +175 -0
  137. package/src/main/lib/project-pages/voicePreview.cjs +196 -0
  138. package/src/main/lib/project-pages/voicesIpc.cjs +186 -0
  139. package/src/main/lib/promptSessionSchema.cjs +6 -0
  140. package/src/main/lib/scheduler/cancelledRow.cjs +57 -0
  141. package/src/main/lib/scheduler/cpuSample.cjs +133 -42
  142. package/src/main/lib/scheduler/criteriaChecks.cjs +169 -0
  143. package/src/main/lib/scheduler/definitionOfDone.cjs +44 -5
  144. package/src/main/lib/scheduler/jobMemoryStats.cjs +313 -0
  145. package/src/main/lib/scheduler/loadGate.cjs +82 -4
  146. package/src/main/lib/scheduler/planRecordHarvest.cjs +32 -2
  147. package/src/main/lib/scheduler/prdOutcomeRecord.cjs +133 -0
  148. package/src/main/lib/scheduler/preflightCheck.cjs +97 -0
  149. package/src/main/lib/scheduler/reviewNotice.cjs +39 -0
  150. package/src/main/lib/scheduler/runLogRetention.cjs +42 -1
  151. package/src/main/lib/scheduler/scheduleJobSchema.cjs +5 -0
  152. package/src/main/lib/scheduler/scheduleJobTransitions.cjs +47 -0
  153. package/src/main/lib/scheduler/schedulerConfig.cjs +47 -0
  154. package/src/main/lib/scheduler/schedulerPaths.cjs +0 -3
  155. package/src/main/lib/scheduler/schedulerRuntimeState.cjs +50 -1
  156. package/src/main/lib/scheduler/sessionSlots.cjs +5 -1
  157. package/src/main/lib/scheduler/slotsRoute.cjs +237 -0
  158. package/src/main/lib/scheduler/toolClearance.cjs +258 -0
  159. package/src/main/lib/scheduler/validatorVerdictSchema.cjs +140 -10
  160. package/src/main/lib/tasks/memoryConsolidation.cjs +300 -0
  161. package/src/main/lib/tasks/mitigationReview.cjs +294 -0
  162. package/src/main/lib/tasks/taskAdminRoutes.cjs +312 -22
  163. package/src/main/lib/tasks/taskIpc.cjs +22 -18
  164. package/src/main/lib/tasks/taskLedger.cjs +147 -25
  165. package/src/main/lib/tasks/taskRun.cjs +186 -17
  166. package/src/main/lib/tasks/taskSwitch.cjs +85 -12
  167. package/src/main/lib/tasks/taskSwitchRoute.cjs +172 -0
  168. package/src/main/lib/telemetry/auditEvents.cjs +207 -6
  169. package/src/main/lib/telemetry/eventsAdminRoutes.cjs +198 -6
  170. package/src/main/lib/telemetry/webhookDelivery.cjs +205 -0
  171. package/src/main/lib/telemetry/webhookRegistry.cjs +281 -0
  172. package/src/main/lib/toolUseClassify.cjs +181 -0
  173. package/src/main/lib/util/smfileRange.cjs +77 -0
  174. package/src/main/projectPages.cjs +3 -1
  175. package/src/main/promptSessionEvents.cjs +5 -0
  176. package/src/main/pty.cjs +68 -0
  177. package/src/main/queueOps.cjs +32 -13
  178. package/src/main/runVerify.cjs +74 -9
  179. package/src/main/scheduler/AGENTS.md +1 -0
  180. package/src/main/scheduler/budget.cjs +6 -5
  181. package/src/main/scheduler/prdParser.cjs +62 -14
  182. package/src/main/scheduler/reviewLadder.cjs +45 -28
  183. package/src/main/scheduler/starvation.cjs +69 -0
  184. package/src/main/scheduler/utilizationHold.cjs +101 -0
  185. package/src/main/scheduler.cjs +1745 -210
  186. package/src/main/templates/PRD_AUTHORING.md +13 -2
  187. package/src/main/webRemote.cjs +463 -6
  188. package/src/preload/api.d.ts +529 -38
  189. package/src/preload/apiSurface.json +209 -7
  190. package/src/preload/index.cjs +46 -1
  191. package/src/seed/agents/architect.md +6 -1
  192. package/src/seed/agents/blender-artist.md +2 -1
  193. package/src/seed/agents/competitive-analyst.md +3 -1
  194. package/src/seed/agents/competitive-researcher.md +2 -1
  195. package/src/seed/agents/demo-video-builder.md +87 -83
  196. package/src/seed/agents/dev-lead.md +3 -3
  197. package/src/seed/agents/project-home-builder.md +9 -31
  198. package/src/seed/agents/validator.md +9 -10
  199. package/dist/assets/AppSettings-CMFEM68R.js +0 -2
  200. package/dist/assets/HomeClaudeConfig-ijEXs--3.js +0 -3
  201. package/dist/assets/Scheduler-YT3j8SUa.js +0 -16
  202. package/dist/assets/ViewTabs-B7qLXRAH.js +0 -1
  203. package/dist/assets/index-CtxruO1L.js +0 -3121
  204. package/src/main/lib/epic/epicStateWatcher.cjs +0 -157
@@ -12,10 +12,14 @@
12
12
  */
13
13
  'use strict';
14
14
 
15
+ const fs = require('node:fs');
15
16
  const os = require('node:os');
16
17
  const path = require('node:path');
17
18
  const {
18
19
  BLOCKING_MARKS,
20
+ CONFIRM_MARK,
21
+ confirmationRequestsPath,
22
+ argsDigest,
19
23
  systemMarksPath,
20
24
  projectMarksPath,
21
25
  parseRule,
@@ -23,11 +27,14 @@ const {
23
27
  readMarksLayer,
24
28
  resolveMark,
25
29
  } = require('../../../src/main/lib/claude/toolRiskMarks.cjs');
30
+ const { webToolWouldBlock, wouldBlockRecord } = require('../../../src/main/lib/claude/jobSandboxPolicy.cjs');
26
31
 
27
32
  const TAG = '[guard-tool-risk]';
28
33
  const WRITE_TOOLS = new Set(['Write', 'Edit', 'MultiEdit', 'NotebookEdit']);
29
34
  const MAX_SHOWN = 200;
30
35
  const LAYER_LABEL = { system: 'System', project: 'Project' };
36
+ // Marks the guard refuses unless cleared: the blocking marks plus 'confirm'.
37
+ const GUARDED_MARKS = new Set([...BLOCKING_MARKS, CONFIRM_MARK]);
31
38
 
32
39
  function buildAllow() {
33
40
  return { continue: true };
@@ -115,7 +122,7 @@ function findBlocking(call, layers, clearance) {
115
122
  };
116
123
  for (let i = 0; i < 64; i++) {
117
124
  const hit = resolveMark(call, work);
118
- if (!hit || !BLOCKING_MARKS.has(hit.mark)) return null;
125
+ if (!hit || !GUARDED_MARKS.has(hit.mark)) return null;
119
126
  if (!isCleared(clearance, call, hit)) return hit;
120
127
  work[hit.layer].marks[hit.rule] = 'read';
121
128
  }
@@ -133,6 +140,84 @@ function blockReason(call, hit, headless) {
133
140
  ].join(' ');
134
141
  }
135
142
 
143
+ function confirmReason(call, hit, digest, recorded) {
144
+ const layer = LAYER_LABEL[hit.layer] || hit.layer;
145
+ return [
146
+ `Blocked, pending confirmation: \`${shown(call)}\` is marked 'confirm' by rule \`${hit.rule}\` in the ${layer} tool-risk file ${hit.file || '(unknown file)'}.`,
147
+ recorded
148
+ ? `A confirmation request (args digest ${digest}) was sent to the owner's Needs you list; if the owner approves, this same session is resumed and this exact call (same arguments) may run once.`
149
+ : `No confirmation request could be sent from this run (args digest ${digest}); a headless job may run it only when its PRD names "${hit.rule}" in riskTools.`,
150
+ 'Do not retry it and do not work around this refusal (no other tool, wrapper, script or alias for the same effect); finish the rest of the work and report that this step is pending confirmation.',
151
+ ].join(' ');
152
+ }
153
+
154
+ /**
155
+ * Append one confirmation request for the main process to post (Needs you +
156
+ * the Epic's job.confirmation_requested event). Only a scheduler job records
157
+ * one: it names the job and Epic the answer belongs to. Never throws.
158
+ * @returns {boolean} whether the record was written
159
+ */
160
+ function recordConfirmationRequest(call, hit, digest, env, deps, payload = {}) {
161
+ const jobSlug = env.SM_SCHEDULER_JOB_SLUG || null;
162
+ if (!jobSlug) return false;
163
+ // The pending record names the session to resume once the owner approves.
164
+ const sessionId = typeof payload.session_id === 'string' && payload.session_id ? payload.session_id : null;
165
+ try {
166
+ (deps.toolClearance || require('../../../src/main/lib/scheduler/toolClearance.cjs')).recordPendingConfirmation({
167
+ tool: call.tool,
168
+ argsDigest: digest,
169
+ jobSlug,
170
+ sessionId,
171
+ epicId: env.SM_SCHEDULER_JOB_EPIC_ID || null,
172
+ cwd: env.SM_PROJECT_ROOT || null,
173
+ rule: hit.rule,
174
+ summary: shown(call),
175
+ });
176
+ } catch (e) {
177
+ console.error(`${TAG} pending confirmation not recorded: ${e?.message}`);
178
+ }
179
+ try {
180
+ const file = deps.confirmationRequestsFile
181
+ || confirmationRequestsPath(require('../../../src/main/lib/scheduler/schedulerPaths.cjs').schedulerHome());
182
+ const record = {
183
+ time: new Date().toISOString(),
184
+ tool: call.tool,
185
+ argsDigest: digest,
186
+ jobSlug,
187
+ epicId: env.SM_SCHEDULER_JOB_EPIC_ID || null,
188
+ cwd: env.SM_PROJECT_ROOT || null,
189
+ rule: hit.rule,
190
+ layer: hit.layer,
191
+ summary: shown(call),
192
+ };
193
+ fs.mkdirSync(path.dirname(file), { recursive: true });
194
+ fs.appendFileSync(file, `${JSON.stringify(record)}\n`);
195
+ return true;
196
+ } catch (e) {
197
+ console.error(`${TAG} confirmation request not recorded: ${e?.message}`);
198
+ return false;
199
+ }
200
+ }
201
+
202
+ /**
203
+ * Consume a live single-use clearance for this job's exact call. Only a
204
+ * scheduler job (named by SM_SCHEDULER_JOB_SLUG) can hold one. Never throws.
205
+ * @returns {boolean} whether a clearance was consumed
206
+ */
207
+ function consumeConfirmClearance(call, digest, env, deps) {
208
+ const jobSlug = env.SM_SCHEDULER_JOB_SLUG || null;
209
+ if (!jobSlug) return false;
210
+ try {
211
+ const lib = deps.toolClearance || require('../../../src/main/lib/scheduler/toolClearance.cjs');
212
+ const r = lib.consumeClearance({ cwd: env.SM_PROJECT_ROOT || null, jobSlug, tool: call.tool, argsDigest: digest });
213
+ if (!r.ok && r.reason !== 'none') console.error(`${TAG} clearance for ${call.tool} refused: ${r.reason}`);
214
+ return r.ok === true;
215
+ } catch (e) {
216
+ console.error(`${TAG} clearance check failed, refusing: ${e?.message}`);
217
+ return false;
218
+ }
219
+ }
220
+
136
221
  function unreadableReason(layerObj, which) {
137
222
  return [
138
223
  `Blocked: the ${which} tool-risk file ${layerObj.file} cannot be used (${layerObj.error}), so every Bash and MCP call is refused (fail closed).`,
@@ -154,6 +239,64 @@ function protectedTarget(payload, homeDir, projectRoot) {
154
239
  return guarded.some((g) => path.resolve(g) === resolved) ? resolved : null;
155
240
  }
156
241
 
242
+ function parseJobEnvironment(env) {
243
+ const raw = env.SM_JOB_ENVIRONMENT;
244
+ if (!raw) return null;
245
+ try {
246
+ const v = JSON.parse(raw);
247
+ return v && typeof v === 'object' && !Array.isArray(v) ? v : null;
248
+ } catch (e) {
249
+ console.error(`${TAG} SM_JOB_ENVIRONMENT is not a JSON object, ignoring it: ${e?.message}`);
250
+ return null;
251
+ }
252
+ }
253
+
254
+ /**
255
+ * Environment check for a headless job's WebFetch/WebSearch call that its
256
+ * environment (env SM_JOB_ENVIRONMENT, set by the scheduler) disallows — tool
257
+ * not allowed, or host off the allow-list. Appends one
258
+ * 'environment_would_block' audit record and returns the deny reason when the
259
+ * mode (SM_JOB_ENVIRONMENT_MODE) is 'enforce' — the default; returns null in
260
+ * 'report' mode, when nothing applies, or on an internal error.
261
+ * @returns {string|null}
262
+ */
263
+ function environmentWebToolDenial(payload, env, deps) {
264
+ try {
265
+ const toolName = payload.tool_name;
266
+ if (toolName !== 'WebFetch' && toolName !== 'WebSearch') return null;
267
+ const jobEnv = parseJobEnvironment(env);
268
+ const hit = webToolWouldBlock(jobEnv, toolName, payload.tool_input);
269
+ if (!hit) return null;
270
+ const mode = env.SM_JOB_ENVIRONMENT_MODE === 'report' ? 'report' : 'enforce';
271
+ const envId = jobEnv && typeof jobEnv.id === 'string' ? jobEnv.id : '(unnamed)';
272
+ try {
273
+ const append = deps.appendAuditEvent || require('../../../src/main/lib/telemetry/auditLog.cjs').appendAuditEvent;
274
+ append('environment_would_block', wouldBlockRecord({
275
+ slug: env.SM_SCHEDULER_JOB_SLUG || null,
276
+ persona: env.SM_JOB_PERSONA || null,
277
+ environment: envId,
278
+ what: hit.what,
279
+ detail: hit.detail,
280
+ mode,
281
+ }));
282
+ } catch (e) {
283
+ console.error(`${TAG} environment audit failed: ${e?.message}`);
284
+ }
285
+ if (mode !== 'enforce') return null;
286
+ const why = hit.what === 'host_off_allowlist'
287
+ ? `host ${hit.detail} is outside environment '${envId}'s network allow-list`
288
+ : `environment '${envId}' does not allow ${toolName}`;
289
+ return [
290
+ `Blocked: ${toolName} — ${why}.`,
291
+ `A persona that needs the open web declares \`environment: open-web\` in its frontmatter.`,
292
+ 'Do not work around this refusal (no curl, wget or other tool for the same fetch); stop and report that this step needs the open web.',
293
+ ].join(' ');
294
+ } catch (e) {
295
+ console.error(`${TAG} environment check failed: ${e?.message}`);
296
+ return null;
297
+ }
298
+ }
299
+
157
300
  /**
158
301
  * PreToolUse payload in, hook-response object out. No stdin/stdout and no
159
302
  * process.exit. `env` defaults to process.env; `deps.homeDir` to os.homedir().
@@ -164,6 +307,10 @@ function decide(payload, env = process.env, deps = {}) {
164
307
  const projectRoot = env.SM_PROJECT_ROOT || null;
165
308
  const headless = Boolean(env.SM_SCHEDULER_JOB_SLUG) || env.SM_TOOL_RISK_HEADLESS === '1';
166
309
  const toolName = payload.tool_name;
310
+ if (headless) {
311
+ const envDenial = environmentWebToolDenial(payload, env, deps);
312
+ if (envDenial) return buildDeny(envDenial);
313
+ }
167
314
 
168
315
  const system = readMarksLayer(systemMarksPath(homeDir));
169
316
  const project = projectRoot
@@ -197,6 +344,16 @@ function decide(payload, env = process.env, deps = {}) {
197
344
  const clearance = headless ? parseClearance(env) : [];
198
345
  const hit = findBlocking(call, { system, project }, clearance);
199
346
  if (!hit) return buildAllow();
347
+ if (hit.mark === CONFIRM_MARK) {
348
+ // Interactive Terminal: the CLI's own approval prompt IS the confirmation.
349
+ if (!headless) return refuse(`Confirm: \`${shown(call)}\` is marked 'confirm' by rule \`${hit.rule}\`.`);
350
+ const digest = argsDigest(payload.tool_input);
351
+ // An owner-approved clearance for this exact call (same job, tool and
352
+ // args digest) lets ONE call through; it is consumed atomically here.
353
+ if (consumeConfirmClearance(call, digest, env, deps)) return buildAllow();
354
+ const recorded = recordConfirmationRequest(call, hit, digest, env, deps, payload);
355
+ return buildDeny(confirmReason(call, hit, digest, recorded));
356
+ }
200
357
  return refuse(blockReason(call, hit, headless));
201
358
  } catch (e) {
202
359
  console.error(`${TAG} internal error, failing open: ${e?.message}`);