@femtomc/mu-orchestrator 0.1.0 → 26.2.14

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.
@@ -2,7 +2,7 @@ import { existsSync } from "node:fs";
2
2
  import { mkdir } from "node:fs/promises";
3
3
  import { join, relative } from "node:path";
4
4
  import { currentRunId, executionSpecFromDict, fsEventLogFromRepoRoot, getStorePaths, newRunId, runContext, } from "@femtomc/mu-core/node";
5
- import { PiCliBackend } from "./pi_backend.js";
5
+ import { PiSdkBackend } from "./pi_sdk_backend.js";
6
6
  import { readPromptMeta, renderPromptTemplate } from "./prompt.js";
7
7
  function roundTo(n, digits) {
8
8
  const f = 10 ** digits;
@@ -33,7 +33,7 @@ export class DagRunner {
33
33
  this.#forum = forum;
34
34
  this.#repoRoot = repoRoot;
35
35
  this.#events = opts.events ?? fsEventLogFromRepoRoot(repoRoot);
36
- this.#backend = opts.backend ?? new PiCliBackend();
36
+ this.#backend = opts.backend ?? new PiSdkBackend();
37
37
  }
38
38
  async #resolveConfig(issue) {
39
39
  let cli = this.#fallbackCli;
package/dist/index.d.ts CHANGED
@@ -2,6 +2,7 @@ export type { DagResult } from "./dag_runner.js";
2
2
  export { DagRunner } from "./dag_runner.js";
3
3
  export type { BackendRunner, BackendRunOpts } from "./pi_backend.js";
4
4
  export { PiCliBackend, piStreamHasError } from "./pi_backend.js";
5
+ export { PiSdkBackend } from "./pi_sdk_backend.js";
5
6
  export type { PromptMeta } from "./prompt.js";
6
7
  export { buildRoleCatalog, extractDescription, readPromptMeta, renderPromptTemplate, splitFrontmatter, } from "./prompt.js";
7
8
  export declare function orchestratorHello(): string;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,YAAY,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACrE,OAAO,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AACjE,YAAY,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,EACN,gBAAgB,EAChB,kBAAkB,EAClB,cAAc,EACd,oBAAoB,EACpB,gBAAgB,GAChB,MAAM,aAAa,CAAC;AAGrB,wBAAgB,iBAAiB,IAAI,MAAM,CAE1C"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,YAAY,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACrE,OAAO,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AACjE,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,YAAY,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,EACN,gBAAgB,EAChB,kBAAkB,EAClB,cAAc,EACd,oBAAoB,EACpB,gBAAgB,GAChB,MAAM,aAAa,CAAC;AAGrB,wBAAgB,iBAAiB,IAAI,MAAM,CAE1C"}
package/dist/index.js CHANGED
@@ -1,5 +1,6 @@
1
1
  export { DagRunner } from "./dag_runner.js";
2
2
  export { PiCliBackend, piStreamHasError } from "./pi_backend.js";
3
+ export { PiSdkBackend } from "./pi_sdk_backend.js";
3
4
  export { buildRoleCatalog, extractDescription, readPromptMeta, renderPromptTemplate, splitFrontmatter, } from "./prompt.js";
4
5
  // Back-compat placeholder API used by other packages/tests.
