ennodia 0.3.0-rc.2 → 0.3.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.
package/src/server.ts CHANGED
@@ -10,6 +10,7 @@ import {
10
10
  import { renderPlanMermaid } from "./planner";
11
11
  import { formatHarnessPriorityList } from "./priority";
12
12
  import { ENNODIA_VERSION } from "./version";
13
+ import { REASONING_EFFORTS } from "./harnesses";
13
14
 
14
15
  const defaultCore = createDefaultEnnodiaCore();
15
16
  const comparePriorityText = formatHarnessPriorityList();
@@ -20,6 +21,12 @@ const categorySchema = z
20
21
  "Optional caller-provided route category. Pass this when you know the task category; Ennodia then skips keyword classification.",
21
22
  );
22
23
 
24
+ const reasoningEffortSchema = z
25
+ .enum(REASONING_EFFORTS)
26
+ .describe(
27
+ "Optional reasoning effort for a Codex worker. Other harnesses reject explicit effort settings; omit to preserve native defaults.",
28
+ );
29
+
23
30
  const budgetSchema = z
24
31
  .object({
25
32
  maxEstimatedInputTokens: z
@@ -377,7 +384,7 @@ export function createEnnodiaServer(core: EnnodiaCore = defaultCore): McpServer
377
384
  description:
378
385
  "Estimate the input-token budget for a planned Ennodia run and report whether optional limits would be exceeded before starting child tasks.",
379
386
  inputSchema: {
380
- model: z.string().optional().describe("Explicit model selection required for Pragmatic mode."),
387
+ model: z.string().optional().describe("Optional model override. Omit to use the selected harness default."),
381
388
  pragmatic: pragmaticSchema.optional(),
382
389
  prompt: z
383
390
  .string()
@@ -428,6 +435,7 @@ export function createEnnodiaServer(core: EnnodiaCore = defaultCore): McpServer
428
435
  description:
429
436
  "Resolve focused compositional slices to harnesses and estimate child-task and later Judge + Result Advisor budget without starting child processes.",
430
437
  inputSchema: {
438
+ pragmatic: pragmaticSchema.optional(),
431
439
  prompt: z
432
440
  .string()
433
441
  .min(1)
@@ -516,6 +524,9 @@ export function createEnnodiaServer(core: EnnodiaCore = defaultCore): McpServer
516
524
  .string()
517
525
  .optional()
518
526
  .describe("Optional model override passed through to harnesses that support it."),
527
+ reasoningEffort: reasoningEffortSchema.optional(),
528
+ nativeSubagents: z.literal("disabled").optional().describe("Disable Codex built-in subagent tools for workers. Other harnesses reject this setting. Does not block external commands or affect Judge/Advisor tasks."),
529
+ nativeSandbox: z.enum(["read-only", "workspace-write"]).optional().describe("Codex worker native sandbox. Defaults to read-only on every turn, including continuation. Request workspace-write only for authorized edits. Other harnesses reject this setting; Judge/Advisor settings are unchanged."),
519
530
  timeoutMs: z
520
531
  .number()
521
532
  .int()
@@ -548,6 +559,7 @@ export function createEnnodiaServer(core: EnnodiaCore = defaultCore): McpServer
548
559
  description:
549
560
  "Start one focused child task per slice for compositional reviews. Poll the returned task IDs, then pass useful completed task IDs to ennodia_start_compare for a Judge + Result Advisor comparison.",
550
561
  inputSchema: {
562
+ pragmatic: pragmaticSchema.optional(),
551
563
  prompt: z
552
564
  .string()
553
565
  .min(1)
@@ -626,7 +638,7 @@ export function createEnnodiaServer(core: EnnodiaCore = defaultCore): McpServer
626
638
  {
627
639
  title: "Run Ennodia",
628
640
  description:
629
- "Start a high-level Ennodia orchestration. Set pragmatic for a bounded investigation or patch proposal using one explicit model. Use this as the default entrypoint: it plans routing, starts one or more local harness tasks, optionally compares successful outputs, and returns a run ID. Runs usually take minutes; poll ennodia_get_run with sensible spacing and trust remainingMs/etaConfidence instead of aborting early.",
641
+ "Start a high-level Ennodia orchestration. Set pragmatic for evidence-focused investigation or patch proposals with one or more independent workers. Use Plan Advisor for tailored model and skill assignments. Use this as the default entrypoint: it plans routing, starts one or more local harness tasks, optionally compares successful outputs, and returns a run ID. Runs usually take minutes; use ennodia_get_run with waitMs: 30000 and includeEvents: false until terminal, then consume and verify its answer. A wait timeout does not cancel or finish the run.",
630
642
  inputSchema: {
631
643
  pragmatic: pragmaticSchema.optional(),
632
644
  prompt: z
@@ -666,6 +678,11 @@ export function createEnnodiaServer(core: EnnodiaCore = defaultCore): McpServer
666
678
  .string()
667
679
  .optional()
668
680
  .describe("Optional model override passed to the selected task harnesses."),
681
+ persistSession: z.boolean().optional().describe("Opt in to native Codex session persistence. Requires one explicit harness and a persistent cwd. Default tasks remain ephemeral."),
682
+ continueTaskId: z.string().optional().describe("Continue the latest settled persistent task owned by this server. Use its Ennodia task ID. The working directory and harness stay the same. Each follow-up gets a new task and execution allowance."),
683
+ reasoningEffort: reasoningEffortSchema.optional(),
684
+ nativeSubagents: z.literal("disabled").optional().describe("Disable Codex built-in subagent tools for workers. Other harnesses reject this setting. Does not block external commands or affect Judge/Advisor tasks."),
685
+ nativeSandbox: z.enum(["read-only", "workspace-write"]).optional().describe("Codex worker native sandbox. Defaults to read-only on every turn, including continuation. Request workspace-write only for authorized edits. Other harnesses reject this setting; Judge/Advisor settings are unchanged."),
669
686
  timeoutMs: z
670
687
  .number()
671
688
  .int()
@@ -787,9 +804,11 @@ export function createEnnodiaServer(core: EnnodiaCore = defaultCore): McpServer
787
804
  {
788
805
  title: "Get Ennodia run",
789
806
  description:
790
- "Inspect run status, selected harnesses, child task IDs, comparison ID, final Advisor answer, events, and ETA.",
807
+ "Inspect a run or wait up to waitMs for completion. Prefer waitMs: 30000, compact: true and includeEvents: false while awaiting results. A nonterminal response means work continues; do not claim its findings were consumed.",
791
808
  inputSchema: {
792
809
  runId: z.string().min(1).describe("Run ID returned by ennodia_run."),
810
+ compact: z.boolean().default(false).describe("Omit repeated routing, budget, prompt preview and skill metadata. Preserve status, timing, task IDs, answers and errors. Answer and event limits still apply. Use false for full diagnostics."),
811
+ waitMs: z.number().int().min(0).max(300000).default(0).describe("Wait for a terminal state without cancelling or extending the run. Use 30000 for ordinary polling. Longer waits require a client tool timeout greater than waitMs."),
793
812
  includeEvents: z
794
813
  .boolean()
795
814
  .default(true)
@@ -812,13 +831,20 @@ export function createEnnodiaServer(core: EnnodiaCore = defaultCore): McpServer
812
831
  ),
813
832
  },
814
833
  },
815
- async ({ runId, ...options }) => {
816
- const run = core.getRun(runId, options);
834
+ async ({ runId, waitMs, compact, ...options }) => {
835
+ const run = waitMs > 0
836
+ ? await core.waitForRun(runId, waitMs, options)
837
+ : core.getRun(runId, options);
817
838
  if (!run) {
818
839
  throw new Error(`Unknown run: ${runId}`);
819
840
  }
820
841
 
821
- return jsonResult(run);
842
+ const result = compact
843
+ ? Object.fromEntries(Object.entries(run).filter(([key]) =>
844
+ !["plan", "budget", "promptPreview", "appliedSkills", "unrequestedSkillsPresent"].includes(key)
845
+ ))
846
+ : run;
847
+ return jsonResult(result);
822
848
  },
823
849
  );
824
850
 
package/src/tasks.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { cpSync, existsSync, lstatSync, mkdtempSync, rmSync } from "node:fs";
2
2
  import { readFile } from "node:fs/promises";
3
- import { basename, join } from "node:path";
3
+ import { basename, join, resolve } from "node:path";
4
4
  import { tmpdir } from "node:os";
5
5
  import { randomUUID } from "node:crypto";
6
6
  import type {
@@ -10,7 +10,7 @@ import type {
10
10
  HarnessRunInput,
11
11
  HarnessUsage,
12
12
  } from "./harnesses";
13
- import { withInputGuidance } from "./harnesses";
13
+ import { assertNativeSandboxSupported, assertNativeSubagentsSupported, assertReasoningEffortSupported, DEFAULT_TASK_TIMEOUT_MS, withInputGuidance } from "./harnesses";
14
14
  import { preview, tailItems } from "./internal";
15
15
  import { signalOwnedProcess } from "./process";
16
16
  import {
@@ -31,6 +31,14 @@ export type TaskView = {
31
31
  id: string;
32
32
  harnessId: string;
33
33
  harnessName: string;
34
+ model?: string;
35
+ reasoningEffort?: HarnessRunInput["reasoningEffort"];
36
+ nativeSubagents?: "disabled";
37
+ nativeSandbox?: "read-only" | "workspace-write";
38
+ persistSession?: boolean;
39
+ continueTaskId?: string;
40
+ continuationTaskId?: string;
41
+ canContinue?: boolean;
34
42
  status: TaskStatus;
35
43
  cancelRequested: boolean;
36
44
  pid?: number;
@@ -42,6 +50,9 @@ export type TaskView = {
42
50
  endedAt?: string;
43
51
  elapsedMs: number;
44
52
  timeoutMs: number;
53
+ /** Execution cutoff, not an estimate of task completion. */
54
+ deadlineAt?: string;
55
+ timeoutSource?: "caller" | "task-manager-default";
45
56
  remainingMs: number | null;
46
57
  etaConfidence: "timeout-budget" | "unknown" | "complete";
47
58
  lastOutputAt?: string;
@@ -65,6 +76,8 @@ export type TaskView = {
65
76
  hasOutput?: boolean;
66
77
  /** The preferred answer was truncated during capture or in this view. */
67
78
  outputTruncated?: boolean;
79
+ /** True when preferred answer bytes were lost during stream capture, independent of view limits. */
80
+ captureTruncated?: boolean;
68
81
  /** Best-effort usage metrics parsed from the adapter's own output. */
69
82
  usage?: HarnessUsage;
70
83
  /** Set when this task ran against an isolated copy of the requested cwd
@@ -105,6 +118,8 @@ type InternalTask = Omit<
105
118
  | "eventCount"
106
119
  | "finalMessageChars"
107
120
  > & {
121
+ nativeSessionId?: string;
122
+ extractSessionId?: HarnessAdapter["extractSessionId"];
108
123
  streamCaptureTruncated?: boolean;
109
124
  createdAtMs: number;
110
125
  updatedAtMs: number;
@@ -140,7 +155,6 @@ export type TaskManagerShutdownOptions = {
140
155
  deadlineMs?: number;
141
156
  };
142
157
 
143
- const DEFAULT_TIMEOUT_MS = 5 * 60 * 1000;
144
158
  const DEFAULT_DRAIN_TIMEOUT_MS = 1_000;
145
159
  const DEFAULT_SHUTDOWN_DEADLINE_MS = 5_000;
146
160
  const DEFAULT_MAX_TASKS = 200;
@@ -182,6 +196,29 @@ export class TaskManager {
182
196
  throw new Error(`${adapter.name} is not runnable through Ennodia yet.`);
183
197
  }
184
198
 
199
+ if (input.nativeSessionId) throw new Error("Use continueTaskId, not a native session ID.");
200
+ let previous: InternalTask | undefined;
201
+ if (input.continueTaskId) {
202
+ previous = this.tasks.get(input.continueTaskId);
203
+ if (!previous || previous.status === "running" || !previous.nativeSessionId || !previous.persistSession) {
204
+ throw new Error("Continuation requires a settled persistent task owned by this TaskManager.");
205
+ }
206
+ if (previous.continuationTaskId) throw new Error("Continue the latest task in this session, not an earlier turn.");
207
+ if (previous.harnessId !== adapter.id) throw new Error("Continuation must use the same harness.");
208
+ if (input.cwd && resolve(input.cwd) !== resolve(previous.cwd)) throw new Error("Continuation must use the same working directory.");
209
+ if (input.persistSession === false) throw new Error("Continuation requires session persistence.");
210
+ input = { ...input, cwd: previous.cwd, model: input.model ?? previous.model,
211
+ reasoningEffort: input.reasoningEffort ?? previous.reasoningEffort,
212
+ nativeSubagents: input.nativeSubagents ?? previous.nativeSubagents, persistSession: true };
213
+ }
214
+ if (input.persistSession && (!adapter.supportsSessionContinuation || input.isolateCwd)) {
215
+ throw new Error("Persistent sessions require a supported harness and a persistent working directory.");
216
+ }
217
+ assertReasoningEffortSupported(adapter, input.reasoningEffort);
218
+ assertNativeSubagentsSupported(adapter, input.nativeSubagents);
219
+ assertNativeSandboxSupported(adapter, input.nativeSandbox);
220
+ if (adapter.supportsNativeSandbox) input = { ...input, nativeSandbox: input.nativeSandbox ?? "read-only" };
221
+
185
222
  const sourceCwd = input.cwd ?? process.cwd();
186
223
  if (!existsSync(sourceCwd)) {
187
224
  throw new Error(`Working directory does not exist: ${sourceCwd}`);
@@ -203,11 +240,22 @@ export class TaskManager {
203
240
  // as a no-op.
204
241
  const finalMessagePath = join(tmpdir(), `ennodia-final-${randomUUID()}.txt`);
205
242
 
206
- const timeoutMs = input.timeoutMs ?? DEFAULT_TIMEOUT_MS;
243
+ const timeoutMs = input.timeoutMs ?? DEFAULT_TASK_TIMEOUT_MS;
244
+ const now = Date.now();
245
+ const deadlineMs = now + timeoutMs;
246
+ const deadlineAt = new Date(deadlineMs).toISOString();
207
247
  const guidedPrompt = withInputGuidance(input.prompt, adapter);
248
+ const executionPrompt = `${guidedPrompt}
249
+
250
+ Ennodia execution notice:
251
+ Execution allowance: ${timeoutMs} ms from task launch (${input.timeoutMs === undefined ? "Ennodia default" : "caller supplied"}). Deadline (UTC): ${deadlineAt}. This is a hard cutoff, not a completion estimate or a target duration.
252
+ Check actual UTC time before attributing incomplete work to the deadline. Do not report a cutoff merely because the task is difficult or the answer is getting long. Continue within the remaining allowance unless complete or blocked by a demonstrated access or tool failure.
253
+ Configured native sandbox: ${input.nativeSandbox ?? "harness-managed; check available permissions"}. Report any mismatch between the assignment and available access before attempting the work.
254
+ Before the cutoff, return useful partial findings, verification performed, remaining work, and a justified continuation budget if needed. Only the caller can authorize a follow-up.
255
+ Use only tools and permissions actually available in this session; the caller's tools are not automatically inherited. If access is missing, report the exact tool, file, or permission and its impact. Try a permitted alternative when useful; do not repeat an unchanged failed attempt or claim success without evidence.`;
208
256
  const augmentedPrompt = input.skills && input.skills.length > 0
209
- ? augmentPrompt(guidedPrompt, input.skills, adapter.id)
210
- : guidedPrompt;
257
+ ? augmentPrompt(executionPrompt, input.skills, adapter.id)
258
+ : executionPrompt;
211
259
  let commandSpec: CommandSpec;
212
260
  let cwd: string;
213
261
  let child: TaskProcess;
@@ -217,6 +265,7 @@ export class TaskManager {
217
265
  cwd: resolvedInputCwd,
218
266
  prompt: augmentedPrompt,
219
267
  finalMessagePath,
268
+ nativeSessionId: previous?.nativeSessionId,
220
269
  });
221
270
  cwd = commandSpec.cwd ?? process.cwd();
222
271
 
@@ -241,11 +290,18 @@ export class TaskManager {
241
290
  throw error;
242
291
  }
243
292
 
244
- const now = Date.now();
245
293
  const task: InternalTask = {
246
294
  id: randomUUID(),
247
295
  harnessId: adapter.id,
248
296
  harnessName: adapter.name,
297
+ model: input.model,
298
+ reasoningEffort: input.reasoningEffort,
299
+ nativeSubagents: input.nativeSubagents,
300
+ nativeSandbox: input.nativeSandbox,
301
+ persistSession: input.persistSession,
302
+ continueTaskId: input.continueTaskId,
303
+ nativeSessionId: previous?.nativeSessionId,
304
+ extractSessionId: input.persistSession ? adapter.extractSessionId : undefined,
249
305
  status: "running",
250
306
  cwd,
251
307
  isolatedFrom,
@@ -258,6 +314,8 @@ export class TaskManager {
258
314
  createdAtMs: now,
259
315
  updatedAtMs: now,
260
316
  timeoutMs,
317
+ timeoutSource: input.timeoutMs === undefined ? "task-manager-default" : "caller",
318
+ deadlineAt,
261
319
  cancelRequested: false,
262
320
  drainTimedOut: false,
263
321
  timedOut: false,
@@ -278,8 +336,9 @@ export class TaskManager {
278
336
  // Publish a task only after the process exists. A synchronous spawn
279
337
  // failure must not leave a phantom running task that cannot settle.
280
338
  this.tasks.set(task.id, task);
339
+ if (previous) previous.continuationTaskId = task.id;
281
340
  this.pruneTasks(task.id);
282
- this.pushEvent(task, { type: "started", message: "Task started." });
341
+ this.pushEvent(task, { type: "started", message: `Task started. Execution limit: ${timeoutMs}ms (${task.timeoutSource}); deadline: ${task.deadlineAt}. This is not a completion estimate.` });
283
342
  if (guidedPrompt !== input.prompt) {
284
343
  this.pushEvent(task, {
285
344
  type: "input-guidance",
@@ -303,7 +362,7 @@ export class TaskManager {
303
362
  message: `Timed out after ${timeoutMs}ms.`,
304
363
  });
305
364
  this.terminate(task);
306
- }, timeoutMs);
365
+ }, Math.max(0, deadlineMs - Date.now()));
307
366
 
308
367
  task.settled = this.watchExit(task, child);
309
368
  void task.settled;
@@ -518,7 +577,7 @@ export class TaskManager {
518
577
  }
519
578
 
520
579
  private collectUsage(task: InternalTask): void {
521
- if (!task.extractUsage) {
580
+ if (!task.extractUsage || task.streamCaptureTruncated) {
522
581
  return;
523
582
  }
524
583
 
@@ -712,6 +771,14 @@ export class TaskManager {
712
771
  }
713
772
 
714
773
  const chunk = decoder.decode(value, { stream: true });
774
+ if (streamName === "stdout" && task.extractSessionId && !task.nativeSessionId) {
775
+ try {
776
+ task.nativeSessionId = task.extractSessionId(task.stdout + chunk);
777
+ } catch (error) {
778
+ task.extractSessionId = undefined;
779
+ this.pushEvent(task, { type: "error", message: `Session ID extraction failed: ${String(error)}` });
780
+ }
781
+ }
715
782
  task.streamCaptureTruncated ||= task[streamName].length + chunk.length > MAX_CAPTURE_CHARS;
716
783
  task[streamName] = appendLimited(task[streamName], chunk);
717
784
  task.lastOutputAtMs = Date.now();
@@ -750,6 +817,14 @@ export class TaskManager {
750
817
  id: task.id,
751
818
  harnessId: task.harnessId,
752
819
  harnessName: task.harnessName,
820
+ model: task.model,
821
+ reasoningEffort: task.reasoningEffort,
822
+ nativeSubagents: task.nativeSubagents,
823
+ nativeSandbox: task.nativeSandbox,
824
+ persistSession: task.persistSession,
825
+ continueTaskId: task.continueTaskId,
826
+ continuationTaskId: task.continuationTaskId,
827
+ canContinue: Boolean(!running && task.persistSession && task.nativeSessionId && !task.continuationTaskId),
753
828
  status: task.status,
754
829
  cancelRequested: task.cancelRequested,
755
830
  pid: task.pid,
@@ -761,6 +836,8 @@ export class TaskManager {
761
836
  endedAt: task.endedAtMs ? new Date(task.endedAtMs).toISOString() : undefined,
762
837
  elapsedMs,
763
838
  timeoutMs: task.timeoutMs,
839
+ timeoutSource: task.timeoutSource,
840
+ deadlineAt: task.deadlineAt,
764
841
  remainingMs,
765
842
  etaConfidence: running ? "timeout-budget" : "complete",
766
843
  lastOutputAt: task.lastOutputAtMs
@@ -780,6 +857,7 @@ export class TaskManager {
780
857
  ? tail(task.finalMessage, maxOutputChars) : undefined,
781
858
  finalMessageChars: task.finalMessage?.length ?? 0,
782
859
  hasOutput: Boolean(task.finalMessage?.trim() || task.stdout.trim() || task.stderr.trim()),
860
+ captureTruncated: !task.finalMessage?.trim() && Boolean(task.streamCaptureTruncated),
783
861
  outputTruncated: task.finalMessage?.trim()
784
862
  ? !includeOutput || task.finalMessage.length > maxOutputChars
785
863
  : Boolean(task.streamCaptureTruncated ||
package/src/version.ts CHANGED
@@ -1 +1 @@
1
- export const ENNODIA_VERSION = "0.3.0-rc.2";
1
+ export const ENNODIA_VERSION = "0.3.0";