@firstpick/pi-package-webui 0.10.0 → 0.10.2

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.
Files changed (49) hide show
  1. package/DEVELOPMENT.md +20 -21
  2. package/README.md +7 -5
  3. package/TECHNICAL.md +6 -2
  4. package/bin/pi-webui.mjs +26 -60
  5. package/index.ts +1 -256
  6. package/package.json +1 -1
  7. package/public/app.js +145 -33
  8. package/public/index.html +10 -7
  9. package/public/service-worker.js +1 -1
  10. package/public/styles.css +51 -7
  11. package/tests/boot-failure-diagnostics.test.mjs +3 -3
  12. package/tests/browser/interaction-continuity.spec.mjs +9 -3
  13. package/tests/codex-fast-mode-static.test.mjs +2 -2
  14. package/tests/composer-action-grid-reorder-static.test.mjs +3 -3
  15. package/tests/control-visibility-static.test.mjs +3 -3
  16. package/tests/controls-layout-static.test.mjs +3 -3
  17. package/tests/events-tree-context-menu-static.test.mjs +3 -3
  18. package/tests/fast-mode-client-static.test.mjs +1 -1
  19. package/tests/feature-decision-output-popup-static.test.mjs +2 -2
  20. package/tests/file-viewer-image-static.test.mjs +3 -3
  21. package/tests/guided-git-activation-static.test.mjs +11 -4
  22. package/tests/guided-git-fallback-runtime.test.mjs +46 -21
  23. package/tests/guided-git-fallback-ui-static.test.mjs +3 -3
  24. package/tests/guided-git-publication-backend-static.test.mjs +10 -5
  25. package/tests/http-endpoints-harness.test.mjs +5 -9
  26. package/tests/intercom-conversation-viewer-static.test.mjs +3 -3
  27. package/tests/main-output-loading-static.test.mjs +18 -12
  28. package/tests/middle-button-drag-scroll-static.test.mjs +3 -3
  29. package/tests/mobile-continuity-tablet-static.test.mjs +3 -3
  30. package/tests/mobile-foundation-static.test.mjs +3 -3
  31. package/tests/mobile-phone-experience-static.test.mjs +1 -1
  32. package/tests/mobile-static.test.mjs +11 -7
  33. package/tests/open-issue-wizard-static.test.mjs +1 -1
  34. package/tests/optional-feature-prompt-impact-static.test.mjs +67 -0
  35. package/tests/persistent-ui-layout-static.test.mjs +3 -3
  36. package/tests/prompt-input-vertical-scroll-static.test.mjs +3 -3
  37. package/tests/questionnaire-dialog.test.mjs +3 -3
  38. package/tests/resource-tui-extension.test.mjs +4 -18
  39. package/tests/session-sampling-ui-static.test.mjs +3 -3
  40. package/tests/side-panel-section-height-removal-static.test.mjs +3 -3
  41. package/tests/streaming-ui-coupling.test.mjs +2 -0
  42. package/tests/subagent-observability-static.test.mjs +2 -2
  43. package/tests/syntax-highlighting-static.test.mjs +3 -3
  44. package/tests/theme-customizer-static.test.mjs +1 -1
  45. package/tests/windows-drive-cwd-picker-static.test.mjs +3 -3
  46. package/lib/tui-model-profile-selector.mjs +0 -183
  47. package/lib/tui-resource-selector.mjs +0 -173
  48. package/tests/tui-model-profile-selector.test.mjs +0 -102
  49. package/tests/tui-resource-selector.test.mjs +0 -74
package/index.ts CHANGED
@@ -3,7 +3,7 @@ import path from "node:path";
3
3
  import { homedir } from "node:os";
4
4
  import type { Readable } from "node:stream";
5
5
  import { fileURLToPath } from "node:url";
6
- import { formatSkillsForPrompt, type ExtensionAPI, type ExtensionCommandContext } from "@earendil-works/pi-coding-agent";
6
+ import type { ExtensionAPI, ExtensionCommandContext } from "@earendil-works/pi-coding-agent";
7
7
  import { delay, takeValue, tokenizeArgs } from "@firstpick/pi-utils";
