@agimon-ai/doompi-core 0.0.1-alpha.113 → 0.0.1-alpha.115
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/apiContracts.cjs.map +1 -1
- package/dist/apiContracts.mjs.map +1 -1
- package/dist/headless.cjs +1 -0
- package/dist/headless.d.mts +2 -2
- package/dist/headless.mjs +2 -2
- package/dist/headlessHub.cjs +1 -1
- package/dist/headlessHub.cjs.map +1 -1
- package/dist/headlessHub.mjs +1 -1
- package/dist/headlessHub.mjs.map +1 -1
- package/dist/headlessServer.d.mts +1 -1
- package/dist/headlessSessionHost.d.mts +3 -1
- package/dist/headlessSessionHost.d.mts.map +1 -1
- package/dist/packageApiServer.d.mts +1 -1
- package/dist/src/pi/piSessionRuntime.cjs +1 -1
- package/dist/src/pi/piSessionRuntime.mjs +1 -1
- package/dist/src/schemas/headless.cjs +7 -0
- package/dist/src/schemas/headless.cjs.map +1 -1
- package/dist/src/schemas/headless.d.mts +7 -0
- package/dist/src/schemas/headless.d.mts.map +1 -1
- package/dist/src/schemas/headless.mjs +7 -1
- package/dist/src/schemas/headless.mjs.map +1 -1
- package/dist/src/schemas/pluginProtocol.cjs.map +1 -1
- package/dist/src/schemas/pluginProtocol.d.mts +2 -0
- package/dist/src/schemas/pluginProtocol.d.mts.map +1 -1
- package/dist/src/schemas/pluginProtocol.mjs.map +1 -1
- package/dist/src/server/directHarnessRuntime.cjs +5 -2
- package/dist/src/server/directHarnessRuntime.cjs.map +1 -1
- package/dist/src/server/directHarnessRuntime.mjs +5 -2
- package/dist/src/server/directHarnessRuntime.mjs.map +1 -1
- package/dist/src/server/headlessProtocol.cjs +6 -1
- package/dist/src/server/headlessProtocol.cjs.map +1 -1
- package/dist/src/server/headlessProtocol.mjs +6 -1
- package/dist/src/server/headlessProtocol.mjs.map +1 -1
- package/dist/src/services/rpcTranscript/index.cjs +4 -2
- package/dist/src/services/rpcTranscript/index.cjs.map +1 -1
- package/dist/src/services/rpcTranscript/index.mjs +4 -2
- package/dist/src/services/rpcTranscript/index.mjs.map +1 -1
- package/dist/src/systems/main/adapters/headlessHost.cjs +19 -3
- package/dist/src/systems/main/adapters/headlessHost.cjs.map +1 -1
- package/dist/src/systems/main/adapters/headlessHost.d.mts +3 -0
- package/dist/src/systems/main/adapters/headlessHost.d.mts.map +1 -1
- package/dist/src/systems/main/adapters/headlessHost.mjs +20 -4
- package/dist/src/systems/main/adapters/headlessHost.mjs.map +1 -1
- package/dist/src/systems/main/adapters/headlessSessionHost.cjs +46 -8
- package/dist/src/systems/main/adapters/headlessSessionHost.cjs.map +1 -1
- package/dist/src/systems/main/adapters/headlessSessionHost.d.mts.map +1 -1
- package/dist/src/systems/main/adapters/headlessSessionHost.mjs +47 -9
- package/dist/src/systems/main/adapters/headlessSessionHost.mjs.map +1 -1
- package/dist/src/systems/main/types/headlessHost.d.mts +2 -1
- package/dist/src/systems/main/types/headlessHost.d.mts.map +1 -1
- package/dist/src/testing/pi/testHost.cjs +1 -0
- package/dist/src/testing/pi/testHost.cjs.map +1 -1
- package/dist/src/testing/pi/testHost.mjs +1 -0
- package/dist/src/testing/pi/testHost.mjs.map +1 -1
- package/dist/src/types/server/sessionToolSurface.d.mts +1 -1
- package/dist/src/web/types/webPlugin.d.mts +3 -2
- package/dist/src/web/types/webPlugin.d.mts.map +1 -1
- package/package.json +18 -18
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { DOOM_CHILD_SESSION_HOOKS_SERVICE, DOOM_CHILD_SESSION_MCP_TOOL_SERVICE, DOOM_CHILD_SESSION_SERVICE } from "../../child/types/childSession.mjs";
|
|
2
|
-
import { DoomHeadlessPromptAdmissionError } from "../../../schemas/headless.mjs";
|
|
2
|
+
import { DoomHeadlessPromptAdmissionError, isDoomHeadlessToolModelVisible } from "../../../schemas/headless.mjs";
|
|
3
3
|
import { createHistoryOwnership } from "../../../../historyOwnership.mjs";
|
|
4
4
|
import { SessionMetadataDoc } from "../../../../sqliteSessionStorage.mjs";
|
|
5
5
|
import { createPiExtensionHost, formatSkillsForSystemPrompt, preloadPiExtensions, resolvePiExtensionEntries, resolvePiSettingsPackageEntries } from "../../../services/piExtensionHost/index.mjs";
|
|
@@ -10,6 +10,7 @@ import { buildContextDetail } from "../../../../contextDetail.mjs";
|
|
|
10
10
|
import { writeContextDetail } from "../../../../contextDetailStore.mjs";
|
|
11
11
|
import { DOOM_CONTEXT_ENTRY_TYPE, projectContext } from "../../../../contextProjection.mjs";
|
|
12
12
|
import { createHeadlessClient } from "../../../services/headlessClient/index.mjs";
|
|
13
|
+
import { observe } from "../../../../serverTelemetry.mjs";
|
|
13
14
|
import { formatToolPrompt } from "../../../services/toolPrompt/index.mjs";
|
|
14
15
|
import { createHeadlessChildSessionServiceProvider } from "../../child/adapters/headlessChildSessionService.mjs";
|
|
15
16
|
import { randomUUID } from "node:crypto";
|
|
@@ -20,6 +21,7 @@ import { BACKGROUND_CONTEXT, withAbortSignal } from "@earendil-works/chord/conte
|
|
|
20
21
|
import { ModelRuntime, SettingsManager, getAgentDir, loadProjectContextFiles, parseArgs, resolveCliModel, resolveModelScopeWithDiagnostics } from "@earendil-works/pi-coding-agent";
|
|
21
22
|
//#region src/systems/main/adapters/headlessSessionHost.ts
|
|
22
23
|
const EXTERNAL_OPERATION = "external";
|
|
24
|
+
const PROMPT_PREPARATION_FAILED_EVENT = "doompi_server.system_prompt_preparation_failed";
|
|
23
25
|
function isRecord(value) {
|
|
24
26
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
25
27
|
}
|
|
@@ -313,6 +315,7 @@ async function createHeadlessSessionHost(options) {
|
|
|
313
315
|
if (parsed.apiKey !== void 0) await modelRuntime.setRuntimeApiKey(resolved.model.provider, parsed.apiKey);
|
|
314
316
|
const reportedToolErrors = /* @__PURE__ */ new Set();
|
|
315
317
|
let promptPreparationFailed = false;
|
|
318
|
+
let promptPreparationError;
|
|
316
319
|
let headlessReady = false;
|
|
317
320
|
let toolGuidance = [];
|
|
318
321
|
const initialSystemPrompt = [parsed.systemPrompt, ...parsed.appendSystemPrompt ?? []].filter(Boolean).join("\n\n");
|
|
@@ -422,14 +425,28 @@ async function createHeadlessSessionHost(options) {
|
|
|
422
425
|
let isError = original.isError;
|
|
423
426
|
let usage = original.usage;
|
|
424
427
|
let terminate;
|
|
428
|
+
let resultRewritten = false;
|
|
425
429
|
for (const patch of patches) {
|
|
426
430
|
if (!isRecord(patch)) continue;
|
|
427
|
-
if (isToolContent(patch.content))
|
|
428
|
-
|
|
429
|
-
|
|
431
|
+
if (isToolContent(patch.content)) {
|
|
432
|
+
content = patch.content;
|
|
433
|
+
resultRewritten = true;
|
|
434
|
+
}
|
|
435
|
+
if ("details" in patch && isJsonValue(patch.details)) {
|
|
436
|
+
details = patch.details;
|
|
437
|
+
resultRewritten = true;
|
|
438
|
+
}
|
|
439
|
+
if (typeof patch.isError === "boolean") {
|
|
440
|
+
isError = patch.isError;
|
|
441
|
+
resultRewritten = true;
|
|
442
|
+
}
|
|
430
443
|
if (isUsage(patch.usage)) usage = patch.usage;
|
|
431
444
|
if (typeof patch.terminate === "boolean") terminate = patch.terminate;
|
|
432
445
|
}
|
|
446
|
+
if (resultRewritten && isRecord(details) && "app" in details) {
|
|
447
|
+
const { app: _app, ...redactedDetails } = details;
|
|
448
|
+
details = redactedDetails;
|
|
449
|
+
}
|
|
433
450
|
return {
|
|
434
451
|
...content === event.content ? {} : { content },
|
|
435
452
|
...details === event.details ? {} : { details },
|
|
@@ -454,6 +471,7 @@ async function createHeadlessSessionHost(options) {
|
|
|
454
471
|
beforeModelRequest: async ({ phase }) => {
|
|
455
472
|
if (!headlessReady || !headlessHost) throw new Error("Headless capabilities are not installed.");
|
|
456
473
|
if (phase === "turn" && options.inheritedSelection) await headlessHost.inheritSelection(await options.inheritedSelection());
|
|
474
|
+
await headlessHost.settled();
|
|
457
475
|
},
|
|
458
476
|
transformContext: async (event) => {
|
|
459
477
|
if (!headlessReady || !headlessHost) throw new Error("Headless capabilities are not installed.");
|
|
@@ -520,12 +538,16 @@ async function createHeadlessSessionHost(options) {
|
|
|
520
538
|
return piHost?.beforeCompaction(event);
|
|
521
539
|
},
|
|
522
540
|
systemPrompt: async () => {
|
|
541
|
+
let stage = "resources";
|
|
523
542
|
try {
|
|
524
543
|
if (!headlessHost) throw new Error("Headless capabilities are not installed.");
|
|
544
|
+
await headlessHost.settled();
|
|
525
545
|
let prompt = composeSystemPrompt(await headlessHost.readResources());
|
|
546
|
+
stage = "before_agent_start hooks";
|
|
526
547
|
const patches = await headlessHost.dispatchHook("before_agent_start", { systemPrompt: prompt });
|
|
527
548
|
for (const patch of patches) if (patch && typeof patch === "object" && "systemPrompt" in patch && typeof patch.systemPrompt === "string") prompt = patch.systemPrompt;
|
|
528
549
|
promptPreparationFailed = false;
|
|
550
|
+
promptPreparationError = void 0;
|
|
529
551
|
if (prompt !== builtSystemPrompt) {
|
|
530
552
|
builtSystemPrompt = prompt;
|
|
531
553
|
try {
|
|
@@ -533,8 +555,13 @@ async function createHeadlessSessionHost(options) {
|
|
|
533
555
|
} catch {}
|
|
534
556
|
}
|
|
535
557
|
return prompt;
|
|
536
|
-
} catch {
|
|
558
|
+
} catch (error) {
|
|
537
559
|
promptPreparationFailed = true;
|
|
560
|
+
promptPreparationError = error;
|
|
561
|
+
observe(Promise.resolve().then(() => options.telemetry?.recordError(PROMPT_PREPARATION_FAILED_EVENT, error, {
|
|
562
|
+
session_id: options.sessionId,
|
|
563
|
+
stage
|
|
564
|
+
}, { includeException: true })));
|
|
538
565
|
return "";
|
|
539
566
|
}
|
|
540
567
|
},
|
|
@@ -553,7 +580,8 @@ async function createHeadlessSessionHost(options) {
|
|
|
553
580
|
return true;
|
|
554
581
|
},
|
|
555
582
|
guardModelRequest: () => {
|
|
556
|
-
if (
|
|
583
|
+
if (promptPreparationFailed) throw new Error(`Headless capability preparation is not ready: ${harnessErrorMessage(promptPreparationError)}`, { cause: promptPreparationError });
|
|
584
|
+
if (!headlessReady || !headlessHost?.status.ready) throw new Error("Headless capability preparation is not ready.");
|
|
557
585
|
}
|
|
558
586
|
});
|
|
559
587
|
const opened = await (async () => {
|
|
@@ -913,7 +941,8 @@ async function createHeadlessSessionHost(options) {
|
|
|
913
941
|
};
|
|
914
942
|
const applyToolSurface = async (tools) => {
|
|
915
943
|
toolSurfaceReady = false;
|
|
916
|
-
const
|
|
944
|
+
const modelTools = tools.filter(isDoomHeadlessToolModelVisible);
|
|
945
|
+
const facetTools = modelTools.map((tool) => toolAdapter(tool.name === "load_skill" ? {
|
|
917
946
|
...tool,
|
|
918
947
|
description: describeLoadSkillTool(tool.description, headlessHost?.appliedResources ?? [])
|
|
919
948
|
} : tool, () => headlessHost.context, reportedToolErrors));
|
|
@@ -927,7 +956,7 @@ async function createHeadlessSessionHost(options) {
|
|
|
927
956
|
}
|
|
928
957
|
}));
|
|
929
958
|
const piNames = new Set(piTools.map((tool) => tool.name));
|
|
930
|
-
const nextToolGuidance = [...(piHost?.toolGuidance ?? []).filter((entry) => piNames.has(entry.name)), ...
|
|
959
|
+
const nextToolGuidance = [...(piHost?.toolGuidance ?? []).filter((entry) => piNames.has(entry.name)), ...modelTools.map((tool) => ({
|
|
931
960
|
name: tool.name,
|
|
932
961
|
...tool.promptSnippet === void 0 ? {} : { promptSnippet: tool.promptSnippet },
|
|
933
962
|
...tool.promptGuidelines === void 0 ? {} : { promptGuidelines: tool.promptGuidelines }
|
|
@@ -948,7 +977,10 @@ async function createHeadlessSessionHost(options) {
|
|
|
948
977
|
name: tool.name,
|
|
949
978
|
label: tool.label ?? tool.name,
|
|
950
979
|
description: tool.description,
|
|
951
|
-
parameters: tool.parameters
|
|
980
|
+
parameters: tool.parameters,
|
|
981
|
+
...tool.annotations === void 0 ? {} : { annotations: tool.annotations },
|
|
982
|
+
...tool.outputSchema === void 0 ? {} : { outputSchema: tool.outputSchema },
|
|
983
|
+
...tool._meta === void 0 ? {} : { _meta: tool._meta }
|
|
952
984
|
},
|
|
953
985
|
execute: (toolCallId, parameters, signal, onUpdate) => tool.execute(toolCallId, parameters, signal, onUpdate, headlessHost.context)
|
|
954
986
|
});
|
|
@@ -978,6 +1010,7 @@ async function createHeadlessSessionHost(options) {
|
|
|
978
1010
|
applyLatestTools().catch((error) => options.onNotice?.(`Pi extension tool refresh failed: ${error instanceof Error ? error.message : String(error)}`));
|
|
979
1011
|
});
|
|
980
1012
|
};
|
|
1013
|
+
let admittedToolSurface;
|
|
981
1014
|
const prepareFacets = (root) => {
|
|
982
1015
|
mcpServiceRoot = root;
|
|
983
1016
|
root.plugin((context) => {
|
|
@@ -1004,6 +1037,7 @@ async function createHeadlessSessionHost(options) {
|
|
|
1004
1037
|
});
|
|
1005
1038
|
headlessHost = new HeadlessHost(root, {
|
|
1006
1039
|
candidates: options.candidates,
|
|
1040
|
+
toolSurface: () => admittedToolSurface,
|
|
1007
1041
|
selection: initialSelection,
|
|
1008
1042
|
selectionOverrides: [.../* @__PURE__ */ new Set([...options.selectionOverrides ?? [], ...[
|
|
1009
1043
|
"majorMode",
|
|
@@ -1246,6 +1280,10 @@ async function createHeadlessSessionHost(options) {
|
|
|
1246
1280
|
return skill.content;
|
|
1247
1281
|
}
|
|
1248
1282
|
};
|
|
1283
|
+
admittedToolSurface = {
|
|
1284
|
+
readSurface: () => toolSurface.readSurface(),
|
|
1285
|
+
invokeTool: (invocation) => toolSurface.invokeTool(invocation)
|
|
1286
|
+
};
|
|
1249
1287
|
const mcpSurface = {
|
|
1250
1288
|
readSurface() {
|
|
1251
1289
|
if (disposed || !headlessReady || !mcpSurfaceReady || !headlessHost?.status.ready) throw new Error("MCP capability preparation is not ready.");
|