@femtomc/mu-orchestrator 0.1.0 → 26.2.15
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/dist/dag_runner.js +2 -2
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/pi_sdk_backend.d.ts +11 -0
- package/dist/pi_sdk_backend.d.ts.map +1 -0
- package/dist/pi_sdk_backend.js +99 -0
- package/package.json +7 -4
package/dist/dag_runner.js
CHANGED
|
@@ -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 {
|
|
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
|
|
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;
|
package/dist/index.d.ts.map
CHANGED
|
@@ -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":"AAaA,OAAO,KAAK,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AA8BrE;;;;;GAKG;AACH,qBAAa,YAAa,YAAW,aAAa;IAC3C,GAAG,CAAC,IAAI,EAAE,cAAc,GAAG,OAAO,CAAC,MAAM,CAAC;CAyEhD"}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { mkdir, open } from "node:fs/promises";
|
|
2
|
+
import { dirname } from "node:path";
|
|
3
|
+
import { AuthStorage, 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
|
+
*
|
|
9
|
+
* When multiple providers offer the same model ID, prefer providers that
|
|
10
|
+
* have auth configured (env var, OAuth, or stored API key).
|
|
11
|
+
*/
|
|
12
|
+
function resolveModel(modelId, authStorage) {
|
|
13
|
+
let fallback;
|
|
14
|
+
for (const provider of getProviders()) {
|
|
15
|
+
const models = getModels(provider);
|
|
16
|
+
const match = models.find((m) => m.id === modelId);
|
|
17
|
+
if (!match)
|
|
18
|
+
continue;
|
|
19
|
+
// Prefer providers that have auth configured.
|
|
20
|
+
if (authStorage.hasAuth(provider)) {
|
|
21
|
+
return match;
|
|
22
|
+
}
|
|
23
|
+
// Keep first match as fallback.
|
|
24
|
+
if (!fallback) {
|
|
25
|
+
fallback = match;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return fallback;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* In-process backend using the pi SDK.
|
|
32
|
+
*
|
|
33
|
+
* Replaces subprocess spawning of the `pi` CLI with direct use of
|
|
34
|
+
* `createAgentSession` from `@mariozechner/pi-coding-agent`.
|
|
35
|
+
*/
|
|
36
|
+
export class PiSdkBackend {
|
|
37
|
+
async run(opts) {
|
|
38
|
+
const authStorage = new AuthStorage();
|
|
39
|
+
const model = resolveModel(opts.model, authStorage);
|
|
40
|
+
if (!model) {
|
|
41
|
+
throw new Error(`Model "${opts.model}" not found in pi-ai registry. ` +
|
|
42
|
+
`Available providers: ${getProviders().join(", ")}`);
|
|
43
|
+
}
|
|
44
|
+
const sessionOpts = {
|
|
45
|
+
cwd: opts.cwd,
|
|
46
|
+
model,
|
|
47
|
+
thinkingLevel: opts.thinking,
|
|
48
|
+
tools: createCodingTools(opts.cwd),
|
|
49
|
+
sessionManager: SessionManager.inMemory(opts.cwd),
|
|
50
|
+
settingsManager: SettingsManager.inMemory(),
|
|
51
|
+
authStorage,
|
|
52
|
+
};
|
|
53
|
+
const { session } = await createAgentSession(sessionOpts);
|
|
54
|
+
let teeFh = null;
|
|
55
|
+
try {
|
|
56
|
+
if (opts.teePath) {
|
|
57
|
+
await mkdir(dirname(opts.teePath), { recursive: true });
|
|
58
|
+
teeFh = await open(opts.teePath, "w");
|
|
59
|
+
}
|
|
60
|
+
// Bind extensions (required for tools to work in print mode).
|
|
61
|
+
await session.bindExtensions({
|
|
62
|
+
commandContextActions: {
|
|
63
|
+
waitForIdle: () => session.agent.waitForIdle(),
|
|
64
|
+
newSession: async () => ({ cancelled: true }),
|
|
65
|
+
fork: async () => ({ cancelled: true }),
|
|
66
|
+
navigateTree: async () => ({ cancelled: true }),
|
|
67
|
+
switchSession: async () => ({ cancelled: true }),
|
|
68
|
+
reload: async () => { },
|
|
69
|
+
},
|
|
70
|
+
onError: () => { },
|
|
71
|
+
});
|
|
72
|
+
let sawError = false;
|
|
73
|
+
// Subscribe to events — serialize to JSONL for tee and error detection.
|
|
74
|
+
const unsub = session.subscribe((event) => {
|
|
75
|
+
const line = JSON.stringify(event);
|
|
76
|
+
if (piStreamHasError(line)) {
|
|
77
|
+
sawError = true;
|
|
78
|
+
}
|
|
79
|
+
opts.onLine?.(line);
|
|
80
|
+
if (teeFh) {
|
|
81
|
+
teeFh.write(`${line}\n`).catch(() => { });
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
try {
|
|
85
|
+
await session.prompt(opts.prompt, { expandPromptTemplates: false });
|
|
86
|
+
}
|
|
87
|
+
finally {
|
|
88
|
+
unsub();
|
|
89
|
+
}
|
|
90
|
+
return sawError ? 1 : 0;
|
|
91
|
+
}
|
|
92
|
+
finally {
|
|
93
|
+
session.dispose();
|
|
94
|
+
if (teeFh) {
|
|
95
|
+
await teeFh.close();
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@femtomc/mu-orchestrator",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "26.2.15",
|
|
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": "
|
|
16
|
-
"@femtomc/mu-forum": "
|
|
17
|
-
"@femtomc/mu-issue": "
|
|
15
|
+
"@femtomc/mu-core": "26.2.15",
|
|
16
|
+
"@femtomc/mu-forum": "26.2.15",
|
|
17
|
+
"@femtomc/mu-issue": "26.2.15",
|
|
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
|
}
|