@bastani/atomic 0.9.5-alpha.5 → 0.9.5-alpha.6
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/CHANGELOG.md +12 -0
- package/dist/builtin/cursor/package.json +2 -2
- package/dist/builtin/intercom/package.json +1 -1
- package/dist/builtin/mcp/package.json +1 -1
- package/dist/builtin/subagents/package.json +1 -1
- package/dist/builtin/web-access/package.json +1 -1
- package/dist/builtin/workflows/CHANGELOG.md +6 -0
- package/dist/builtin/workflows/package.json +1 -1
- package/dist/builtin/workflows/src/runs/foreground/executor-stage-control.ts +8 -0
- package/dist/builtin/workflows/src/runs/foreground/stage-control-registry.ts +2 -0
- package/dist/builtin/workflows/src/runs/foreground/stage-tool-execution-buffer.ts +47 -0
- package/dist/builtin/workflows/src/tui/stage-chat-view-pending-tools.ts +9 -0
- package/dist/builtin/workflows/src/tui/stage-chat-view-render-settings.ts +27 -0
- package/dist/builtin/workflows/src/tui/stage-chat-view-state.ts +5 -6
- package/dist/core/extensions/loader-core.d.ts.map +1 -1
- package/dist/core/extensions/loader-core.js +6 -0
- package/dist/core/extensions/loader-core.js.map +1 -1
- package/dist/core/model-resolver-scope.d.ts +9 -0
- package/dist/core/model-resolver-scope.d.ts.map +1 -1
- package/dist/core/model-resolver-scope.js +12 -4
- package/dist/core/model-resolver-scope.js.map +1 -1
- package/dist/core/model-resolver.d.ts +3 -2
- package/dist/core/model-resolver.d.ts.map +1 -1
- package/dist/core/model-resolver.js +1 -1
- package/dist/core/model-resolver.js.map +1 -1
- package/dist/core/resource-loader-extensions.d.ts.map +1 -1
- package/dist/core/resource-loader-extensions.js +4 -0
- package/dist/core/resource-loader-extensions.js.map +1 -1
- package/dist/core/resource-loader-reload.d.ts.map +1 -1
- package/dist/core/resource-loader-reload.js +11 -0
- package/dist/core/resource-loader-reload.js.map +1 -1
- package/dist/core/settings-manager-core.d.ts.map +1 -1
- package/dist/core/settings-manager-core.js +3 -2
- package/dist/core/settings-manager-core.js.map +1 -1
- package/dist/core/settings-storage.d.ts.map +1 -1
- package/dist/core/settings-storage.js +2 -1
- package/dist/core/settings-storage.js.map +1 -1
- package/dist/core/trust-manager.d.ts +9 -0
- package/dist/core/trust-manager.d.ts.map +1 -1
- package/dist/core/trust-manager.js +44 -2
- package/dist/core/trust-manager.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/main-deferred-startup.d.ts +19 -0
- package/dist/main-deferred-startup.d.ts.map +1 -0
- package/dist/main-deferred-startup.js +21 -0
- package/dist/main-deferred-startup.js.map +1 -0
- package/dist/main.d.ts.map +1 -1
- package/dist/main.js +24 -22
- package/dist/main.js.map +1 -1
- package/dist/modes/interactive/interactive-deferred-startup.d.ts +2 -1
- package/dist/modes/interactive/interactive-deferred-startup.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-deferred-startup.js +34 -1
- package/dist/modes/interactive/interactive-deferred-startup.js.map +1 -1
- package/dist/modes/interactive/interactive-mode-deps.d.ts +2 -2
- package/dist/modes/interactive/interactive-mode-deps.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode-deps.js +2 -2
- package/dist/modes/interactive/interactive-mode-deps.js.map +1 -1
- package/dist/modes/interactive/interactive-mode-types.d.ts +5 -1
- package/dist/modes/interactive/interactive-mode-types.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode-types.js.map +1 -1
- package/dist/modes/interactive/interactive-session-routing.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-session-routing.js +2 -2
- package/dist/modes/interactive/interactive-session-routing.js.map +1 -1
- package/dist/utils/child-process.d.ts +8 -1
- package/dist/utils/child-process.d.ts.map +1 -1
- package/dist/utils/child-process.js +39 -6
- package/dist/utils/child-process.js.map +1 -1
- package/dist/utils/event-loop.d.ts +7 -0
- package/dist/utils/event-loop.d.ts.map +1 -0
- package/dist/utils/event-loop.js +14 -0
- package/dist/utils/event-loop.js.map +1 -0
- package/dist/utils/json.d.ts +4 -0
- package/dist/utils/json.d.ts.map +1 -1
- package/dist/utils/json.js +8 -0
- package/dist/utils/json.js.map +1 -1
- package/docs/settings.md +5 -1
- package/docs/workflows.md +1 -1
- package/npm-shrinkwrap.json +23 -23
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,18 @@
|
|
|
2
2
|
|
|
3
3
|
## [Unreleased]
|
|
4
4
|
|
|
5
|
+
## [0.9.5-alpha.6] - 2026-07-06
|
|
6
|
+
|
|
7
|
+
### Fixed
|
|
8
|
+
|
|
9
|
+
- Fixed deferred TUI extension loading so the editor keeps accepting and echoing keystrokes after first paint: startup now yields cooperatively between extension/resource-loading chunks, preserves text typed during completion, and safely queues Enter submissions made before the main prompt loop is ready.
|
|
10
|
+
- Fixed a warm-start TUI first-paint regression where persisted `enabledModels` or `--models` patterns forced all extensions to load synchronously before the first frame. Interactive startup now keeps the deferred-extension fast path and reapplies the model scope after extensions finish loading, preserving extension-registered provider matches and unmatched-pattern warnings without blocking paint.
|
|
11
|
+
- Fixed project trust prompts for bare projects that only create inert `.atomic/` or `.pi/` state: state-only directories such as `todos/` and `sessions/` no longer count as trust inputs or disable deferred extension startup, while trust-requiring config continues to prompt until the user makes an explicit persistent decision and implicit trust is persisted only by the `/reload` path.
|
|
12
|
+
- Fixed a security regression that could silently persist project trust at shutdown or deferred-startup completion after trust-requiring config appeared mid-session; Atomic now preserves the startup trust prompt unless the user explicitly saves a decision or the existing `/reload` implicit-trust flow applies.
|
|
13
|
+
- Fixed BOM-prefixed JSON state files being treated as parse failures: settings and project trust JSON readers now strip a leading UTF-8 BOM before parsing, so Windows-authored `settings.json` and `trust.json` files load the same as BOM-less files instead of silently ignoring user settings.
|
|
14
|
+
- Fixed the bundled workflows documentation to reflect that attached workflow stage chats render live `subagent` widgets for single, parallel, and chain calls, keep them live across attach/re-attach cycles, and let Ctrl+O expand live detail for every child. ([#1643](https://github.com/bastani-inc/atomic/issues/1643))
|
|
15
|
+
- Fixed a Windows `waitForChildProcess` exit-code race where the process-alive poll could report a fast-dying child as gone before Node emitted the real `exit` event, causing bash commands such as `exit 1` to be reported as successful with a fabricated exit code 0 ([#1647](https://github.com/bastani-inc/atomic/issues/1647)).
|
|
16
|
+
|
|
5
17
|
## [0.9.5-alpha.5] - 2026-07-06
|
|
6
18
|
|
|
7
19
|
### Added
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bastani/cursor",
|
|
3
|
-
"version": "0.9.5-alpha.
|
|
3
|
+
"version": "0.9.5-alpha.6",
|
|
4
4
|
"private": true,
|
|
5
5
|
"description": "Experimental first-party Atomic extension for Cursor OAuth, model discovery, and streaming provider registration.",
|
|
6
6
|
"contributors": [
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
}
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"@bastani/atomic-natives": "0.9.5-alpha.
|
|
43
|
+
"@bastani/atomic-natives": "0.9.5-alpha.6",
|
|
44
44
|
"@bufbuild/protobuf": "^2.12.1",
|
|
45
45
|
"@earendil-works/pi-ai": "^0.80.3"
|
|
46
46
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bastani/intercom",
|
|
3
|
-
"version": "0.9.5-alpha.
|
|
3
|
+
"version": "0.9.5-alpha.6",
|
|
4
4
|
"private": true,
|
|
5
5
|
"description": "Atomic extension providing a private coordination channel between parent and child agent sessions. Fork of: https://github.com/nicobailon/pi-intercom",
|
|
6
6
|
"contributors": [
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bastani/mcp",
|
|
3
|
-
"version": "0.9.5-alpha.
|
|
3
|
+
"version": "0.9.5-alpha.6",
|
|
4
4
|
"private": true,
|
|
5
5
|
"description": "Atomic extension that adapts MCP (Model Context Protocol) servers into the coding agent. Fork of: https://github.com/nicobailon/pi-mcp-adapter",
|
|
6
6
|
"contributors": [
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bastani/subagents",
|
|
3
|
-
"version": "0.9.5-alpha.
|
|
3
|
+
"version": "0.9.5-alpha.6",
|
|
4
4
|
"private": true,
|
|
5
5
|
"description": "Atomic extension for delegating tasks to subagents with chains, parallel execution, and TUI clarification. Fork of: https://github.com/nicobailon/pi-subagents",
|
|
6
6
|
"contributors": [
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bastani/web-access",
|
|
3
|
-
"version": "0.9.5-alpha.
|
|
3
|
+
"version": "0.9.5-alpha.6",
|
|
4
4
|
"private": true,
|
|
5
5
|
"description": "Atomic extension for web search, URL fetching, GitHub repo cloning, PDF/video extraction. Fork of: https://github.com/nicobailon/pi-web-access",
|
|
6
6
|
"contributors": [
|
|
@@ -6,6 +6,12 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
|
|
6
6
|
|
|
7
7
|
## [Unreleased]
|
|
8
8
|
|
|
9
|
+
## [0.9.5-alpha.6] - 2026-07-06
|
|
10
|
+
|
|
11
|
+
### Fixed
|
|
12
|
+
|
|
13
|
+
- Fixed workflow stage chats so attach, exit, and re-attach cycles during an in-flight `subagent` call replay the latest live tool partial result immediately instead of collapsing single, parallel, or chain calls back to the bare `renderCall` title until the next update; stage chats also prefer renderers from the stage's own agent session before falling back to the host chat so nested workflow stages can render tools that the parent chat does not expose. ([#1643](https://github.com/bastani-inc/atomic/issues/1643))
|
|
14
|
+
|
|
9
15
|
## [0.9.5-alpha.5] - 2026-07-06
|
|
10
16
|
|
|
11
17
|
### Added
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { StageControlHandle, AgentSessionEventListener } from "./stage-control-registry.js";
|
|
2
2
|
import type { LiveStageRuntime } from "./executor-stage-types.js";
|
|
3
3
|
import { isTerminalStage } from "./executor-scheduler.js";
|
|
4
|
+
import { StageToolExecutionBuffer } from "./stage-tool-execution-buffer.js";
|
|
4
5
|
|
|
5
6
|
export function createStageControlHandle(runtime: LiveStageRuntime): StageControlHandle {
|
|
6
7
|
const ensureMessagingSession = async (): Promise<void> => {
|
|
@@ -15,6 +16,8 @@ export function createStageControlHandle(runtime: LiveStageRuntime): StageContro
|
|
|
15
16
|
throw new Error(`atomic-workflows: cannot message stage "${runtime.name}" because no retained session metadata is available.`);
|
|
16
17
|
}
|
|
17
18
|
};
|
|
19
|
+
const toolExecutions = new StageToolExecutionBuffer();
|
|
20
|
+
const unsubscribeToolExecutions = runtime.innerCtx.subscribe((event) => toolExecutions.record(event));
|
|
18
21
|
|
|
19
22
|
return {
|
|
20
23
|
runId: runtime.runId,
|
|
@@ -41,6 +44,9 @@ export function createStageControlHandle(runtime: LiveStageRuntime): StageContro
|
|
|
41
44
|
get agentSession() {
|
|
42
45
|
return runtime.innerCtx.__agentSession();
|
|
43
46
|
},
|
|
47
|
+
pendingToolExecutionEvents() {
|
|
48
|
+
return toolExecutions.replayEvents();
|
|
49
|
+
},
|
|
44
50
|
async ensureAttached() {
|
|
45
51
|
runtime.throwIfStageMutationBlocked();
|
|
46
52
|
await ensureMessagingSession();
|
|
@@ -120,6 +126,8 @@ export function createStageControlHandle(runtime: LiveStageRuntime): StageContro
|
|
|
120
126
|
return runtime.innerCtx.subscribe(listener);
|
|
121
127
|
},
|
|
122
128
|
async dispose() {
|
|
129
|
+
unsubscribeToolExecutions();
|
|
130
|
+
toolExecutions.clear();
|
|
123
131
|
await runtime.releaseLiveHandle();
|
|
124
132
|
},
|
|
125
133
|
};
|
|
@@ -59,6 +59,8 @@ export interface StageControlHandle {
|
|
|
59
59
|
readonly messages: AgentSession["messages"];
|
|
60
60
|
/** Live coding-agent session when available, used by embedded chat/footer UI. */
|
|
61
61
|
readonly agentSession?: AgentSession;
|
|
62
|
+
/** Replayable in-flight tool starts/partial updates for stage-chat remounts. */
|
|
63
|
+
pendingToolExecutionEvents?(): readonly AgentSessionEvent[];
|
|
62
64
|
/** Ensure the SDK session exists. Cheap when already attached. */
|
|
63
65
|
ensureAttached(): Promise<void>;
|
|
64
66
|
/** Send a prompt. Use only when the stage is idle / not streaming. */
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { AgentSessionEvent } from "@bastani/atomic";
|
|
2
|
+
|
|
3
|
+
interface PendingToolExecution {
|
|
4
|
+
start: AgentSessionEvent;
|
|
5
|
+
update?: AgentSessionEvent;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
function eventType(event: AgentSessionEvent): string {
|
|
9
|
+
return String((event as { type?: unknown }).type ?? "");
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
function toolCallId(event: AgentSessionEvent): string | undefined {
|
|
13
|
+
const value = (event as { toolCallId?: unknown }).toolCallId;
|
|
14
|
+
return typeof value === "string" && value.length > 0 ? value : undefined;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export class StageToolExecutionBuffer {
|
|
18
|
+
private readonly pending = new Map<string, PendingToolExecution>();
|
|
19
|
+
|
|
20
|
+
record(event: AgentSessionEvent): void {
|
|
21
|
+
const type = eventType(event);
|
|
22
|
+
if (type === "agent_start" || type === "agent_end") {
|
|
23
|
+
this.pending.clear();
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
const id = toolCallId(event);
|
|
27
|
+
if (id === undefined) return;
|
|
28
|
+
if (type === "tool_execution_start") {
|
|
29
|
+
this.pending.set(id, { start: event });
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
if (type === "tool_execution_update") {
|
|
33
|
+
const existing = this.pending.get(id);
|
|
34
|
+
if (existing) existing.update = event;
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
if (type === "tool_execution_end") this.pending.delete(id);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
replayEvents(): readonly AgentSessionEvent[] {
|
|
41
|
+
return [...this.pending.values()].flatMap((entry) => entry.update ? [entry.start, entry.update] : [entry.start]);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
clear(): void {
|
|
45
|
+
this.pending.clear();
|
|
46
|
+
}
|
|
47
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { AgentSessionEvent } from "@bastani/atomic";
|
|
2
|
+
import type { StageChatViewContext } from "./stage-chat-view-types.js";
|
|
3
|
+
|
|
4
|
+
export function replayPendingToolExecutions(ctx: StageChatViewContext): void {
|
|
5
|
+
const events = ctx.handle?.isDisposed === true
|
|
6
|
+
? []
|
|
7
|
+
: ctx.handle?.pendingToolExecutionEvents?.() ?? [];
|
|
8
|
+
for (const event of events) ctx.chatHost.applyAgentEvent(event as AgentSessionEvent);
|
|
9
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { ChatMessageRenderOptions } from "@bastani/atomic";
|
|
2
|
+
import type { StageChatViewContext, StageChatViewOpts } from "./stage-chat-view-types.js";
|
|
3
|
+
|
|
4
|
+
type StageChatRenderSettings = Partial<Omit<ChatMessageRenderOptions, "ui" | "cwd">>;
|
|
5
|
+
|
|
6
|
+
type MessageRendererHost = {
|
|
7
|
+
extensionRunner?: {
|
|
8
|
+
getMessageRenderer?: (customType: string) => ReturnType<NonNullable<StageChatRenderSettings["getCustomMessageRenderer"]>>;
|
|
9
|
+
};
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export function stageChatRenderSettings(
|
|
13
|
+
ctx: StageChatViewContext,
|
|
14
|
+
opts: StageChatViewOpts,
|
|
15
|
+
): StageChatRenderSettings | undefined {
|
|
16
|
+
const inherited = opts.getChatRenderSettings?.();
|
|
17
|
+
const stageSession = ctx.handle?.isDisposed === true ? undefined : ctx.handle?.agentSession;
|
|
18
|
+
if (!stageSession) return inherited;
|
|
19
|
+
const rendererHost = stageSession as MessageRendererHost;
|
|
20
|
+
return {
|
|
21
|
+
...inherited,
|
|
22
|
+
getToolDefinition: (toolName) =>
|
|
23
|
+
stageSession.getToolDefinition(toolName) ?? inherited?.getToolDefinition?.(toolName),
|
|
24
|
+
getCustomMessageRenderer: (customType) =>
|
|
25
|
+
rendererHost.extensionRunner?.getMessageRenderer?.(customType) ?? inherited?.getCustomMessageRenderer?.(customType),
|
|
26
|
+
};
|
|
27
|
+
}
|
|
@@ -4,11 +4,7 @@ import type { PendingPrompt, RunSnapshot, StageSnapshot } from "../shared/store-
|
|
|
4
4
|
import { stageUiBroker } from "../shared/stage-ui-broker.js";
|
|
5
5
|
import { resolveStageChatViewportRows } from "./stage-chat-layout.js";
|
|
6
6
|
import { createPromptCardState } from "./prompt-card.js";
|
|
7
|
-
import {
|
|
8
|
-
hideMountedCustomUi,
|
|
9
|
-
releaseMountedCustomUi,
|
|
10
|
-
showCustomUi,
|
|
11
|
-
} from "./stage-chat-view-custom-ui.js";
|
|
7
|
+
import { hideMountedCustomUi, releaseMountedCustomUi, showCustomUi } from "./stage-chat-view-custom-ui.js";
|
|
12
8
|
import { editorRuleColor } from "./stage-chat-view-footer-status.js";
|
|
13
9
|
import {
|
|
14
10
|
blankLine,
|
|
@@ -30,6 +26,8 @@ import {
|
|
|
30
26
|
} from "./stage-chat-view-types.js";
|
|
31
27
|
import { noticeRow, noticeSummary } from "./stage-chat-view-transcript.js";
|
|
32
28
|
import { applyStageChatLiveHandleEvent } from "./stage-chat-view-live-events.js";
|
|
29
|
+
import { replayPendingToolExecutions } from "./stage-chat-view-pending-tools.js";
|
|
30
|
+
import { stageChatRenderSettings } from "./stage-chat-view-render-settings.js";
|
|
33
31
|
import { hexToAnsi, RESET } from "./color-utils.js";
|
|
34
32
|
import {
|
|
35
33
|
isTerminalOrNonStreamingStageChatStatus,
|
|
@@ -89,6 +87,7 @@ export function initializeStageChatView(
|
|
|
89
87
|
});
|
|
90
88
|
|
|
91
89
|
snapshotMessagesFromHandle(ctx);
|
|
90
|
+
replayPendingToolExecutions(ctx);
|
|
92
91
|
const initialRun = currentRun(ctx);
|
|
93
92
|
const initialStage = initialRun?.stages.find((s) => s.id === ctx.stageId);
|
|
94
93
|
ctx.lastObservedRunStatus = initialRun?.status;
|
|
@@ -187,7 +186,7 @@ function createChatHost(
|
|
|
187
186
|
keybindings: opts.piKeybindings,
|
|
188
187
|
editorFactory: opts.piEditorFactory,
|
|
189
188
|
editorTheme: editorThemeFromGraphTheme(ctx.theme),
|
|
190
|
-
getChatRenderSettings: opts
|
|
189
|
+
getChatRenderSettings: () => stageChatRenderSettings(ctx, opts),
|
|
191
190
|
footerData: opts.footerData,
|
|
192
191
|
renderExtraEntry: (entry) => noticeRow(entry, ctx.theme),
|
|
193
192
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"loader-core.d.ts","sourceRoot":"","sources":["../../../src/core/extensions/loader-core.ts"],"names":[],"mappings":"AAEA,OAAO,EAAkB,KAAK,QAAQ,EAAE,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"loader-core.d.ts","sourceRoot":"","sources":["../../../src/core/extensions/loader-core.ts"],"names":[],"mappings":"AAEA,OAAO,EAAkB,KAAK,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAKhE,OAAO,EAEL,KAAK,yCAAyC,EAC9C,KAAK,6BAA6B,EACnC,MAAM,uBAAuB,CAAC;AAO/B,OAAO,KAAK,EAAE,SAAS,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAkEtG;;GAEG;AACH,wBAAsB,wBAAwB,CAC5C,OAAO,EAAE,gBAAgB,EACzB,GAAG,EAAE,MAAM,EACX,QAAQ,EAAE,QAAQ,EAClB,OAAO,EAAE,gBAAgB,EACzB,aAAa,SAAa,EAC1B,wBAAwB,GAAE,6BAA6D,EACvF,yCAAyC,CAAC,EAAE,yCAAyC,GACpF,OAAO,CAAC,SAAS,CAAC,CAapB;AAuDD,wBAAsB,cAAc,CAClC,KAAK,EAAE,MAAM,EAAE,EACf,GAAG,EAAE,MAAM,EACX,QAAQ,CAAC,EAAE,QAAQ,EACnB,wBAAwB,GAAE,6BAA6D,EACvF,OAAO,CAAC,EAAE,gBAAgB,EAC1B,yCAAyC,CAAC,EAAE,yCAAyC,GACpF,OAAO,CAAC,oBAAoB,CAAC,CAS/B;AAED,wBAAsB,oBAAoB,CACxC,KAAK,EAAE,MAAM,EAAE,EACf,GAAG,EAAE,MAAM,EACX,QAAQ,CAAC,EAAE,QAAQ,EACnB,wBAAwB,GAAE,6BAA6D,EACvF,OAAO,CAAC,EAAE,gBAAgB,EAC1B,yCAAyC,CAAC,EAAE,yCAAyC,GACpF,OAAO,CAAC,oBAAoB,CAAC,CAU/B","sourcesContent":["import * as path from \"node:path\";\nimport { resolvePath } from \"../../utils/paths.ts\";\nimport { createEventBus, type EventBus } from \"../event-bus.ts\";\nimport { createSyntheticSourceInfo } from \"../source-info.ts\";\nimport { endTimingSpan, startTimingSpan } from \"../timings.ts\";\nimport { yieldToEventLoop } from \"../../utils/event-loop.ts\";\nimport { createExtensionAPI } from \"./loader-api.ts\";\nimport {\n emptyWorkflowResourceProvider,\n type ResourceLoaderInheritanceSnapshotProvider,\n type WorkflowResourceProviderInput,\n} from \"./loader-resources.ts\";\nimport { createExtensionRuntime } from \"./loader-runtime.ts\";\nimport {\n loadExtensionModule,\n type ExtensionCacheToken,\n useExtensionCacheCwd,\n} from \"./loader-virtual-modules.ts\";\nimport type { Extension, ExtensionFactory, ExtensionRuntime, LoadExtensionsResult } from \"./types.ts\";\n\n/**\n * Create an Extension object with empty collections.\n */\nfunction createExtension(extensionPath: string, resolvedPath: string): Extension {\n const source = extensionPath.startsWith(\"<\") && extensionPath.endsWith(\">\")\n ? extensionPath.slice(1, -1).split(\":\")[0] || \"temporary\"\n : \"local\";\n const baseDir = extensionPath.startsWith(\"<\") ? undefined : path.dirname(resolvedPath);\n\n return {\n path: extensionPath,\n resolvedPath,\n sourceInfo: createSyntheticSourceInfo(extensionPath, { source, baseDir }),\n handlers: new Map(),\n tools: new Map(),\n messageRenderers: new Map(),\n commands: new Map(),\n flags: new Map(),\n shortcuts: new Map(),\n };\n}\n\nasync function loadExtension(\n extensionPath: string,\n cwd: string,\n eventBus: EventBus,\n runtime: ExtensionRuntime,\n workflowResourceProvider: WorkflowResourceProviderInput = emptyWorkflowResourceProvider,\n resourceLoaderInheritanceSnapshotProvider?: ResourceLoaderInheritanceSnapshotProvider,\n cacheToken?: ExtensionCacheToken,\n): Promise<{ extension: Extension | null; error: string | null }> {\n const resolvedPath = resolvePath(extensionPath, cwd, { normalizeUnicodeSpaces: true });\n\n try {\n const moduleSpan = startTimingSpan(`loadExtensions.${extensionPath}.module`, \"extensions\");\n const factory = await loadExtensionModule(resolvedPath, cacheToken);\n endTimingSpan(moduleSpan);\n if (!factory) {\n return {\n extension: null,\n error: `Extension does not export a valid factory function: ${extensionPath}`,\n };\n }\n\n const extension = createExtension(extensionPath, resolvedPath);\n const api = createExtensionAPI(\n extension,\n runtime,\n cwd,\n eventBus,\n workflowResourceProvider,\n resourceLoaderInheritanceSnapshotProvider,\n );\n const factorySpan = startTimingSpan(`loadExtensions.${extensionPath}.factory`, \"extensions\");\n await factory(api);\n endTimingSpan(factorySpan);\n\n return { extension, error: null };\n } catch (err) {\n const message = err instanceof Error ? err.message : String(err);\n return { extension: null, error: `Failed to load extension: ${message}` };\n }\n}\n\n/**\n * Create an Extension from an inline factory function.\n */\nexport async function loadExtensionFromFactory(\n factory: ExtensionFactory,\n cwd: string,\n eventBus: EventBus,\n runtime: ExtensionRuntime,\n extensionPath = \"<inline>\",\n workflowResourceProvider: WorkflowResourceProviderInput = emptyWorkflowResourceProvider,\n resourceLoaderInheritanceSnapshotProvider?: ResourceLoaderInheritanceSnapshotProvider,\n): Promise<Extension> {\n const extension = createExtension(extensionPath, extensionPath);\n const resolvedCwd = resolvePath(cwd);\n const api = createExtensionAPI(\n extension,\n runtime,\n resolvedCwd,\n eventBus,\n workflowResourceProvider,\n resourceLoaderInheritanceSnapshotProvider,\n );\n await factory(api);\n return extension;\n}\n\n/**\n * Load extensions from paths.\n */\nasync function loadExtensionsInternal(\n paths: string[],\n cwd: string,\n eventBus?: EventBus,\n workflowResourceProvider: WorkflowResourceProviderInput = emptyWorkflowResourceProvider,\n runtime?: ExtensionRuntime,\n resourceLoaderInheritanceSnapshotProvider?: ResourceLoaderInheritanceSnapshotProvider,\n useCache = false,\n): Promise<LoadExtensionsResult> {\n const extensions: Extension[] = [];\n const errors: Array<{ path: string; error: string }> = [];\n const cacheToken = useCache ? useExtensionCacheCwd(cwd) : undefined;\n const resolvedCwd = cacheToken?.cwd ?? resolvePath(cwd);\n const resolvedEventBus = eventBus ?? createEventBus();\n const resolvedRuntime = runtime ?? createExtensionRuntime();\n\n let processedExtensionCount = 0;\n for (const extPath of paths) {\n if (processedExtensionCount > 0) {\n await yieldToEventLoop();\n }\n const extensionSpan = startTimingSpan(`loadExtensions.${extPath}.total`, \"extensions\");\n const { extension, error } = await loadExtension(\n extPath,\n resolvedCwd,\n resolvedEventBus,\n resolvedRuntime,\n workflowResourceProvider,\n resourceLoaderInheritanceSnapshotProvider,\n cacheToken,\n );\n endTimingSpan(extensionSpan);\n processedExtensionCount += 1;\n if (error) {\n errors.push({ path: extPath, error });\n continue;\n }\n\n if (extension) {\n extensions.push(extension);\n }\n }\n\n return {\n extensions,\n errors,\n runtime: resolvedRuntime,\n };\n}\n\nexport async function loadExtensions(\n paths: string[],\n cwd: string,\n eventBus?: EventBus,\n workflowResourceProvider: WorkflowResourceProviderInput = emptyWorkflowResourceProvider,\n runtime?: ExtensionRuntime,\n resourceLoaderInheritanceSnapshotProvider?: ResourceLoaderInheritanceSnapshotProvider,\n): Promise<LoadExtensionsResult> {\n return loadExtensionsInternal(\n paths,\n cwd,\n eventBus,\n workflowResourceProvider,\n runtime,\n resourceLoaderInheritanceSnapshotProvider,\n );\n}\n\nexport async function loadExtensionsCached(\n paths: string[],\n cwd: string,\n eventBus?: EventBus,\n workflowResourceProvider: WorkflowResourceProviderInput = emptyWorkflowResourceProvider,\n runtime?: ExtensionRuntime,\n resourceLoaderInheritanceSnapshotProvider?: ResourceLoaderInheritanceSnapshotProvider,\n): Promise<LoadExtensionsResult> {\n return loadExtensionsInternal(\n paths,\n cwd,\n eventBus,\n workflowResourceProvider,\n runtime,\n resourceLoaderInheritanceSnapshotProvider,\n true,\n );\n}\n"]}
|
|
@@ -3,6 +3,7 @@ import { resolvePath } from "../../utils/paths.js";
|
|
|
3
3
|
import { createEventBus } from "../event-bus.js";
|
|
4
4
|
import { createSyntheticSourceInfo } from "../source-info.js";
|
|
5
5
|
import { endTimingSpan, startTimingSpan } from "../timings.js";
|
|
6
|
+
import { yieldToEventLoop } from "../../utils/event-loop.js";
|
|
6
7
|
import { createExtensionAPI } from "./loader-api.js";
|
|
7
8
|
import { emptyWorkflowResourceProvider, } from "./loader-resources.js";
|
|
8
9
|
import { createExtensionRuntime } from "./loader-runtime.js";
|
|
@@ -71,10 +72,15 @@ async function loadExtensionsInternal(paths, cwd, eventBus, workflowResourceProv
|
|
|
71
72
|
const resolvedCwd = cacheToken?.cwd ?? resolvePath(cwd);
|
|
72
73
|
const resolvedEventBus = eventBus ?? createEventBus();
|
|
73
74
|
const resolvedRuntime = runtime ?? createExtensionRuntime();
|
|
75
|
+
let processedExtensionCount = 0;
|
|
74
76
|
for (const extPath of paths) {
|
|
77
|
+
if (processedExtensionCount > 0) {
|
|
78
|
+
await yieldToEventLoop();
|
|
79
|
+
}
|
|
75
80
|
const extensionSpan = startTimingSpan(`loadExtensions.${extPath}.total`, "extensions");
|
|
76
81
|
const { extension, error } = await loadExtension(extPath, resolvedCwd, resolvedEventBus, resolvedRuntime, workflowResourceProvider, resourceLoaderInheritanceSnapshotProvider, cacheToken);
|
|
77
82
|
endTimingSpan(extensionSpan);
|
|
83
|
+
processedExtensionCount += 1;
|
|
78
84
|
if (error) {
|
|
79
85
|
errors.push({ path: extPath, error });
|
|
80
86
|
continue;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"loader-core.js","sourceRoot":"","sources":["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EAAE,CAAC;QAC5B,MAAM,aAAa,GAAG,eAAe,CAAC,kBAAkB,OAAO,QAAQ,EAAE,YAAY,CAAC,CAAC;QACvF,MAAM,EAAE,SAAS,EAAE,KAAK,EAAE,GAAG,MAAM,aAAa,CAC9C,OAAO,EACP,WAAW,EACX,gBAAgB,EAChB,eAAe,EACf,wBAAwB,EACxB,yCAAyC,EACzC,UAAU,CACX,CAAC;QACF,aAAa,CAAC,aAAa,CAAC,CAAC;QAE7B,IAAI,KAAK,EAAE,CAAC;YACV,MAAM,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC,CAAC;YACtC,SAAS;QACX,CAAC;QAED,IAAI,SAAS,EAAE,CAAC;YACd,UAAU,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QAC7B,CAAC;IACH,CAAC;IAED,OAAO;QACL,UAAU;QACV,MAAM;QACN,OAAO,EAAE,eAAe;KACzB,CAAC;AACJ,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,cAAc,CAClC,KAAe,EACf,GAAW,EACX,QAAmB,EACnB,wBAAwB,GAAkC,6BAA6B,EACvF,OAA0B,EAC1B,yCAAqF;IAErF,OAAO,sBAAsB,CAC3B,KAAK,EACL,GAAG,EACH,QAAQ,EACR,wBAAwB,EACxB,OAAO,EACP,yCAAyC,CAC1C,CAAC;AACJ,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,oBAAoB,CACxC,KAAe,EACf,GAAW,EACX,QAAmB,EACnB,wBAAwB,GAAkC,6BAA6B,EACvF,OAA0B,EAC1B,yCAAqF;IAErF,OAAO,sBAAsB,CAC3B,KAAK,EACL,GAAG,EACH,QAAQ,EACR,wBAAwB,EACxB,OAAO,EACP,yCAAyC,EACzC,IAAI,CACL,CAAC;AACJ,CAAC","sourcesContent":["import * as path from \"node:path\";\nimport { resolvePath } from \"../../utils/paths.ts\";\nimport { createEventBus, type EventBus } from \"../event-bus.ts\";\nimport { createSyntheticSourceInfo } from \"../source-info.ts\";\nimport { endTimingSpan, startTimingSpan } from \"../timings.ts\";\nimport { createExtensionAPI } from \"./loader-api.ts\";\nimport {\n emptyWorkflowResourceProvider,\n type ResourceLoaderInheritanceSnapshotProvider,\n type WorkflowResourceProviderInput,\n} from \"./loader-resources.ts\";\nimport { createExtensionRuntime } from \"./loader-runtime.ts\";\nimport {\n loadExtensionModule,\n type ExtensionCacheToken,\n useExtensionCacheCwd,\n} from \"./loader-virtual-modules.ts\";\nimport type { Extension, ExtensionFactory, ExtensionRuntime, LoadExtensionsResult } from \"./types.ts\";\n\n/**\n * Create an Extension object with empty collections.\n */\nfunction createExtension(extensionPath: string, resolvedPath: string): Extension {\n const source = extensionPath.startsWith(\"<\") && extensionPath.endsWith(\">\")\n ? extensionPath.slice(1, -1).split(\":\")[0] || \"temporary\"\n : \"local\";\n const baseDir = extensionPath.startsWith(\"<\") ? undefined : path.dirname(resolvedPath);\n\n return {\n path: extensionPath,\n resolvedPath,\n sourceInfo: createSyntheticSourceInfo(extensionPath, { source, baseDir }),\n handlers: new Map(),\n tools: new Map(),\n messageRenderers: new Map(),\n commands: new Map(),\n flags: new Map(),\n shortcuts: new Map(),\n };\n}\n\nasync function loadExtension(\n extensionPath: string,\n cwd: string,\n eventBus: EventBus,\n runtime: ExtensionRuntime,\n workflowResourceProvider: WorkflowResourceProviderInput = emptyWorkflowResourceProvider,\n resourceLoaderInheritanceSnapshotProvider?: ResourceLoaderInheritanceSnapshotProvider,\n cacheToken?: ExtensionCacheToken,\n): Promise<{ extension: Extension | null; error: string | null }> {\n const resolvedPath = resolvePath(extensionPath, cwd, { normalizeUnicodeSpaces: true });\n\n try {\n const moduleSpan = startTimingSpan(`loadExtensions.${extensionPath}.module`, \"extensions\");\n const factory = await loadExtensionModule(resolvedPath, cacheToken);\n endTimingSpan(moduleSpan);\n if (!factory) {\n return {\n extension: null,\n error: `Extension does not export a valid factory function: ${extensionPath}`,\n };\n }\n\n const extension = createExtension(extensionPath, resolvedPath);\n const api = createExtensionAPI(\n extension,\n runtime,\n cwd,\n eventBus,\n workflowResourceProvider,\n resourceLoaderInheritanceSnapshotProvider,\n );\n const factorySpan = startTimingSpan(`loadExtensions.${extensionPath}.factory`, \"extensions\");\n await factory(api);\n endTimingSpan(factorySpan);\n\n return { extension, error: null };\n } catch (err) {\n const message = err instanceof Error ? err.message : String(err);\n return { extension: null, error: `Failed to load extension: ${message}` };\n }\n}\n\n/**\n * Create an Extension from an inline factory function.\n */\nexport async function loadExtensionFromFactory(\n factory: ExtensionFactory,\n cwd: string,\n eventBus: EventBus,\n runtime: ExtensionRuntime,\n extensionPath = \"<inline>\",\n workflowResourceProvider: WorkflowResourceProviderInput = emptyWorkflowResourceProvider,\n resourceLoaderInheritanceSnapshotProvider?: ResourceLoaderInheritanceSnapshotProvider,\n): Promise<Extension> {\n const extension = createExtension(extensionPath, extensionPath);\n const resolvedCwd = resolvePath(cwd);\n const api = createExtensionAPI(\n extension,\n runtime,\n resolvedCwd,\n eventBus,\n workflowResourceProvider,\n resourceLoaderInheritanceSnapshotProvider,\n );\n await factory(api);\n return extension;\n}\n\n/**\n * Load extensions from paths.\n */\nasync function loadExtensionsInternal(\n paths: string[],\n cwd: string,\n eventBus?: EventBus,\n workflowResourceProvider: WorkflowResourceProviderInput = emptyWorkflowResourceProvider,\n runtime?: ExtensionRuntime,\n resourceLoaderInheritanceSnapshotProvider?: ResourceLoaderInheritanceSnapshotProvider,\n useCache = false,\n): Promise<LoadExtensionsResult> {\n const extensions: Extension[] = [];\n const errors: Array<{ path: string; error: string }> = [];\n const cacheToken = useCache ? useExtensionCacheCwd(cwd) : undefined;\n const resolvedCwd = cacheToken?.cwd ?? resolvePath(cwd);\n const resolvedEventBus = eventBus ?? createEventBus();\n const resolvedRuntime = runtime ?? createExtensionRuntime();\n\n for (const extPath of paths) {\n const extensionSpan = startTimingSpan(`loadExtensions.${extPath}.total`, \"extensions\");\n const { extension, error } = await loadExtension(\n extPath,\n resolvedCwd,\n resolvedEventBus,\n resolvedRuntime,\n workflowResourceProvider,\n resourceLoaderInheritanceSnapshotProvider,\n cacheToken,\n );\n endTimingSpan(extensionSpan);\n\n if (error) {\n errors.push({ path: extPath, error });\n continue;\n }\n\n if (extension) {\n extensions.push(extension);\n }\n }\n\n return {\n extensions,\n errors,\n runtime: resolvedRuntime,\n };\n}\n\nexport async function loadExtensions(\n paths: string[],\n cwd: string,\n eventBus?: EventBus,\n workflowResourceProvider: WorkflowResourceProviderInput = emptyWorkflowResourceProvider,\n runtime?: ExtensionRuntime,\n resourceLoaderInheritanceSnapshotProvider?: ResourceLoaderInheritanceSnapshotProvider,\n): Promise<LoadExtensionsResult> {\n return loadExtensionsInternal(\n paths,\n cwd,\n eventBus,\n workflowResourceProvider,\n runtime,\n resourceLoaderInheritanceSnapshotProvider,\n );\n}\n\nexport async function loadExtensionsCached(\n paths: string[],\n cwd: string,\n eventBus?: EventBus,\n workflowResourceProvider: WorkflowResourceProviderInput = emptyWorkflowResourceProvider,\n runtime?: ExtensionRuntime,\n resourceLoaderInheritanceSnapshotProvider?: ResourceLoaderInheritanceSnapshotProvider,\n): Promise<LoadExtensionsResult> {\n return loadExtensionsInternal(\n paths,\n cwd,\n eventBus,\n workflowResourceProvider,\n runtime,\n resourceLoaderInheritanceSnapshotProvider,\n true,\n );\n}\n"]}
|
|
1
|
+
{"version":3,"file":"loader-core.js","sourceRoot":"","sources":["../../../src/core/extensions/loader-core.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACnD,OAAO,EAAE,cAAc,EAAiB,MAAM,iBAAiB,CAAC;AAChE,OAAO,EAAE,yBAAyB,EAAE,MAAM,mBAAmB,CAAC;AAC9D,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAC/D,OAAO,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAC7D,OAAO,EAAE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AAgB,EAChB,eAAe,EACf,wBAAwB,EACxB,yCAAyC,EACzC,UAAU,CACX,CAAC;QACF,aAAa,CAAC,aAAa,CAAC,CAAC;QAC7B,uBAAuB,IAAI,CAAC,CAAC;QAC7B,IAAI,KAAK,EAAE,CAAC;YACV,MAAM,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC,CAAC;YACtC,SAAS;QACX,CAAC;QAED,IAAI,SAAS,EAAE,CAAC;YACd,UAAU,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QAC7B,CAAC;IACH,CAAC;IAED,OAAO;QACL,UAAU;QACV,MAAM;QACN,OAAO,EAAE,eAAe;KACzB,CAAC;AACJ,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,cAAc,CAClC,KAAe,EACf,GAAW,EACX,QAAmB,EACnB,wBAAwB,GAAkC,6BAA6B,EACvF,OAA0B,EAC1B,yCAAqF;IAErF,OAAO,sBAAsB,CAC3B,KAAK,EACL,GAAG,EACH,QAAQ,EACR,wBAAwB,EACxB,OAAO,EACP,yCAAyC,CAC1C,CAAC;AACJ,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,oBAAoB,CACxC,KAAe,EACf,GAAW,EACX,QAAmB,EACnB,wBAAwB,GAAkC,6BAA6B,EACvF,OAA0B,EAC1B,yCAAqF;IAErF,OAAO,sBAAsB,CAC3B,KAAK,EACL,GAAG,EACH,QAAQ,EACR,wBAAwB,EACxB,OAAO,EACP,yCAAyC,EACzC,IAAI,CACL,CAAC;AACJ,CAAC","sourcesContent":["import * as path from \"node:path\";\nimport { resolvePath } from \"../../utils/paths.ts\";\nimport { createEventBus, type EventBus } from \"../event-bus.ts\";\nimport { createSyntheticSourceInfo } from \"../source-info.ts\";\nimport { endTimingSpan, startTimingSpan } from \"../timings.ts\";\nimport { yieldToEventLoop } from \"../../utils/event-loop.ts\";\nimport { createExtensionAPI } from \"./loader-api.ts\";\nimport {\n emptyWorkflowResourceProvider,\n type ResourceLoaderInheritanceSnapshotProvider,\n type WorkflowResourceProviderInput,\n} from \"./loader-resources.ts\";\nimport { createExtensionRuntime } from \"./loader-runtime.ts\";\nimport {\n loadExtensionModule,\n type ExtensionCacheToken,\n useExtensionCacheCwd,\n} from \"./loader-virtual-modules.ts\";\nimport type { Extension, ExtensionFactory, ExtensionRuntime, LoadExtensionsResult } from \"./types.ts\";\n\n/**\n * Create an Extension object with empty collections.\n */\nfunction createExtension(extensionPath: string, resolvedPath: string): Extension {\n const source = extensionPath.startsWith(\"<\") && extensionPath.endsWith(\">\")\n ? extensionPath.slice(1, -1).split(\":\")[0] || \"temporary\"\n : \"local\";\n const baseDir = extensionPath.startsWith(\"<\") ? undefined : path.dirname(resolvedPath);\n\n return {\n path: extensionPath,\n resolvedPath,\n sourceInfo: createSyntheticSourceInfo(extensionPath, { source, baseDir }),\n handlers: new Map(),\n tools: new Map(),\n messageRenderers: new Map(),\n commands: new Map(),\n flags: new Map(),\n shortcuts: new Map(),\n };\n}\n\nasync function loadExtension(\n extensionPath: string,\n cwd: string,\n eventBus: EventBus,\n runtime: ExtensionRuntime,\n workflowResourceProvider: WorkflowResourceProviderInput = emptyWorkflowResourceProvider,\n resourceLoaderInheritanceSnapshotProvider?: ResourceLoaderInheritanceSnapshotProvider,\n cacheToken?: ExtensionCacheToken,\n): Promise<{ extension: Extension | null; error: string | null }> {\n const resolvedPath = resolvePath(extensionPath, cwd, { normalizeUnicodeSpaces: true });\n\n try {\n const moduleSpan = startTimingSpan(`loadExtensions.${extensionPath}.module`, \"extensions\");\n const factory = await loadExtensionModule(resolvedPath, cacheToken);\n endTimingSpan(moduleSpan);\n if (!factory) {\n return {\n extension: null,\n error: `Extension does not export a valid factory function: ${extensionPath}`,\n };\n }\n\n const extension = createExtension(extensionPath, resolvedPath);\n const api = createExtensionAPI(\n extension,\n runtime,\n cwd,\n eventBus,\n workflowResourceProvider,\n resourceLoaderInheritanceSnapshotProvider,\n );\n const factorySpan = startTimingSpan(`loadExtensions.${extensionPath}.factory`, \"extensions\");\n await factory(api);\n endTimingSpan(factorySpan);\n\n return { extension, error: null };\n } catch (err) {\n const message = err instanceof Error ? err.message : String(err);\n return { extension: null, error: `Failed to load extension: ${message}` };\n }\n}\n\n/**\n * Create an Extension from an inline factory function.\n */\nexport async function loadExtensionFromFactory(\n factory: ExtensionFactory,\n cwd: string,\n eventBus: EventBus,\n runtime: ExtensionRuntime,\n extensionPath = \"<inline>\",\n workflowResourceProvider: WorkflowResourceProviderInput = emptyWorkflowResourceProvider,\n resourceLoaderInheritanceSnapshotProvider?: ResourceLoaderInheritanceSnapshotProvider,\n): Promise<Extension> {\n const extension = createExtension(extensionPath, extensionPath);\n const resolvedCwd = resolvePath(cwd);\n const api = createExtensionAPI(\n extension,\n runtime,\n resolvedCwd,\n eventBus,\n workflowResourceProvider,\n resourceLoaderInheritanceSnapshotProvider,\n );\n await factory(api);\n return extension;\n}\n\n/**\n * Load extensions from paths.\n */\nasync function loadExtensionsInternal(\n paths: string[],\n cwd: string,\n eventBus?: EventBus,\n workflowResourceProvider: WorkflowResourceProviderInput = emptyWorkflowResourceProvider,\n runtime?: ExtensionRuntime,\n resourceLoaderInheritanceSnapshotProvider?: ResourceLoaderInheritanceSnapshotProvider,\n useCache = false,\n): Promise<LoadExtensionsResult> {\n const extensions: Extension[] = [];\n const errors: Array<{ path: string; error: string }> = [];\n const cacheToken = useCache ? useExtensionCacheCwd(cwd) : undefined;\n const resolvedCwd = cacheToken?.cwd ?? resolvePath(cwd);\n const resolvedEventBus = eventBus ?? createEventBus();\n const resolvedRuntime = runtime ?? createExtensionRuntime();\n\n let processedExtensionCount = 0;\n for (const extPath of paths) {\n if (processedExtensionCount > 0) {\n await yieldToEventLoop();\n }\n const extensionSpan = startTimingSpan(`loadExtensions.${extPath}.total`, \"extensions\");\n const { extension, error } = await loadExtension(\n extPath,\n resolvedCwd,\n resolvedEventBus,\n resolvedRuntime,\n workflowResourceProvider,\n resourceLoaderInheritanceSnapshotProvider,\n cacheToken,\n );\n endTimingSpan(extensionSpan);\n processedExtensionCount += 1;\n if (error) {\n errors.push({ path: extPath, error });\n continue;\n }\n\n if (extension) {\n extensions.push(extension);\n }\n }\n\n return {\n extensions,\n errors,\n runtime: resolvedRuntime,\n };\n}\n\nexport async function loadExtensions(\n paths: string[],\n cwd: string,\n eventBus?: EventBus,\n workflowResourceProvider: WorkflowResourceProviderInput = emptyWorkflowResourceProvider,\n runtime?: ExtensionRuntime,\n resourceLoaderInheritanceSnapshotProvider?: ResourceLoaderInheritanceSnapshotProvider,\n): Promise<LoadExtensionsResult> {\n return loadExtensionsInternal(\n paths,\n cwd,\n eventBus,\n workflowResourceProvider,\n runtime,\n resourceLoaderInheritanceSnapshotProvider,\n );\n}\n\nexport async function loadExtensionsCached(\n paths: string[],\n cwd: string,\n eventBus?: EventBus,\n workflowResourceProvider: WorkflowResourceProviderInput = emptyWorkflowResourceProvider,\n runtime?: ExtensionRuntime,\n resourceLoaderInheritanceSnapshotProvider?: ResourceLoaderInheritanceSnapshotProvider,\n): Promise<LoadExtensionsResult> {\n return loadExtensionsInternal(\n paths,\n cwd,\n eventBus,\n workflowResourceProvider,\n runtime,\n resourceLoaderInheritanceSnapshotProvider,\n true,\n );\n}\n"]}
|
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
import type { ModelRegistry } from "./model-registry.ts";
|
|
2
2
|
import type { ScopedModel } from "./model-resolver-types.ts";
|
|
3
|
+
export interface ModelScopeDiagnostic {
|
|
4
|
+
type: "warning";
|
|
5
|
+
message: string;
|
|
6
|
+
}
|
|
7
|
+
export interface ResolveModelScopeResult {
|
|
8
|
+
scopedModels: ScopedModel[];
|
|
9
|
+
diagnostics: ModelScopeDiagnostic[];
|
|
10
|
+
}
|
|
3
11
|
/**
|
|
4
12
|
* Resolve model patterns to actual Model objects with optional thinking levels
|
|
5
13
|
* Format: "pattern:level" where :level is optional
|
|
@@ -11,5 +19,6 @@ import type { ScopedModel } from "./model-resolver-types.ts";
|
|
|
11
19
|
* The algorithm tries to match the full pattern first, then progressively
|
|
12
20
|
* strips colon-suffixes to find a match.
|
|
13
21
|
*/
|
|
22
|
+
export declare function resolveModelScopeWithDiagnostics(patterns: string[], modelRegistry: ModelRegistry): Promise<ResolveModelScopeResult>;
|
|
14
23
|
export declare function resolveModelScope(patterns: string[], modelRegistry: ModelRegistry): Promise<ScopedModel[]>;
|
|
15
24
|
//# sourceMappingURL=model-resolver-scope.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"model-resolver-scope.d.ts","sourceRoot":"","sources":["../../src/core/model-resolver-scope.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEzD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;
|
|
1
|
+
{"version":3,"file":"model-resolver-scope.d.ts","sourceRoot":"","sources":["../../src/core/model-resolver-scope.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEzD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAE7D,MAAM,WAAW,oBAAoB;IACnC,IAAI,EAAE,SAAS,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,uBAAuB;IACtC,YAAY,EAAE,WAAW,EAAE,CAAC;IAC5B,WAAW,EAAE,oBAAoB,EAAE,CAAC;CACrC;AAoBD;;;;;;;;;;GAUG;AACH,wBAAsB,gCAAgC,CACpD,QAAQ,EAAE,MAAM,EAAE,EAClB,aAAa,EAAE,aAAa,GAC3B,OAAO,CAAC,uBAAuB,CAAC,CA0ClC;AAED,wBAAsB,iBAAiB,CAAC,QAAQ,EAAE,MAAM,EAAE,EAAE,aAAa,EAAE,aAAa,GAAG,OAAO,CAAC,WAAW,EAAE,CAAC,CAMhH","sourcesContent":["import type { ThinkingLevel } from \"@earendil-works/pi-agent-core\";\nimport { modelsAreEqual } from \"@earendil-works/pi-ai/compat\";\nimport chalk from \"chalk\";\nimport { minimatch } from \"minimatch\";\nimport { isValidThinkingLevel } from \"../cli/args.ts\";\nimport type { ModelRegistry } from \"./model-registry.ts\";\nimport { parseModelPattern } from \"./model-resolver-patterns.ts\";\nimport type { ScopedModel } from \"./model-resolver-types.ts\";\n\nexport interface ModelScopeDiagnostic {\n type: \"warning\";\n message: string;\n}\n\nexport interface ResolveModelScopeResult {\n scopedModels: ScopedModel[];\n diagnostics: ModelScopeDiagnostic[];\n}\n\nfunction hasGlobCharacters(pattern: string): boolean {\n return pattern.includes(\"*\") || pattern.includes(\"?\") || pattern.includes(\"[\");\n}\n\nfunction parseGlobThinkingLevel(pattern: string): { globPattern: string; thinkingLevel?: ThinkingLevel } {\n const colonIdx = pattern.lastIndexOf(\":\");\n if (colonIdx === -1) {\n return { globPattern: pattern };\n }\n\n const suffix = pattern.substring(colonIdx + 1);\n if (!isValidThinkingLevel(suffix)) {\n return { globPattern: pattern };\n }\n\n return { globPattern: pattern.substring(0, colonIdx), thinkingLevel: suffix };\n}\n\n/**\n * Resolve model patterns to actual Model objects with optional thinking levels\n * Format: \"pattern:level\" where :level is optional\n * For each pattern, finds all matching models and picks the best version:\n * 1. Prefer alias (e.g., claude-sonnet-4-5) over dated versions (claude-sonnet-4-5-20250929)\n * 2. If no alias, pick the latest dated version\n *\n * Supports models with colons in their IDs (e.g., OpenRouter's model:exacto).\n * The algorithm tries to match the full pattern first, then progressively\n * strips colon-suffixes to find a match.\n */\nexport async function resolveModelScopeWithDiagnostics(\n patterns: string[],\n modelRegistry: ModelRegistry,\n): Promise<ResolveModelScopeResult> {\n const availableModels = await modelRegistry.getAvailable();\n const scopedModels: ScopedModel[] = [];\n const diagnostics: ModelScopeDiagnostic[] = [];\n for (const pattern of patterns) {\n if (hasGlobCharacters(pattern)) {\n const { globPattern, thinkingLevel } = parseGlobThinkingLevel(pattern);\n const matchingModels = availableModels.filter((m) => {\n const fullId = `${m.provider}/${m.id}`;\n return minimatch(fullId, globPattern, { nocase: true }) || minimatch(m.id, globPattern, { nocase: true });\n });\n\n if (matchingModels.length === 0) {\n diagnostics.push({ type: \"warning\", message: `No models match pattern \"${pattern}\"` });\n continue;\n }\n\n for (const model of matchingModels) {\n if (!scopedModels.find((sm) => modelsAreEqual(sm.model, model))) {\n scopedModels.push({ model, thinkingLevel });\n }\n }\n continue;\n }\n\n const { model, thinkingLevel, warning } = parseModelPattern(pattern, availableModels);\n\n if (warning) {\n diagnostics.push({ type: \"warning\", message: warning });\n }\n\n if (!model) {\n diagnostics.push({ type: \"warning\", message: `No models match pattern \"${pattern}\"` });\n continue;\n }\n\n if (!scopedModels.find((sm) => modelsAreEqual(sm.model, model))) {\n scopedModels.push({ model, thinkingLevel });\n }\n }\n\n return { scopedModels, diagnostics };\n}\n\nexport async function resolveModelScope(patterns: string[], modelRegistry: ModelRegistry): Promise<ScopedModel[]> {\n const { scopedModels, diagnostics } = await resolveModelScopeWithDiagnostics(patterns, modelRegistry);\n for (const diagnostic of diagnostics) {\n console.warn(chalk.yellow(`Warning: ${diagnostic.message}`));\n }\n return scopedModels;\n}\n"]}
|
|
@@ -28,9 +28,10 @@ function parseGlobThinkingLevel(pattern) {
|
|
|
28
28
|
* The algorithm tries to match the full pattern first, then progressively
|
|
29
29
|
* strips colon-suffixes to find a match.
|
|
30
30
|
*/
|
|
31
|
-
export async function
|
|
31
|
+
export async function resolveModelScopeWithDiagnostics(patterns, modelRegistry) {
|
|
32
32
|
const availableModels = await modelRegistry.getAvailable();
|
|
33
33
|
const scopedModels = [];
|
|
34
|
+
const diagnostics = [];
|
|
34
35
|
for (const pattern of patterns) {
|
|
35
36
|
if (hasGlobCharacters(pattern)) {
|
|
36
37
|
const { globPattern, thinkingLevel } = parseGlobThinkingLevel(pattern);
|
|
@@ -39,7 +40,7 @@ export async function resolveModelScope(patterns, modelRegistry) {
|
|
|
39
40
|
return minimatch(fullId, globPattern, { nocase: true }) || minimatch(m.id, globPattern, { nocase: true });
|
|
40
41
|
});
|
|
41
42
|
if (matchingModels.length === 0) {
|
|
42
|
-
|
|
43
|
+
diagnostics.push({ type: "warning", message: `No models match pattern "${pattern}"` });
|
|
43
44
|
continue;
|
|
44
45
|
}
|
|
45
46
|
for (const model of matchingModels) {
|
|
@@ -51,16 +52,23 @@ export async function resolveModelScope(patterns, modelRegistry) {
|
|
|
51
52
|
}
|
|
52
53
|
const { model, thinkingLevel, warning } = parseModelPattern(pattern, availableModels);
|
|
53
54
|
if (warning) {
|
|
54
|
-
|
|
55
|
+
diagnostics.push({ type: "warning", message: warning });
|
|
55
56
|
}
|
|
56
57
|
if (!model) {
|
|
57
|
-
|
|
58
|
+
diagnostics.push({ type: "warning", message: `No models match pattern "${pattern}"` });
|
|
58
59
|
continue;
|
|
59
60
|
}
|
|
60
61
|
if (!scopedModels.find((sm) => modelsAreEqual(sm.model, model))) {
|
|
61
62
|
scopedModels.push({ model, thinkingLevel });
|
|
62
63
|
}
|
|
63
64
|
}
|
|
65
|
+
return { scopedModels, diagnostics };
|
|
66
|
+
}
|
|
67
|
+
export async function resolveModelScope(patterns, modelRegistry) {
|
|
68
|
+
const { scopedModels, diagnostics } = await resolveModelScopeWithDiagnostics(patterns, modelRegistry);
|
|
69
|
+
for (const diagnostic of diagnostics) {
|
|
70
|
+
console.warn(chalk.yellow(`Warning: ${diagnostic.message}`));
|
|
71
|
+
}
|
|
64
72
|
return scopedModels;
|
|
65
73
|
}
|
|
66
74
|
//# sourceMappingURL=model-resolver-scope.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"model-resolver-scope.js","sourceRoot":"","sources":["../../src/core/model-resolver-scope.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAC9D,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,EAAE,oBAAoB,EAA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B,CAAC,OAAO,EAAE,eAAe,CAAC,CAAC;QAEtF,IAAI,OAAO,EAAE,CAAC;YACZ,WAAW,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC,CAAC;QAC1D,CAAC;QAED,IAAI,CAAC,KAAK,EAAE,CAAC;YACX,WAAW,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,4BAA4B,OAAO,GAAG,EAAE,CAAC,CAAC;YACvF,SAAS;QACX,CAAC;QAED,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,cAAc,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC,EAAE,CAAC;YAChE,YAAY,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,aAAa,EAAE,CAAC,CAAC;QAC9C,CAAC;IACH,CAAC;IAED,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,CAAC;AACvC,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,iBAAiB,CAAC,QAAkB,EAAE,aAA4B;IACtF,MAAM,EAAE,YAAY,EAAE,WAAW,EAAE,GAAG,MAAM,gCAAgC,CAAC,QAAQ,EAAE,aAAa,CAAC,CAAC;IACtG,KAAK,MAAM,UAAU,IAAI,WAAW,EAAE,CAAC;QACrC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,YAAY,UAAU,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC;IAC/D,CAAC;IACD,OAAO,YAAY,CAAC;AACtB,CAAC","sourcesContent":["import type { ThinkingLevel } from \"@earendil-works/pi-agent-core\";\nimport { modelsAreEqual } from \"@earendil-works/pi-ai/compat\";\nimport chalk from \"chalk\";\nimport { minimatch } from \"minimatch\";\nimport { isValidThinkingLevel } from \"../cli/args.ts\";\nimport type { ModelRegistry } from \"./model-registry.ts\";\nimport { parseModelPattern } from \"./model-resolver-patterns.ts\";\nimport type { ScopedModel } from \"./model-resolver-types.ts\";\n\nexport interface ModelScopeDiagnostic {\n type: \"warning\";\n message: string;\n}\n\nexport interface ResolveModelScopeResult {\n scopedModels: ScopedModel[];\n diagnostics: ModelScopeDiagnostic[];\n}\n\nfunction hasGlobCharacters(pattern: string): boolean {\n return pattern.includes(\"*\") || pattern.includes(\"?\") || pattern.includes(\"[\");\n}\n\nfunction parseGlobThinkingLevel(pattern: string): { globPattern: string; thinkingLevel?: ThinkingLevel } {\n const colonIdx = pattern.lastIndexOf(\":\");\n if (colonIdx === -1) {\n return { globPattern: pattern };\n }\n\n const suffix = pattern.substring(colonIdx + 1);\n if (!isValidThinkingLevel(suffix)) {\n return { globPattern: pattern };\n }\n\n return { globPattern: pattern.substring(0, colonIdx), thinkingLevel: suffix };\n}\n\n/**\n * Resolve model patterns to actual Model objects with optional thinking levels\n * Format: \"pattern:level\" where :level is optional\n * For each pattern, finds all matching models and picks the best version:\n * 1. Prefer alias (e.g., claude-sonnet-4-5) over dated versions (claude-sonnet-4-5-20250929)\n * 2. If no alias, pick the latest dated version\n *\n * Supports models with colons in their IDs (e.g., OpenRouter's model:exacto).\n * The algorithm tries to match the full pattern first, then progressively\n * strips colon-suffixes to find a match.\n */\nexport async function resolveModelScopeWithDiagnostics(\n patterns: string[],\n modelRegistry: ModelRegistry,\n): Promise<ResolveModelScopeResult> {\n const availableModels = await modelRegistry.getAvailable();\n const scopedModels: ScopedModel[] = [];\n const diagnostics: ModelScopeDiagnostic[] = [];\n for (const pattern of patterns) {\n if (hasGlobCharacters(pattern)) {\n const { globPattern, thinkingLevel } = parseGlobThinkingLevel(pattern);\n const matchingModels = availableModels.filter((m) => {\n const fullId = `${m.provider}/${m.id}`;\n return minimatch(fullId, globPattern, { nocase: true }) || minimatch(m.id, globPattern, { nocase: true });\n });\n\n if (matchingModels.length === 0) {\n diagnostics.push({ type: \"warning\", message: `No models match pattern \"${pattern}\"` });\n continue;\n }\n\n for (const model of matchingModels) {\n if (!scopedModels.find((sm) => modelsAreEqual(sm.model, model))) {\n scopedModels.push({ model, thinkingLevel });\n }\n }\n continue;\n }\n\n const { model, thinkingLevel, warning } = parseModelPattern(pattern, availableModels);\n\n if (warning) {\n diagnostics.push({ type: \"warning\", message: warning });\n }\n\n if (!model) {\n diagnostics.push({ type: \"warning\", message: `No models match pattern \"${pattern}\"` });\n continue;\n }\n\n if (!scopedModels.find((sm) => modelsAreEqual(sm.model, model))) {\n scopedModels.push({ model, thinkingLevel });\n }\n }\n\n return { scopedModels, diagnostics };\n}\n\nexport async function resolveModelScope(patterns: string[], modelRegistry: ModelRegistry): Promise<ScopedModel[]> {\n const { scopedModels, diagnostics } = await resolveModelScopeWithDiagnostics(patterns, modelRegistry);\n for (const diagnostic of diagnostics) {\n console.warn(chalk.yellow(`Warning: ${diagnostic.message}`));\n }\n return scopedModels;\n}\n"]}
|
|
@@ -5,6 +5,7 @@ export { defaultModelPerProvider } from "./model-resolver-defaults.ts";
|
|
|
5
5
|
export { resolveCliModel } from "./model-resolver-cli.ts";
|
|
6
6
|
export { findInitialModel, resolveSavedModelReference, restoreModelFromSession } from "./model-resolver-initial.ts";
|
|
7
7
|
export { findExactModelReferenceMatch, parseModelPattern } from "./model-resolver-patterns.ts";
|
|
8
|
-
export { resolveModelScope } from "./model-resolver-scope.ts";
|
|
9
|
-
export type {
|
|
8
|
+
export { resolveModelScope, resolveModelScopeWithDiagnostics } from "./model-resolver-scope.ts";
|
|
9
|
+
export type { ModelScopeDiagnostic, ResolveModelScopeResult } from "./model-resolver-scope.ts";
|
|
10
|
+
export type { InitialModelResult, ParsedModelResult, ResolveCliModelResult, ScopedModel } from "./model-resolver-types.ts";
|
|
10
11
|
//# sourceMappingURL=model-resolver.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"model-resolver.d.ts","sourceRoot":"","sources":["../../src/core/model-resolver.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,uBAAuB,EAAE,MAAM,8BAA8B,CAAC;AACvE,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAC1D,OAAO,EAAE,gBAAgB,EAAE,0BAA0B,EAAE,uBAAuB,EAAE,MAAM,6BAA6B,CAAC;AACpH,OAAO,EAAE,4BAA4B,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AAC/F,OAAO,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;
|
|
1
|
+
{"version":3,"file":"model-resolver.d.ts","sourceRoot":"","sources":["../../src/core/model-resolver.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,uBAAuB,EAAE,MAAM,8BAA8B,CAAC;AACvE,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAC1D,OAAO,EAAE,gBAAgB,EAAE,0BAA0B,EAAE,uBAAuB,EAAE,MAAM,6BAA6B,CAAC;AACpH,OAAO,EAAE,4BAA4B,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AAC/F,OAAO,EAAE,iBAAiB,EAAE,gCAAgC,EAAE,MAAM,2BAA2B,CAAC;AAChG,YAAY,EAAE,oBAAoB,EAAE,uBAAuB,EAAE,MAAM,2BAA2B,CAAC;AAC/F,YAAY,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,qBAAqB,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC","sourcesContent":["/**\n * Model resolution, scoping, and initial selection\n */\n\nexport { defaultModelPerProvider } from \"./model-resolver-defaults.ts\";\nexport { resolveCliModel } from \"./model-resolver-cli.ts\";\nexport { findInitialModel, resolveSavedModelReference, restoreModelFromSession } from \"./model-resolver-initial.ts\";\nexport { findExactModelReferenceMatch, parseModelPattern } from \"./model-resolver-patterns.ts\";\nexport { resolveModelScope, resolveModelScopeWithDiagnostics } from \"./model-resolver-scope.ts\";\nexport type { ModelScopeDiagnostic, ResolveModelScopeResult } from \"./model-resolver-scope.ts\";\nexport type { InitialModelResult, ParsedModelResult, ResolveCliModelResult, ScopedModel } from \"./model-resolver-types.ts\";\n"]}
|
|
@@ -5,5 +5,5 @@ export { defaultModelPerProvider } from "./model-resolver-defaults.js";
|
|
|
5
5
|
export { resolveCliModel } from "./model-resolver-cli.js";
|
|
6
6
|
export { findInitialModel, resolveSavedModelReference, restoreModelFromSession } from "./model-resolver-initial.js";
|
|
7
7
|
export { findExactModelReferenceMatch, parseModelPattern } from "./model-resolver-patterns.js";
|
|
8
|
-
export { resolveModelScope } from "./model-resolver-scope.js";
|
|
8
|
+
export { resolveModelScope, resolveModelScopeWithDiagnostics } from "./model-resolver-scope.js";
|
|
9
9
|
//# sourceMappingURL=model-resolver.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"model-resolver.js","sourceRoot":"","sources":["../../src/core/model-resolver.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,uBAAuB,EAAE,MAAM,8BAA8B,CAAC;AACvE,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAC1D,OAAO,EAAE,gBAAgB,EAAE,0BAA0B,EAAE,uBAAuB,EAAE,MAAM,6BAA6B,CAAC;AACpH,OAAO,EAAE,4BAA4B,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AAC/F,OAAO,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC","sourcesContent":["/**\n * Model resolution, scoping, and initial selection\n */\n\nexport { defaultModelPerProvider } from \"./model-resolver-defaults.ts\";\nexport { resolveCliModel } from \"./model-resolver-cli.ts\";\nexport { findInitialModel, resolveSavedModelReference, restoreModelFromSession } from \"./model-resolver-initial.ts\";\nexport { findExactModelReferenceMatch, parseModelPattern } from \"./model-resolver-patterns.ts\";\nexport { resolveModelScope } from \"./model-resolver-scope.ts\";\nexport type {\
|
|
1
|
+
{"version":3,"file":"model-resolver.js","sourceRoot":"","sources":["../../src/core/model-resolver.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,uBAAuB,EAAE,MAAM,8BAA8B,CAAC;AACvE,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAC1D,OAAO,EAAE,gBAAgB,EAAE,0BAA0B,EAAE,uBAAuB,EAAE,MAAM,6BAA6B,CAAC;AACpH,OAAO,EAAE,4BAA4B,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AAC/F,OAAO,EAAE,iBAAiB,EAAE,gCAAgC,EAAE,MAAM,2BAA2B,CAAC","sourcesContent":["/**\n * Model resolution, scoping, and initial selection\n */\n\nexport { defaultModelPerProvider } from \"./model-resolver-defaults.ts\";\nexport { resolveCliModel } from \"./model-resolver-cli.ts\";\nexport { findInitialModel, resolveSavedModelReference, restoreModelFromSession } from \"./model-resolver-initial.ts\";\nexport { findExactModelReferenceMatch, parseModelPattern } from \"./model-resolver-patterns.ts\";\nexport { resolveModelScope, resolveModelScopeWithDiagnostics } from \"./model-resolver-scope.ts\";\nexport type { ModelScopeDiagnostic, ResolveModelScopeResult } from \"./model-resolver-scope.ts\";\nexport type { InitialModelResult, ParsedModelResult, ResolveCliModelResult, ScopedModel } from \"./model-resolver-types.ts\";\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resource-loader-extensions.d.ts","sourceRoot":"","sources":["../../src/core/resource-loader-extensions.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"resource-loader-extensions.d.ts","sourceRoot":"","sources":["../../src/core/resource-loader-extensions.ts"],"names":[],"mappings":"AAGA,OAAO,EAGN,KAAK,wBAAwB,EAC7B,MAAM,wBAAwB,CAAC;AAChC,OAAO,KAAK,EAAE,SAAS,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAC;AAE/F,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,2BAA2B,CAAC;AACvE,OAAO,KAAK,EAAE,wCAAwC,EAAE,MAAM,4BAA4B,CAAC;AAM3F,wBAAsB,qBAAqB,CAC1C,MAAM,EAAE,qBAAqB,EAC7B,cAAc,EAAE,MAAM,EAAE,EACxB,kBAAkB,EAAE,oBAAoB,GAAG,SAAS,EACpD,wBAAwB,EAAE,wBAAwB,EAClD,2BAA2B,EAAE,MAAM,wCAAwC,GACzE,OAAO,CAAC,oBAAoB,CAAC,CAmE/B;AAED,wBAAsB,sBAAsB,CAC3C,MAAM,EAAE,qBAAqB,EAC7B,OAAO,EAAE,gBAAgB,EACzB,wBAAwB,EAAE,wBAAwB,EAClD,2BAA2B,EAAE,MAAM,wCAAwC,GACzE,OAAO,CAAC;IACV,UAAU,EAAE,SAAS,EAAE,CAAC;IACxB,MAAM,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CAC/C,CAAC,CA4BD","sourcesContent":["import { resolvePath } from \"../utils/paths.ts\";\nimport { yieldToEventLoop } from \"../utils/event-loop.ts\";\nimport { startTimingSpan, endTimingSpan } from \"./timings.ts\";\nimport {\n\tloadExtensionFromFactory,\n\tloadExtensionsCached,\n\ttype WorkflowResourceProvider,\n} from \"./extensions/loader.ts\";\nimport type { Extension, ExtensionRuntime, LoadExtensionsResult } from \"./extensions/types.ts\";\nimport { resourceInternals } from \"./resource-loader-internals.ts\";\nimport type { DefaultResourceLoader } from \"./resource-loader-core.ts\";\nimport type { DefaultResourceLoaderInheritanceSnapshot } from \"./resource-loader-types.ts\";\n\nfunction resolveExtensionLoadPath(loader: DefaultResourceLoader, path: string): string {\n\treturn resolvePath(path, resourceInternals(loader).cwd, { normalizeUnicodeSpaces: true });\n}\n\nexport async function loadFinalExtensionSet(\n\tloader: DefaultResourceLoader,\n\textensionPaths: string[],\n\tpreTrustExtensions: LoadExtensionsResult | undefined,\n\tworkflowResourceProvider: WorkflowResourceProvider,\n\tinheritanceSnapshotProvider: () => DefaultResourceLoaderInheritanceSnapshot,\n): Promise<LoadExtensionsResult> {\n\tconst state = resourceInternals(loader);\n\tif (!preTrustExtensions) {\n\t\tconst loadExtensionsSpan = startTimingSpan(\"DefaultResourceLoader.reload.loadExtensions\");\n\t\tconst extensionsResult = await loadExtensionsCached(\n\t\t\textensionPaths,\n\t\t\tstate.cwd,\n\t\t\tstate.eventBus,\n\t\t\tworkflowResourceProvider,\n\t\t\tundefined,\n\t\t\tinheritanceSnapshotProvider,\n\t\t);\n\t\tendTimingSpan(loadExtensionsSpan);\n\t\tconst inlineExtensionsSpan = startTimingSpan(\"DefaultResourceLoader.reload.loadInlineExtensionFactories\");\n\t\tconst inlineExtensions = await loadExtensionFactories(\n\t\t\tloader,\n\t\t\textensionsResult.runtime,\n\t\t\tworkflowResourceProvider,\n\t\t\tinheritanceSnapshotProvider,\n\t\t);\n\t\tendTimingSpan(inlineExtensionsSpan);\n\t\textensionsResult.extensions.push(...inlineExtensions.extensions);\n\t\textensionsResult.errors.push(...inlineExtensions.errors);\n\t\taddExtensionConflictDiagnostics(extensionsResult);\n\t\treturn extensionsResult;\n\t}\n\n\tconst preloadedByPath = new Map(\n\t\tpreTrustExtensions.extensions\n\t\t\t.filter((extension) => !extension.path.startsWith(\"<inline:\"))\n\t\t\t.map((extension) => [extension.resolvedPath, extension]),\n\t);\n\tconst failedPreloadPaths = new Set(\n\t\tpreTrustExtensions.errors.map((error) => resolveExtensionLoadPath(loader, error.path)),\n\t);\n\tconst remainingPaths = extensionPaths.filter((path) => {\n\t\tconst resolvedPath = resolveExtensionLoadPath(loader, path);\n\t\treturn !preloadedByPath.has(resolvedPath) && !failedPreloadPaths.has(resolvedPath);\n\t});\n\tconst loadExtensionsSpan = startTimingSpan(\"DefaultResourceLoader.reload.loadExtensions\");\n\tconst remainingExtensions = await loadExtensionsCached(\n\t\tremainingPaths,\n\t\tstate.cwd,\n\t\tstate.eventBus,\n\t\tworkflowResourceProvider,\n\t\tpreTrustExtensions.runtime,\n\t\tinheritanceSnapshotProvider,\n\t);\n\tendTimingSpan(loadExtensionsSpan);\n\tconst loadedByPath = new Map(preloadedByPath);\n\tfor (const extension of remainingExtensions.extensions) {\n\t\tloadedByPath.set(extension.resolvedPath, extension);\n\t}\n\n\tconst inlineExtensions = preTrustExtensions.extensions.filter((extension) => extension.path.startsWith(\"<inline:\"));\n\tconst orderedExtensions = extensionPaths\n\t\t.map((path) => loadedByPath.get(resolveExtensionLoadPath(loader, path)))\n\t\t.filter((extension): extension is Extension => extension !== undefined);\n\torderedExtensions.push(...inlineExtensions);\n\n\tconst extensionsResult: LoadExtensionsResult = {\n\t\textensions: orderedExtensions,\n\t\terrors: [...preTrustExtensions.errors, ...remainingExtensions.errors],\n\t\truntime: preTrustExtensions.runtime,\n\t};\n\taddExtensionConflictDiagnostics(extensionsResult);\n\treturn extensionsResult;\n}\n\nexport async function loadExtensionFactories(\n\tloader: DefaultResourceLoader,\n\truntime: ExtensionRuntime,\n\tworkflowResourceProvider: WorkflowResourceProvider,\n\tinheritanceSnapshotProvider: () => DefaultResourceLoaderInheritanceSnapshot,\n): Promise<{\n\textensions: Extension[];\n\terrors: Array<{ path: string; error: string }>;\n}> {\n\tconst state = resourceInternals(loader);\n\tconst extensions: Extension[] = [];\n\tconst errors: Array<{ path: string; error: string }> = [];\n\n\tfor (const [index, factory] of state.extensionFactories.entries()) {\n\t\tif (index > 0) {\n\t\t\tawait yieldToEventLoop();\n\t\t}\n\t\tconst extensionPath = `<inline:${index + 1}>`;\n\t\ttry {\n\t\t\tconst extension = await loadExtensionFromFactory(\n\t\t\t\tfactory,\n\t\t\t\tstate.cwd,\n\t\t\t\tstate.eventBus,\n\t\t\t\truntime,\n\t\t\t\textensionPath,\n\t\t\t\tworkflowResourceProvider,\n\t\t\t\tinheritanceSnapshotProvider,\n\t\t\t);\n\t\t\textensions.push(extension);\n\t\t} catch (error) {\n\t\t\tconst message = error instanceof Error ? error.message : \"failed to load extension\";\n\t\t\terrors.push({ path: extensionPath, error: message });\n\t\t}\n\t}\n\n\treturn { extensions, errors };\n}\n\nfunction addExtensionConflictDiagnostics(extensionsResult: LoadExtensionsResult): void {\n\t// Detect extension conflicts (tools, commands, flags with same names from different extensions)\n\t// Keep all extensions loaded. Conflicts are reported as diagnostics, and precedence is handled by load order.\n\tconst conflicts = detectExtensionConflicts(extensionsResult.extensions);\n\tfor (const conflict of conflicts) {\n\t\textensionsResult.errors.push({ path: conflict.path, error: conflict.message });\n\t}\n}\n\nfunction detectExtensionConflicts(extensions: Extension[]): Array<{ path: string; message: string }> {\n\tconst conflicts: Array<{ path: string; message: string }> = [];\n\n\t// Track which extension registered each tool and flag\n\tconst toolOwners = new Map<string, string>();\n\tconst flagOwners = new Map<string, string>();\n\n\tfor (const ext of extensions) {\n\t\t// Check tools\n\t\tfor (const toolName of ext.tools.keys()) {\n\t\t\tconst existingOwner = toolOwners.get(toolName);\n\t\t\tif (existingOwner && existingOwner !== ext.path) {\n\t\t\t\tconflicts.push({\n\t\t\t\t\tpath: ext.path,\n\t\t\t\t\tmessage: `Tool \"${toolName}\" conflicts with ${existingOwner}`,\n\t\t\t\t});\n\t\t\t} else {\n\t\t\t\ttoolOwners.set(toolName, ext.path);\n\t\t\t}\n\t\t}\n\n\t\t// Check flags\n\t\tfor (const flagName of ext.flags.keys()) {\n\t\t\tconst existingOwner = flagOwners.get(flagName);\n\t\t\tif (existingOwner && existingOwner !== ext.path) {\n\t\t\t\tconflicts.push({\n\t\t\t\t\tpath: ext.path,\n\t\t\t\t\tmessage: `Flag \"--${flagName}\" conflicts with ${existingOwner}`,\n\t\t\t\t});\n\t\t\t} else {\n\t\t\t\tflagOwners.set(flagName, ext.path);\n\t\t\t}\n\t\t}\n\t}\n\n\treturn conflicts;\n}\n"]}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { resolvePath } from "../utils/paths.js";
|
|
2
|
+
import { yieldToEventLoop } from "../utils/event-loop.js";
|
|
2
3
|
import { startTimingSpan, endTimingSpan } from "./timings.js";
|
|
3
4
|
import { loadExtensionFromFactory, loadExtensionsCached, } from "./extensions/loader.js";
|
|
4
5
|
import { resourceInternals } from "./resource-loader-internals.js";
|
|
@@ -52,6 +53,9 @@ export async function loadExtensionFactories(loader, runtime, workflowResourcePr
|
|
|
52
53
|
const extensions = [];
|
|
53
54
|
const errors = [];
|
|
54
55
|
for (const [index, factory] of state.extensionFactories.entries()) {
|
|
56
|
+
if (index > 0) {
|
|
57
|
+
await yieldToEventLoop();
|
|
58
|
+
}
|
|
55
59
|
const extensionPath = `<inline:${index + 1}>`;
|
|
56
60
|
try {
|
|
57
61
|
const extension = await loadExtensionFromFactory(factory, state.cwd, state.eventBus, runtime, extensionPath, workflowResourceProvider, inheritanceSnapshotProvider);
|