5
6
  export function orchestratorHello() {
@@ -0,0 +1,11 @@
1
+ import type { BackendRunOpts, BackendRunner } from "./pi_backend.js";
2
+ /**
3
+ * In-process backend using the pi SDK.
4
+ *
5
+ * Replaces subprocess spawning of the `pi` CLI with direct use of
6
+ * `createAgentSession` from `@mariozechner/pi-coding-agent`.
7
+ */
8
+ export declare class PiSdkBackend implements BackendRunner {
9
+ run(opts: BackendRunOpts): Promise<number>;
10
+ }
11
+ //# sourceMappingURL=pi_sdk_backend.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pi_sdk_backend.d.ts","sourceRoot":"","sources":["../src/pi_sdk_backend.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAgBrE;;;;;GAKG;AACH,qBAAa,YAAa,YAAW,aAAa;IAC3C,GAAG,CAAC,IAAI,EAAE,cAAc,GAAG,OAAO,CAAC,MAAM,CAAC;CAsEhD"}
@@ -0,0 +1,88 @@
1
+ import { mkdir, open } from "node:fs/promises";
2
+ import { dirname } from "node:path";
3
+ import { SessionManager, SettingsManager, createAgentSession, createCodingTools, } from "@mariozechner/pi-coding-agent";
4
+ import { getModels, getProviders } from "@mariozechner/pi-ai";
5
+ import { piStreamHasError } from "./pi_backend.js";
6
+ /**
7
+ * Resolve a bare model ID (e.g. "gpt-5.3-codex") to a pi-ai Model object
8
+ * by searching across all known providers.
9
+ */
10
+ function resolveModel(modelId) {
11
+ for (const provider of getProviders()) {
12
+ const models = getModels(provider);
13
+ const match = models.find((m) => m.id === modelId);
14
+ if (match)
15
+ return match;
16
+ }
17
+ return undefined;
18
+ }
19
+ /**
20
+ * In-process backend using the pi SDK.
21
+ *
22
+ * Replaces subprocess spawning of the `pi` CLI with direct use of
23
+ * `createAgentSession` from `@mariozechner/pi-coding-agent`.
24
+ */
25
+ export class PiSdkBackend {
26
+ async run(opts) {
27
+ const model = resolveModel(opts.model);
28
+ if (!model) {
29
+ throw new Error(`Model "${opts.model}" not found in pi-ai registry`);
30
+ }
31
+ const sessionOpts = {
32
+ cwd: opts.cwd,
33
+ model,
34
+ thinkingLevel: opts.thinking,
35
+ tools: createCodingTools(opts.cwd),
36
+ sessionManager: SessionManager.inMemory(opts.cwd),
37
+ settingsManager: SettingsManager.inMemory(),
38
+ };
39
+ const { session } = await createAgentSession(sessionOpts);
40
+ let teeFh = null;
41
+ try {
42
+ if (opts.teePath) {
43
+ await mkdir(dirname(opts.teePath), { recursive: true });
44
+ teeFh = await open(opts.teePath, "w");
45
+ }
46
+ // Bind extensions (required for tools to work in print mode).
47
+ await session.bindExtensions({
48
+ commandContextActions: {
49
+ waitForIdle: () => session.agent.waitForIdle(),
50
+ newSession: async () => ({ cancelled: true }),
51
+ fork: async () => ({ cancelled: true }),
52
+ navigateTree: async () => ({ cancelled: true }),
53
+ switchSession: async () => ({ cancelled: true }),
54
+ reload: async () => { },
55
+ },
56
+ onError: () => { },
57
+ });
58
+ let sawError = false;
59
+ // Subscribe to events — serialize to JSONL for tee and error detection.
60
+ const unsub = session.subscribe((event) => {
61
+ const line = JSON.stringify(event);
62
+ if (piStreamHasError(line)) {
63
+ sawError = true;
64
+ }
65
+ opts.onLine?.(line);
66
+ if (teeFh) {
67
+ teeFh.write(`${line}\n`).catch(() => { });
68
+ }
69
+ });
70
+ try {
71
+ await session.prompt(opts.prompt, { expandPromptTemplates: false });
72
+ }
73
+ catch {
74
+ return 1;
75
+ }
76
+ finally {
77
+ unsub();
78
+ }
79
+ return sawError ? 1 : 0;
80
+ }
81
+ finally {
82
+ session.dispose();
83
+ if (teeFh) {
84
+ await teeFh.close();
85
+ }
86
+ }
87
+ }
88
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@femtomc/mu-orchestrator",
3
- "version": "0.1.0",
3
+ "version": "26.2.14",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -12,8 +12,11 @@
12
12
  },
13
13
  "files": ["dist/**"],
14
14
  "dependencies": {
15
- "@femtomc/mu-core": "0.1.0",
16
- "@femtomc/mu-forum": "0.1.0",
17
- "@femtomc/mu-issue": "0.1.0"
15
+ "@femtomc/mu-core": "26.2.14",
16
+ "@femtomc/mu-forum": "26.2.14",
17
+ "@femtomc/mu-issue": "26.2.14",
18
+ "@mariozechner/pi-agent-core": "^0.52.12",
19
+ "@mariozechner/pi-coding-agent": "^0.52.12",
20
+ "@mariozechner/pi-ai": "^0.52.12"
18
21
  }
19
22
  }