@astralyn/pi 1.4.5 → 1.4.7
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 +42 -0
- package/dist/bundle/chunks/chunk-FODCTZXW.js +230 -0
- package/dist/bundle/chunks/{chunk-I5S7H7GA.js → chunk-FYKNSJG6.js} +1 -1
- package/dist/bundle/chunks/{chunk-AXFWZIHH.js → chunk-MG5XDTXV.js} +1 -1
- package/dist/bundle/chunks/{chunk-ALHAFUHP.js → chunk-PU2IWWXV.js} +1 -1
- package/dist/bundle/chunks/{chunk-5M3YJ54Z.js → chunk-RO2VH6UZ.js} +1 -1
- package/dist/bundle/chunks/chunk-YJTSOLP2.js +1499 -0
- package/dist/bundle/chunks/{cli-FH77R7JR.js → cli-MEL7SGJD.js} +1 -1
- package/dist/bundle/chunks/{execute-GMFGC27P.js → execute-4CWRNHPO.js} +1 -1
- package/dist/bundle/chunks/{runtime-R5CMHJ5P.js → runtime-R3X67XMR.js} +1 -1
- package/dist/bundle/chunks/{virtual-modules-6FUV7ZDV.js → virtual-modules-PKEOKGYI.js} +1 -1
- package/dist/bundle/cli.js +1 -1
- package/dist/bundle/index.js +1 -1
- package/dist/bundle/rpc-entry.js +1 -1
- package/dist/core/agent-session.d.ts +0 -3
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +0 -4
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/extensions/index.d.ts +1 -1
- package/dist/core/extensions/index.d.ts.map +1 -1
- package/dist/core/extensions/index.js.map +1 -1
- package/dist/core/isolated-session.d.ts +23 -0
- package/dist/core/isolated-session.d.ts.map +1 -0
- package/dist/core/isolated-session.js +55 -0
- package/dist/core/isolated-session.js.map +1 -0
- package/dist/core/package-manager.d.ts +7 -1
- package/dist/core/package-manager.d.ts.map +1 -1
- package/dist/core/package-manager.js +72 -1
- package/dist/core/package-manager.js.map +1 -1
- package/dist/core/resource-loader.d.ts +1 -0
- package/dist/core/resource-loader.d.ts.map +1 -1
- package/dist/core/resource-loader.js +23 -7
- package/dist/core/resource-loader.js.map +1 -1
- package/dist/core/settings-manager.d.ts +4 -2
- package/dist/core/settings-manager.d.ts.map +1 -1
- package/dist/core/settings-manager.js +11 -0
- package/dist/core/settings-manager.js.map +1 -1
- package/dist/core/settings-schema.d.ts +7 -0
- package/dist/core/settings-schema.d.ts.map +1 -1
- package/dist/core/settings-schema.js +6 -0
- package/dist/core/settings-schema.js.map +1 -1
- package/dist/core/skills.d.ts +10 -0
- package/dist/core/skills.d.ts.map +1 -1
- package/dist/core/skills.js +23 -0
- package/dist/core/skills.js.map +1 -1
- package/dist/core/tasks/codec.d.ts +12 -0
- package/dist/core/tasks/codec.d.ts.map +1 -0
- package/dist/core/tasks/codec.js +139 -0
- package/dist/core/tasks/codec.js.map +1 -0
- package/dist/core/tasks/delivery.d.ts +11 -4
- package/dist/core/tasks/delivery.d.ts.map +1 -1
- package/dist/core/tasks/delivery.js +9 -9
- package/dist/core/tasks/delivery.js.map +1 -1
- package/dist/core/tasks/execution.d.ts +71 -0
- package/dist/core/tasks/execution.d.ts.map +1 -0
- package/dist/core/tasks/execution.js +292 -0
- package/dist/core/tasks/execution.js.map +1 -0
- package/dist/core/tasks/format.d.ts +0 -2
- package/dist/core/tasks/format.d.ts.map +1 -1
- package/dist/core/tasks/format.js +1 -16
- package/dist/core/tasks/format.js.map +1 -1
- package/dist/core/tasks/limits.d.ts +12 -1
- package/dist/core/tasks/limits.d.ts.map +1 -1
- package/dist/core/tasks/limits.js +20 -1
- package/dist/core/tasks/limits.js.map +1 -1
- package/dist/core/tasks/output.d.ts +17 -17
- package/dist/core/tasks/output.d.ts.map +1 -1
- package/dist/core/tasks/output.js +72 -69
- package/dist/core/tasks/output.js.map +1 -1
- package/dist/core/tasks/presentation.d.ts +14 -5
- package/dist/core/tasks/presentation.d.ts.map +1 -1
- package/dist/core/tasks/presentation.js +56 -185
- package/dist/core/tasks/presentation.js.map +1 -1
- package/dist/core/tasks/record.d.ts +45 -0
- package/dist/core/tasks/record.d.ts.map +1 -0
- package/dist/core/tasks/record.js +80 -0
- package/dist/core/tasks/record.js.map +1 -0
- package/dist/core/tasks/runtime.d.ts +22 -22
- package/dist/core/tasks/runtime.d.ts.map +1 -1
- package/dist/core/tasks/runtime.js +170 -343
- package/dist/core/tasks/runtime.js.map +1 -1
- package/dist/core/tasks/scheduler.d.ts +16 -0
- package/dist/core/tasks/scheduler.d.ts.map +1 -0
- package/dist/core/tasks/scheduler.js +42 -0
- package/dist/core/tasks/scheduler.js.map +1 -0
- package/dist/core/tasks/session.d.ts +1 -1
- package/dist/core/tasks/session.d.ts.map +1 -1
- package/dist/core/tasks/session.js +22 -35
- package/dist/core/tasks/session.js.map +1 -1
- package/dist/core/tasks/store.d.ts +18 -25
- package/dist/core/tasks/store.d.ts.map +1 -1
- package/dist/core/tasks/store.js +45 -43
- package/dist/core/tasks/store.js.map +1 -1
- package/dist/core/tasks/types.d.ts +159 -70
- package/dist/core/tasks/types.d.ts.map +1 -1
- package/dist/core/tasks/types.js +3 -9
- package/dist/core/tasks/types.js.map +1 -1
- package/dist/core/tools/shell-execution.d.ts +8 -7
- package/dist/core/tools/shell-execution.d.ts.map +1 -1
- package/dist/core/tools/shell-execution.js +19 -27
- package/dist/core/tools/shell-execution.js.map +1 -1
- package/dist/core/tools/shell-tool.d.ts.map +1 -1
- package/dist/core/tools/shell-tool.js +42 -47
- package/dist/core/tools/shell-tool.js.map +1 -1
- package/dist/core/usage-totals.d.ts +4 -3
- package/dist/core/usage-totals.d.ts.map +1 -1
- package/dist/core/usage-totals.js +32 -8
- package/dist/core/usage-totals.js.map +1 -1
- package/dist/extensions/agent/activity.d.ts +4 -4
- package/dist/extensions/agent/activity.d.ts.map +1 -1
- package/dist/extensions/agent/activity.js +15 -24
- package/dist/extensions/agent/activity.js.map +1 -1
- package/dist/extensions/agent/index.d.ts +2 -11
- package/dist/extensions/agent/index.d.ts.map +1 -1
- package/dist/extensions/agent/index.js +3 -88
- package/dist/extensions/agent/index.js.map +1 -1
- package/dist/extensions/agent/progress.d.ts +31 -0
- package/dist/extensions/agent/progress.d.ts.map +1 -0
- package/dist/extensions/agent/progress.js +135 -0
- package/dist/extensions/agent/progress.js.map +1 -0
- package/dist/extensions/agent/render.d.ts.map +1 -1
- package/dist/extensions/agent/render.js +8 -17
- package/dist/extensions/agent/render.js.map +1 -1
- package/dist/extensions/agent/report.d.ts +9 -0
- package/dist/extensions/agent/report.d.ts.map +1 -0
- package/dist/extensions/agent/report.js +40 -0
- package/dist/extensions/agent/report.js.map +1 -0
- package/dist/extensions/agent/settings-panel.d.ts +43 -0
- package/dist/extensions/agent/settings-panel.d.ts.map +1 -0
- package/dist/extensions/agent/settings-panel.js +125 -0
- package/dist/extensions/agent/settings-panel.js.map +1 -0
- package/dist/extensions/agent/settings.d.ts +1 -1
- package/dist/extensions/agent/settings.d.ts.map +1 -1
- package/dist/extensions/agent/settings.js +101 -83
- package/dist/extensions/agent/settings.js.map +1 -1
- package/dist/extensions/agent/tool.d.ts +13 -0
- package/dist/extensions/agent/tool.d.ts.map +1 -0
- package/dist/extensions/agent/tool.js +88 -0
- package/dist/extensions/agent/tool.js.map +1 -0
- package/dist/extensions/agent/types.d.ts +19 -21
- package/dist/extensions/agent/types.d.ts.map +1 -1
- package/dist/extensions/agent/types.js +2 -10
- package/dist/extensions/agent/types.js.map +1 -1
- package/dist/extensions/agent/worker.d.ts +16 -0
- package/dist/extensions/agent/worker.d.ts.map +1 -0
- package/dist/extensions/agent/worker.js +66 -0
- package/dist/extensions/agent/worker.js.map +1 -0
- package/dist/extensions/btw/agent.d.ts +1 -1
- package/dist/extensions/btw/agent.d.ts.map +1 -1
- package/dist/extensions/btw/agent.js +3 -20
- package/dist/extensions/btw/agent.js.map +1 -1
- package/dist/extensions/cached-compaction/index.d.ts.map +1 -1
- package/dist/extensions/cached-compaction/index.js +3 -22
- package/dist/extensions/cached-compaction/index.js.map +1 -1
- package/dist/extensions/cached-compaction/render.d.ts +1 -0
- package/dist/extensions/cached-compaction/render.d.ts.map +1 -1
- package/dist/extensions/cached-compaction/render.js +42 -14
- package/dist/extensions/cached-compaction/render.js.map +1 -1
- package/dist/extensions/deepwiki/client.d.ts.map +1 -1
- package/dist/extensions/deepwiki/client.js +6 -78
- package/dist/extensions/deepwiki/client.js.map +1 -1
- package/dist/extensions/deepwiki/transport.d.ts +3 -0
- package/dist/extensions/deepwiki/transport.d.ts.map +1 -0
- package/dist/extensions/deepwiki/transport.js +96 -0
- package/dist/extensions/deepwiki/transport.js.map +1 -0
- package/dist/extensions/provider/ui/builtin-data.d.ts +3 -3
- package/dist/extensions/provider/ui/builtin-data.d.ts.map +1 -1
- package/dist/extensions/provider/ui/builtin-data.js.map +1 -1
- package/dist/extensions/provider/ui/compat.d.ts +3 -3
- package/dist/extensions/provider/ui/compat.d.ts.map +1 -1
- package/dist/extensions/provider/ui/compat.js.map +1 -1
- package/dist/extensions/provider/ui/controls.d.ts +2 -2
- package/dist/extensions/provider/ui/controls.d.ts.map +1 -1
- package/dist/extensions/provider/ui/controls.js.map +1 -1
- package/dist/extensions/provider/ui/dialogs.d.ts +3 -3
- package/dist/extensions/provider/ui/dialogs.d.ts.map +1 -1
- package/dist/extensions/provider/ui/dialogs.js.map +1 -1
- package/dist/extensions/provider/ui/dictionary.d.ts +2 -2
- package/dist/extensions/provider/ui/dictionary.d.ts.map +1 -1
- package/dist/extensions/provider/ui/dictionary.js.map +1 -1
- package/dist/extensions/provider/ui/editor.d.ts.map +1 -1
- package/dist/extensions/provider/ui/editor.js +1 -3
- package/dist/extensions/provider/ui/editor.js.map +1 -1
- package/dist/extensions/provider/ui/fetch-models.d.ts +2 -2
- package/dist/extensions/provider/ui/fetch-models.d.ts.map +1 -1
- package/dist/extensions/provider/ui/fetch-models.js.map +1 -1
- package/dist/extensions/provider/ui/model-fields.d.ts +2 -2
- package/dist/extensions/provider/ui/model-fields.d.ts.map +1 -1
- package/dist/extensions/provider/ui/model-fields.js.map +1 -1
- package/dist/extensions/provider/ui/model-options.d.ts +6 -6
- package/dist/extensions/provider/ui/model-options.d.ts.map +1 -1
- package/dist/extensions/provider/ui/model-options.js.map +1 -1
- package/dist/extensions/provider/ui/pane.d.ts +21 -12
- package/dist/extensions/provider/ui/pane.d.ts.map +1 -1
- package/dist/extensions/provider/ui/pane.js.map +1 -1
- package/dist/extensions/provider/ui/provider-fields.d.ts +3 -3
- package/dist/extensions/provider/ui/provider-fields.d.ts.map +1 -1
- package/dist/extensions/provider/ui/provider-fields.js.map +1 -1
- package/dist/extensions/provider/ui/thinking-map.d.ts +2 -2
- package/dist/extensions/provider/ui/thinking-map.d.ts.map +1 -1
- package/dist/extensions/provider/ui/thinking-map.js.map +1 -1
- package/dist/extensions/run-summary/format.js +1 -1
- package/dist/extensions/run-summary/format.js.map +1 -1
- package/dist/extensions/statusline/usage.d.ts.map +1 -1
- package/dist/extensions/statusline/usage.js +2 -6
- package/dist/extensions/statusline/usage.js.map +1 -1
- package/dist/extensions/tasks/tool/actions.d.ts +1 -1
- package/dist/extensions/tasks/tool/actions.d.ts.map +1 -1
- package/dist/extensions/tasks/tool/actions.js +50 -115
- package/dist/extensions/tasks/tool/actions.js.map +1 -1
- package/dist/extensions/tasks/tool/constants.d.ts +1 -6
- package/dist/extensions/tasks/tool/constants.d.ts.map +1 -1
- package/dist/extensions/tasks/tool/constants.js +1 -6
- package/dist/extensions/tasks/tool/constants.js.map +1 -1
- package/dist/extensions/tasks/tool/schema.d.ts +0 -3
- package/dist/extensions/tasks/tool/schema.d.ts.map +1 -1
- package/dist/extensions/tasks/tool/schema.js +5 -14
- package/dist/extensions/tasks/tool/schema.js.map +1 -1
- package/dist/extensions/tasks/tool/types.d.ts +2 -8
- package/dist/extensions/tasks/tool/types.d.ts.map +1 -1
- package/dist/extensions/tasks/tool/types.js +0 -2
- package/dist/extensions/tasks/tool/types.js.map +1 -1
- package/dist/extensions/tasks/tool.d.ts.map +1 -1
- package/dist/extensions/tasks/tool.js +2 -2
- package/dist/extensions/tasks/tool.js.map +1 -1
- package/dist/extensions/tasks/ui/completion-render.d.ts.map +1 -1
- package/dist/extensions/tasks/ui/completion-render.js +46 -47
- package/dist/extensions/tasks/ui/completion-render.js.map +1 -1
- package/dist/extensions/tasks/ui/inspector.d.ts +5 -3
- package/dist/extensions/tasks/ui/inspector.d.ts.map +1 -1
- package/dist/extensions/tasks/ui/inspector.js +18 -6
- package/dist/extensions/tasks/ui/inspector.js.map +1 -1
- package/dist/extensions/tasks/ui/layout.d.ts +7 -7
- package/dist/extensions/tasks/ui/layout.d.ts.map +1 -1
- package/dist/extensions/tasks/ui/layout.js +118 -84
- package/dist/extensions/tasks/ui/layout.js.map +1 -1
- package/dist/extensions/tasks/ui/list.d.ts.map +1 -1
- package/dist/extensions/tasks/ui/list.js +45 -31
- package/dist/extensions/tasks/ui/list.js.map +1 -1
- package/dist/extensions/tasks/ui/manager.d.ts +16 -7
- package/dist/extensions/tasks/ui/manager.d.ts.map +1 -1
- package/dist/extensions/tasks/ui/manager.js +167 -129
- package/dist/extensions/tasks/ui/manager.js.map +1 -1
- package/dist/extensions/tasks/ui/model.d.ts +29 -0
- package/dist/extensions/tasks/ui/model.d.ts.map +1 -1
- package/dist/extensions/tasks/ui/model.js +16 -1
- package/dist/extensions/tasks/ui/model.js.map +1 -1
- package/dist/extensions/tasks/ui/render.d.ts +1 -1
- package/dist/extensions/tasks/ui/render.d.ts.map +1 -1
- package/dist/extensions/tasks/ui/render.js +12 -9
- package/dist/extensions/tasks/ui/render.js.map +1 -1
- package/dist/extensions/tasks/ui/status.d.ts +15 -0
- package/dist/extensions/tasks/ui/status.d.ts.map +1 -0
- package/dist/extensions/tasks/ui/status.js +16 -0
- package/dist/extensions/tasks/ui/status.js.map +1 -0
- package/dist/extensions/tasks/ui/tree.js +1 -1
- package/dist/extensions/tasks/ui/tree.js.map +1 -1
- package/dist/extensions/tasks/ui/views.d.ts +10 -5
- package/dist/extensions/tasks/ui/views.d.ts.map +1 -1
- package/dist/extensions/tasks/ui/views.js +61 -36
- package/dist/extensions/tasks/ui/views.js.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/modes/interactive/components/config-selector.d.ts +14 -1
- package/dist/modes/interactive/components/config-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/config-selector.js +258 -7
- package/dist/modes/interactive/components/config-selector.js.map +1 -1
- package/dist/modes/interactive/components/keybinding-hints.d.ts.map +1 -1
- package/dist/modes/interactive/components/keybinding-hints.js +2 -1
- package/dist/modes/interactive/components/keybinding-hints.js.map +1 -1
- package/dist/modes/interactive/components/model-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/model-selector.js +7 -4
- package/dist/modes/interactive/components/model-selector.js.map +1 -1
- package/dist/modes/interactive/components/status-marker.d.ts +2 -1
- package/dist/modes/interactive/components/status-marker.d.ts.map +1 -1
- package/dist/modes/interactive/components/status-marker.js +0 -1
- package/dist/modes/interactive/components/status-marker.js.map +1 -1
- package/dist/modes/interactive/components/thinking-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/thinking-selector.js +10 -3
- package/dist/modes/interactive/components/thinking-selector.js.map +1 -1
- package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode.js +7 -1
- package/dist/modes/interactive/interactive-mode.js.map +1 -1
- package/dist/utils/duration.d.ts +3 -0
- package/dist/utils/duration.d.ts.map +1 -0
- package/dist/utils/duration.js +17 -0
- package/dist/utils/duration.js.map +1 -0
- package/dist/utils/number.d.ts +3 -0
- package/dist/utils/number.d.ts.map +1 -0
- package/dist/utils/number.js +5 -0
- package/dist/utils/number.js.map +1 -0
- package/docs/bundled/extensions/agent.md +14 -12
- package/docs/bundled/extensions/cached-compaction.md +13 -4
- package/docs/bundled/extensions/deepwiki.md +3 -1
- package/docs/bundled/extensions/statusline.md +1 -1
- package/docs/bundled/tasks.md +15 -14
- package/docs/extensions.md +26 -10
- package/docs/packages.md +5 -3
- package/docs/sdk.md +3 -3
- package/docs/session-format.md +28 -24
- package/docs/settings.md +11 -0
- package/docs/skills.md +23 -0
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
- package/schemas/settings.schema.json +36 -0
- package/dist/bundle/chunks/chunk-FSJ45CRP.js +0 -229
- package/dist/bundle/chunks/chunk-W3FIUMGM.js +0 -1501
- package/dist/core/tasks/history.d.ts +0 -4
- package/dist/core/tasks/history.d.ts.map +0 -1
- package/dist/core/tasks/history.js +0 -131
- package/dist/core/tasks/history.js.map +0 -1
- package/dist/extensions/agent/runner.d.ts +0 -24
- package/dist/extensions/agent/runner.d.ts.map +0 -1
- package/dist/extensions/agent/runner.js +0 -274
- package/dist/extensions/agent/runner.js.map +0 -1
- package/dist/extensions/deepwiki/http.d.ts +0 -13
- package/dist/extensions/deepwiki/http.d.ts.map +0 -1
- package/dist/extensions/deepwiki/http.js +0 -88
- package/dist/extensions/deepwiki/http.js.map +0 -1
- package/dist/extensions/tasks/ui/task-view.d.ts +0 -13
- package/dist/extensions/tasks/ui/task-view.d.ts.map +0 -1
- package/dist/extensions/tasks/ui/task-view.js +0 -20
- package/dist/extensions/tasks/ui/task-view.js.map +0 -1
|
@@ -2,6 +2,8 @@ import { clampThinkingLevel, getSupportedThinkingLevels } from "@earendil-works/
|
|
|
2
2
|
import { DEFAULT_THINKING_LEVEL, THINKING_LEVEL_OPTIONS } from "../../core/defaults.js";
|
|
3
3
|
import { truncateHead } from "../../core/tools/truncate.js";
|
|
4
4
|
import { ModelSelectorComponent } from "../../modes/interactive/components/model-selector.js";
|
|
5
|
+
import { ThinkingSelectorComponent } from "../../modes/interactive/components/thinking-selector.js";
|
|
6
|
+
import { AgentSettingsPanel, } from "./settings-panel.js";
|
|
5
7
|
import { AGENT_SETTINGS_NAMESPACE } from "./types.js";
|
|
6
8
|
function inspectAgentSettings(ctx) {
|
|
7
9
|
const raw = ctx.getExtensionSettings(AGENT_SETTINGS_NAMESPACE);
|
|
@@ -32,24 +34,43 @@ export function readAgentSettings(ctx) {
|
|
|
32
34
|
if (inspection.invalidModel !== undefined)
|
|
33
35
|
throw new Error("Invalid Agent model setting. Choose a model with /agent.");
|
|
34
36
|
if (inspection.invalidThinking !== undefined)
|
|
35
|
-
throw new Error("Invalid Agent
|
|
37
|
+
throw new Error("Invalid Agent effort setting. Choose an effort level with /agent.");
|
|
36
38
|
return { model: inspection.model, thinking: inspection.thinking };
|
|
37
39
|
}
|
|
40
|
+
function resolveAgentModel(ctx, reference) {
|
|
41
|
+
if (!reference)
|
|
42
|
+
return ctx.model ? { model: ctx.model, available: true } : undefined;
|
|
43
|
+
const slash = reference.indexOf("/");
|
|
44
|
+
if (slash <= 0)
|
|
45
|
+
return undefined;
|
|
46
|
+
const model = ctx.modelRuntime.getModel(reference.slice(0, slash), reference.slice(slash + 1));
|
|
47
|
+
if (!model)
|
|
48
|
+
return undefined;
|
|
49
|
+
const available = ctx.modelRuntime
|
|
50
|
+
.getAvailableSnapshot()
|
|
51
|
+
.some((item) => item.provider === model.provider && item.id === model.id);
|
|
52
|
+
return { model, available };
|
|
53
|
+
}
|
|
54
|
+
function requestedEffort(ctx, settings) {
|
|
55
|
+
return settings.thinking ?? ctx.thinkingLevel ?? DEFAULT_THINKING_LEVEL;
|
|
56
|
+
}
|
|
57
|
+
/** Clamp a requested level to what the model supports. */
|
|
58
|
+
function supportedEffort(model, requested) {
|
|
59
|
+
return clampThinkingLevel(model, requested);
|
|
60
|
+
}
|
|
38
61
|
export function resolveAgentConfiguration(ctx) {
|
|
39
62
|
const settings = readAgentSettings(ctx);
|
|
40
|
-
|
|
41
|
-
if (
|
|
42
|
-
|
|
43
|
-
model = ctx.modelRuntime.getModel(settings.model.slice(0, slash), settings.model.slice(slash + 1));
|
|
44
|
-
if (!model)
|
|
63
|
+
const resolution = resolveAgentModel(ctx, settings.model);
|
|
64
|
+
if (!resolution) {
|
|
65
|
+
if (settings.model)
|
|
45
66
|
throw new Error(`Agent model is unavailable: ${settings.model}`);
|
|
46
|
-
}
|
|
47
|
-
else
|
|
48
|
-
model = ctx.model;
|
|
49
|
-
if (!model)
|
|
50
67
|
throw new Error("Agent has no model to follow. Choose one with /agent.");
|
|
51
|
-
|
|
52
|
-
return {
|
|
68
|
+
}
|
|
69
|
+
return {
|
|
70
|
+
model: resolution.model,
|
|
71
|
+
thinking: supportedEffort(resolution.model, requestedEffort(ctx, settings)),
|
|
72
|
+
settings,
|
|
73
|
+
};
|
|
53
74
|
}
|
|
54
75
|
async function saveAgentSettings(ctx, patch) {
|
|
55
76
|
const next = { ...ctx.getExtensionSettings(AGENT_SETTINGS_NAMESPACE) };
|
|
@@ -64,31 +85,77 @@ async function saveAgentSettings(ctx, patch) {
|
|
|
64
85
|
await ctx.setExtensionSettings(AGENT_SETTINGS_NAMESPACE, next);
|
|
65
86
|
}
|
|
66
87
|
async function selectAgentModel(ctx, current) {
|
|
67
|
-
|
|
68
|
-
const
|
|
88
|
+
// Preselect the saved reference even when it is unavailable, so the picker can repair it.
|
|
89
|
+
const saved = resolveAgentModel(ctx, current)?.model;
|
|
90
|
+
const selected = await ctx.ui.custom((tui, _theme, _keys, done) => new ModelSelectorComponent(tui, saved ?? ctx.model, ctx.modelRuntime, ctx.scopedModels, done, () => done(undefined)));
|
|
69
91
|
return selected ? `${selected.provider}/${selected.id}` : undefined;
|
|
70
92
|
}
|
|
71
|
-
function
|
|
93
|
+
async function selectAgentThinking(ctx, settings, model) {
|
|
94
|
+
const requested = requestedEffort(ctx, settings);
|
|
95
|
+
const current = model ? supportedEffort(model, requested) : requested;
|
|
96
|
+
const available = model ? getSupportedThinkingLevels(model) : [...THINKING_LEVEL_OPTIONS];
|
|
97
|
+
return ctx.ui.custom((_tui, _theme, _keys, done) => new ThinkingSelectorComponent(current, available, done, () => done(undefined)));
|
|
98
|
+
}
|
|
99
|
+
function formatInvalidValue(value) {
|
|
72
100
|
let text = "";
|
|
73
101
|
try {
|
|
74
102
|
text = typeof value === "string" ? value : (JSON.stringify(value) ?? "");
|
|
75
103
|
}
|
|
76
104
|
catch { }
|
|
77
|
-
|
|
78
|
-
|
|
105
|
+
return truncateHead(text, { maxLines: 1, maxBytes: 80 }).content;
|
|
106
|
+
}
|
|
107
|
+
function invalidField(raw) {
|
|
108
|
+
return { value: formatInvalidValue(raw), status: "[invalid]", tone: "error" };
|
|
109
|
+
}
|
|
110
|
+
function describeModel(inspection, resolution) {
|
|
111
|
+
if (inspection.invalidModel !== undefined)
|
|
112
|
+
return invalidField(inspection.invalidModel);
|
|
113
|
+
if (!resolution)
|
|
114
|
+
return { value: inspection.model ?? "", status: "[unavailable]", tone: "warning" };
|
|
115
|
+
return {
|
|
116
|
+
value: `${resolution.model.provider}/${resolution.model.id}`,
|
|
117
|
+
following: inspection.model === undefined,
|
|
118
|
+
...(resolution.available ? {} : { status: "[unavailable]", tone: "warning" }),
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
function describeEffort(ctx, inspection, model) {
|
|
122
|
+
if (inspection.invalidThinking !== undefined)
|
|
123
|
+
return invalidField(inspection.invalidThinking);
|
|
124
|
+
const requested = requestedEffort(ctx, inspection);
|
|
125
|
+
const following = inspection.thinking === undefined;
|
|
126
|
+
if (!model)
|
|
127
|
+
return { value: requested, following, status: "[unresolved]", tone: "warning" };
|
|
128
|
+
const effective = supportedEffort(model, requested);
|
|
129
|
+
if (effective === requested)
|
|
130
|
+
return { value: requested, following };
|
|
131
|
+
return { value: `${requested} → ${effective}`, following, tone: "warning" };
|
|
132
|
+
}
|
|
133
|
+
function hasOverrides(inspection) {
|
|
134
|
+
return (inspection.model !== undefined ||
|
|
135
|
+
inspection.thinking !== undefined ||
|
|
136
|
+
inspection.invalidModel !== undefined ||
|
|
137
|
+
inspection.invalidThinking !== undefined);
|
|
79
138
|
}
|
|
80
|
-
|
|
139
|
+
function settingsRows(ctx, inspection, resolution) {
|
|
140
|
+
return [
|
|
141
|
+
{ action: "model", label: "Model", field: describeModel(inspection, resolution) },
|
|
142
|
+
{ action: "thinking", label: "Effort", field: describeEffort(ctx, inspection, resolution?.model) },
|
|
143
|
+
{ action: "reset", label: "Reset to follow current session" },
|
|
144
|
+
];
|
|
145
|
+
}
|
|
146
|
+
/** The native pickers save only Agent overrides; reset clears both in one write. */
|
|
81
147
|
export async function openAgentSettings(ctx) {
|
|
82
148
|
if (ctx.mode !== "tui") {
|
|
83
149
|
try {
|
|
84
150
|
const settings = readAgentSettings(ctx);
|
|
85
|
-
ctx.ui.notify(`Agent model: ${settings.model ?? "Follow current session"} ·
|
|
151
|
+
ctx.ui.notify(`Agent model: ${settings.model ?? "Follow current session"} · Effort: ${settings.thinking ?? "Follow current session"}`, "info");
|
|
86
152
|
}
|
|
87
153
|
catch (error) {
|
|
88
154
|
ctx.ui.notify(error instanceof Error ? error.message : String(error), "error");
|
|
89
155
|
}
|
|
90
156
|
return;
|
|
91
157
|
}
|
|
158
|
+
let selectedAction = "model";
|
|
92
159
|
while (true) {
|
|
93
160
|
let inspection;
|
|
94
161
|
try {
|
|
@@ -98,81 +165,32 @@ export async function openAgentSettings(ctx) {
|
|
|
98
165
|
ctx.ui.notify(error instanceof Error ? error.message : String(error), "error");
|
|
99
166
|
return;
|
|
100
167
|
}
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
modelLabel = formatInvalid(inspection.invalidModel);
|
|
104
|
-
}
|
|
105
|
-
else if (inspection.model) {
|
|
106
|
-
const modelAvailable = ctx.modelRuntime
|
|
107
|
-
.getAvailableSnapshot()
|
|
108
|
-
.some((model) => `${model.provider}/${model.id}` === inspection.model);
|
|
109
|
-
modelLabel = `${inspection.model}${modelAvailable ? "" : " [unavailable]"}`;
|
|
110
|
-
}
|
|
111
|
-
else {
|
|
112
|
-
modelLabel = `Follow current session${ctx.model ? ` (${ctx.model.provider}/${ctx.model.id})` : ""}`;
|
|
113
|
-
}
|
|
114
|
-
let thinkingLabel;
|
|
115
|
-
if (inspection.invalidThinking !== undefined) {
|
|
116
|
-
thinkingLabel = formatInvalid(inspection.invalidThinking);
|
|
117
|
-
}
|
|
118
|
-
else if (inspection.thinking) {
|
|
119
|
-
thinkingLabel = inspection.thinking;
|
|
120
|
-
}
|
|
121
|
-
else {
|
|
122
|
-
thinkingLabel = `Follow current session (${ctx.thinkingLevel ?? DEFAULT_THINKING_LEVEL})`;
|
|
123
|
-
}
|
|
124
|
-
const modelAction = `Model · ${modelLabel}`;
|
|
125
|
-
const thinkingAction = `Thinking · ${thinkingLabel}`;
|
|
126
|
-
const followModelAction = "Reset model to follow current session";
|
|
127
|
-
const followThinkingAction = "Reset thinking to follow current session";
|
|
128
|
-
const hasModelOverride = inspection.model !== undefined || inspection.invalidModel !== undefined;
|
|
129
|
-
const hasThinkingOverride = inspection.thinking !== undefined || inspection.invalidThinking !== undefined;
|
|
130
|
-
const action = await ctx.ui.select("Agent settings", [
|
|
131
|
-
modelAction,
|
|
132
|
-
thinkingAction,
|
|
133
|
-
...(hasModelOverride ? [followModelAction] : []),
|
|
134
|
-
...(hasThinkingOverride ? [followThinkingAction] : []),
|
|
135
|
-
]);
|
|
168
|
+
const resolution = inspection.invalidModel !== undefined ? undefined : resolveAgentModel(ctx, inspection.model);
|
|
169
|
+
const action = await ctx.ui.custom((tui, theme, keys, done) => new AgentSettingsPanel(tui, theme, keys, settingsRows(ctx, inspection, resolution), selectedAction, done, () => done(undefined)));
|
|
136
170
|
if (!action)
|
|
137
171
|
return;
|
|
172
|
+
selectedAction = action;
|
|
138
173
|
try {
|
|
139
|
-
if (action ===
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
await saveAgentSettings(ctx, { thinking: null });
|
|
145
|
-
ctx.ui.notify("Agent thinking: Follow current session", "info");
|
|
174
|
+
if (action === "reset") {
|
|
175
|
+
if (!hasOverrides(inspection))
|
|
176
|
+
continue;
|
|
177
|
+
await saveAgentSettings(ctx, { model: null, thinking: null });
|
|
178
|
+
ctx.ui.notify("Agent settings: Follow current session", "info");
|
|
146
179
|
}
|
|
147
|
-
else if (action ===
|
|
180
|
+
else if (action === "model") {
|
|
148
181
|
const selected = await selectAgentModel(ctx, inspection.model ?? "");
|
|
149
182
|
if (selected === undefined || selected === inspection.model)
|
|
150
183
|
continue;
|
|
151
184
|
await saveAgentSettings(ctx, { model: selected });
|
|
152
185
|
ctx.ui.notify(`Agent model: ${selected}`, "info");
|
|
153
186
|
}
|
|
154
|
-
else if (action ===
|
|
155
|
-
|
|
156
|
-
if (
|
|
157
|
-
|
|
158
|
-
const model = ctx.modelRuntime.getModel(inspection.model.slice(0, slash), inspection.model.slice(slash + 1));
|
|
159
|
-
if (model)
|
|
160
|
-
supported = new Set(getSupportedThinkingLevels(model));
|
|
161
|
-
}
|
|
162
|
-
if (!supported && ctx.model) {
|
|
163
|
-
supported = new Set(getSupportedThinkingLevels(ctx.model));
|
|
164
|
-
}
|
|
165
|
-
const selected = await ctx.ui.select("Agent thinking", [
|
|
166
|
-
"Follow current session",
|
|
167
|
-
...THINKING_LEVEL_OPTIONS.filter((level) => !supported || supported.has(level)),
|
|
168
|
-
]);
|
|
169
|
-
if (selected === undefined)
|
|
170
|
-
continue;
|
|
171
|
-
const thinking = selected === "Follow current session" ? null : selected;
|
|
172
|
-
if ((thinking ?? undefined) === inspection.thinking && inspection.invalidThinking === undefined)
|
|
187
|
+
else if (action === "thinking") {
|
|
188
|
+
const selected = await selectAgentThinking(ctx, inspection, resolution?.model);
|
|
189
|
+
if (selected === undefined ||
|
|
190
|
+
(selected === inspection.thinking && inspection.invalidThinking === undefined))
|
|
173
191
|
continue;
|
|
174
|
-
await saveAgentSettings(ctx, { thinking });
|
|
175
|
-
ctx.ui.notify(`Agent
|
|
192
|
+
await saveAgentSettings(ctx, { thinking: selected });
|
|
193
|
+
ctx.ui.notify(`Agent effort: ${selected}`, "info");
|
|
176
194
|
}
|
|
177
195
|
}
|
|
178
196
|
catch (error) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"settings.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KAAK,CAAC,CAAC,CAAC;gBAC5D,CAAC;gBACD,MAAM,QAAQ,GAAG,MAAM,GAAG,CAAC,EAAE,CAAC,MAAM,CAAC,gBAAgB,EAAE;oBACtD,wBAAwB;oBACxB,GAAG,sBAAsB,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,SAAS,IAAI,SAAS,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;iBAC/E,CAAC,CAAC;gBACH,IAAI,QAAQ,KAAK,SAAS;oBAAE,SAAS;gBACrC,MAAM,QAAQ,GAAG,QAAQ,KAAK,wBAAwB,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAE,QAA0B,CAAC;gBAC5F,IAAI,CAAC,QAAQ,IAAI,SAAS,CAAC,KAAK,UAAU,CAAC,QAAQ,IAAI,UAAU,CAAC,eAAe,KAAK,SAAS;oBAAE,SAAS;gBAC1G,MAAM,iBAAiB,CAAC,GAAG,EAAE,EAAE,QAAQ,EAAE,CAAC,CAAC;gBAC3C,GAAG,CAAC,EAAE,CAAC,MAAM,CAAC,mBAAmB,QAAQ,IAAI,wBAAwB,EAAE,EAAE,MAAM,CAAC,CAAC;YAClF,CAAC;QACF,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YAChB,GAAG,CAAC,EAAE,CAAC,MAAM,CACZ,kCAAkC,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,EAC1F,OAAO,CACP,CAAC;QACH,CAAC;IACF,CAAC;AACF,CAAC","sourcesContent":["import type { ThinkingLevel } from \"@earendil-works/pi-agent-core\";\nimport { clampThinkingLevel, getSupportedThinkingLevels, type Model } from \"@earendil-works/pi-ai/compat\";\nimport { DEFAULT_THINKING_LEVEL, THINKING_LEVEL_OPTIONS } from \"../../core/defaults.ts\";\nimport type { ExtensionCommandContext, ExtensionContext } from \"../../core/extensions/types.ts\";\nimport { truncateHead } from \"../../core/tools/truncate.ts\";\nimport { ModelSelectorComponent } from \"../../modes/interactive/components/model-selector.ts\";\nimport { AGENT_SETTINGS_NAMESPACE, type AgentSettings } from \"./types.ts\";\n\ntype SettingsContext = Pick<ExtensionContext, \"getExtensionSettings\" | \"setExtensionSettings\">;\ntype ModelContext = Pick<ExtensionContext, \"model\" | \"modelRuntime\" | \"thinkingLevel\">;\n\ninterface InspectedAgentSettings extends AgentSettings {\n\tinvalidModel?: unknown;\n\tinvalidThinking?: unknown;\n}\n\nfunction inspectAgentSettings(ctx: Pick<ExtensionContext, \"getExtensionSettings\">): InspectedAgentSettings {\n\tconst raw = ctx.getExtensionSettings(AGENT_SETTINGS_NAMESPACE);\n\tlet model: string | undefined;\n\tlet invalidModel: unknown;\n\tif (raw.model !== undefined) {\n\t\tif (typeof raw.model === \"string\" && raw.model.includes(\"/\")) {\n\t\t\tmodel = raw.model;\n\t\t} else {\n\t\t\tinvalidModel = raw.model;\n\t\t}\n\t}\n\tlet thinking: ThinkingLevel | undefined;\n\tlet invalidThinking: unknown;\n\tif (raw.thinking !== undefined) {\n\t\tif (typeof raw.thinking === \"string\" && THINKING_LEVEL_OPTIONS.includes(raw.thinking as ThinkingLevel)) {\n\t\t\tthinking = raw.thinking as ThinkingLevel;\n\t\t} else {\n\t\t\tinvalidThinking = raw.thinking;\n\t\t}\n\t}\n\treturn { model, thinking, invalidModel, invalidThinking };\n}\n\nexport function readAgentSettings(ctx: Pick<ExtensionContext, \"getExtensionSettings\">): AgentSettings {\n\tconst inspection = inspectAgentSettings(ctx);\n\tif (inspection.invalidModel !== undefined)\n\t\tthrow new Error(\"Invalid Agent model setting. Choose a model with /agent.\");\n\tif (inspection.invalidThinking !== undefined)\n\t\tthrow new Error(\"Invalid Agent thinking setting. Choose a thinking level with /agent.\");\n\treturn { model: inspection.model, thinking: inspection.thinking };\n}\n\nexport function resolveAgentConfiguration(ctx: ModelContext & Pick<ExtensionContext, \"getExtensionSettings\">): {\n\tmodel: Model<any>;\n\tthinking: ThinkingLevel;\n\tsettings: AgentSettings;\n} {\n\tconst settings = readAgentSettings(ctx);\n\tlet model: Model<any> | undefined;\n\tif (settings.model) {\n\t\tconst slash = settings.model.indexOf(\"/\");\n\t\tmodel = ctx.modelRuntime.getModel(settings.model.slice(0, slash), settings.model.slice(slash + 1));\n\t\tif (!model) throw new Error(`Agent model is unavailable: ${settings.model}`);\n\t} else model = ctx.model;\n\tif (!model) throw new Error(\"Agent has no model to follow. Choose one with /agent.\");\n\tconst thinking = clampThinkingLevel(\n\t\tmodel,\n\t\tsettings.thinking ?? ctx.thinkingLevel ?? DEFAULT_THINKING_LEVEL,\n\t) as ThinkingLevel;\n\treturn { model, thinking, settings };\n}\n\nasync function saveAgentSettings(\n\tctx: SettingsContext,\n\tpatch: { model?: string | null; thinking?: ThinkingLevel | null },\n): Promise<void> {\n\tconst next = { ...ctx.getExtensionSettings(AGENT_SETTINGS_NAMESPACE) };\n\tif (patch.model === null || patch.model === \"\") delete next.model;\n\telse if (patch.model !== undefined) next.model = patch.model;\n\tif (patch.thinking === null) delete next.thinking;\n\telse if (patch.thinking !== undefined) next.thinking = patch.thinking;\n\tawait ctx.setExtensionSettings(AGENT_SETTINGS_NAMESPACE, next);\n}\n\nasync function selectAgentModel(ctx: ExtensionCommandContext, current: string): Promise<string | undefined> {\n\tconst saved = ctx.modelRuntime.getAvailableSnapshot().find((model) => `${model.provider}/${model.id}` === current);\n\tconst selected = await ctx.ui.custom<Model<any> | undefined>(\n\t\t(tui, _theme, _keys, done) =>\n\t\t\tnew ModelSelectorComponent(\n\t\t\t\ttui,\n\t\t\t\tsaved ?? ctx.model,\n\t\t\t\tctx.modelRuntime,\n\t\t\t\tctx.scopedModels,\n\t\t\t\t(model) => done(model),\n\t\t\t\t() => done(undefined),\n\t\t\t),\n\t);\n\treturn selected ? `${selected.provider}/${selected.id}` : undefined;\n}\n\nfunction formatInvalid(value: unknown): string {\n\tlet text = \"\";\n\ttry {\n\t\ttext = typeof value === \"string\" ? value : (JSON.stringify(value) ?? \"\");\n\t} catch {}\n\tconst label = truncateHead(text, { maxLines: 1, maxBytes: 80 }).content;\n\treturn label ? `${label} [invalid]` : \"[invalid]\";\n}\n\n/** Two small native selectors; every confirmed choice affects future Agents only. */\nexport async function openAgentSettings(ctx: ExtensionCommandContext): Promise<void> {\n\tif (ctx.mode !== \"tui\") {\n\t\ttry {\n\t\t\tconst settings = readAgentSettings(ctx);\n\t\t\tctx.ui.notify(\n\t\t\t\t`Agent model: ${settings.model ?? \"Follow current session\"} · Thinking: ${settings.thinking ?? \"Follow current session\"}`,\n\t\t\t\t\"info\",\n\t\t\t);\n\t\t} catch (error) {\n\t\t\tctx.ui.notify(error instanceof Error ? error.message : String(error), \"error\");\n\t\t}\n\t\treturn;\n\t}\n\twhile (true) {\n\t\tlet inspection: InspectedAgentSettings;\n\t\ttry {\n\t\t\tinspection = inspectAgentSettings(ctx);\n\t\t} catch (error) {\n\t\t\tctx.ui.notify(error instanceof Error ? error.message : String(error), \"error\");\n\t\t\treturn;\n\t\t}\n\t\tlet modelLabel: string;\n\t\tif (inspection.invalidModel !== undefined) {\n\t\t\tmodelLabel = formatInvalid(inspection.invalidModel);\n\t\t} else if (inspection.model) {\n\t\t\tconst modelAvailable = ctx.modelRuntime\n\t\t\t\t.getAvailableSnapshot()\n\t\t\t\t.some((model) => `${model.provider}/${model.id}` === inspection.model);\n\t\t\tmodelLabel = `${inspection.model}${modelAvailable ? \"\" : \" [unavailable]\"}`;\n\t\t} else {\n\t\t\tmodelLabel = `Follow current session${ctx.model ? ` (${ctx.model.provider}/${ctx.model.id})` : \"\"}`;\n\t\t}\n\t\tlet thinkingLabel: string;\n\t\tif (inspection.invalidThinking !== undefined) {\n\t\t\tthinkingLabel = formatInvalid(inspection.invalidThinking);\n\t\t} else if (inspection.thinking) {\n\t\t\tthinkingLabel = inspection.thinking;\n\t\t} else {\n\t\t\tthinkingLabel = `Follow current session (${ctx.thinkingLevel ?? DEFAULT_THINKING_LEVEL})`;\n\t\t}\n\t\tconst modelAction = `Model · ${modelLabel}`;\n\t\tconst thinkingAction = `Thinking · ${thinkingLabel}`;\n\t\tconst followModelAction = \"Reset model to follow current session\";\n\t\tconst followThinkingAction = \"Reset thinking to follow current session\";\n\t\tconst hasModelOverride = inspection.model !== undefined || inspection.invalidModel !== undefined;\n\t\tconst hasThinkingOverride = inspection.thinking !== undefined || inspection.invalidThinking !== undefined;\n\t\tconst action = await ctx.ui.select(\"Agent settings\", [\n\t\t\tmodelAction,\n\t\t\tthinkingAction,\n\t\t\t...(hasModelOverride ? [followModelAction] : []),\n\t\t\t...(hasThinkingOverride ? [followThinkingAction] : []),\n\t\t]);\n\t\tif (!action) return;\n\t\ttry {\n\t\t\tif (action === followModelAction) {\n\t\t\t\tawait saveAgentSettings(ctx, { model: null });\n\t\t\t\tctx.ui.notify(\"Agent model: Follow current session\", \"info\");\n\t\t\t} else if (action === followThinkingAction) {\n\t\t\t\tawait saveAgentSettings(ctx, { thinking: null });\n\t\t\t\tctx.ui.notify(\"Agent thinking: Follow current session\", \"info\");\n\t\t\t} else if (action === modelAction) {\n\t\t\t\tconst selected = await selectAgentModel(ctx, inspection.model ?? \"\");\n\t\t\t\tif (selected === undefined || selected === inspection.model) continue;\n\t\t\t\tawait saveAgentSettings(ctx, { model: selected });\n\t\t\t\tctx.ui.notify(`Agent model: ${selected}`, \"info\");\n\t\t\t} else if (action === thinkingAction) {\n\t\t\t\tlet supported: Set<ThinkingLevel> | undefined;\n\t\t\t\tif (inspection.model) {\n\t\t\t\t\tconst slash = inspection.model.indexOf(\"/\");\n\t\t\t\t\tconst model = ctx.modelRuntime.getModel(\n\t\t\t\t\t\tinspection.model.slice(0, slash),\n\t\t\t\t\t\tinspection.model.slice(slash + 1),\n\t\t\t\t\t);\n\t\t\t\t\tif (model) supported = new Set(getSupportedThinkingLevels(model));\n\t\t\t\t}\n\t\t\t\tif (!supported && ctx.model) {\n\t\t\t\t\tsupported = new Set(getSupportedThinkingLevels(ctx.model));\n\t\t\t\t}\n\t\t\t\tconst selected = await ctx.ui.select(\"Agent thinking\", [\n\t\t\t\t\t\"Follow current session\",\n\t\t\t\t\t...THINKING_LEVEL_OPTIONS.filter((level) => !supported || supported.has(level)),\n\t\t\t\t]);\n\t\t\t\tif (selected === undefined) continue;\n\t\t\t\tconst thinking = selected === \"Follow current session\" ? null : (selected as ThinkingLevel);\n\t\t\t\tif ((thinking ?? undefined) === inspection.thinking && inspection.invalidThinking === undefined) continue;\n\t\t\t\tawait saveAgentSettings(ctx, { thinking });\n\t\t\t\tctx.ui.notify(`Agent thinking: ${thinking ?? \"Follow current session\"}`, \"info\");\n\t\t\t}\n\t\t} catch (error) {\n\t\t\tctx.ui.notify(\n\t\t\t\t`Could not save Agent settings: ${error instanceof Error ? error.message : String(error)}`,\n\t\t\t\t\"error\",\n\t\t\t);\n\t\t}\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"settings.js","sourceRoot":"","sources":["../../../src/extensions/agent/settings.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,0BAA0B,EAAc,MAAM,8BAA8B,CAAC;AAC1G,OAAO,EAAE,sBAAsB,EAAE,sBAAsB,EAAE,MAAM,wBAAwB,CAAC;AAExF,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAC5D,OAAO,EAAE,sBAAsB,EAAE,MAAM,sDAAsD,CAAC;AAC9F,OAAO,EAAE,yBAAyB,EAAE,MAAM,yDAAyD,CAAC;AACpG,OAAO,EAGN,kBAAkB,GAElB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,wBAAwB,EAAsB,MAAM,YAAY,CAAC;AAU1E,SAAS,oBAAoB,CAAC,GAAmD;IAChF,MAAM,GAAG,GAAG,GAAG,CAAC,oBAAoB,CAAC,wBAAwB,CAAC,CAAC;IAC/D,IAAI,KAAyB,CAAC;IAC9B,IAAI,YAAqB,CAAC;IAC1B,IAAI,GAAG,CAAC,KAAK,KA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YAChB,GAAG,CAAC,EAAE,CAAC,MAAM,CACZ,kCAAkC,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,EAC1F,OAAO,CACP,CAAC;QACH,CAAC;IACF,CAAC;AACF,CAAC","sourcesContent":["import type { ThinkingLevel } from \"@earendil-works/pi-agent-core\";\nimport { clampThinkingLevel, getSupportedThinkingLevels, type Model } from \"@earendil-works/pi-ai/compat\";\nimport { DEFAULT_THINKING_LEVEL, THINKING_LEVEL_OPTIONS } from \"../../core/defaults.ts\";\nimport type { ExtensionCommandContext, ExtensionContext } from \"../../core/extensions/types.ts\";\nimport { truncateHead } from \"../../core/tools/truncate.ts\";\nimport { ModelSelectorComponent } from \"../../modes/interactive/components/model-selector.ts\";\nimport { ThinkingSelectorComponent } from \"../../modes/interactive/components/thinking-selector.ts\";\nimport {\n\ttype AgentSettingsAction,\n\ttype AgentSettingsField,\n\tAgentSettingsPanel,\n\ttype AgentSettingsRow,\n} from \"./settings-panel.ts\";\nimport { AGENT_SETTINGS_NAMESPACE, type AgentSettings } from \"./types.ts\";\n\ntype SettingsContext = Pick<ExtensionContext, \"getExtensionSettings\" | \"setExtensionSettings\">;\ntype ModelContext = Pick<ExtensionContext, \"model\" | \"modelRuntime\" | \"thinkingLevel\">;\n\ninterface InspectedAgentSettings extends AgentSettings {\n\tinvalidModel?: unknown;\n\tinvalidThinking?: unknown;\n}\n\nfunction inspectAgentSettings(ctx: Pick<ExtensionContext, \"getExtensionSettings\">): InspectedAgentSettings {\n\tconst raw = ctx.getExtensionSettings(AGENT_SETTINGS_NAMESPACE);\n\tlet model: string | undefined;\n\tlet invalidModel: unknown;\n\tif (raw.model !== undefined) {\n\t\tif (typeof raw.model === \"string\" && raw.model.includes(\"/\")) {\n\t\t\tmodel = raw.model;\n\t\t} else {\n\t\t\tinvalidModel = raw.model;\n\t\t}\n\t}\n\tlet thinking: ThinkingLevel | undefined;\n\tlet invalidThinking: unknown;\n\tif (raw.thinking !== undefined) {\n\t\tif (typeof raw.thinking === \"string\" && THINKING_LEVEL_OPTIONS.includes(raw.thinking as ThinkingLevel)) {\n\t\t\tthinking = raw.thinking as ThinkingLevel;\n\t\t} else {\n\t\t\tinvalidThinking = raw.thinking;\n\t\t}\n\t}\n\treturn { model, thinking, invalidModel, invalidThinking };\n}\n\nexport function readAgentSettings(ctx: Pick<ExtensionContext, \"getExtensionSettings\">): AgentSettings {\n\tconst inspection = inspectAgentSettings(ctx);\n\tif (inspection.invalidModel !== undefined)\n\t\tthrow new Error(\"Invalid Agent model setting. Choose a model with /agent.\");\n\tif (inspection.invalidThinking !== undefined)\n\t\tthrow new Error(\"Invalid Agent effort setting. Choose an effort level with /agent.\");\n\treturn { model: inspection.model, thinking: inspection.thinking };\n}\n\ninterface AgentModelResolution {\n\tmodel: Model<any>;\n\t/** Listed by `/model` right now. The availability snapshot can lag auth changes, so this is display-only. */\n\tavailable: boolean;\n}\n\nfunction resolveAgentModel(\n\tctx: Pick<ModelContext, \"model\" | \"modelRuntime\">,\n\treference?: string,\n): AgentModelResolution | undefined {\n\tif (!reference) return ctx.model ? { model: ctx.model, available: true } : undefined;\n\tconst slash = reference.indexOf(\"/\");\n\tif (slash <= 0) return undefined;\n\tconst model = ctx.modelRuntime.getModel(reference.slice(0, slash), reference.slice(slash + 1));\n\tif (!model) return undefined;\n\tconst available = ctx.modelRuntime\n\t\t.getAvailableSnapshot()\n\t\t.some((item) => item.provider === model.provider && item.id === model.id);\n\treturn { model, available };\n}\n\nfunction requestedEffort(ctx: Pick<ModelContext, \"thinkingLevel\">, settings: AgentSettings): ThinkingLevel {\n\treturn settings.thinking ?? ctx.thinkingLevel ?? DEFAULT_THINKING_LEVEL;\n}\n\n/** Clamp a requested level to what the model supports. */\nfunction supportedEffort(model: Model<any>, requested: ThinkingLevel): ThinkingLevel {\n\treturn clampThinkingLevel(model, requested) as ThinkingLevel;\n}\n\nexport function resolveAgentConfiguration(ctx: ModelContext & Pick<ExtensionContext, \"getExtensionSettings\">): {\n\tmodel: Model<any>;\n\tthinking: ThinkingLevel;\n\tsettings: AgentSettings;\n} {\n\tconst settings = readAgentSettings(ctx);\n\tconst resolution = resolveAgentModel(ctx, settings.model);\n\tif (!resolution) {\n\t\tif (settings.model) throw new Error(`Agent model is unavailable: ${settings.model}`);\n\t\tthrow new Error(\"Agent has no model to follow. Choose one with /agent.\");\n\t}\n\treturn {\n\t\tmodel: resolution.model,\n\t\tthinking: supportedEffort(resolution.model, requestedEffort(ctx, settings)),\n\t\tsettings,\n\t};\n}\n\nasync function saveAgentSettings(\n\tctx: SettingsContext,\n\tpatch: { model?: string | null; thinking?: ThinkingLevel | null },\n): Promise<void> {\n\tconst next = { ...ctx.getExtensionSettings(AGENT_SETTINGS_NAMESPACE) };\n\tif (patch.model === null || patch.model === \"\") delete next.model;\n\telse if (patch.model !== undefined) next.model = patch.model;\n\tif (patch.thinking === null) delete next.thinking;\n\telse if (patch.thinking !== undefined) next.thinking = patch.thinking;\n\tawait ctx.setExtensionSettings(AGENT_SETTINGS_NAMESPACE, next);\n}\n\nasync function selectAgentModel(ctx: ExtensionCommandContext, current: string): Promise<string | undefined> {\n\t// Preselect the saved reference even when it is unavailable, so the picker can repair it.\n\tconst saved = resolveAgentModel(ctx, current)?.model;\n\tconst selected = await ctx.ui.custom<Model<any> | undefined>(\n\t\t(tui, _theme, _keys, done) =>\n\t\t\tnew ModelSelectorComponent(tui, saved ?? ctx.model, ctx.modelRuntime, ctx.scopedModels, done, () =>\n\t\t\t\tdone(undefined),\n\t\t\t),\n\t);\n\treturn selected ? `${selected.provider}/${selected.id}` : undefined;\n}\n\nasync function selectAgentThinking(\n\tctx: ExtensionCommandContext,\n\tsettings: AgentSettings,\n\tmodel: Model<any> | undefined,\n): Promise<ThinkingLevel | undefined> {\n\tconst requested = requestedEffort(ctx, settings);\n\tconst current = model ? supportedEffort(model, requested) : requested;\n\tconst available = model ? getSupportedThinkingLevels(model) : [...THINKING_LEVEL_OPTIONS];\n\treturn ctx.ui.custom<ThinkingLevel | undefined>(\n\t\t(_tui, _theme, _keys, done) => new ThinkingSelectorComponent(current, available, done, () => done(undefined)),\n\t);\n}\n\nfunction formatInvalidValue(value: unknown): string {\n\tlet text = \"\";\n\ttry {\n\t\ttext = typeof value === \"string\" ? value : (JSON.stringify(value) ?? \"\");\n\t} catch {}\n\treturn truncateHead(text, { maxLines: 1, maxBytes: 80 }).content;\n}\n\nfunction invalidField(raw: unknown): AgentSettingsField {\n\treturn { value: formatInvalidValue(raw), status: \"[invalid]\", tone: \"error\" };\n}\n\nfunction describeModel(\n\tinspection: InspectedAgentSettings,\n\tresolution: AgentModelResolution | undefined,\n): AgentSettingsField {\n\tif (inspection.invalidModel !== undefined) return invalidField(inspection.invalidModel);\n\tif (!resolution) return { value: inspection.model ?? \"\", status: \"[unavailable]\", tone: \"warning\" };\n\treturn {\n\t\tvalue: `${resolution.model.provider}/${resolution.model.id}`,\n\t\tfollowing: inspection.model === undefined,\n\t\t...(resolution.available ? {} : { status: \"[unavailable]\", tone: \"warning\" as const }),\n\t};\n}\n\nfunction describeEffort(\n\tctx: ModelContext,\n\tinspection: InspectedAgentSettings,\n\tmodel: Model<any> | undefined,\n): AgentSettingsField {\n\tif (inspection.invalidThinking !== undefined) return invalidField(inspection.invalidThinking);\n\tconst requested = requestedEffort(ctx, inspection);\n\tconst following = inspection.thinking === undefined;\n\tif (!model) return { value: requested, following, status: \"[unresolved]\", tone: \"warning\" };\n\tconst effective = supportedEffort(model, requested);\n\tif (effective === requested) return { value: requested, following };\n\treturn { value: `${requested} → ${effective}`, following, tone: \"warning\" };\n}\n\nfunction hasOverrides(inspection: InspectedAgentSettings): boolean {\n\treturn (\n\t\tinspection.model !== undefined ||\n\t\tinspection.thinking !== undefined ||\n\t\tinspection.invalidModel !== undefined ||\n\t\tinspection.invalidThinking !== undefined\n\t);\n}\n\nfunction settingsRows(\n\tctx: ModelContext,\n\tinspection: InspectedAgentSettings,\n\tresolution: AgentModelResolution | undefined,\n): AgentSettingsRow[] {\n\treturn [\n\t\t{ action: \"model\", label: \"Model\", field: describeModel(inspection, resolution) },\n\t\t{ action: \"thinking\", label: \"Effort\", field: describeEffort(ctx, inspection, resolution?.model) },\n\t\t{ action: \"reset\", label: \"Reset to follow current session\" },\n\t];\n}\n\n/** The native pickers save only Agent overrides; reset clears both in one write. */\nexport async function openAgentSettings(ctx: ExtensionCommandContext): Promise<void> {\n\tif (ctx.mode !== \"tui\") {\n\t\ttry {\n\t\t\tconst settings = readAgentSettings(ctx);\n\t\t\tctx.ui.notify(\n\t\t\t\t`Agent model: ${settings.model ?? \"Follow current session\"} · Effort: ${settings.thinking ?? \"Follow current session\"}`,\n\t\t\t\t\"info\",\n\t\t\t);\n\t\t} catch (error) {\n\t\t\tctx.ui.notify(error instanceof Error ? error.message : String(error), \"error\");\n\t\t}\n\t\treturn;\n\t}\n\tlet selectedAction: AgentSettingsAction = \"model\";\n\twhile (true) {\n\t\tlet inspection: InspectedAgentSettings;\n\t\ttry {\n\t\t\tinspection = inspectAgentSettings(ctx);\n\t\t} catch (error) {\n\t\t\tctx.ui.notify(error instanceof Error ? error.message : String(error), \"error\");\n\t\t\treturn;\n\t\t}\n\t\tconst resolution = inspection.invalidModel !== undefined ? undefined : resolveAgentModel(ctx, inspection.model);\n\t\tconst action = await ctx.ui.custom<AgentSettingsAction | undefined>(\n\t\t\t(tui, theme, keys, done) =>\n\t\t\t\tnew AgentSettingsPanel(\n\t\t\t\t\ttui,\n\t\t\t\t\ttheme,\n\t\t\t\t\tkeys,\n\t\t\t\t\tsettingsRows(ctx, inspection, resolution),\n\t\t\t\t\tselectedAction,\n\t\t\t\t\tdone,\n\t\t\t\t\t() => done(undefined),\n\t\t\t\t),\n\t\t);\n\t\tif (!action) return;\n\t\tselectedAction = action;\n\t\ttry {\n\t\t\tif (action === \"reset\") {\n\t\t\t\tif (!hasOverrides(inspection)) continue;\n\t\t\t\tawait saveAgentSettings(ctx, { model: null, thinking: null });\n\t\t\t\tctx.ui.notify(\"Agent settings: Follow current session\", \"info\");\n\t\t\t} else if (action === \"model\") {\n\t\t\t\tconst selected = await selectAgentModel(ctx, inspection.model ?? \"\");\n\t\t\t\tif (selected === undefined || selected === inspection.model) continue;\n\t\t\t\tawait saveAgentSettings(ctx, { model: selected });\n\t\t\t\tctx.ui.notify(`Agent model: ${selected}`, \"info\");\n\t\t\t} else if (action === \"thinking\") {\n\t\t\t\tconst selected = await selectAgentThinking(ctx, inspection, resolution?.model);\n\t\t\t\tif (\n\t\t\t\t\tselected === undefined ||\n\t\t\t\t\t(selected === inspection.thinking && inspection.invalidThinking === undefined)\n\t\t\t\t)\n\t\t\t\t\tcontinue;\n\t\t\t\tawait saveAgentSettings(ctx, { thinking: selected });\n\t\t\t\tctx.ui.notify(`Agent effort: ${selected}`, \"info\");\n\t\t\t}\n\t\t} catch (error) {\n\t\t\tctx.ui.notify(\n\t\t\t\t`Could not save Agent settings: ${error instanceof Error ? error.message : String(error)}`,\n\t\t\t\t\"error\",\n\t\t\t);\n\t\t}\n\t}\n}\n"]}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Type } from "typebox";
|
|
2
|
+
import type { ToolDefinition } from "../../core/extensions/types.ts";
|
|
3
|
+
import { type AgentToolDetails } from "./types.ts";
|
|
4
|
+
declare const agentSchema: Type.TObject<{
|
|
5
|
+
prompt: Type.TString;
|
|
6
|
+
description: Type.TOptional<Type.TString>;
|
|
7
|
+
background: Type.TOptional<Type.TBoolean>;
|
|
8
|
+
}>;
|
|
9
|
+
export declare function createAgentTool(options?: {
|
|
10
|
+
concurrency?: number;
|
|
11
|
+
}): ToolDefinition<typeof agentSchema, AgentToolDetails>;
|
|
12
|
+
export {};
|
|
13
|
+
//# sourceMappingURL=tool.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tool.d.ts","sourceRoot":"","sources":["../../../src/extensions/agent/tool.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAC/B,OAAO,KAAK,EAAmB,cAAc,EAAE,MAAM,gCAAgC,CAAC;AAMtF,OAAO,EAAyC,KAAK,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAG1F,QAAA,MAAM,WAAW;;;;EAehB,CAAC;AAmBF,wBAAgB,eAAe,CAC9B,OAAO,GAAE;IAAE,WAAW,CAAC,EAAE,MAAM,CAAA;CAAO,GACpC,cAAc,CAAC,OAAO,WAAW,EAAE,gBAAgB,CAAC,CAuDtD"}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { Type } from "typebox";
|
|
2
|
+
import { defineTool } from "../../core/extensions/types.js";
|
|
3
|
+
import { clipText } from "./activity.js";
|
|
4
|
+
import { agentRenderers } from "./render.js";
|
|
5
|
+
import { resolveAgentConfiguration } from "./settings.js";
|
|
6
|
+
import { AGENT_CONCURRENCY, AGENT_PROMPT_BYTES } from "./types.js";
|
|
7
|
+
import { runWorker } from "./worker.js";
|
|
8
|
+
const agentSchema = Type.Object({
|
|
9
|
+
prompt: Type.String({
|
|
10
|
+
minLength: 1,
|
|
11
|
+
description: "Complete, self-contained task briefing: goal, relevant context and paths, constraints, whether to edit or only investigate, and expected verification and report. The Agent cannot see this conversation.",
|
|
12
|
+
}),
|
|
13
|
+
description: Type.Optional(Type.String({ description: "Short (3–5 word) task label for the transcript and Tasks panel" })),
|
|
14
|
+
background: Type.Optional(Type.Boolean({ description: "Return a task ID and deliver the final report asynchronously" })),
|
|
15
|
+
}, { additionalProperties: false });
|
|
16
|
+
/** The model-facing handoff: who moved the Agent, whether it waits for a slot, and how to follow it. */
|
|
17
|
+
function handoffResult(task, byUser) {
|
|
18
|
+
const moved = byUser
|
|
19
|
+
? `The user moved this Agent to the background while it was running: ${task.id}. It continues unchanged.`
|
|
20
|
+
: `Agent running in background: ${task.id}.`;
|
|
21
|
+
const queued = task.status === "queued" ? " It is queued until an Agent slot frees." : "";
|
|
22
|
+
return {
|
|
23
|
+
content: [
|
|
24
|
+
{
|
|
25
|
+
type: "text",
|
|
26
|
+
text: `${moved}${queued} The report will be delivered automatically. Use tasks read/wait/kill to inspect, wait or stop.`,
|
|
27
|
+
},
|
|
28
|
+
],
|
|
29
|
+
details: { version: 2, state: "background", taskId: task.id, byUser },
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
export function createAgentTool(options = {}) {
|
|
33
|
+
const limit = options.concurrency ?? AGENT_CONCURRENCY;
|
|
34
|
+
return defineTool({
|
|
35
|
+
name: "Agent",
|
|
36
|
+
label: "Agent",
|
|
37
|
+
description: "Run one self-contained task in a fresh Agent session and get back only its final report. Use Agent when separate context or parallel execution clearly helps; handle known-path reads and small edits directly. The Agent cannot see this conversation, but shares your working directory and applicable project instructions, with read, bash, edit, and write. Foreground returns the report; background returns a task ID and delivers the report automatically.",
|
|
38
|
+
promptSnippet: "Delegate a self-contained task and receive only its final report",
|
|
39
|
+
promptGuidelines: [
|
|
40
|
+
"Use Agent primarily for independent research, verification, or well-specified, self-contained implementation when separate context or parallel execution clearly helps. Keep design and substantial coding in the main session; handle known-path reads and small edits directly. “Multiple angles” or “be thorough” alone does not justify an Agent.",
|
|
41
|
+
"Give Agent a self-contained briefing: the goal and why it matters, prior findings or ruled-out options, relevant paths and constraints, whether to investigate or edit, and expected verification. For open investigations, hand over the question rather than a fragile step-by-step procedure; state any report-length limit.",
|
|
42
|
+
"Keep ownership of synthesis when using Agent—never delegate understanding. For edits, supply your conclusions, target behavior, relevant files, and acceptance checks rather than “based on your findings, fix it.” Verify actual edits and test evidence before calling the work done.",
|
|
43
|
+
"Run parallel Agents only on independent work; concurrent writers must not touch the same files or shared state. Do not duplicate delegated work or repeatedly poll a background Agent. Continue independent work, or wait when its result is needed.",
|
|
44
|
+
"An Agent report is not automatically presented to the user. Relay the important outcome, verification result, and remaining risks concisely.",
|
|
45
|
+
],
|
|
46
|
+
parameters: agentSchema,
|
|
47
|
+
constrainedSampling: { type: "json_schema", strict: "prefer" },
|
|
48
|
+
executionMode: "parallel",
|
|
49
|
+
async execute(toolCallId, params, signal, onUpdate, ctx) {
|
|
50
|
+
if (!params.prompt.trim() || Buffer.byteLength(params.prompt) > AGENT_PROMPT_BYTES)
|
|
51
|
+
throw new Error("Agent prompt must contain text and fit within 16 KiB.");
|
|
52
|
+
const { model, thinking } = resolveAgentConfiguration(ctx);
|
|
53
|
+
const auth = await ctx.modelRuntime.getAuth(model, { signal });
|
|
54
|
+
if (!auth)
|
|
55
|
+
throw new Error(`No authentication for Agent model ${model.provider}/${model.id}`);
|
|
56
|
+
const outcome = await ctx.tasks.execute({
|
|
57
|
+
kind: "agent",
|
|
58
|
+
label: "Agent",
|
|
59
|
+
title: clipText((params.description?.trim() || params.prompt).replace(/\s+/gu, " ").trim(), 160),
|
|
60
|
+
output: "report",
|
|
61
|
+
input: { label: "Prompt", text: params.prompt, truncated: false },
|
|
62
|
+
facts: [
|
|
63
|
+
["Model", `${model.provider}/${model.id}`],
|
|
64
|
+
["Thinking", thinking],
|
|
65
|
+
["Directory", ctx.cwd],
|
|
66
|
+
],
|
|
67
|
+
concurrency: { key: "agent", limit },
|
|
68
|
+
toolCallId,
|
|
69
|
+
background: params.background,
|
|
70
|
+
signal,
|
|
71
|
+
onUpdate,
|
|
72
|
+
run: (control) => runWorker(control, {
|
|
73
|
+
prompt: params.prompt,
|
|
74
|
+
cwd: ctx.cwd,
|
|
75
|
+
model,
|
|
76
|
+
thinking,
|
|
77
|
+
modelRuntime: ctx.modelRuntime,
|
|
78
|
+
projectTrusted: ctx.isProjectTrusted(),
|
|
79
|
+
}),
|
|
80
|
+
});
|
|
81
|
+
if (outcome.kind === "result")
|
|
82
|
+
return outcome.result;
|
|
83
|
+
return handoffResult(outcome.task, params.background !== true);
|
|
84
|
+
},
|
|
85
|
+
...agentRenderers,
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
//# sourceMappingURL=tool.js.map
|
|
@@ -0,0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,UAAU,KAAK,IAAI,CAAC,CAAC;QAChE,CAAC;QACD,GAAG,cAAc;KACjB,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import { Type } from \"typebox\";\nimport type { AgentToolResult, ToolDefinition } from \"../../core/extensions/types.ts\";\nimport { defineTool } from \"../../core/extensions/types.ts\";\nimport type { TaskSnapshot } from \"../../core/tasks/types.ts\";\nimport { clipText } from \"./activity.ts\";\nimport { agentRenderers } from \"./render.ts\";\nimport { resolveAgentConfiguration } from \"./settings.ts\";\nimport { AGENT_CONCURRENCY, AGENT_PROMPT_BYTES, type AgentToolDetails } from \"./types.ts\";\nimport { runWorker } from \"./worker.ts\";\n\nconst agentSchema = Type.Object(\n\t{\n\t\tprompt: Type.String({\n\t\t\tminLength: 1,\n\t\t\tdescription:\n\t\t\t\t\"Complete, self-contained task briefing: goal, relevant context and paths, constraints, whether to edit or only investigate, and expected verification and report. The Agent cannot see this conversation.\",\n\t\t}),\n\t\tdescription: Type.Optional(\n\t\t\tType.String({ description: \"Short (3–5 word) task label for the transcript and Tasks panel\" }),\n\t\t),\n\t\tbackground: Type.Optional(\n\t\t\tType.Boolean({ description: \"Return a task ID and deliver the final report asynchronously\" }),\n\t\t),\n\t},\n\t{ additionalProperties: false },\n);\n\n/** The model-facing handoff: who moved the Agent, whether it waits for a slot, and how to follow it. */\nfunction handoffResult(task: TaskSnapshot, byUser: boolean): AgentToolResult<AgentToolDetails> {\n\tconst moved = byUser\n\t\t? `The user moved this Agent to the background while it was running: ${task.id}. It continues unchanged.`\n\t\t: `Agent running in background: ${task.id}.`;\n\tconst queued = task.status === \"queued\" ? \" It is queued until an Agent slot frees.\" : \"\";\n\treturn {\n\t\tcontent: [\n\t\t\t{\n\t\t\t\ttype: \"text\",\n\t\t\t\ttext: `${moved}${queued} The report will be delivered automatically. Use tasks read/wait/kill to inspect, wait or stop.`,\n\t\t\t},\n\t\t],\n\t\tdetails: { version: 2, state: \"background\", taskId: task.id, byUser },\n\t};\n}\n\nexport function createAgentTool(\n\toptions: { concurrency?: number } = {},\n): ToolDefinition<typeof agentSchema, AgentToolDetails> {\n\tconst limit = options.concurrency ?? AGENT_CONCURRENCY;\n\treturn defineTool({\n\t\tname: \"Agent\",\n\t\tlabel: \"Agent\",\n\t\tdescription:\n\t\t\t\"Run one self-contained task in a fresh Agent session and get back only its final report. Use Agent when separate context or parallel execution clearly helps; handle known-path reads and small edits directly. The Agent cannot see this conversation, but shares your working directory and applicable project instructions, with read, bash, edit, and write. Foreground returns the report; background returns a task ID and delivers the report automatically.\",\n\t\tpromptSnippet: \"Delegate a self-contained task and receive only its final report\",\n\t\tpromptGuidelines: [\n\t\t\t\"Use Agent primarily for independent research, verification, or well-specified, self-contained implementation when separate context or parallel execution clearly helps. Keep design and substantial coding in the main session; handle known-path reads and small edits directly. “Multiple angles” or “be thorough” alone does not justify an Agent.\",\n\t\t\t\"Give Agent a self-contained briefing: the goal and why it matters, prior findings or ruled-out options, relevant paths and constraints, whether to investigate or edit, and expected verification. For open investigations, hand over the question rather than a fragile step-by-step procedure; state any report-length limit.\",\n\t\t\t\"Keep ownership of synthesis when using Agent—never delegate understanding. For edits, supply your conclusions, target behavior, relevant files, and acceptance checks rather than “based on your findings, fix it.” Verify actual edits and test evidence before calling the work done.\",\n\t\t\t\"Run parallel Agents only on independent work; concurrent writers must not touch the same files or shared state. Do not duplicate delegated work or repeatedly poll a background Agent. Continue independent work, or wait when its result is needed.\",\n\t\t\t\"An Agent report is not automatically presented to the user. Relay the important outcome, verification result, and remaining risks concisely.\",\n\t\t],\n\t\tparameters: agentSchema,\n\t\tconstrainedSampling: { type: \"json_schema\", strict: \"prefer\" },\n\t\texecutionMode: \"parallel\",\n\t\tasync execute(toolCallId, params, signal, onUpdate, ctx) {\n\t\t\tif (!params.prompt.trim() || Buffer.byteLength(params.prompt) > AGENT_PROMPT_BYTES)\n\t\t\t\tthrow new Error(\"Agent prompt must contain text and fit within 16 KiB.\");\n\t\t\tconst { model, thinking } = resolveAgentConfiguration(ctx);\n\t\t\tconst auth = await ctx.modelRuntime.getAuth(model, { signal });\n\t\t\tif (!auth) throw new Error(`No authentication for Agent model ${model.provider}/${model.id}`);\n\t\t\tconst outcome = await ctx.tasks.execute<AgentToolDetails>({\n\t\t\t\tkind: \"agent\",\n\t\t\t\tlabel: \"Agent\",\n\t\t\t\ttitle: clipText((params.description?.trim() || params.prompt).replace(/\\s+/gu, \" \").trim(), 160),\n\t\t\t\toutput: \"report\",\n\t\t\t\tinput: { label: \"Prompt\", text: params.prompt, truncated: false },\n\t\t\t\tfacts: [\n\t\t\t\t\t[\"Model\", `${model.provider}/${model.id}`],\n\t\t\t\t\t[\"Thinking\", thinking],\n\t\t\t\t\t[\"Directory\", ctx.cwd],\n\t\t\t\t],\n\t\t\t\tconcurrency: { key: \"agent\", limit },\n\t\t\t\ttoolCallId,\n\t\t\t\tbackground: params.background,\n\t\t\t\tsignal,\n\t\t\t\tonUpdate,\n\t\t\t\trun: (control) =>\n\t\t\t\t\trunWorker(control, {\n\t\t\t\t\t\tprompt: params.prompt,\n\t\t\t\t\t\tcwd: ctx.cwd,\n\t\t\t\t\t\tmodel,\n\t\t\t\t\t\tthinking,\n\t\t\t\t\t\tmodelRuntime: ctx.modelRuntime,\n\t\t\t\t\t\tprojectTrusted: ctx.isProjectTrusted(),\n\t\t\t\t\t}),\n\t\t\t});\n\t\t\tif (outcome.kind === \"result\") return outcome.result;\n\t\t\treturn handoffResult(outcome.task, params.background !== true);\n\t\t},\n\t\t...agentRenderers,\n\t});\n}\n"]}
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import type { ThinkingLevel } from "@earendil-works/pi-agent-core";
|
|
2
2
|
import type { TaskTerminalStatus } from "../../core/tasks/types.ts";
|
|
3
3
|
export declare const AGENT_SETTINGS_NAMESPACE = "agent";
|
|
4
|
+
export declare const AGENT_PROMPT_BYTES: number;
|
|
4
5
|
export declare const AGENT_REPORT_BYTES: number;
|
|
5
6
|
export declare const AGENT_MAX_ACTIVITIES = 50;
|
|
7
|
+
export declare const AGENT_CONCURRENCY = 4;
|
|
6
8
|
export interface AgentSettings {
|
|
7
9
|
model?: string;
|
|
8
10
|
thinking?: ThinkingLevel;
|
|
@@ -18,28 +20,24 @@ export interface AgentActivity {
|
|
|
18
20
|
durationMs?: number;
|
|
19
21
|
error?: string;
|
|
20
22
|
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
+
/**
|
|
24
|
+
* Agent tool-result details. Only progress updates carry activities; the persisted result
|
|
25
|
+
* keeps the transcript row's facts, and the full history lives in the task's Output.
|
|
26
|
+
*/
|
|
27
|
+
export type AgentToolDetails = {
|
|
28
|
+
version: 2;
|
|
29
|
+
state: "running";
|
|
23
30
|
taskId: string;
|
|
24
|
-
status: "running" | "background" | TaskTerminalStatus;
|
|
25
|
-
model: string;
|
|
26
|
-
thinking: ThinkingLevel;
|
|
27
|
-
/** Short terminal diagnostic; the complete report and error remain in Tasks Output. */
|
|
28
|
-
error?: string;
|
|
29
31
|
activities: AgentActivity[];
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
cacheRead: number;
|
|
41
|
-
cacheWrite: number;
|
|
42
|
-
total: number;
|
|
43
|
-
};
|
|
32
|
+
} | {
|
|
33
|
+
version: 2;
|
|
34
|
+
state: "background";
|
|
35
|
+
taskId: string;
|
|
36
|
+
byUser: boolean;
|
|
37
|
+
} | {
|
|
38
|
+
version: 2;
|
|
39
|
+
state: TaskTerminalStatus;
|
|
40
|
+
taskId: string;
|
|
41
|
+
error?: string;
|
|
44
42
|
};
|
|
45
43
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/extensions/agent/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,+B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,OAAO,EAAE,CAAC,CAAC;IAAC,KAAK,EAAE,YAAY,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,OAAO,CAAA;CAAE,GACpE;IAAE,OAAO,EAAE,CAAC,CAAC;IAAC,KAAK,EAAE,kBAAkB,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC"}
|
|
@@ -1,14 +1,6 @@
|
|
|
1
1
|
export const AGENT_SETTINGS_NAMESPACE = "agent";
|
|
2
|
+
export const AGENT_PROMPT_BYTES = 16 * 1024;
|
|
2
3
|
export const AGENT_REPORT_BYTES = 24 * 1024;
|
|
3
4
|
export const AGENT_MAX_ACTIVITIES = 50;
|
|
4
|
-
export
|
|
5
|
-
return {
|
|
6
|
-
input: 0,
|
|
7
|
-
output: 0,
|
|
8
|
-
cacheRead: 0,
|
|
9
|
-
cacheWrite: 0,
|
|
10
|
-
totalTokens: 0,
|
|
11
|
-
cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 },
|
|
12
|
-
};
|
|
13
|
-
}
|
|
5
|
+
export const AGENT_CONCURRENCY = 4;
|
|
14
6
|
//# sourceMappingURL=types.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/extensions/agent/types.ts"],"names":[],"mappings":"AAGA,MAAM,CAAC,MAAM,wBAAwB,GAAG,OAAO,CAAC;AAChD,MAAM,CAAC,MAAM,kBAAkB,GAAG,EAAE,GAAG,IAAI,CAAC;AAC5C,MAAM,CAAC,MAAM,
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/extensions/agent/types.ts"],"names":[],"mappings":"AAGA,MAAM,CAAC,MAAM,wBAAwB,GAAG,OAAO,CAAC;AAChD,MAAM,CAAC,MAAM,kBAAkB,GAAG,EAAE,GAAG,IAAI,CAAC;AAC5C,MAAM,CAAC,MAAM,kBAAkB,GAAG,EAAE,GAAG,IAAI,CAAC;AAC5C,MAAM,CAAC,MAAM,oBAAoB,GAAG,EAAE,CAAC;AACvC,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,CAAC","sourcesContent":["import type { ThinkingLevel } from \"@earendil-works/pi-agent-core\";\nimport type { TaskTerminalStatus } from \"../../core/tasks/types.ts\";\n\nexport const AGENT_SETTINGS_NAMESPACE = \"agent\";\nexport const AGENT_PROMPT_BYTES = 16 * 1024;\nexport const AGENT_REPORT_BYTES = 24 * 1024;\nexport const AGENT_MAX_ACTIVITIES = 50;\nexport const AGENT_CONCURRENCY = 4;\n\nexport interface AgentSettings {\n\tmodel?: string;\n\tthinking?: ThinkingLevel;\n}\n\nexport type AgentActivityStatus = \"running\" | \"ok\" | \"error\" | \"cancelled\";\n\nexport interface AgentActivity {\n\tid: string;\n\tname: string;\n\targs: string;\n\t/** Short display label derived from the original arguments; args remains the full bounded form. */\n\ttarget?: string;\n\tstatus: AgentActivityStatus;\n\tdurationMs?: number;\n\terror?: string;\n}\n\n/**\n * Agent tool-result details. Only progress updates carry activities; the persisted result\n * keeps the transcript row's facts, and the full history lives in the task's Output.\n */\nexport type AgentToolDetails =\n\t| { version: 2; state: \"running\"; taskId: string; activities: AgentActivity[] }\n\t| { version: 2; state: \"background\"; taskId: string; byUser: boolean }\n\t| { version: 2; state: TaskTerminalStatus; taskId: string; error?: string };\n"]}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { ThinkingLevel } from "@earendil-works/pi-agent-core";
|
|
2
|
+
import type { Model } from "@earendil-works/pi-ai/compat";
|
|
3
|
+
import type { ModelRuntime } from "../../core/model-runtime.ts";
|
|
4
|
+
import type { TaskCompletion, TaskControl } from "../../core/tasks/types.ts";
|
|
5
|
+
import type { AgentToolDetails } from "./types.ts";
|
|
6
|
+
export interface AgentRequest {
|
|
7
|
+
prompt: string;
|
|
8
|
+
cwd: string;
|
|
9
|
+
model: Model<any>;
|
|
10
|
+
thinking: ThinkingLevel;
|
|
11
|
+
modelRuntime: ModelRuntime;
|
|
12
|
+
projectTrusted: boolean;
|
|
13
|
+
}
|
|
14
|
+
/** Run one delegated task in an isolated session and settle it with a self-contained report. */
|
|
15
|
+
export declare function runWorker(control: TaskControl<AgentToolDetails>, request: AgentRequest): Promise<TaskCompletion<AgentToolDetails>>;
|
|
16
|
+
//# sourceMappingURL=worker.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"worker.d.ts","sourceRoot":"","sources":["../../../src/extensions/agent/worker.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AACnE,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,8BAA8B,CAAC;AAG1D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,KAAK,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAI7E,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAInD,MAAM,WAAW,YAAY;IAC5B,MAAM,EAAE,MAAM,CAAC;IACf,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC;IAClB,QAAQ,EAAE,aAAa,CAAC;IACxB,YAAY,EAAE,YAAY,CAAC;IAC3B,cAAc,EAAE,OAAO,CAAC;CACxB;AAaD,gGAAgG;AAChG,wBAAsB,SAAS,CAC9B,OAAO,EAAE,WAAW,CAAC,gBAAgB,CAAC,EACtC,OAAO,EAAE,YAAY,GACnB,OAAO,CAAC,cAAc,CAAC,gBAAgB,CAAC,CAAC,CA6C3C"}
|