8
8
  import { detachChildProcess as releaseStartedChild, isProcessRunning, terminateChildProcess as terminateFailedChild } from "@firstpick/pi-utils/process";
9
9
  import { fetchJsonWithTimeout as fetchJsonWithTimeoutBase } from "@firstpick/pi-utils/http";
@@ -12,21 +12,9 @@ import { createRestoreFile } from "./lib/update/supervisor.mjs";
12
12
  import {
13
13
  gitWorkflowPreferencesSummary,
14
14
  readGitWorkflowPreferences,
15
- readWebuiSettings,
16
15
  supportedGitWorkflowThinkingLevels,
17
- updateWebuiSettings,
18
16
  writeGitWorkflowPreferences,
19
17
  } from "./lib/git-workflow-preferences.mjs";
20
- import {
21
- branchResourceDirective,
22
- exactModelProfile,
23
- normalizeResourceNameList,
24
- preserveUnavailableResourceNames,
25
- resolveResourceSelection,
26
- setExactModelProfile,
27
- } from "./lib/resource-selection.mjs";
28
- import { selectTuiModelProfile } from "./lib/tui-model-profile-selector.mjs";
29
- import { selectTuiResources } from "./lib/tui-resource-selector.mjs";
30
18
 
31
19
  const __dirname = path.dirname(fileURLToPath(import.meta.url));
32
20
  const packageRoot = __dirname;
@@ -881,250 +869,7 @@ async function runGitWorkflowSetup(ctx: ExtensionCommandContext): Promise<void>
881
869
  }
882
870
  }
883
871
 
