patchwork-os 1.2.0-beta.3.canary.905 → 1.2.0-beta.3.canary.907

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 (61) hide show
  1. package/dist/attachmentResponse.d.ts +17 -0
  2. package/dist/attachmentResponse.js +23 -0
  3. package/dist/attachmentResponse.js.map +1 -0
  4. package/dist/bridge.js +6 -0
  5. package/dist/bridge.js.map +1 -1
  6. package/dist/claudeOrchestrator.d.ts +31 -0
  7. package/dist/claudeOrchestrator.js +62 -3
  8. package/dist/claudeOrchestrator.js.map +1 -1
  9. package/dist/governance/untrustedContent.d.ts +9 -0
  10. package/dist/governance/untrustedContent.js +20 -2
  11. package/dist/governance/untrustedContent.js.map +1 -1
  12. package/dist/inboxRoutes.js +5 -7
  13. package/dist/inboxRoutes.js.map +1 -1
  14. package/dist/recipeOrchestration.js +14 -0
  15. package/dist/recipeOrchestration.js.map +1 -1
  16. package/dist/recipeRoutes.js +24 -1
  17. package/dist/recipeRoutes.js.map +1 -1
  18. package/dist/recipes/agentExecutor.d.ts +10 -0
  19. package/dist/recipes/agentExecutor.js +12 -1
  20. package/dist/recipes/agentExecutor.js.map +1 -1
  21. package/dist/recipes/chainedRunner.d.ts +25 -0
  22. package/dist/recipes/chainedRunner.js +79 -8
  23. package/dist/recipes/chainedRunner.js.map +1 -1
  24. package/dist/recipes/fileInputs.d.ts +85 -0
  25. package/dist/recipes/fileInputs.js +157 -0
  26. package/dist/recipes/fileInputs.js.map +1 -0
  27. package/dist/recipes/replayRun.js +35 -0
  28. package/dist/recipes/replayRun.js.map +1 -1
  29. package/dist/recipes/schemaGenerator.js +2 -2
  30. package/dist/recipes/schemaGenerator.js.map +1 -1
  31. package/dist/recipes/simulation/synthesizeMockedOutputs.js +4 -0
  32. package/dist/recipes/simulation/synthesizeMockedOutputs.js.map +1 -1
  33. package/dist/recipes/textInputs.d.ts +10 -4
  34. package/dist/recipes/textInputs.js +15 -9
  35. package/dist/recipes/textInputs.js.map +1 -1
  36. package/dist/recipes/triggerVars.d.ts +4 -3
  37. package/dist/recipes/triggerVars.js +2 -1
  38. package/dist/recipes/triggerVars.js.map +1 -1
  39. package/dist/recipes/validation.js +31 -3
  40. package/dist/recipes/validation.js.map +1 -1
  41. package/dist/recipes/withheldOutputs.d.ts +64 -0
  42. package/dist/recipes/withheldOutputs.js +141 -0
  43. package/dist/recipes/withheldOutputs.js.map +1 -0
  44. package/dist/recipes/yamlRunner.d.ts +20 -0
  45. package/dist/recipes/yamlRunner.js +127 -31
  46. package/dist/recipes/yamlRunner.js.map +1 -1
  47. package/dist/runLog.d.ts +16 -0
  48. package/dist/runLog.js +7 -3
  49. package/dist/runLog.js.map +1 -1
  50. package/dist/runStore/sqliteRunRepository.js +4 -0
  51. package/dist/runStore/sqliteRunRepository.js.map +1 -1
  52. package/dist/schemas/recipe.v1.json +2 -2
  53. package/dist/server.js +6 -0
  54. package/dist/server.js.map +1 -1
  55. package/dist/uploadStore.d.ts +106 -0
  56. package/dist/uploadStore.js +434 -0
  57. package/dist/uploadStore.js.map +1 -0
  58. package/dist/uploadsRoutes.d.ts +25 -0
  59. package/dist/uploadsRoutes.js +136 -0
  60. package/dist/uploadsRoutes.js.map +1 -0
  61. package/package.json +1 -1
@@ -39,7 +39,7 @@ import { readKillSwitch } from "../governance/killSwitchPolicy.js";
39
39
  import { activeProfile, COMPAT_PROFILE, resolveAgentContainment, } from "../governance/profile.js";
