@pqpo/pragma 0.1.0-next.8 → 0.1.0-next.9

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 (2) hide show
  1. package/dist/cli.js +41 -3
  2. package/package.json +1 -1
package/dist/cli.js CHANGED
@@ -36965,7 +36965,7 @@ async function runExpertInvocation(options2) {
36965
36965
  ]
36966
36966
  });
36967
36967
  const formattedPrompt = formatExpertPromptWithAttachments(options2.prompt, options2.attachments ?? []);
36968
- await appendUserMessage(options2, formattedPrompt, `invocation-user-message:${options2.invocationId}`);
36968
+ await appendUserMessage(options2, formattedPrompt, options2.isRecovery === true ? `invocation-recovery-user-message:${options2.invocationId}` : `invocation-user-message:${options2.invocationId}`);
36969
36969
  const invocationSignal = options2.controller.signalForInvocation(options2.invocationId, options2.parentInvocationId);
36970
36970
  throwIfAborted(invocationSignal, options2.invocationId);
36971
36971
  const modelSelection = options2.modelSelection ?? options2.context.modelSelection;
@@ -37175,6 +37175,9 @@ async function runExpertInvocation(options2) {
37175
37175
  const invocationOutput = await contextOutputs.normalize(options2.invocationId, options2.context.contextId, turn.output);
37176
37176
  await appendInvocationFinalMessage(options2, turn.runId, turn.finalMessage, invocationOutput);
37177
37177
  while (true) {
37178
+ const checkpoint = options2.controller.getHumanInteractionCheckpoint(options2.invocationId);
37179
+ if (checkpoint !== void 0)
37180
+ throw checkpoint;
37178
37181
  const currentExecution = await requireExecution2(options2.store, options2.executionId);
37179
37182
  const currentInvocation = await options2.store.getInvocation(options2.executionId, options2.invocationId);
37180
37183
  if (currentInvocation === void 0) {
@@ -37661,6 +37664,9 @@ async function submitRuntimeTurn(options2) {
37661
37664
  const result = await handle.result;
37662
37665
  await drain;
37663
37666
  await usagePreview;
37667
+ const checkpoint = options2.options.controller.getHumanInteractionCheckpoint(options2.options.invocationId);
37668
+ if (checkpoint !== void 0)
37669
+ throw checkpoint;
37664
37670
  const output = result.result.output;
37665
37671
  const finalMessage = completedRootAssistant ?? rootMessageAccumulator.complete(output, result.result.usage);
37666
37672
  await settleRuntimeTurnUsage(options2, result.result.usage);
@@ -37674,7 +37680,7 @@ async function submitRuntimeTurn(options2) {
37674
37680
  const usage = await handle.usage?.catch(() => void 0);
37675
37681
  await usagePreview;
37676
37682
  await settleRuntimeTurnUsage(options2, usage);
37677
- throw error52;
37683
+ throw options2.options.controller.getHumanInteractionCheckpoint(options2.options.invocationId) ?? error52;
37678
37684
  } finally {
37679
37685
  await drain.catch(() => void 0);
37680
37686
  options2.options.controller.unregisterRuntimeSubmission(options2.options.invocationId, handle.runId);
@@ -37992,6 +37998,7 @@ var init_expert_runner = __esm({
37992
37998
  linkedInvocationSignals = /* @__PURE__ */ new Map();
37993
37999
  orchestrators = /* @__PURE__ */ new Map();
37994
38000
  pendingInteractions = /* @__PURE__ */ new Map();
38001
+ checkpointedInvocations = /* @__PURE__ */ new Map();
37995
38002
  humanResponseOperations = /* @__PURE__ */ new Map();
37996
38003
  cancelled = false;
37997
38004
  cancellationReason;
@@ -38065,8 +38072,28 @@ var init_expert_runner = __esm({
38065
38072
  }
38066
38073
  }
38067
38074
  const checkpoint = new HumanInteractionCheckpointError(this.executionId);
38075
+ const invocationIds = new Set(pending.map((interaction) => interaction.invocationId));
38076
+ const runtimeStops = [];
38077
+ for (const invocationId of invocationIds) {
38078
+ this.checkpointedInvocations.set(invocationId, checkpoint);
38079
+ const signal = this.invocationSignals.get(invocationId);
38080
+ if (signal !== void 0 && !signal.signal.aborted)
38081
+ signal.abort(checkpoint);
38082
+ const submission = this.activeRuntimeSubmissions.get(invocationId);
38083
+ if (submission !== void 0) {
38084
+ runtimeStops.push(Promise.resolve().then(async () => await submission.handle.cancel()));
38085
+ }
38086
+ }
38068
38087
  for (const interaction of pending)
38069
38088
  interaction.reject(checkpoint);
38089
+ await Promise.allSettled(runtimeStops);
38090
+ }
38091
+ /**
38092
+ * Returns the durable checkpoint reason for an invocation whose Runtime turn
38093
+ * must not be converted into a terminal failure or success.
38094
+ */
38095
+ getHumanInteractionCheckpoint(invocationId) {
38096
+ return this.checkpointedInvocations.get(invocationId);
38070
38097
  }
38071
38098
  signalForInvocation(invocationId, parentInvocationId) {
38072
38099
  const linked = this.linkedInvocationSignals.get(invocationId);
@@ -38105,6 +38132,9 @@ var init_expert_runner = __esm({
38105
38132
  registerRuntimeSubmission(invocationId, contextId, session, handle, supportsSteer) {
38106
38133
  const submission = { invocationId, contextId, session, handle, supportsSteer };
38107
38134
  this.activeRuntimeSubmissions.set(invocationId, submission);
38135
+ if (this.checkpointedInvocations.has(invocationId)) {
38136
+ void Promise.resolve().then(async () => await handle.cancel()).catch(() => void 0);
38137
+ }
38108
38138
  const waiters = this.runtimeSubmissionWaiters.get(contextId);
38109
38139
  if (waiters === void 0)
38110
38140
  return;
@@ -38218,6 +38248,9 @@ var init_expert_runner = __esm({
38218
38248
  return descendants;
38219
38249
  }
38220
38250
  async requestHumanInteraction(invocationId, request, requestedInteractionId) {
38251
+ const checkpoint = this.getHumanInteractionCheckpoint(invocationId);
38252
+ if (checkpoint !== void 0)
38253
+ throw checkpoint;
38221
38254
  if (this.cancelled)
38222
38255
  throw new Error("Execution was cancelled.");
38223
38256
  const signal = this.signalForInvocation(invocationId);
@@ -38459,6 +38492,7 @@ var init_expert_runner = __esm({
38459
38492
  finish() {
38460
38493
  this.rejectRuntimeSubmissionWaiters(new Error("ExpertTurn completed before its Runtime submission became active."));
38461
38494
  this.activeRuntimeSubmissions.clear();
38495
+ this.checkpointedInvocations.clear();
38462
38496
  this.invocationSignals.clear();
38463
38497
  this.linkedInvocationSignals.clear();
38464
38498
  this.orchestrators.clear();
@@ -39851,6 +39885,7 @@ var init_expert_session = __esm({
39851
39885
  output = InvocationOutputSchema.parse(await runExpertInvocation({
39852
39886
  executionId: prompt.executionId,
39853
39887
  invocationId: prompt.executionId,
39888
+ isRecovery: this.recoveredExecutionId === prompt.executionId,
39854
39889
  expert: this.expert,
39855
39890
  prompt: this.recoveredExecutionId === prompt.executionId ? recoveryPrompt(prompt.content) : prompt.content,
39856
39891
  attachments: promptInput.attachments,
@@ -73821,6 +73856,8 @@ function registerLocalTool(server, runtimeName, tool, options2) {
73821
73856
  });
73822
73857
  return toCallToolResult(result);
73823
73858
  } catch (error52) {
73859
+ if (isHumanInteractionCheckpointError(error52))
73860
+ throw error52;
73824
73861
  const message = error52 instanceof Error ? error52.message : String(error52);
73825
73862
  const payload = {
73826
73863
  ok: false,
@@ -74022,6 +74059,7 @@ var init_expert_tools_mcp_server = __esm({
74022
74059
  "packages/core/dist/expert-tools-mcp-server.js"() {
74023
74060
  "use strict";
74024
74061
  init_dist5();
74062
+ init_expert_runner();
74025
74063
  init_execution_tools();
74026
74064
  RUNTIME_PERMISSION_APPROVAL_REASON = "Runtime requested tool approval.";
74027
74065
  SESSION_MCP_PATH_PATTERN = /^\/sessions\/([A-Za-z0-9_-]{43})\/mcp$/;
@@ -421616,7 +421654,7 @@ init_dist13();
421616
421654
  init_integration();
421617
421655
 
421618
421656
  // apps/cli/src/version.ts
421619
- var CLI_VERSION = false ? "0.0.0" : "0.1.0-next.8";
421657
+ var CLI_VERSION = false ? "0.0.0" : "0.1.0-next.9";
421620
421658
 
421621
421659
  // apps/cli/src/composition/default.ts
421622
421660
  function createCliLocalHost(input = {}) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pqpo/pragma",
3
- "version": "0.1.0-next.8",
3
+ "version": "0.1.0-next.9",
4
4
  "description": "Pragma command-line interface",
5
5
  "license": "SEE LICENSE IN LICENSE",
6
6
  "type": "module",