884
- function lastResourceBranchConfig(ctx: ExtensionCommandContext, customType: string): any {
885
- let found: any;
886
- for (const entry of ctx.sessionManager.getBranch()) {
887
- if ((entry as any)?.type === "custom" && (entry as any).customType === customType) found = (entry as any).data;
888
- }
889
- return found;
890
- }
891
-
892
- function registerTuiResourceController(pi: ExtensionAPI): void {
893
- let runtimeToolBaseline: string[] | undefined;
894
- let enabledTools = new Set<string>();
895
- let enabledSkills: Set<string> | null = null;
896
- let legacyDisabledSkills = new Set<string>();
897
- let toolsPinned = false;
898
- let skillsPinned = false;
899
- let tuiActive = false;
900
- let generation = 0;
901
-
902
- const modelKey = (model: any): string => model?.provider && model?.id ? `${model.provider}\0${model.id}` : "";
903
- const runtimeTools = (): string[] => runtimeToolBaseline ??= normalizeResourceNameList(pi.getActiveTools()) || [];
904
- const toolNames = (): string[] => pi.getAllTools().map((tool: any) => tool.name);
905
- const skills = (ctx: ExtensionCommandContext): any[] => {
906
- const options = (ctx as any).getSystemPromptOptions?.();
907
- return Array.isArray(options?.skills) ? options.skills : [];
908
- };
909
- const isSkillEnabled = (name: string): boolean => enabledSkills instanceof Set ? enabledSkills.has(name) : !legacyDisabledSkills.has(name);
910
-
911
- function applyResolvedState(ctx: ExtensionCommandContext, defaults: any, model: any): void {
912
- const toolDirective = branchResourceDirective(lastResourceBranchConfig(ctx, "webui-tools-config"), "tools");
913
- toolsPinned = toolDirective.pinned;
914
- const baseline = runtimeTools();
915
- const resolvedTools = toolDirective.pinned
916
- ? { names: toolDirective.names || [], source: "session" }
917
- : resolveResourceSelection(defaults, "tools", model?.provider, model?.id, baseline);
918
- enabledTools = new Set(resolvedTools.names || baseline);
919
- const existingTools = new Set(toolNames());
920
- pi.setActiveTools([...enabledTools].filter((name) => existingTools.has(name)));
921
-
922
- const skillDirective = branchResourceDirective(lastResourceBranchConfig(ctx, "webui-skills-config"), "skills");
923
- skillsPinned = skillDirective.pinned;
924
- legacyDisabledSkills = new Set();
925
- if (skillDirective.pinned && skillDirective.legacyDisabledNames !== null) {
926
- enabledSkills = null;
927
- legacyDisabledSkills = new Set(skillDirective.legacyDisabledNames);
928
- } else {
929
- const resolvedSkills = skillDirective.pinned
930
- ? { names: skillDirective.names || [], source: "session" }
931
- : resolveResourceSelection(defaults, "skills", model?.provider, model?.id, null);
932
- enabledSkills = resolvedSkills.names === null ? null : new Set(resolvedSkills.names);
933
- }
934
- }
935
-
936
- async function recompute(ctx: ExtensionCommandContext, requestedModel: any = ctx.model): Promise<boolean> {
937
- if (ctx.mode !== "tui") return false;
938
- const requestedKey = modelKey(requestedModel);
939
- const currentGeneration = ++generation;
940
- let defaults;
941
- try {
942
- defaults = (await readWebuiSettings()).resourceDefaults;
943
- } catch (error) {
944
- ctx.ui.notify(`Resource defaults could not be read: ${error instanceof Error ? error.message : String(error)}`, "error");
945
- return false;
946
- }
947
- if (currentGeneration !== generation || modelKey(ctx.model) !== requestedKey) return false;
948
- applyResolvedState(ctx, defaults, requestedModel);
949
- return true;
950
- }
951
-
952
- function availableModels(ctx: ExtensionCommandContext): any[] {
953
- return ctx.modelRegistry.getAvailable()
954
- .filter((model: any) => model?.provider && model?.id)
955
- .sort((left: any, right: any) => `${left.provider}/${left.id}`.localeCompare(`${right.provider}/${right.id}`));
956
- }
957
-
958
- async function runSelector(resourceType: "tools" | "skills", ctx: ExtensionCommandContext): Promise<void> {
959
- if (ctx.mode !== "tui") {
960
- ctx.ui.notify(`/${resourceType} is available in interactive TUI mode only.`, "warning");
961
- return;
962
- }
963
- const resourceLabel = resourceType === "tools" ? "Tools" : "Skills";
964
- const scope = await ctx.ui.select(`${resourceLabel} setup`, ["Session only", "Global default", "Model default"]);
965
- if (!scope) return;
966
- const settings = await readWebuiSettings();
967
- const visibleNames = resourceType === "tools" ? toolNames() : skills(ctx).map((skill: any) => skill.name);
968
- const selectionKey = resourceType === "tools" ? "enabledTools" : "enabledSkills";
969
- let previousNames: string[] | null = null;
970
- let provider = "";
971
- let modelId = "";
972
-
973
- if (scope === "Session only") {
974
- const action = await ctx.ui.select(`${resourceLabel} for this session`, ["Edit selection", "Use inherited defaults"]);
975
- if (!action) return;
976
- if (action === "Use inherited defaults") {
977
- pi.appendEntry(resourceType === "tools" ? "webui-tools-config" : "webui-skills-config", { version: 2, mode: "inherit" });
978
- await recompute(ctx);
979
- ctx.ui.notify(`${resourceLabel} now use inherited defaults.`, "info");
980
- return;
981
- }
982
- previousNames = resourceType === "tools"
983
- ? [...enabledTools]
984
- : enabledSkills instanceof Set ? [...enabledSkills] : visibleNames.filter((name) => !legacyDisabledSkills.has(name));
985
- } else if (scope === "Global default") {
986
- const action = await ctx.ui.select(`Global ${resourceLabel.toLowerCase()} default`, ["Edit selection", "Use Pi runtime default"]);
987
- if (!action) return;
988
- if (action === "Use Pi runtime default") {
989
- await updateWebuiSettings(() => ({ resourceDefaults: { [resourceType]: { [selectionKey]: null } } }));
990
- await recompute(ctx);
991
- ctx.ui.notify(`Global ${resourceLabel.toLowerCase()} default now inherits Pi runtime behavior.`, "info");
992
- return;
993
- }
994
- previousNames = settings.resourceDefaults?.[resourceType]?.[selectionKey];
995
- if (previousNames === null) previousNames = resolveResourceSelection(settings.resourceDefaults, resourceType, "", "", resourceType === "tools" ? runtimeTools() : null).names;
996
- } else {
997
- const models = availableModels(ctx);
998
- if (!models.length) {
999
- ctx.ui.notify("No authenticated Pi models are available.", "warning");
1000
- return;
1001
- }
1002
- const configuredModelKeys = (Array.isArray(settings.resourceDefaults?.modelProfiles)
1003
- ? settings.resourceDefaults.modelProfiles
1004
- : [])
1005
- .filter((profile: any) => Array.isArray(profile?.[resourceType]?.[selectionKey]))
1006
- .map((profile: any) => `${profile.provider}\0${profile.modelId}`);
1007
- const model = await selectTuiModelProfile(ctx, {
1008
- title: `${resourceLabel} Model Profile`,
1009
- subtitle: "Choose a profile to edit. This does not switch the active model.",
1010
- models,
1011
- activeModelKey: modelKey(ctx.model),
1012
- configuredModelKeys,
1013
- });
1014
- if (!model) return;
1015
- provider = model.provider;
1016
- modelId = model.id;
1017
- const action = await ctx.ui.select(`${resourceLabel} for ${provider}/${modelId}`, ["Edit selection", "Use inherited defaults"]);
1018
- if (!action) return;
1019
- const profile = exactModelProfile(settings.resourceDefaults, provider, modelId);
1020
- previousNames = profile?.[resourceType]?.[selectionKey] ?? null;
1021
- if (action === "Use inherited defaults") {
1022
- await updateWebuiSettings((current: any) => ({
1023
- resourceDefaults: {
1024
- modelProfiles: setExactModelProfile(current.resourceDefaults, provider, modelId, resourceType, null),
1025
- },
1026
- }));
1027
- await recompute(ctx);
1028
- ctx.ui.notify(`${resourceLabel} for ${provider}/${modelId} now use inherited defaults.`, "info");
1029
- return;
1030
- }
1031
- if (previousNames === null) {
1032
- previousNames = resolveResourceSelection(settings.resourceDefaults, resourceType, provider, modelId, resourceType === "tools" ? runtimeTools() : null).names;
1033
- }
1034
- }
1035
-
1036
- const selectionTarget = scope === "Model default" ? `${provider}/${modelId} model profile` : scope;
1037
- const selected = await selectTuiResources(ctx, {
1038
- title: `${resourceLabel} Configuration`,
1039
- subtitle: `${selectionTarget}. Changes apply only after Ctrl+S.`,
1040
- resources: visibleNames,
1041
- enabledResourceNames: previousNames || [],
1042
- });
1043
- if (!selected) return;
1044
- if (scope === "Session only") {
1045
- const preserved = preserveUnavailableResourceNames(previousNames, visibleNames, selected);
1046
- pi.appendEntry(resourceType === "tools" ? "webui-tools-config" : "webui-skills-config", {
1047
- version: 2,
1048
- mode: "explicit",
1049
- [selectionKey]: preserved,
1050
- });
1051
- } else if (scope === "Global default") {
1052
- await updateWebuiSettings((current: any) => ({
1053
- resourceDefaults: {
1054
- [resourceType]: {
1055
- [selectionKey]: preserveUnavailableResourceNames(current.resourceDefaults?.[resourceType]?.[selectionKey], visibleNames, selected),
1056
- },
1057
- },
1058
- }));
1059
- } else {
1060
- await updateWebuiSettings((current: any) => {
1061
- const currentNames = exactModelProfile(current.resourceDefaults, provider, modelId)?.[resourceType]?.[selectionKey];
1062
- const preserved = preserveUnavailableResourceNames(currentNames, visibleNames, selected);
1063
- return {
1064
- resourceDefaults: {
1065
- modelProfiles: setExactModelProfile(current.resourceDefaults, provider, modelId, resourceType, preserved),
1066
- },
1067
- };
1068
- });
1069
- }
1070
- await recompute(ctx);
1071
- ctx.ui.notify(`${resourceLabel} ${selectionTarget.toLowerCase()} saved.`, "info");
1072
- }
1073
-
1074
- pi.registerCommand("tools", {
1075
- description: "Choose session, global, or exact-model tools",
1076
- handler: async (_args, ctx) => runSelector("tools", ctx),
1077
- });
1078
- pi.registerCommand("skills", {
1079
- description: "Choose session, global, or exact-model skills",
1080
- handler: async (_args, ctx) => runSelector("skills", ctx),
1081
- });
1082
- pi.on("session_start", async (_event, ctx) => {
1083
- tuiActive = ctx.mode === "tui";
1084
- if (tuiActive) {
1085
- if (runtimeToolBaseline === undefined) enabledTools = new Set(runtimeTools());
1086
- await recompute(ctx);
1087
- }
1088
- });
1089
- pi.on("session_tree", async (_event, ctx) => {
1090
- tuiActive = ctx.mode === "tui";
1091
- if (tuiActive) await recompute(ctx);
1092
- });
1093
- pi.on("model_select", async (event, ctx) => {
1094
- if (ctx.mode === "tui") await recompute(ctx, event.model);
1095
- });
1096
- pi.on("session_shutdown", () => {
1097
- tuiActive = false;
1098
- generation += 1;
1099
- });
1100
- pi.on("input", async (event, ctx) => {
1101
- if (!tuiActive || ctx.mode !== "tui") return { action: "continue" };
1102
- const match = String(event.text || "").trim().match(/^\/skill:([^\s]+)/i);
1103
- if (!match || isSkillEnabled(match[1])) return { action: "continue" };
1104
- ctx.ui.notify(`Skill /skill:${match[1]} is disabled by /skills.`, "warning");
1105
- return { action: "handled" };
1106
- });
1107
- pi.on("before_agent_start", async (event) => {
1108
- if (!tuiActive || (enabledSkills === null && legacyDisabledSkills.size === 0)) return undefined;
1109
- const allSkills = Array.isArray(event.systemPromptOptions?.skills) ? event.systemPromptOptions.skills : [];
1110
- const disabledNames = allSkills.filter((skill: any) => !isSkillEnabled(skill.name)).map((skill: any) => skill.name);
1111
- const filtered = allSkills.filter((skill: any) => isSkillEnabled(skill.name) && skill.disableModelInvocation !== true);
1112
- if (filtered.length === allSkills.length) return undefined;
1113
- let nextPrompt = event.systemPrompt;
1114
- const nextSection = formatSkillsForPrompt(filtered);
1115
- if (nextPrompt.includes("<available_skills>")) {
1116
- nextPrompt = nextPrompt.replace(/\n?The following skills provide[\s\S]*?<\/available_skills>\n?/m, nextSection ? `\n${nextSection}\n` : "\n");
1117
- }
1118
- for (const name of disabledNames) {
1119
- const escaped = name.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
1120
- nextPrompt = nextPrompt.replace(new RegExp(`\\n? <skill>\\n <name>${escaped}<\\/name>[\\s\\S]*? <\\/skill>`, "g"), "");
1121
- }
1122
- return { systemPrompt: nextPrompt };
1123
- });
1124
- }
1125
-
1126
872
  export default function (pi: ExtensionAPI) {
1127
- registerTuiResourceController(pi);
1128
873
  const subagentGate = registerSubagentGate(pi);
1129
874
  pi.on("session_shutdown", () => subagentGate.dispose());
1130
875
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@firstpick/pi-package-webui",
3
- "version": "0.10.0",
3
+ "version": "0.10.2",
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",