40
40
  import { redactKnownSecrets, registerEnvBlock, } from "../governance/secretValues.js";
41
41
  import { toolFactsFor } from "../governance/toolFacts.js";
42
- import { isConnectorSource, provenanceOf, runInputProvenance, wrapUntrusted, } from "../governance/untrustedContent.js";
42
+ import { isConnectorSource, provenanceOf, runInputProvenance, uploadInputProvenance, wrapUntrusted, } from "../governance/untrustedContent.js";
43
43
  import { isLoopbackOrPrivateEndpoint } from "../localEndpointGuard.js";
44
44
  import { loadConfig as loadPatchworkConfigSync } from "../patchworkConfig.js";
45
45
  import { findYamlRecipePath } from "../recipesHttp.js";
@@ -60,6 +60,7 @@ import { normaliseApprovalVerdict, recipeApprovalIdentityMatches, } from "./appr
60
60
  import { deriveBreakerKey, getCircuitBreaker } from "./circuitBreaker.js";
61
61
  import { expandFlatParallel, unsupportedKeysOf, unsupportedStepMessage, } from "./compoundSteps.js";
62
62
  import { fanOutApprovalSummary, fanOutChildReversibilityCeiling, fanOutChildToolId, } from "./fanOutChild.js";
63
+ import { agentReadDirsFor, FILE_INPUT_IN_IDENTIFIER, fileInputInIdentifierMessage, fileInputNamesOf, findFileInputsInIdentifiers, holdFileInputValues, resolveFileInputs, } from "./fileInputs.js";
63
64
  import { FileRollbackLog } from "./fileRollback.js";
64
65
  import { assertRollbackNotWorsened, reversibilityCeilingFor, stepRollbackability, } from "./fileWriteRollbackability.js";
65
66
  import { agentAuthHaltReason, approvalHaltFor, categoriseHaltReason, isAgentAuthFailure, } from "./haltCategory.js";
@@ -82,6 +83,7 @@ import { enforceToolPolicy } from "./toolPolicyCheck.js";
82
83
  import { applyToolOutputContext, executeTool, getTool, hasTool, registerPluginTools, } from "./toolRegistry.js";
83
84
  import { classifyHttpStepResult, httpFailureEvidence, isHttpFailureFromTool, } from "./tools/httpOutcome.js";
84
85
  import { evaluateWhen } from "./whenGuard.js";
86
+ import { outputWithheldMarker, runWithholdsOutputs, } from "./withheldOutputs.js";
85
87
  import { resolveWorkspaceRoot } from "./workspaceRoot.js";
86
88
  import "./tools/index.js";
87
89
  import { patchworkPath } from "../patchworkHome.js";
@@ -536,18 +538,31 @@ export function declaredRecipeEnv(recipe, processEnv = process.env) {
536
538
  return out;
537
539
  }
538
540
  export async function runYamlRecipe(recipe, deps = {}, seedContext = {}) {
541
+ // `type: file` inputs: each upload NAME becomes the upload's absolute path
542
+ // before anything renders. Fails CLOSED — an upload that no longer exists
543
+ // stops the run here, before any step (src/recipes/fileInputs.ts).
544
+ const files = resolveFileInputs(recipe, seedContext);
545
+ if (!files.ok)
546
+ throw new Error(files.error);
547
+ const resolvedSeed = files.values;
539
548
  // `type: text` inputs are held by the value-redaction layer for exactly the
540
549
  // life of the run, so no ledger written during it records the prose
541
- // (src/recipes/textInputs.ts). Released whatever way the run ends.
542
- const releaseTextInputs = holdTextInputValues(textInputNamesOf(recipe), seedContext);
550
+ // (src/recipes/textInputs.ts). File inputs' paths likewise, as
551
+ // `[upload: <name>, sha256:…]`. Released whatever way the run ends.
552
+ const releaseTextInputs = holdTextInputValues(textInputNamesOf(recipe), resolvedSeed);
553
+ const releaseFileInputs = holdFileInputValues(files.uploads);
543
554
  try {
544
- return await runYamlRecipeHeld(recipe, deps, seedContext);
555
+ return await runYamlRecipeHeld(recipe, deps, resolvedSeed, {
556
+ fileInputNames: fileInputNamesOf(recipe),
557
+ agentReadDirs: agentReadDirsFor(files.uploads),
558
+ });
545
559
  }
546
560
  finally {
561
+ releaseFileInputs();
547
562
  releaseTextInputs();
548
563
  }
549
564
  }
