@firstpick/pi-package-webui 0.9.5 → 0.9.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/README.md +11 -5
- package/bin/pi-webui.mjs +457 -77
- package/lib/git-workflow-preferences.mjs +21 -1
- package/lib/optional-feature-catalog.mjs +1 -1
- package/lib/session-actions.mjs +20 -2
- package/lib/session-tree-event-targets.mjs +70 -0
- package/lib/subagent-launch-policy.mjs +375 -0
- package/lib/subagent-launch-slots.mjs +2 -1
- package/package.json +1 -1
- package/public/app.js +2539 -292
- package/public/index.html +87 -31
- package/public/service-worker.js +4 -1
- package/public/stream-derived-output.mjs +799 -0
- package/public/stream-markdown-tail.mjs +204 -0
- package/public/stream-output-controller.mjs +193 -51
- package/public/stream-render-scheduler.mjs +85 -0
- package/public/styles.css +501 -19
- package/public/transcript-renderer.mjs +73 -24
- package/tests/boot-failure-diagnostics.test.mjs +3 -3
- package/tests/browser/composer-action-grid-reorder.spec.mjs +114 -31
- package/tests/browser/control-visibility.spec.mjs +141 -2
- package/tests/browser/events-tree-context-menu.spec.mjs +240 -0
- package/tests/browser/guided-git-fallback.spec.mjs +153 -0
- package/tests/browser/mobile-foundation.spec.mjs +28 -0
- package/tests/browser/stream-output-isolation.spec.mjs +308 -3
- package/tests/browser/user-noticeable-fixes.spec.mjs +204 -0
- package/tests/codex-fast-mode-static.test.mjs +2 -2
- package/tests/compact-sections-static.test.mjs +4 -0
- package/tests/composer-action-grid-reorder-static.test.mjs +8 -7
- package/tests/control-visibility-static.test.mjs +66 -3
- package/tests/controls-layout-static.test.mjs +3 -3
- package/tests/cwd-footer-reliability-static.test.mjs +1 -1
- package/tests/events-tree-context-menu-static.test.mjs +131 -0
- package/tests/fast-mode-client-static.test.mjs +5 -2
- package/tests/feature-decision-output-popup-static.test.mjs +2 -2
- package/tests/file-viewer-image-static.test.mjs +3 -3
- package/tests/fixtures/fake-pi.mjs +57 -10
- package/tests/fixtures/streaming-workloads.mjs +36 -0
- package/tests/footer-provider-usage-visual-static.test.mjs +15 -0
- package/tests/foreground-transcript-catch-up-static.test.mjs +7 -1
- package/tests/git-workflow-preferences.test.mjs +30 -1
- package/tests/guided-git-fallback-runtime.test.mjs +418 -0
- package/tests/guided-git-fallback-ui-static.test.mjs +60 -0
- package/tests/guided-git-message-reliability-static.test.mjs +8 -7
- package/tests/interaction-state-stability-static.test.mjs +3 -1
- package/tests/intercom-conversation-viewer-static.test.mjs +3 -3
- package/tests/intercom-conversations-http.test.mjs +16 -0
- package/tests/main-output-loading-static.test.mjs +3 -3
- package/tests/middle-button-drag-scroll-static.test.mjs +3 -3
- package/tests/mobile-continuity-tablet-static.test.mjs +3 -3
- package/tests/mobile-foundation-static.test.mjs +3 -3
- package/tests/mobile-phone-experience-static.test.mjs +1 -1
- package/tests/mobile-static.test.mjs +80 -67
- package/tests/open-issue-wizard-static.test.mjs +1 -1
- package/tests/persistent-ui-layout-static.test.mjs +4 -4
- package/tests/prompt-input-vertical-scroll-static.test.mjs +26 -0
- package/tests/questionnaire-dialog.test.mjs +3 -3
- package/tests/remote-auth-settings-harness.test.mjs +23 -0
- package/tests/resource-defaults-helper.test.mjs +12 -0
- package/tests/runtime-error-visibility.test.mjs +3 -3
- package/tests/session-auth-harness.test.mjs +26 -1
- package/tests/session-sampling-helper.test.mjs +1 -0
- package/tests/session-sampling-ui-static.test.mjs +3 -3
- package/tests/session-tree-event-targets.test.mjs +106 -0
- package/tests/side-panel-section-height-removal-static.test.mjs +3 -3
- package/tests/stream-derived-output.test.mjs +121 -0
- package/tests/stream-markdown-tail.test.mjs +218 -0
- package/tests/stream-output-controller.test.mjs +119 -4
- package/tests/stream-output-isolation-static.test.mjs +27 -6
- package/tests/stream-output-workloads.test.mjs +40 -3
- package/tests/stream-render-scheduler.test.mjs +115 -0
- package/tests/streaming-ui-coupling.test.mjs +1 -1
- package/tests/subagent-launch-policy.test.mjs +532 -0
- package/tests/subagent-observability-static.test.mjs +2 -2
- package/tests/subagents-helper.test.mjs +211 -1
- package/tests/syntax-highlighting-static.test.mjs +3 -3
- package/tests/tab-close-continuity-static.test.mjs +23 -0
- package/tests/theme-customizer-static.test.mjs +1 -1
- package/tests/thinking-format-parser.test.mjs +15 -0
- package/tests/todo-filter-static.test.mjs +148 -0
- package/tests/transcript-markdown-tail.test.mjs +137 -0
- package/webui-rpc-helper.mjs +220 -3
|
@@ -52,6 +52,11 @@ export function defaultGitWorkflowPreferences() {
|
|
|
52
52
|
modelId: "",
|
|
53
53
|
thinkingLevel: "low",
|
|
54
54
|
unavailablePolicy: "ask",
|
|
55
|
+
fallback: {
|
|
56
|
+
provider: "",
|
|
57
|
+
modelId: "",
|
|
58
|
+
thinkingLevel: "low",
|
|
59
|
+
},
|
|
55
60
|
},
|
|
56
61
|
commit: {
|
|
57
62
|
language: "en",
|
|
@@ -69,6 +74,8 @@ export function normalizeGitWorkflowPreferences(value) {
|
|
|
69
74
|
const defaults = defaultGitWorkflowPreferences();
|
|
70
75
|
const provider = cleanBoundedString(value?.generation?.provider, 160);
|
|
71
76
|
const modelId = cleanBoundedString(value?.generation?.modelId, 512);
|
|
77
|
+
const fallbackProvider = cleanBoundedString(value?.generation?.fallback?.provider, 160);
|
|
78
|
+
const fallbackModelId = cleanBoundedString(value?.generation?.fallback?.modelId, 512);
|
|
72
79
|
return {
|
|
73
80
|
setupVersion: provider && modelId ? GIT_WORKFLOW_SETUP_VERSION : 0,
|
|
74
81
|
generation: {
|
|
@@ -76,6 +83,11 @@ export function normalizeGitWorkflowPreferences(value) {
|
|
|
76
83
|
modelId,
|
|
77
84
|
thinkingLevel: choice(value?.generation?.thinkingLevel, GIT_WORKFLOW_THINKING_LEVELS, defaults.generation.thinkingLevel),
|
|
78
85
|
unavailablePolicy: choice(value?.generation?.unavailablePolicy, GIT_WORKFLOW_UNAVAILABLE_POLICIES, defaults.generation.unavailablePolicy),
|
|
86
|
+
fallback: {
|
|
87
|
+
provider: fallbackProvider,
|
|
88
|
+
modelId: fallbackModelId,
|
|
89
|
+
thinkingLevel: choice(value?.generation?.fallback?.thinkingLevel, GIT_WORKFLOW_THINKING_LEVELS, defaults.generation.fallback.thinkingLevel),
|
|
90
|
+
},
|
|
79
91
|
},
|
|
80
92
|
commit: {
|
|
81
93
|
language: choice(value?.commit?.language, GIT_WORKFLOW_LANGUAGES, defaults.commit.language),
|
|
@@ -94,7 +106,11 @@ export function mergeGitWorkflowPreferences(current, patch) {
|
|
|
94
106
|
return normalizeGitWorkflowPreferences({
|
|
95
107
|
...base,
|
|
96
108
|
...(patch || {}),
|
|
97
|
-
generation: {
|
|
109
|
+
generation: {
|
|
110
|
+
...base.generation,
|
|
111
|
+
...(patch?.generation || {}),
|
|
112
|
+
fallback: { ...base.generation.fallback, ...(patch?.generation?.fallback || {}) },
|
|
113
|
+
},
|
|
98
114
|
commit: { ...base.commit, ...(patch?.commit || {}) },
|
|
99
115
|
});
|
|
100
116
|
}
|
|
@@ -107,9 +123,13 @@ export function isGitWorkflowSetupComplete(preferences) {
|
|
|
107
123
|
export function gitWorkflowPreferencesSummary(preferences) {
|
|
108
124
|
const value = normalizeGitWorkflowPreferences(preferences);
|
|
109
125
|
const model = isGitWorkflowSetupComplete(value) ? `${value.generation.provider}/${value.generation.modelId}` : "not configured";
|
|
126
|
+
const fallback = value.generation.fallback.provider && value.generation.fallback.modelId
|
|
127
|
+
? `${value.generation.fallback.provider}/${value.generation.fallback.modelId} · ${value.generation.fallback.thinkingLevel}`
|
|
128
|
+
: "disabled";
|
|
110
129
|
return [
|
|
111
130
|
`Model: ${model}`,
|
|
112
131
|
`Thinking: ${value.generation.thinkingLevel}`,
|
|
132
|
+
`Fallback: ${fallback}`,
|
|
113
133
|
`Commit: ${value.commit.language} · ${value.commit.defaultVariant} · scope ${value.commit.scope}`,
|
|
114
134
|
`Staging: ${value.stagingPolicy}`,
|
|
115
135
|
`Review process: ${value.reviewProcessEnabled ? "enabled" : "disabled"}`,
|
|
@@ -15,7 +15,7 @@ const entries = [
|
|
|
15
15
|
["remoteWebui", "@firstpick/pi-package-remote-webui", "^0.1.8"],
|
|
16
16
|
["questionnaire", "@firstpick/pi-package-questionnaire", "^0.1.0"],
|
|
17
17
|
["naturalConversation", "@firstpick/pi-package-natural-conversation", "^0.1.4"],
|
|
18
|
-
["gitFooterStatus", "@firstpick/pi-extension-git-footer-status", "^0.
|
|
18
|
+
["gitFooterStatus", "@firstpick/pi-extension-git-footer-status", "^0.5.0"],
|
|
19
19
|
["statsCommand", "@firstpick/pi-extension-stats", "^0.2.9"],
|
|
20
20
|
["codexFastMode", "@firstpick/pi-extension-codex-fast-mode", "^0.1.0"],
|
|
21
21
|
["themeBundle", "@firstpick/pi-themes-bundle", "^0.1.5"],
|
package/lib/session-actions.mjs
CHANGED
|
@@ -11,14 +11,32 @@ export function normalizeSessionFilePath(value) {
|
|
|
11
11
|
return text ? path.resolve(text) : "";
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
-
/**
|
|
14
|
+
/**
|
|
15
|
+
* Resolve symlinks where possible so confinement checks compare canonical paths.
|
|
16
|
+
* For paths that do not exist yet (e.g. a brand-new session file), realpath the
|
|
17
|
+
* nearest existing ancestor and re-append the rest, so a symlinked session
|
|
18
|
+
* directory (such as ~/.pi pointing into a dotfiles repo) still canonicalizes
|
|
19
|
+
* instead of silently comparing against the unresolved path.
|
|
20
|
+
*/
|
|
15
21
|
function canonicalSessionPath(value) {
|
|
16
22
|
const resolved = normalizeSessionFilePath(value);
|
|
17
23
|
if (!resolved) return "";
|
|
18
24
|
try {
|
|
19
25
|
return realpathSync(resolved);
|
|
20
26
|
} catch {
|
|
21
|
-
|
|
27
|
+
const tail = [];
|
|
28
|
+
let current = resolved;
|
|
29
|
+
while (true) {
|
|
30
|
+
const parent = path.dirname(current);
|
|
31
|
+
if (parent === current) return resolved;
|
|
32
|
+
tail.unshift(path.basename(current));
|
|
33
|
+
current = parent;
|
|
34
|
+
try {
|
|
35
|
+
return path.join(realpathSync(current), ...tail);
|
|
36
|
+
} catch {
|
|
37
|
+
// keep walking up
|
|
38
|
+
}
|
|
39
|
+
}
|
|
22
40
|
}
|
|
23
41
|
}
|
|
24
42
|
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
function nonEmptyString(value) {
|
|
2
|
+
return typeof value === "string" && value.trim() ? value.trim() : "";
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
function entryId(entry) {
|
|
6
|
+
return nonEmptyString(entry?.id);
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
function assistantToolCallId(part) {
|
|
10
|
+
return nonEmptyString(part?.id) || nonEmptyString(part?.toolCallId);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function toolResultCallId(message) {
|
|
14
|
+
return nonEmptyString(message?.toolCallId);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function toolName(record) {
|
|
18
|
+
return nonEmptyString(record?.toolName) || nonEmptyString(record?.name);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function targetFor(toolCallId, name = "") {
|
|
22
|
+
return {
|
|
23
|
+
toolCallId,
|
|
24
|
+
toolName: name,
|
|
25
|
+
startEntryId: null,
|
|
26
|
+
finishEntryId: null,
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Extract minimal tool-call boundaries from persisted Pi session entries.
|
|
32
|
+
* Duplicate boundaries are resolved deterministically by keeping the first
|
|
33
|
+
* persisted entry ID for each boundary.
|
|
34
|
+
*/
|
|
35
|
+
export function sessionTreeEventTargets(entries) {
|
|
36
|
+
if (!Array.isArray(entries)) return [];
|
|
37
|
+
|
|
38
|
+
const targets = new Map();
|
|
39
|
+
for (const entry of entries) {
|
|
40
|
+
const persistedEntryId = entryId(entry);
|
|
41
|
+
if (!persistedEntryId || entry?.type !== "message") continue;
|
|
42
|
+
|
|
43
|
+
const message = entry.message;
|
|
44
|
+
if (message?.role === "assistant" && Array.isArray(message.content)) {
|
|
45
|
+
for (const part of message.content) {
|
|
46
|
+
if (part?.type !== "toolCall") continue;
|
|
47
|
+
const toolCallId = assistantToolCallId(part);
|
|
48
|
+
if (!toolCallId) continue;
|
|
49
|
+
const existing = targets.get(toolCallId);
|
|
50
|
+
const target = existing || targetFor(toolCallId, toolName(part));
|
|
51
|
+
if (!target.toolName) target.toolName = toolName(part);
|
|
52
|
+
if (!target.startEntryId) target.startEntryId = persistedEntryId;
|
|
53
|
+
if (!existing) targets.set(toolCallId, target);
|
|
54
|
+
}
|
|
55
|
+
continue;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
if (message?.role === "toolResult") {
|
|
59
|
+
const toolCallId = toolResultCallId(message);
|
|
60
|
+
if (!toolCallId) continue;
|
|
61
|
+
const existing = targets.get(toolCallId);
|
|
62
|
+
const target = existing || targetFor(toolCallId, toolName(message));
|
|
63
|
+
if (!target.toolName) target.toolName = toolName(message);
|
|
64
|
+
if (!target.finishEntryId) target.finishEntryId = persistedEntryId;
|
|
65
|
+
if (!existing) targets.set(toolCallId, target);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
return [...targets.values()];
|
|
70
|
+
}
|
|
@@ -0,0 +1,375 @@
|
|
|
1
|
+
import {
|
|
2
|
+
normalizeSubagentLaunchSlotRoles,
|
|
3
|
+
SUBAGENT_LAUNCH_SLOT_THINKING_LEVELS,
|
|
4
|
+
} from "./subagent-launch-slots.mjs";
|
|
5
|
+
|
|
6
|
+
const SUPPORTED_TOOLS = new Set(["subagent", "subagent_gate"]);
|
|
7
|
+
const WORKFLOW_WRAPPER_MARKER = "/* PI_WEBUI_SUBAGENT_LAUNCH_SLOTS_V1 */";
|
|
8
|
+
const WRAPPED_WORKFLOW_INPUTS = new WeakSet();
|
|
9
|
+
const REVIEWER_ROLE = "reviewer";
|
|
10
|
+
const MAX_DEVIATIONS = 8;
|
|
11
|
+
const MAX_DEVIATION_ID_LENGTH = 160;
|
|
12
|
+
const MAX_REQUESTED_MODEL_LENGTH = 280;
|
|
13
|
+
const THINKING_LEVELS = new Set(SUBAGENT_LAUNCH_SLOT_THINKING_LEVELS);
|
|
14
|
+
const THINKING_SUFFIX_PATTERN = new RegExp(`:(${SUBAGENT_LAUNCH_SLOT_THINKING_LEVELS.join("|")})$`, "i");
|
|
15
|
+
|
|
16
|
+
function isRecord(value) {
|
|
17
|
+
return !!value && typeof value === "object" && !Array.isArray(value);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function modelSpec(slot) {
|
|
21
|
+
if (!slot?.model) return "";
|
|
22
|
+
return slot.thinking ? `${slot.model}:${slot.thinking}` : slot.model;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function parseModelSpec(value) {
|
|
26
|
+
const requestedModel = typeof value === "string" ? value.trim() : "";
|
|
27
|
+
const match = requestedModel.match(THINKING_SUFFIX_PATTERN);
|
|
28
|
+
if (!match || !THINKING_LEVELS.has(match[1].toLowerCase())) {
|
|
29
|
+
return { requestedModel, model: requestedModel, thinking: null };
|
|
30
|
+
}
|
|
31
|
+
return {
|
|
32
|
+
requestedModel,
|
|
33
|
+
model: requestedModel.slice(0, -match[0].length),
|
|
34
|
+
thinking: match[1],
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function requestedRole(value) {
|
|
39
|
+
return typeof value === "string" ? value.trim() : "";
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function hasExplicitModel(value) {
|
|
43
|
+
return typeof value === "string" && value.trim().length > 0;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function occurrence(map, role) {
|
|
47
|
+
const index = map.get(role) || 0;
|
|
48
|
+
map.set(role, index + 1);
|
|
49
|
+
return index;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function boundedDeviations(value) {
|
|
53
|
+
if (!Array.isArray(value)) return [];
|
|
54
|
+
const deviations = [];
|
|
55
|
+
const seenIds = new Set();
|
|
56
|
+
for (const item of value.slice(0, MAX_DEVIATIONS)) {
|
|
57
|
+
if (!isRecord(item)
|
|
58
|
+
|| typeof item.id !== "string"
|
|
59
|
+
|| item.id.length === 0
|
|
60
|
+
|| item.id.length > MAX_DEVIATION_ID_LENGTH
|
|
61
|
+
|| item.role !== REVIEWER_ROLE
|
|
62
|
+
|| !Number.isInteger(item.occurrence)
|
|
63
|
+
|| item.occurrence < 1
|
|
64
|
+
|| item.occurrence > MAX_DEVIATIONS
|
|
65
|
+
|| typeof item.requestedModel !== "string"
|
|
66
|
+
|| item.requestedModel.length === 0
|
|
67
|
+
|| item.requestedModel.length > MAX_REQUESTED_MODEL_LENGTH
|
|
68
|
+
|| item.requestedModel.trim() !== item.requestedModel
|
|
69
|
+
|| !Number.isSafeInteger(item.expiresAt)
|
|
70
|
+
|| item.expiresAt <= 0
|
|
71
|
+
|| seenIds.has(item.id)) continue;
|
|
72
|
+
seenIds.add(item.id);
|
|
73
|
+
deviations.push({
|
|
74
|
+
id: item.id,
|
|
75
|
+
role: REVIEWER_ROLE,
|
|
76
|
+
occurrence: item.occurrence,
|
|
77
|
+
requestedModel: item.requestedModel,
|
|
78
|
+
expiresAt: item.expiresAt,
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
return deviations;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function reviewerMismatch(slot, requested, occurrenceNumber, location) {
|
|
85
|
+
const expected = parseModelSpec(modelSpec(slot));
|
|
86
|
+
if (!expected.requestedModel || expected.requestedModel === requested.requestedModel) return null;
|
|
87
|
+
const code = expected.model !== requested.model
|
|
88
|
+
? "reviewer-model-mismatch"
|
|
89
|
+
: "reviewer-thinking-mismatch";
|
|
90
|
+
return {
|
|
91
|
+
code,
|
|
92
|
+
role: REVIEWER_ROLE,
|
|
93
|
+
occurrence: occurrenceNumber,
|
|
94
|
+
location,
|
|
95
|
+
slotId: slot.id,
|
|
96
|
+
expectedModel: expected.requestedModel,
|
|
97
|
+
requestedModel: requested.requestedModel,
|
|
98
|
+
correctionModel: expected.requestedModel,
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
function matchingDeviationIndex(deviations, consumedIndexes, occurrenceNumber, requestedModel, now = Date.now()) {
|
|
103
|
+
return deviations.findIndex((deviation, index) => !consumedIndexes.has(index)
|
|
104
|
+
&& deviation.expiresAt > now
|
|
105
|
+
&& deviation.occurrence === occurrenceNumber
|
|
106
|
+
&& deviation.requestedModel === requestedModel);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function enforceReviewerModel(target, role, slot, occurrenceNumber, location, policy) {
|
|
110
|
+
if (role !== REVIEWER_ROLE || !slot?.model || !hasExplicitModel(target.model)) return;
|
|
111
|
+
const requested = parseModelSpec(target.model);
|
|
112
|
+
const decision = reviewerMismatch(slot, requested, occurrenceNumber, location);
|
|
113
|
+
if (!decision) return;
|
|
114
|
+
const deviationIndex = matchingDeviationIndex(
|
|
115
|
+
policy.deviations,
|
|
116
|
+
policy.consumedDeviationIndexes,
|
|
117
|
+
occurrenceNumber,
|
|
118
|
+
requested.requestedModel,
|
|
119
|
+
);
|
|
120
|
+
if (deviationIndex >= 0) {
|
|
121
|
+
policy.consumedDeviationIndexes.add(deviationIndex);
|
|
122
|
+
const id = policy.deviations[deviationIndex].id;
|
|
123
|
+
if (!policy.report.consumedDeviationIds.includes(id)) policy.report.consumedDeviationIds.push(id);
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
policy.report.blocked.push(decision);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
function applyRolePreset(target, role, roles, occurrences, report, location, policy) {
|
|
130
|
+
if (!isRecord(target) || !Object.hasOwn(roles, role)) return;
|
|
131
|
+
const index = occurrence(occurrences, role);
|
|
132
|
+
const slot = roles[role][index];
|
|
133
|
+
if (!slot) {
|
|
134
|
+
report.unsupported.push({ role, occurrence: index + 1, location, reason: "slot-overflow" });
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
const model = modelSpec(slot);
|
|
138
|
+
enforceReviewerModel(target, role, slot, index + 1, location, policy);
|
|
139
|
+
if (!model || hasExplicitModel(target.model)) return;
|
|
140
|
+
target.model = model;
|
|
141
|
+
report.applied.push({ role, occurrence: index + 1, slotId: slot.id, model, location });
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
function applyCountedRolePreset(target, role, count, roles, occurrences, report, location, policy) {
|
|
145
|
+
const start = occurrences.get(role) || 0;
|
|
146
|
+
const copies = Number.isInteger(count) && count > 0 ? count : 1;
|
|
147
|
+
const slots = roles[role]?.slice(start, start + copies) || [];
|
|
148
|
+
occurrences.set(role, start + copies);
|
|
149
|
+
if (slots.length !== copies) {
|
|
150
|
+
report.unsupported.push({ role, occurrence: start + 1, location, reason: "slot-overflow" });
|
|
151
|
+
}
|
|
152
|
+
if (hasExplicitModel(target.model)) {
|
|
153
|
+
for (const [offset, slot] of slots.entries()) {
|
|
154
|
+
enforceReviewerModel(target, role, slot, start + offset + 1, location, policy);
|
|
155
|
+
}
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
if (slots.length !== copies) return;
|
|
159
|
+
const models = [...new Set(slots.map(modelSpec).filter(Boolean))];
|
|
160
|
+
if (models.length === 0) return;
|
|
161
|
+
if (models.length !== 1 || slots.some((slot) => !modelSpec(slot))) {
|
|
162
|
+
report.unsupported.push({ role, occurrence: start + 1, location, reason: "count-needs-explicit-tasks" });
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
target.model = models[0];
|
|
166
|
+
report.applied.push({ role, occurrence: start + 1, count: copies, slotId: slots[0].id, model: models[0], location });
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
function applyTaskList(tasks, roles, occurrences, report, prefix, policy) {
|
|
170
|
+
if (!Array.isArray(tasks)) return;
|
|
171
|
+
for (const [index, task] of tasks.entries()) {
|
|
172
|
+
const role = requestedRole(task?.agent);
|
|
173
|
+
if (!role) continue;
|
|
174
|
+
applyCountedRolePreset(task, role, task?.count, roles, occurrences, report, `${prefix}[${index}]`, policy);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
function applyLegacyChain(chain, roles, occurrences, report, policy) {
|
|
179
|
+
if (!Array.isArray(chain)) return;
|
|
180
|
+
for (const [stepIndex, step] of chain.entries()) {
|
|
181
|
+
if (!isRecord(step)) continue;
|
|
182
|
+
const role = requestedRole(step.agent);
|
|
183
|
+
if (role) {
|
|
184
|
+
applyRolePreset(step, role, roles, occurrences, report, `chain[${stepIndex}]`, policy);
|
|
185
|
+
continue;
|
|
186
|
+
}
|
|
187
|
+
if (Array.isArray(step.parallel)) {
|
|
188
|
+
applyTaskList(step.parallel, roles, occurrences, report, `chain[${stepIndex}].parallel`, policy);
|
|
189
|
+
continue;
|
|
190
|
+
}
|
|
191
|
+
if (isRecord(step.parallel)) {
|
|
192
|
+
const dynamicRole = requestedRole(step.parallel.agent);
|
|
193
|
+
if (dynamicRole) report.unsupported.push({ role: dynamicRole, occurrence: occurrence(occurrences, dynamicRole) + 1, location: `chain[${stepIndex}].parallel`, reason: "dynamic-needs-explicit-model" });
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
function workflowRoleSlots(roles) {
|
|
199
|
+
return Object.fromEntries(Object.entries(roles).flatMap(([role, slots]) => {
|
|
200
|
+
const values = slots.map((slot) => ({ id: slot.id, model: modelSpec(slot) || null }));
|
|
201
|
+
return values.some((slot) => slot.model) ? [[role, values]] : [];
|
|
202
|
+
}));
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
function wrapWorkflowScript(script, roles, deviations) {
|
|
206
|
+
const roleSlots = workflowRoleSlots(roles);
|
|
207
|
+
if (Object.keys(roleSlots).length === 0) return script;
|
|
208
|
+
return [
|
|
209
|
+
WORKFLOW_WRAPPER_MARKER,
|
|
210
|
+
"runs = ((__piWebuiOriginalRuns) => {",
|
|
211
|
+
" const __piWebuiArrayIsArray = Array.isArray;",
|
|
212
|
+
" const __piWebuiCreateRecord = Object.create;",
|
|
213
|
+
" const __piWebuiDefineProperty = Object.defineProperty;",
|
|
214
|
+
" const __piWebuiSetPrototypeOf = Object.setPrototypeOf;",
|
|
215
|
+
" const __piWebuiHasOwn = Object.hasOwn;",
|
|
216
|
+
" const __piWebuiError = Error;",
|
|
217
|
+
" const __piWebuiTrim = Function.call.bind(String.prototype.trim);",
|
|
218
|
+
" const __piWebuiSlice = Function.call.bind(String.prototype.slice);",
|
|
219
|
+
" const __piWebuiRegExpExec = Function.call.bind(RegExp.prototype.exec);",
|
|
220
|
+
` const __piWebuiRoleSlots = ${JSON.stringify(roleSlots)};`,
|
|
221
|
+
" __piWebuiSetPrototypeOf(__piWebuiRoleSlots, null);",
|
|
222
|
+
` const __piWebuiDeviations = ${JSON.stringify(deviations)};`,
|
|
223
|
+
` const __piWebuiThinkingPattern = ${THINKING_SUFFIX_PATTERN.toString()};`,
|
|
224
|
+
" const __piWebuiNow = Date.now.bind(Date);",
|
|
225
|
+
" const __piWebuiRoleOccurrences = __piWebuiCreateRecord(null);",
|
|
226
|
+
" const __piWebuiConsumedDeviationIndexes = __piWebuiCreateRecord(null);",
|
|
227
|
+
" const __piWebuiOriginalRun = __piWebuiOriginalRuns.run.bind(__piWebuiOriginalRuns);",
|
|
228
|
+
" const __piWebuiOriginalAll = __piWebuiOriginalRuns.all.bind(__piWebuiOriginalRuns);",
|
|
229
|
+
" const __piWebuiOriginalStatus = __piWebuiOriginalRuns.status.bind(__piWebuiOriginalRuns);",
|
|
230
|
+
" const __piWebuiOriginalRef = __piWebuiOriginalRuns.ref.bind(__piWebuiOriginalRuns);",
|
|
231
|
+
" const __piWebuiOriginalRefs = __piWebuiOriginalRuns.refs.bind(__piWebuiOriginalRuns);",
|
|
232
|
+
" const __piWebuiSnapshotRecord = (value) => {",
|
|
233
|
+
" if (!value || typeof value !== 'object' || __piWebuiArrayIsArray(value)) return value;",
|
|
234
|
+
" const snapshot = { ...value };",
|
|
235
|
+
" __piWebuiSetPrototypeOf(snapshot, null);",
|
|
236
|
+
" return snapshot;",
|
|
237
|
+
" };",
|
|
238
|
+
" const __piWebuiCloneRecord = (source) => {",
|
|
239
|
+
" const clone = __piWebuiCreateRecord(null);",
|
|
240
|
+
" for (const key in source) clone[key] = source[key];",
|
|
241
|
+
" return clone;",
|
|
242
|
+
" };",
|
|
243
|
+
" const __piWebuiCommitRecord = (target, source) => {",
|
|
244
|
+
" for (const key in source) target[key] = source[key];",
|
|
245
|
+
" };",
|
|
246
|
+
" const __piWebuiParseModel = (value) => {",
|
|
247
|
+
" const requestedModel = typeof value === 'string' ? __piWebuiTrim(value) : '';",
|
|
248
|
+
" const match = __piWebuiRegExpExec(__piWebuiThinkingPattern, requestedModel);",
|
|
249
|
+
" return match ? { requestedModel, model: __piWebuiSlice(requestedModel, 0, -match[0].length), thinking: match[1] } : { requestedModel, model: requestedModel, thinking: null };",
|
|
250
|
+
" };",
|
|
251
|
+
" const __piWebuiPrepare = (params, location, occurrences, consumedDeviationIndexes, decisions) => {",
|
|
252
|
+
" if (!params || typeof params !== 'object' || __piWebuiArrayIsArray(params) || params.resume !== undefined || typeof params.agent !== 'string') return params;",
|
|
253
|
+
" const role = __piWebuiTrim(params.agent);",
|
|
254
|
+
" const slots = __piWebuiRoleSlots[role];",
|
|
255
|
+
" if (!slots) return params;",
|
|
256
|
+
" const index = occurrences[role] || 0;",
|
|
257
|
+
" occurrences[role] = index + 1;",
|
|
258
|
+
" const slot = __piWebuiHasOwn(slots, index) ? slots[index] : undefined;",
|
|
259
|
+
" if (!slot || !slot.model) return params;",
|
|
260
|
+
" const modelValue = params.model;",
|
|
261
|
+
" const explicit = typeof modelValue === 'string' ? __piWebuiTrim(modelValue) : '';",
|
|
262
|
+
" if (!explicit) {",
|
|
263
|
+
" __piWebuiDefineProperty(params, 'model', { value: slot.model, writable: true, enumerable: true, configurable: true });",
|
|
264
|
+
" return params;",
|
|
265
|
+
" }",
|
|
266
|
+
` if (role !== ${JSON.stringify(REVIEWER_ROLE)}) return params;`,
|
|
267
|
+
" const expected = __piWebuiParseModel(slot.model);",
|
|
268
|
+
" const requested = __piWebuiParseModel(explicit);",
|
|
269
|
+
" if (expected.requestedModel === requested.requestedModel) return params;",
|
|
270
|
+
" const now = __piWebuiNow();",
|
|
271
|
+
" let deviationIndex = -1;",
|
|
272
|
+
" for (let candidateIndex = 0; candidateIndex < __piWebuiDeviations.length; candidateIndex += 1) {",
|
|
273
|
+
" const deviation = __piWebuiDeviations[candidateIndex];",
|
|
274
|
+
" if (consumedDeviationIndexes[candidateIndex] !== true && deviation.expiresAt > now && deviation.occurrence === index + 1 && deviation.requestedModel === requested.requestedModel) {",
|
|
275
|
+
" deviationIndex = candidateIndex;",
|
|
276
|
+
" break;",
|
|
277
|
+
" }",
|
|
278
|
+
" }",
|
|
279
|
+
" if (deviationIndex >= 0) { consumedDeviationIndexes[deviationIndex] = true; return params; }",
|
|
280
|
+
" __piWebuiDefineProperty(decisions, decisions.length, {",
|
|
281
|
+
" value: {",
|
|
282
|
+
" code: expected.model !== requested.model ? 'reviewer-model-mismatch' : 'reviewer-thinking-mismatch',",
|
|
283
|
+
" role, occurrence: index + 1, location, slotId: slot.id, expectedModel: expected.requestedModel, requestedModel: requested.requestedModel, correctionModel: expected.requestedModel,",
|
|
284
|
+
" },",
|
|
285
|
+
" writable: true, enumerable: true, configurable: true,",
|
|
286
|
+
" });",
|
|
287
|
+
" return params;",
|
|
288
|
+
" };",
|
|
289
|
+
" const __piWebuiThrowBlocked = (decisions) => {",
|
|
290
|
+
" const error = new __piWebuiError('Reviewer model policy blocked the requested workflow launch.');",
|
|
291
|
+
" __piWebuiDefineProperty(error, 'code', { value: 'reviewer-model-policy-blocked', writable: true, enumerable: true, configurable: true });",
|
|
292
|
+
" __piWebuiDefineProperty(error, 'decisions', { value: decisions, writable: true, enumerable: true, configurable: true });",
|
|
293
|
+
" throw error;",
|
|
294
|
+
" };",
|
|
295
|
+
" const __piWebuiRuns = Object.freeze({",
|
|
296
|
+
" run(key, params) {",
|
|
297
|
+
" const prepared = __piWebuiSnapshotRecord(params);",
|
|
298
|
+
" const occurrences = __piWebuiCloneRecord(__piWebuiRoleOccurrences);",
|
|
299
|
+
" const consumed = __piWebuiCloneRecord(__piWebuiConsumedDeviationIndexes);",
|
|
300
|
+
" const decisions = [];",
|
|
301
|
+
" __piWebuiPrepare(prepared, 'runs.run', occurrences, consumed, decisions);",
|
|
302
|
+
" if (decisions.length) return __piWebuiThrowBlocked(decisions);",
|
|
303
|
+
" const result = __piWebuiOriginalRun(key, prepared);",
|
|
304
|
+
" __piWebuiCommitRecord(__piWebuiRoleOccurrences, occurrences);",
|
|
305
|
+
" __piWebuiCommitRecord(__piWebuiConsumedDeviationIndexes, consumed);",
|
|
306
|
+
" return result;",
|
|
307
|
+
" },",
|
|
308
|
+
" all(items) {",
|
|
309
|
+
" if (!__piWebuiArrayIsArray(items)) return __piWebuiOriginalAll(items);",
|
|
310
|
+
" const itemCount = items.length;",
|
|
311
|
+
" const prepared = [];",
|
|
312
|
+
" prepared.length = itemCount;",
|
|
313
|
+
" for (let index = 0; index < itemCount; index += 1) {",
|
|
314
|
+
" if (__piWebuiHasOwn(items, index)) {",
|
|
315
|
+
" __piWebuiDefineProperty(prepared, index, { value: __piWebuiSnapshotRecord(items[index]), writable: true, enumerable: true, configurable: true });",
|
|
316
|
+
" }",
|
|
317
|
+
" }",
|
|
318
|
+
" const occurrences = __piWebuiCloneRecord(__piWebuiRoleOccurrences);",
|
|
319
|
+
" const consumed = __piWebuiCloneRecord(__piWebuiConsumedDeviationIndexes);",
|
|
320
|
+
" const decisions = [];",
|
|
321
|
+
" for (let index = 0; index < itemCount; index += 1) {",
|
|
322
|
+
" if (__piWebuiHasOwn(prepared, index)) __piWebuiPrepare(prepared[index], `runs.all[${index}]`, occurrences, consumed, decisions);",
|
|
323
|
+
" }",
|
|
324
|
+
" if (decisions.length) return __piWebuiThrowBlocked(decisions);",
|
|
325
|
+
" const result = __piWebuiOriginalAll(prepared);",
|
|
326
|
+
" __piWebuiCommitRecord(__piWebuiRoleOccurrences, occurrences);",
|
|
327
|
+
" __piWebuiCommitRecord(__piWebuiConsumedDeviationIndexes, consumed);",
|
|
328
|
+
" return result;",
|
|
329
|
+
" },",
|
|
330
|
+
" status(keyOrRunId) { return __piWebuiOriginalStatus(keyOrRunId); },",
|
|
331
|
+
" ref(result) { return __piWebuiOriginalRef(result); },",
|
|
332
|
+
" refs(results) { return __piWebuiOriginalRefs(results); },",
|
|
333
|
+
" });",
|
|
334
|
+
" return __piWebuiRuns;",
|
|
335
|
+
"})(runs);",
|
|
336
|
+
script,
|
|
337
|
+
].join("\n");
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
/**
|
|
341
|
+
* Fill omitted model fields and report explicit reviewer model policy decisions.
|
|
342
|
+
* Deviation descriptors are caller-owned, capped, and matched once per invocation.
|
|
343
|
+
*/
|
|
344
|
+
export function applySubagentLaunchSlotDefaults(toolName, input, roleConfig, options = {}) {
|
|
345
|
+
const report = { applied: [], unsupported: [], blocked: [], consumedDeviationIds: [] };
|
|
346
|
+
if (!SUPPORTED_TOOLS.has(toolName) || !isRecord(input)) return report;
|
|
347
|
+
|
|
348
|
+
const roles = normalizeSubagentLaunchSlotRoles(roleConfig);
|
|
349
|
+
const occurrences = new Map();
|
|
350
|
+
const deviations = boundedDeviations(options?.deviations);
|
|
351
|
+
const policy = { deviations, consumedDeviationIndexes: new Set(), report };
|
|
352
|
+
|
|
353
|
+
if (toolName === "subagent_gate") {
|
|
354
|
+
applyTaskList(input.tasks, roles, occurrences, report, "tasks", policy);
|
|
355
|
+
return report;
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
if (input.action !== undefined || input.resume !== undefined) return report;
|
|
359
|
+
if (typeof input.workflowScript === "string" && input.workflowScript.trim()) {
|
|
360
|
+
if (WRAPPED_WORKFLOW_INPUTS.has(input)) return report;
|
|
361
|
+
const wrapped = wrapWorkflowScript(input.workflowScript, roles, deviations);
|
|
362
|
+
if (wrapped !== input.workflowScript) {
|
|
363
|
+
input.workflowScript = wrapped;
|
|
364
|
+
WRAPPED_WORKFLOW_INPUTS.add(input);
|
|
365
|
+
report.applied.push({ location: "workflowScript", reason: "runtime-role-defaults" });
|
|
366
|
+
}
|
|
367
|
+
return report;
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
const role = requestedRole(input.agent);
|
|
371
|
+
if (role) applyRolePreset(input, role, roles, occurrences, report, "agent", policy);
|
|
372
|
+
applyTaskList(input.tasks, roles, occurrences, report, "tasks", policy);
|
|
373
|
+
applyLegacyChain(input.chain, roles, occurrences, report, policy);
|
|
374
|
+
return report;
|
|
375
|
+
}
|
|
@@ -309,8 +309,9 @@ export function formatSubagentLaunchSlotGuidance(roles) {
|
|
|
309
309
|
if (!assignments.length) return "";
|
|
310
310
|
return [
|
|
311
311
|
"## WebUI subagent launch slots",
|
|
312
|
-
"These are
|
|
312
|
+
"These are the role-specific model defaults for future delegation in this Pi tab. Explicit user instructions in the current request win.",
|
|
313
313
|
...assignments.slice(0, SUBAGENT_LAUNCH_SLOT_LIMITS.totalSlots),
|
|
314
|
+
"The WebUI runtime fills omitted model fields for structured subagent and subagent_gate launches, including runs.run and runs.all workflow children. Preserve those defaults unless the current user explicitly requests another model.",
|
|
314
315
|
"When launching multiple slots of one role, create separate task entries so each model remains explicit; do not replace them with count when model specs differ.",
|
|
315
316
|
].join("\n");
|
|
316
317
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@firstpick/pi-package-webui",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.7",
|
|
4
4
|
"description": "Pi Web UI companion package with a local browser UI CLI plus /webui-start and /webui-status commands.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://github.com/Firstp1ck/pi-coding-agent-forge/tree/main/pi-package-webui#readme",
|