550
- async function runYamlRecipeHeld(recipe, deps, seedContext) {
565
+ async function runYamlRecipeHeld(recipe, deps, seedContext, fileInputs) {
551
566
  if (recipe.servers?.length) {
552
567
  await loadRecipeServers(recipe.servers);
553
568
  }
@@ -575,10 +590,22 @@ async function runYamlRecipeHeld(recipe, deps, seedContext) {
575
590
  // the same envelope, under the same profile, as connector output — and they
576
591
  // may never be rendered outside a content field (checked per step below).
577
592
  const textInputNames = textInputNamesOf(recipe);
593
+ // `type: file` inputs render as an upload's path; the envelope's note says
594
+ // the FILE's content is data, not instructions (fileInputs.ts).
595
+ const fileInputNames = fileInputs.fileInputNames;
596
+ const agentReadDirs = fileInputs.agentReadDirs;
597
+ // A run handed a text or file input records NO step outputs — not the
598
+ // agent's answer (which quotes the material), not any tool result — only a
599
+ // length + sha256 marker per step (src/recipes/withheldOutputs.ts). False
600
+ // for every other run, which is recorded exactly as before.
601
+ const withholdOutputs = runWithholdsOutputs(recipe, seedContext);
578
602
  if (envelopeActive) {
579
603
  for (const name of textInputNames) {
580
604
  untrustedProvenance.set(name, runInputProvenance(name));
581
605
  }
606
+ for (const name of fileInputNames) {
607
+ untrustedProvenance.set(name, uploadInputProvenance(name));
608
+ }
582
609
  }
583
610
  /**
584
611
  * Origins collected during the LAST agent-prompt render.
@@ -1016,6 +1043,8 @@ async function runYamlRecipeHeld(recipe, deps, seedContext) {
1016
1043
  // applies to its refine-loop re-runs (no-op when downshift is absent).
1017
1044
  const routed = resolveRouting({ driver, model }, downshift, prompt, runBudget);
1018
1045
  const agentReturn = await _executeAgent({
1046
+ // A run handed a `type: file` input may READ the uploads dir.
1047
+ ...(agentReadDirs.length > 0 && { readOnlyDirs: agentReadDirs }),
1019
1048
  prompt,
1020
1049
  driver: routed.driver === "api" ? "anthropic" : routed.driver,
1021
1050
  model: routed.model,
@@ -1037,7 +1066,7 @@ async function runYamlRecipeHeld(recipe, deps, seedContext) {
1037
1066
  ...(deps.agentDisallowedTools?.length && { enforceSandbox: true }),
1038
1067
  ...(providerOptions && { providerOptions }),
1039
1068
  ...(dataPolicy !== undefined && { boundary: { dataPolicy } }),
1040
- }, buildAgentExecutorDeps(stepDeps, deps, undefined, runTaskId, currentAgentStepId));
1069
+ }, buildAgentExecutorDeps(stepDeps, deps, undefined, runTaskId, currentAgentStepId, withholdOutputs));
1041
1070
  runBudget.reconcile(
1042
1071
  // Prefer the driver executeAgent actually resolved+ran; fall back to
1043
1072
  // the routed value only when servedBy is absent (non-executeAgent
@@ -1101,6 +1130,8 @@ async function runYamlRecipeHeld(recipe, deps, seedContext) {
1101
1130
  };
1102
1131
  }
1103
1132
  const agentReturn = await _executeAgent({
1133
+ // A run handed a `type: file` input may READ the uploads dir.
1134
+ ...(agentReadDirs.length > 0 && { readOnlyDirs: agentReadDirs }),
1104
1135
  prompt: input.prompt,
1105
1136
  driver: input.driver === "api" ? "anthropic" : input.driver,
1106
1137
  model: input.model,
@@ -1118,7 +1149,7 @@ async function runYamlRecipeHeld(recipe, deps, seedContext) {
1118
1149
  ...(input.dataPolicy !== undefined && {
1119
1150
  boundary: { dataPolicy: input.dataPolicy },
1120
1151
  }),
1121
- }, buildAgentExecutorDeps(stepDeps, deps, undefined, runTaskId, currentAgentStepId));
1152
+ }, buildAgentExecutorDeps(stepDeps, deps, undefined, runTaskId, currentAgentStepId, withholdOutputs));
1122
1153
  runBudget.reconcile(agentReturn.servedBy?.driver ?? input.driver ?? "auto", agentReturn.usage, agentReturn.servedBy?.model, {
1123
1154
  inputChars: input.prompt.length,
1124
1155
  outputChars: agentReturn.text.length,
@@ -1409,15 +1440,23 @@ async function runYamlRecipeHeld(recipe, deps, seedContext) {
1409
1440
  // before ANY of the step renders — the `when:` guard included — so the
1410
1441
  // value never reaches a path, URL, ref, channel, recipient or id. The
1411
1442
  // path jail stays as the backstop; this is the rule.
1443
+ // A `type: file` input is held to the same rule over a narrower list.
1412
1444
  const textPlacement = findTextInputsInIdentifiers(step, textInputNames)[0];
1413
- if (textPlacement) {
1414
- const msg = textInputInIdentifierMessage(textPlacement, `step "${stepIdForEmit}"`);
1445
+ const filePlacement = textPlacement
1446
+ ? undefined
1447
+ : findFileInputsInIdentifiers(step, fileInputNames)[0];
1448
+ if (textPlacement || filePlacement) {
1449
+ const msg = textPlacement
1450
+ ? textInputInIdentifierMessage(textPlacement, `step "${stepIdForEmit}"`)
1451
+ : fileInputInIdentifierMessage(filePlacement, `step "${stepIdForEmit}"`);
1415
1452
  stepResults.push({
1416
1453
  id: stepIdForEmit,
1417
1454
  tool: step.agent ? "agent" : step.tool,
1418
1455
  status: "error",
1419
1456
  error: msg,
1420
- errorCode: TEXT_INPUT_IN_IDENTIFIER,
1457
+ errorCode: textPlacement
1458
+ ? TEXT_INPUT_IN_IDENTIFIER
1459
+ : FILE_INPUT_IN_IDENTIFIER,
1421
1460
  haltReason: msg,
1422
1461
  haltCategory: "policy_denied",
1423
1462
  durationMs: 0,
@@ -1814,6 +1853,8 @@ async function runYamlRecipeHeld(recipe, deps, seedContext) {
1814
1853
  // step's own deny list so the subprocess can't bypass the gate.
1815
1854
  const agentDisallowed = mergeAgentDisallowedTools(agentCfg.disallowedTools, deps.agentDisallowedTools);
1816
1855
  const agentReturn = await _executeAgent({
1856
+ // A run handed a `type: file` input may READ the uploads dir.
1857
+ ...(agentReadDirs.length > 0 && { readOnlyDirs: agentReadDirs }),
1817
1858
  prompt: renderedPrompt,
1818
1859
  driver: routed.driver === "api" ? "anthropic" : routed.driver,
1819
1860
  model: routed.model,
@@ -1854,7 +1895,7 @@ async function runYamlRecipeHeld(recipe, deps, seedContext) {
1854
1895
  ...(agentCfg.data_policy !== undefined && {
1855
1896
  boundary: { dataPolicy: agentCfg.data_policy },
1856
1897
  }),
1857
- }, buildAgentExecutorDeps(stepDeps, deps, undefined, runTaskId, stepId));
1898
+ }, buildAgentExecutorDeps(stepDeps, deps, undefined, runTaskId, stepId, withholdOutputs));
1858
1899
  agentResult = agentReturn.text;
1859
1900
  runBudget.reconcile(
1860
1901
  // Prefer the driver executeAgent actually resolved+ran; the routed
@@ -1986,6 +2027,12 @@ async function runYamlRecipeHeld(recipe, deps, seedContext) {
1986
2027
  tool: "agent",
1987
2028
  status: "ok",
1988
2029
  ...(judgeVerdict !== undefined && { judgeVerdict }),
2030
+ // Flat agent rows never capture the answer; in a run with a
2031
+ // text or file input they say so, so a reader can tell
2032
+ // "withheld" from "nothing produced".
2033
+ ...(withholdOutputs && {
2034
+ outputWithheld: outputWithheldMarker(agentResult),
2035
+ }),
1989
2036
  durationMs: Date.now() - stepStart,
1990
2037
  };
1991
2038
  stepResults.push(judgeStepResult);
@@ -2361,6 +2408,14 @@ async function runYamlRecipeHeld(recipe, deps, seedContext) {
2361
2408
  ? httpFailureEvidence(toCapture)
2362
2409
  : toCapture);
2363
2410
  }
2411
+ // A run with a text or file input keeps no step output — whatever a
2412
+ // tool returned may echo the material or an answer derived from it
2413
+ // (src/recipes/withheldOutputs.ts). Marker over the raw result.
2414
+ let stepOutputWithheld;
2415
+ if (withholdOutputs && stepOutput !== undefined) {
2416
+ stepOutputWithheld = outputWithheldMarker(result);
2417
+ stepOutput = undefined;
2418
+ }
2364
2419
  stepResults.push({
2365
2420
  id: stepId,
2366
2421
  tool: step.tool,
@@ -2375,6 +2430,9 @@ async function runYamlRecipeHeld(recipe, deps, seedContext) {
2375
2430
  }
2376
2431
  : {}),
2377
2432
  ...(stepOutput !== undefined ? { output: stepOutput } : {}),
2433
+ ...(stepOutputWithheld !== undefined
2434
+ ? { outputWithheld: stepOutputWithheld }
2435
+ : {}),
2378
2436
  durationMs: Date.now() - stepStart,
2379
2437
  });
2380
2438
  if (stepError) {
@@ -2530,6 +2588,12 @@ async function runYamlRecipeHeld(recipe, deps, seedContext) {
2530
2588
  // directly into replayFlatMockedRun, never round-tripping through
2531
2589
  // a real runLog persist + reload.
2532
2590
  ...(s.output !== undefined ? { output: s.output } : {}),
2591
+ // Carried for the same reason as `output` above: this whitelist is
2592
+ // what reaches disk, and a marker dropped here would make a withheld
2593
+ // output read as "nothing produced".
2594
+ ...(s.outputWithheld !== undefined
2595
+ ? { outputWithheld: s.outputWithheld }
2596
+ : {}),
2533
2597
  }));
2534
2598
  // P1: run-level token aggregate + budget totals (latter only when a
2535
2599
  // budget was configured — never persist all-zero no-budget totals).
@@ -3271,7 +3335,13 @@ runTaskId,
3271
3335
  * The step this dispatch belongs to, so a replay refusal names it. Falls
3272
3336
  * back to "agent" only when a caller genuinely does not know.
3273
3337
  */
3274
- stepId) {
3338
+ stepId,
3339
+ /**
3340
+ * The run used a `text` or `file` input (src/recipes/withheldOutputs.ts):
3341
+ * tell the Claude CLI caller so the orchestrator task serving this step
3342
+ * keeps a marker instead of the answer. Other drivers write no task row.
3343
+ */
3344
+ withholdOutput) {
3275
3345
  // Replay boundary (replayBoundary.ts, layer 3) — the single place agent
3276
3346
  // executor deps are built for every dispatch site in this runner, so a
3277
3347
  // replay's StepDeps can never hand a driver to an agent step.
@@ -3395,24 +3465,35 @@ stepId) {
3395
3465
  // The orchestrator callback takes a boolean sandbox; the object form
3396
3466
  // (a governed widening) has already been folded into `containment` by
3397
3467
  // the executor, so only "is a sandbox requested" needs to travel here.
3398
- claudeCliFn: async (prompt, opts) => toAgentResult(await claudeCliFn(prompt, opts && {
3399
- ...(opts.mcpAccess !== undefined && { mcpAccess: opts.mcpAccess }),
3400
- ...(opts.sandbox !== undefined && {
3401
- sandbox: opts.sandbox === true || typeof opts.sandbox === "object",
3402
- }),
3403
- ...(opts.allowedTools !== undefined && {
3404
- allowedTools: opts.allowedTools,
3405
- }),
3406
- ...(opts.disallowedTools !== undefined && {
3407
- disallowedTools: opts.disallowedTools,
3408
- }),
3409
- ...(opts.containment !== undefined && {
3410
- containment: opts.containment,
3411
- }),
3412
- ...(opts.systemPrompt !== undefined && {
3413
- systemPrompt: opts.systemPrompt,
3414
- }),
3415
- })),
3468
+ claudeCliFn: async (prompt, opts) => {
3469
+ const mapped = opts && {
3470
+ ...(opts.mcpAccess !== undefined && { mcpAccess: opts.mcpAccess }),
3471
+ ...(opts.sandbox !== undefined && {
3472
+ sandbox: opts.sandbox === true || typeof opts.sandbox === "object",
3473
+ }),
3474
+ ...(opts.allowedTools !== undefined && {
3475
+ allowedTools: opts.allowedTools,
3476
+ }),
3477
+ ...(opts.disallowedTools !== undefined && {
3478
+ disallowedTools: opts.disallowedTools,
3479
+ }),
3480
+ ...(opts.containment !== undefined && {
3481
+ containment: opts.containment,
3482
+ }),
3483
+ ...(opts.readOnlyDirs !== undefined && {
3484
+ readOnlyDirs: opts.readOnlyDirs,
3485
+ }),
3486
+ ...(opts.systemPrompt !== undefined && {
3487
+ systemPrompt: opts.systemPrompt,
3488
+ }),
3489
+ };
3490
+ return toAgentResult(await claudeCliFn(prompt,
3491
+ // Only a protected run adds the key, so every other call keeps its
3492
+ // exact shape (src/recipes/withheldOutputs.ts).
3493
+ withholdOutput === true
3494
+ ? { ...(mapped ?? {}), withholdOutput: true }
3495
+ : mapped));
3496
+ },
3416
3497
  localFn: async (prompt, model, systemPrompt) => toAgentResult(systemPrompt === undefined
3417
3498
  ? await stepDeps.localFn(prompt, model)
3418
3499
  : await stepDeps.localFn(prompt, model, systemPrompt)),
@@ -3557,6 +3638,15 @@ export function defaultClaudeCodeFn(prompt, opts) {
3557
3638
  localArgs.push("--disallowed-tools", ...sandboxDenied);
3558
3639
  }
3559
3640
  }
3641
+ // Extra READ-only directories (a run handed a `type: file` input). The
3642
+ // matching write-tool denies already arrived in `disallowedTools` from
3643
+ // `executeAgent`; this only makes the directory reachable. Same argv rule as
3644
+ // the subprocess driver's `contextFiles` → `--add-dir`.
3645
+ for (const d of opts?.readOnlyDirs ?? []) {
3646
+ if (typeof d === "string" && d.length > 0 && !d.startsWith("-")) {
3647
+ localArgs.push("--add-dir", d);
3648
+ }
3649
+ }
3560
3650
  try {
3561
3651
  const result = spawnSync(binary, localArgs, {
3562
3652
  cwd: workspace.path,
@@ -3996,6 +4086,9 @@ recipeName) {
3996
4086
  allowedTools: opts.allowedTools,
3997
4087
  }),
3998
4088
  ...(opts?.boundary !== undefined && { boundary: opts.boundary }),
4089
+ ...(opts?.readOnlyDirs !== undefined && {
4090
+ readOnlyDirs: opts.readOnlyDirs,
4091
+ }),
3999
4092
  // Worker.autonomy: single chokepoint for the CHAINED path — fold the
4000
4093
  // worker's agent-step deny list into every chained agent call so the
4001
4094
  // subprocess can't bypass the per-step gate (mirrors the flat branch).
@@ -4010,7 +4103,10 @@ recipeName) {
4010
4103
  }, buildAgentExecutorDeps(stepDeps, runnerDeps, claudeCodeFnOverride,
4011
4104
  // Read at DISPATCH time, not build time — by now `runChainedRecipe` has
4012
4105
  // computed and published the run's `taskId`.
4013
- runTaskIdRef.current, opts?.stepId));
4106
+ runTaskIdRef.current, opts?.stepId,
4107
+ // Set by the chained runner per dispatch when the run used a text or
4108
+ // file input (src/recipes/withheldOutputs.ts).
4109
+ opts?.withholdOutput === true));
4014
4110
  };
4015
4111
  // ---------------------------------------------------------------------
4016
4112
  // BEGIN A-PR2 EDIT BLOCK — `loadNestedRecipe` jail (dogfood F-04).