@caupulican/pi-adaptative 0.80.47 → 0.80.49
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 +16 -0
- package/dist/core/profile-resource-selection.d.ts +9 -0
- package/dist/core/profile-resource-selection.d.ts.map +1 -1
- package/dist/core/profile-resource-selection.js +49 -0
- package/dist/core/profile-resource-selection.js.map +1 -1
- package/dist/modes/interactive/components/profile-resource-editor.d.ts +23 -6
- package/dist/modes/interactive/components/profile-resource-editor.d.ts.map +1 -1
- package/dist/modes/interactive/components/profile-resource-editor.js +253 -23
- package/dist/modes/interactive/components/profile-resource-editor.js.map +1 -1
- package/dist/modes/interactive/components/settings-selector.d.ts +1 -7
- package/dist/modes/interactive/components/settings-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/settings-selector.js +41 -108
- package/dist/modes/interactive/components/settings-selector.js.map +1 -1
- package/dist/modes/interactive/interactive-mode.d.ts +13 -2
- package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode.js +533 -95
- package/dist/modes/interactive/interactive-mode.js.map +1 -1
- package/examples/extensions/custom-provider-anthropic/package-lock.json +2 -2
- package/examples/extensions/custom-provider-anthropic/package.json +1 -1
- package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
- package/examples/extensions/sandbox/package-lock.json +2 -2
- package/examples/extensions/sandbox/package.json +1 -1
- package/examples/extensions/with-deps/package-lock.json +2 -2
- package/examples/extensions/with-deps/package.json +1 -1
- package/npm-shrinkwrap.json +12 -12
- package/package.json +4 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,19 @@
|
|
|
1
|
+
## [0.80.49] - 2026-06-26
|
|
2
|
+
|
|
3
|
+
### Added
|
|
4
|
+
|
|
5
|
+
- Added Edit-in-$EDITOR action (key `e`) in the Manage Library browser to directly edit the highlighted resource's source file and reload upon return.
|
|
6
|
+
- Added consistent "Profile / Situation" labeling across all settings selectors.
|
|
7
|
+
- Added friendly empty-state messaging in kind tabs with no available resources.
|
|
8
|
+
|
|
9
|
+
## [0.80.48] - 2026-06-26
|
|
10
|
+
|
|
11
|
+
### Added
|
|
12
|
+
|
|
13
|
+
- Consolidated `/settings` profile and source configuration under a single `Resources` hub with a first-run catalog nudge.
|
|
14
|
+
- Implemented the unified `Manage Library` browser and editor featuring allow/block list toggling, fuzzy description search, missing items detection, and live reload on save.
|
|
15
|
+
|
|
16
|
+
|
|
1
17
|
## [0.80.47] - 2026-06-26
|
|
2
18
|
|
|
3
19
|
### Added
|
|
@@ -16,4 +16,13 @@ export declare function decodeResourceSelection(filter: ResourceProfileFilterSet
|
|
|
16
16
|
* - none enabled -> { block: ["*"] }
|
|
17
17
|
*/
|
|
18
18
|
export declare function encodeResourceSelection(enabled: Set<string>, allIds: string[]): ResourceProfileFilterSettings | undefined;
|
|
19
|
+
export type ResourceFraming = "allow" | "block";
|
|
20
|
+
/**
|
|
21
|
+
* Detect the framing of a given resource profile filter settings.
|
|
22
|
+
*/
|
|
23
|
+
export declare function detectResourceFraming(filter: ResourceProfileFilterSettings | undefined): ResourceFraming;
|
|
24
|
+
/**
|
|
25
|
+
* Encode an enabled set back into a filter, respecting the specified framing.
|
|
26
|
+
*/
|
|
27
|
+
export declare function encodeResourceSelectionWithFraming(enabled: Set<string>, allIds: string[], framing: ResourceFraming): ResourceProfileFilterSettings | undefined;
|
|
19
28
|
//# sourceMappingURL=profile-resource-selection.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"profile-resource-selection.d.ts","sourceRoot":"","sources":["../../src/core/profile-resource-selection.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,6BAA6B,EAAE,MAAM,uBAAuB,CAAC;AAE3E;;;;;;;;GAQG;AACH,wBAAgB,uBAAuB,CACtC,MAAM,EAAE,6BAA6B,GAAG,SAAS,EACjD,MAAM,EAAE,MAAM,EAAE,GACd,GAAG,CAAC,MAAM,CAAC,CA4Cb;AAED;;;;;GAKG;AACH,wBAAgB,uBAAuB,CACtC,OAAO,EAAE,GAAG,CAAC,MAAM,CAAC,EACpB,MAAM,EAAE,MAAM,EAAE,GACd,6BAA6B,GAAG,SAAS,CA6B3C","sourcesContent":["import type { ResourceProfileFilterSettings } from \"./settings-manager.ts\";\n\n/**\n * Decode a stored allow/block filter into the set of enabled resource ids,\n * given the full universe of ids for that kind.\n * - undefined / empty filter -> all enabled\n * - block contains \"*\" -> none enabled\n * - allow non-empty -> exactly the allow entries that exist in allIds\n * - block of specific ids (no \"*\") -> all ids except blocked ones\n * (If both allow and block specific ids are present: start from allow-or-all, then remove blocked.)\n */\nexport function decodeResourceSelection(\n\tfilter: ResourceProfileFilterSettings | undefined,\n\tallIds: string[],\n): Set<string> {\n\t// No filter means all enabled\n\tif (!filter) {\n\t\treturn new Set(allIds);\n\t}\n\n\t// If block contains \"*\", nothing is enabled\n\tif (filter.block?.includes(\"*\")) {\n\t\treturn new Set();\n\t}\n\n\t// If allow is specified, start with the allow list filtered to valid IDs\n\tif (filter.allow && filter.allow.length > 0) {\n\t\tconst allIdsSet = new Set(allIds);\n\t\tconst enabled = new Set<string>();\n\t\tfor (const id of filter.allow) {\n\t\t\tif (allIdsSet.has(id)) {\n\t\t\t\tenabled.add(id);\n\t\t\t}\n\t\t}\n\t\t// If block is also specified, remove blocked ids\n\t\tif (filter.block && filter.block.length > 0) {\n\t\t\tconst blockSet = new Set(filter.block);\n\t\t\tfor (const id of Array.from(enabled)) {\n\t\t\t\tif (blockSet.has(id)) {\n\t\t\t\t\tenabled.delete(id);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn enabled;\n\t}\n\n\t// No allow specified, start with all ids\n\tconst enabled = new Set(allIds);\n\t// Remove any blocked ids\n\tif (filter.block && filter.block.length > 0) {\n\t\tconst blockSet = new Set(filter.block);\n\t\tfor (const id of allIds) {\n\t\t\tif (blockSet.has(id)) {\n\t\t\t\tenabled.delete(id);\n\t\t\t}\n\t\t}\n\t}\n\treturn enabled;\n}\n\n/**\n * Encode an enabled set back into a filter.\n * - all enabled -> undefined (caller omits the kind)\n * - some but not all -> { allow: [...enabled, in allIds order] }\n * - none enabled -> { block: [\"*\"] }\n */\nexport function encodeResourceSelection(\n\tenabled: Set<string>,\n\tallIds: string[],\n): ResourceProfileFilterSettings | undefined {\n\tconst allIdsSet = new Set(allIds);\n\n\t// Count how many enabled ids are actually in allIds\n\tlet validEnabledCount = 0;\n\tfor (const id of enabled) {\n\t\tif (allIdsSet.has(id)) {\n\t\t\tvalidEnabledCount++;\n\t\t}\n\t}\n\n\t// All enabled: return undefined (caller omits the kind)\n\tif (validEnabledCount === allIds.length) {\n\t\treturn undefined;\n\t}\n\n\t// None enabled: return { block: [\"*\"] }\n\tif (validEnabledCount === 0) {\n\t\treturn { block: [\"*\"] };\n\t}\n\n\t// Some but not all: return { allow: [...enabled, in allIds order] }\n\tconst allow: string[] = [];\n\tfor (const id of allIds) {\n\t\tif (enabled.has(id)) {\n\t\t\tallow.push(id);\n\t\t}\n\t}\n\treturn { allow };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"profile-resource-selection.d.ts","sourceRoot":"","sources":["../../src/core/profile-resource-selection.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,6BAA6B,EAAE,MAAM,uBAAuB,CAAC;AAE3E;;;;;;;;GAQG;AACH,wBAAgB,uBAAuB,CACtC,MAAM,EAAE,6BAA6B,GAAG,SAAS,EACjD,MAAM,EAAE,MAAM,EAAE,GACd,GAAG,CAAC,MAAM,CAAC,CA4Cb;AAED;;;;;GAKG;AACH,wBAAgB,uBAAuB,CACtC,OAAO,EAAE,GAAG,CAAC,MAAM,CAAC,EACpB,MAAM,EAAE,MAAM,EAAE,GACd,6BAA6B,GAAG,SAAS,CA6B3C;AAED,MAAM,MAAM,eAAe,GAAG,OAAO,GAAG,OAAO,CAAC;AAEhD;;GAEG;AACH,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,6BAA6B,GAAG,SAAS,GAAG,eAAe,CAcxG;AAED;;GAEG;AACH,wBAAgB,kCAAkC,CACjD,OAAO,EAAE,GAAG,CAAC,MAAM,CAAC,EACpB,MAAM,EAAE,MAAM,EAAE,EAChB,OAAO,EAAE,eAAe,GACtB,6BAA6B,GAAG,SAAS,CA+B3C","sourcesContent":["import type { ResourceProfileFilterSettings } from \"./settings-manager.ts\";\n\n/**\n * Decode a stored allow/block filter into the set of enabled resource ids,\n * given the full universe of ids for that kind.\n * - undefined / empty filter -> all enabled\n * - block contains \"*\" -> none enabled\n * - allow non-empty -> exactly the allow entries that exist in allIds\n * - block of specific ids (no \"*\") -> all ids except blocked ones\n * (If both allow and block specific ids are present: start from allow-or-all, then remove blocked.)\n */\nexport function decodeResourceSelection(\n\tfilter: ResourceProfileFilterSettings | undefined,\n\tallIds: string[],\n): Set<string> {\n\t// No filter means all enabled\n\tif (!filter) {\n\t\treturn new Set(allIds);\n\t}\n\n\t// If block contains \"*\", nothing is enabled\n\tif (filter.block?.includes(\"*\")) {\n\t\treturn new Set();\n\t}\n\n\t// If allow is specified, start with the allow list filtered to valid IDs\n\tif (filter.allow && filter.allow.length > 0) {\n\t\tconst allIdsSet = new Set(allIds);\n\t\tconst enabled = new Set<string>();\n\t\tfor (const id of filter.allow) {\n\t\t\tif (allIdsSet.has(id)) {\n\t\t\t\tenabled.add(id);\n\t\t\t}\n\t\t}\n\t\t// If block is also specified, remove blocked ids\n\t\tif (filter.block && filter.block.length > 0) {\n\t\t\tconst blockSet = new Set(filter.block);\n\t\t\tfor (const id of Array.from(enabled)) {\n\t\t\t\tif (blockSet.has(id)) {\n\t\t\t\t\tenabled.delete(id);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn enabled;\n\t}\n\n\t// No allow specified, start with all ids\n\tconst enabled = new Set(allIds);\n\t// Remove any blocked ids\n\tif (filter.block && filter.block.length > 0) {\n\t\tconst blockSet = new Set(filter.block);\n\t\tfor (const id of allIds) {\n\t\t\tif (blockSet.has(id)) {\n\t\t\t\tenabled.delete(id);\n\t\t\t}\n\t\t}\n\t}\n\treturn enabled;\n}\n\n/**\n * Encode an enabled set back into a filter.\n * - all enabled -> undefined (caller omits the kind)\n * - some but not all -> { allow: [...enabled, in allIds order] }\n * - none enabled -> { block: [\"*\"] }\n */\nexport function encodeResourceSelection(\n\tenabled: Set<string>,\n\tallIds: string[],\n): ResourceProfileFilterSettings | undefined {\n\tconst allIdsSet = new Set(allIds);\n\n\t// Count how many enabled ids are actually in allIds\n\tlet validEnabledCount = 0;\n\tfor (const id of enabled) {\n\t\tif (allIdsSet.has(id)) {\n\t\t\tvalidEnabledCount++;\n\t\t}\n\t}\n\n\t// All enabled: return undefined (caller omits the kind)\n\tif (validEnabledCount === allIds.length) {\n\t\treturn undefined;\n\t}\n\n\t// None enabled: return { block: [\"*\"] }\n\tif (validEnabledCount === 0) {\n\t\treturn { block: [\"*\"] };\n\t}\n\n\t// Some but not all: return { allow: [...enabled, in allIds order] }\n\tconst allow: string[] = [];\n\tfor (const id of allIds) {\n\t\tif (enabled.has(id)) {\n\t\t\tallow.push(id);\n\t\t}\n\t}\n\treturn { allow };\n}\n\nexport type ResourceFraming = \"allow\" | \"block\";\n\n/**\n * Detect the framing of a given resource profile filter settings.\n */\nexport function detectResourceFraming(filter: ResourceProfileFilterSettings | undefined): ResourceFraming {\n\tif (!filter) {\n\t\treturn \"block\";\n\t}\n\tif (filter.allow && filter.allow.length > 0) {\n\t\treturn \"allow\";\n\t}\n\tif (filter.block && filter.block.length > 0) {\n\t\tif (filter.block.includes(\"*\")) {\n\t\t\treturn \"allow\";\n\t\t}\n\t\treturn \"block\";\n\t}\n\treturn \"block\";\n}\n\n/**\n * Encode an enabled set back into a filter, respecting the specified framing.\n */\nexport function encodeResourceSelectionWithFraming(\n\tenabled: Set<string>,\n\tallIds: string[],\n\tframing: ResourceFraming,\n): ResourceProfileFilterSettings | undefined {\n\tif (framing === \"allow\") {\n\t\treturn encodeResourceSelection(enabled, allIds);\n\t}\n\n\tconst allIdsSet = new Set(allIds);\n\tlet validEnabledCount = 0;\n\tfor (const id of enabled) {\n\t\tif (allIdsSet.has(id)) {\n\t\t\tvalidEnabledCount++;\n\t\t}\n\t}\n\n\t// All enabled: return undefined\n\tif (validEnabledCount === allIds.length) {\n\t\treturn undefined;\n\t}\n\n\t// None enabled: return { block: [\"*\"] }\n\tif (validEnabledCount === 0) {\n\t\treturn { block: [\"*\"] };\n\t}\n\n\t// Block framing with subset disabled: list disabled ids in block\n\tconst block: string[] = [];\n\tfor (const id of allIds) {\n\t\tif (!enabled.has(id)) {\n\t\t\tblock.push(id);\n\t\t}\n\t}\n\treturn { block };\n}\n"]}
|
|
@@ -81,4 +81,53 @@ export function encodeResourceSelection(enabled, allIds) {
|
|
|
81
81
|
}
|
|
82
82
|
return { allow };
|
|
83
83
|
}
|
|
84
|
+
/**
|
|
85
|
+
* Detect the framing of a given resource profile filter settings.
|
|
86
|
+
*/
|
|
87
|
+
export function detectResourceFraming(filter) {
|
|
88
|
+
if (!filter) {
|
|
89
|
+
return "block";
|
|
90
|
+
}
|
|
91
|
+
if (filter.allow && filter.allow.length > 0) {
|
|
92
|
+
return "allow";
|
|
93
|
+
}
|
|
94
|
+
if (filter.block && filter.block.length > 0) {
|
|
95
|
+
if (filter.block.includes("*")) {
|
|
96
|
+
return "allow";
|
|
97
|
+
}
|
|
98
|
+
return "block";
|
|
99
|
+
}
|
|
100
|
+
return "block";
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Encode an enabled set back into a filter, respecting the specified framing.
|
|
104
|
+
*/
|
|
105
|
+
export function encodeResourceSelectionWithFraming(enabled, allIds, framing) {
|
|
106
|
+
if (framing === "allow") {
|
|
107
|
+
return encodeResourceSelection(enabled, allIds);
|
|
108
|
+
}
|
|
109
|
+
const allIdsSet = new Set(allIds);
|
|
110
|
+
let validEnabledCount = 0;
|
|
111
|
+
for (const id of enabled) {
|
|
112
|
+
if (allIdsSet.has(id)) {
|
|
113
|
+
validEnabledCount++;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
// All enabled: return undefined
|
|
117
|
+
if (validEnabledCount === allIds.length) {
|
|
118
|
+
return undefined;
|
|
119
|
+
}
|
|
120
|
+
// None enabled: return { block: ["*"] }
|
|
121
|
+
if (validEnabledCount === 0) {
|
|
122
|
+
return { block: ["*"] };
|
|
123
|
+
}
|
|
124
|
+
// Block framing with subset disabled: list disabled ids in block
|
|
125
|
+
const block = [];
|
|
126
|
+
for (const id of allIds) {
|
|
127
|
+
if (!enabled.has(id)) {
|
|
128
|
+
block.push(id);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
return { block };
|
|
132
|
+
}
|
|
84
133
|
//# sourceMappingURL=profile-resource-selection.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"profile-resource-selection.js","sourceRoot":"","sources":["../../src/core/profile-resource-selection.ts"],"names":[],"mappings":"AAEA;;;;;;;;GAQG;AACH,MAAM,UAAU,uBAAuB,CACtC,MAAiD,EACjD,MAAgB,EACF;IACd,8BAA8B;IAC9B,IAAI,CAAC,MAAM,EAAE,CAAC;QACb,OAAO,IAAI,GAAG,CAAC,MAAM,CAAC,CAAC;IACxB,CAAC;IAED,4CAA4C;IAC5C,IAAI,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;QACjC,OAAO,IAAI,GAAG,EAAE,CAAC;IAClB,CAAC;IAED,yEAAyE;IACzE,IAAI,MAAM,CAAC,KAAK,IAAI,MAAM,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAC7C,MAAM,SAAS,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,CAAC;QAClC,MAAM,OAAO,GAAG,IAAI,GAAG,EAAU,CAAC;QAClC,KAAK,MAAM,EAAE,IAAI,MAAM,CAAC,KAAK,EAAE,CAAC;YAC/B,IAAI,SAAS,CAAC,GAAG,CAAC,EAAE,CA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AAE,CAAC;QAC1B,IAAI,SAAS,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,CAAC;YACvB,iBAAiB,EAAE,CAAC;QACrB,CAAC;IACF,CAAC;IAED,wDAAwD;IACxD,IAAI,iBAAiB,KAAK,MAAM,CAAC,MAAM,EAAE,CAAC;QACzC,OAAO,SAAS,CAAC;IAClB,CAAC;IAED,wCAAwC;IACxC,IAAI,iBAAiB,KAAK,CAAC,EAAE,CAAC;QAC7B,OAAO,EAAE,KAAK,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC;IACzB,CAAC;IAED,oEAAoE;IACpE,MAAM,KAAK,GAAa,EAAE,CAAC;IAC3B,KAAK,MAAM,EAAE,IAAI,MAAM,EAAE,CAAC;QACzB,IAAI,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,CAAC;YACrB,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QAChB,CAAC;IACF,CAAC;IACD,OAAO,EAAE,KAAK,EAAE,CAAC;AAAA,CACjB","sourcesContent":["import type { ResourceProfileFilterSettings } from \"./settings-manager.ts\";\n\n/**\n * Decode a stored allow/block filter into the set of enabled resource ids,\n * given the full universe of ids for that kind.\n * - undefined / empty filter -> all enabled\n * - block contains \"*\" -> none enabled\n * - allow non-empty -> exactly the allow entries that exist in allIds\n * - block of specific ids (no \"*\") -> all ids except blocked ones\n * (If both allow and block specific ids are present: start from allow-or-all, then remove blocked.)\n */\nexport function decodeResourceSelection(\n\tfilter: ResourceProfileFilterSettings | undefined,\n\tallIds: string[],\n): Set<string> {\n\t// No filter means all enabled\n\tif (!filter) {\n\t\treturn new Set(allIds);\n\t}\n\n\t// If block contains \"*\", nothing is enabled\n\tif (filter.block?.includes(\"*\")) {\n\t\treturn new Set();\n\t}\n\n\t// If allow is specified, start with the allow list filtered to valid IDs\n\tif (filter.allow && filter.allow.length > 0) {\n\t\tconst allIdsSet = new Set(allIds);\n\t\tconst enabled = new Set<string>();\n\t\tfor (const id of filter.allow) {\n\t\t\tif (allIdsSet.has(id)) {\n\t\t\t\tenabled.add(id);\n\t\t\t}\n\t\t}\n\t\t// If block is also specified, remove blocked ids\n\t\tif (filter.block && filter.block.length > 0) {\n\t\t\tconst blockSet = new Set(filter.block);\n\t\t\tfor (const id of Array.from(enabled)) {\n\t\t\t\tif (blockSet.has(id)) {\n\t\t\t\t\tenabled.delete(id);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn enabled;\n\t}\n\n\t// No allow specified, start with all ids\n\tconst enabled = new Set(allIds);\n\t// Remove any blocked ids\n\tif (filter.block && filter.block.length > 0) {\n\t\tconst blockSet = new Set(filter.block);\n\t\tfor (const id of allIds) {\n\t\t\tif (blockSet.has(id)) {\n\t\t\t\tenabled.delete(id);\n\t\t\t}\n\t\t}\n\t}\n\treturn enabled;\n}\n\n/**\n * Encode an enabled set back into a filter.\n * - all enabled -> undefined (caller omits the kind)\n * - some but not all -> { allow: [...enabled, in allIds order] }\n * - none enabled -> { block: [\"*\"] }\n */\nexport function encodeResourceSelection(\n\tenabled: Set<string>,\n\tallIds: string[],\n): ResourceProfileFilterSettings | undefined {\n\tconst allIdsSet = new Set(allIds);\n\n\t// Count how many enabled ids are actually in allIds\n\tlet validEnabledCount = 0;\n\tfor (const id of enabled) {\n\t\tif (allIdsSet.has(id)) {\n\t\t\tvalidEnabledCount++;\n\t\t}\n\t}\n\n\t// All enabled: return undefined (caller omits the kind)\n\tif (validEnabledCount === allIds.length) {\n\t\treturn undefined;\n\t}\n\n\t// None enabled: return { block: [\"*\"] }\n\tif (validEnabledCount === 0) {\n\t\treturn { block: [\"*\"] };\n\t}\n\n\t// Some but not all: return { allow: [...enabled, in allIds order] }\n\tconst allow: string[] = [];\n\tfor (const id of allIds) {\n\t\tif (enabled.has(id)) {\n\t\t\tallow.push(id);\n\t\t}\n\t}\n\treturn { allow };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"profile-resource-selection.js","sourceRoot":"","sources":["../../src/core/profile-resource-selection.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,CAAC,GAAG,CAAC,EAAE,CAAC;IACzB,CAAC;IAED,iEAAiE;IACjE,MAAM,KAAK,GAAa,EAAE,CAAC;IAC3B,KAAK,MAAM,EAAE,IAAI,MAAM,EAAE,CAAC;QACzB,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,CAAC;YACtB,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QAChB,CAAC;IACF,CAAC;IACD,OAAO,EAAE,KAAK,EAAE,CAAC;AAAA,CACjB","sourcesContent":["import type { ResourceProfileFilterSettings } from \"./settings-manager.ts\";\n\n/**\n * Decode a stored allow/block filter into the set of enabled resource ids,\n * given the full universe of ids for that kind.\n * - undefined / empty filter -> all enabled\n * - block contains \"*\" -> none enabled\n * - allow non-empty -> exactly the allow entries that exist in allIds\n * - block of specific ids (no \"*\") -> all ids except blocked ones\n * (If both allow and block specific ids are present: start from allow-or-all, then remove blocked.)\n */\nexport function decodeResourceSelection(\n\tfilter: ResourceProfileFilterSettings | undefined,\n\tallIds: string[],\n): Set<string> {\n\t// No filter means all enabled\n\tif (!filter) {\n\t\treturn new Set(allIds);\n\t}\n\n\t// If block contains \"*\", nothing is enabled\n\tif (filter.block?.includes(\"*\")) {\n\t\treturn new Set();\n\t}\n\n\t// If allow is specified, start with the allow list filtered to valid IDs\n\tif (filter.allow && filter.allow.length > 0) {\n\t\tconst allIdsSet = new Set(allIds);\n\t\tconst enabled = new Set<string>();\n\t\tfor (const id of filter.allow) {\n\t\t\tif (allIdsSet.has(id)) {\n\t\t\t\tenabled.add(id);\n\t\t\t}\n\t\t}\n\t\t// If block is also specified, remove blocked ids\n\t\tif (filter.block && filter.block.length > 0) {\n\t\t\tconst blockSet = new Set(filter.block);\n\t\t\tfor (const id of Array.from(enabled)) {\n\t\t\t\tif (blockSet.has(id)) {\n\t\t\t\t\tenabled.delete(id);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn enabled;\n\t}\n\n\t// No allow specified, start with all ids\n\tconst enabled = new Set(allIds);\n\t// Remove any blocked ids\n\tif (filter.block && filter.block.length > 0) {\n\t\tconst blockSet = new Set(filter.block);\n\t\tfor (const id of allIds) {\n\t\t\tif (blockSet.has(id)) {\n\t\t\t\tenabled.delete(id);\n\t\t\t}\n\t\t}\n\t}\n\treturn enabled;\n}\n\n/**\n * Encode an enabled set back into a filter.\n * - all enabled -> undefined (caller omits the kind)\n * - some but not all -> { allow: [...enabled, in allIds order] }\n * - none enabled -> { block: [\"*\"] }\n */\nexport function encodeResourceSelection(\n\tenabled: Set<string>,\n\tallIds: string[],\n): ResourceProfileFilterSettings | undefined {\n\tconst allIdsSet = new Set(allIds);\n\n\t// Count how many enabled ids are actually in allIds\n\tlet validEnabledCount = 0;\n\tfor (const id of enabled) {\n\t\tif (allIdsSet.has(id)) {\n\t\t\tvalidEnabledCount++;\n\t\t}\n\t}\n\n\t// All enabled: return undefined (caller omits the kind)\n\tif (validEnabledCount === allIds.length) {\n\t\treturn undefined;\n\t}\n\n\t// None enabled: return { block: [\"*\"] }\n\tif (validEnabledCount === 0) {\n\t\treturn { block: [\"*\"] };\n\t}\n\n\t// Some but not all: return { allow: [...enabled, in allIds order] }\n\tconst allow: string[] = [];\n\tfor (const id of allIds) {\n\t\tif (enabled.has(id)) {\n\t\t\tallow.push(id);\n\t\t}\n\t}\n\treturn { allow };\n}\n\nexport type ResourceFraming = \"allow\" | \"block\";\n\n/**\n * Detect the framing of a given resource profile filter settings.\n */\nexport function detectResourceFraming(filter: ResourceProfileFilterSettings | undefined): ResourceFraming {\n\tif (!filter) {\n\t\treturn \"block\";\n\t}\n\tif (filter.allow && filter.allow.length > 0) {\n\t\treturn \"allow\";\n\t}\n\tif (filter.block && filter.block.length > 0) {\n\t\tif (filter.block.includes(\"*\")) {\n\t\t\treturn \"allow\";\n\t\t}\n\t\treturn \"block\";\n\t}\n\treturn \"block\";\n}\n\n/**\n * Encode an enabled set back into a filter, respecting the specified framing.\n */\nexport function encodeResourceSelectionWithFraming(\n\tenabled: Set<string>,\n\tallIds: string[],\n\tframing: ResourceFraming,\n): ResourceProfileFilterSettings | undefined {\n\tif (framing === \"allow\") {\n\t\treturn encodeResourceSelection(enabled, allIds);\n\t}\n\n\tconst allIdsSet = new Set(allIds);\n\tlet validEnabledCount = 0;\n\tfor (const id of enabled) {\n\t\tif (allIdsSet.has(id)) {\n\t\t\tvalidEnabledCount++;\n\t\t}\n\t}\n\n\t// All enabled: return undefined\n\tif (validEnabledCount === allIds.length) {\n\t\treturn undefined;\n\t}\n\n\t// None enabled: return { block: [\"*\"] }\n\tif (validEnabledCount === 0) {\n\t\treturn { block: [\"*\"] };\n\t}\n\n\t// Block framing with subset disabled: list disabled ids in block\n\tconst block: string[] = [];\n\tfor (const id of allIds) {\n\t\tif (!enabled.has(id)) {\n\t\t\tblock.push(id);\n\t\t}\n\t}\n\treturn { block };\n}\n"]}
|
|
@@ -1,32 +1,47 @@
|
|
|
1
1
|
import { Container, type Focusable, Input } from "@caupulican/pi-tui";
|
|
2
2
|
import type { ResourceProfileKind, ResourceProfileSettings } from "../../../core/settings-manager.ts";
|
|
3
|
+
export interface ProfileResourceItem {
|
|
4
|
+
id: string;
|
|
5
|
+
path?: string;
|
|
6
|
+
description?: string;
|
|
7
|
+
}
|
|
3
8
|
export interface ProfileResourceEditorKind {
|
|
4
9
|
kind: ResourceProfileKind;
|
|
5
10
|
label: string;
|
|
6
|
-
|
|
11
|
+
items: ProfileResourceItem[];
|
|
7
12
|
}
|
|
8
13
|
export interface ProfileResourceEditorOptions {
|
|
9
14
|
profileName: string;
|
|
15
|
+
profileScope: string;
|
|
10
16
|
initialResources: ResourceProfileSettings;
|
|
11
17
|
kinds: ProfileResourceEditorKind[];
|
|
12
18
|
onSave: (resources: ResourceProfileSettings) => void;
|
|
13
19
|
onCancel: () => void;
|
|
20
|
+
onScopeChange?: () => void;
|
|
21
|
+
onEdit?: (id: string, path: string, kind: ResourceProfileKind) => void;
|
|
22
|
+
cwd?: string;
|
|
23
|
+
agentDir?: string;
|
|
24
|
+
externalResourceRoots?: string[];
|
|
14
25
|
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
* Shows a selectable list of resources for each kind (tools, skills, etc.),
|
|
18
|
-
* with space-to-toggle, search filtering, and save/cancel callbacks.
|
|
19
|
-
*/
|
|
26
|
+
export declare function resolveResourceEditPath(_id: string, filePath: string | undefined, kind: ResourceProfileKind): string | undefined;
|
|
27
|
+
export declare function classifyResourceSource(filePath: string | undefined, cwd: string, agentDir: string, externalRoots: string[]): "catalog" | "user" | "project" | "bundled";
|
|
20
28
|
export declare class ProfileResourceEditorComponent extends Container implements Focusable {
|
|
21
29
|
private profileName;
|
|
30
|
+
private profileScope;
|
|
22
31
|
private kinds;
|
|
23
32
|
private enabledByKind;
|
|
33
|
+
private framingByKind;
|
|
34
|
+
private missingIdsByKind;
|
|
24
35
|
private currentKindIndex;
|
|
36
|
+
private cwd;
|
|
37
|
+
private agentDir;
|
|
38
|
+
private externalResourceRoots;
|
|
25
39
|
private filteredItems;
|
|
26
40
|
private selectedIndex;
|
|
27
41
|
private searchInput;
|
|
28
42
|
private kindHeaderText;
|
|
29
43
|
private listContainer;
|
|
44
|
+
private descriptionText;
|
|
30
45
|
private footerText;
|
|
31
46
|
private isDirty;
|
|
32
47
|
private maxVisible;
|
|
@@ -35,6 +50,8 @@ export declare class ProfileResourceEditorComponent extends Container implements
|
|
|
35
50
|
set focused(value: boolean);
|
|
36
51
|
private onSave;
|
|
37
52
|
private onCancel;
|
|
53
|
+
private onScopeChange?;
|
|
54
|
+
private onEdit?;
|
|
38
55
|
constructor(options: ProfileResourceEditorOptions);
|
|
39
56
|
private getKindHeaderText;
|
|
40
57
|
private getCurrentKind;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"profile-resource-editor.d.ts","sourceRoot":"","sources":["../../../../src/modes/interactive/components/profile-resource-editor.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,SAAS,EACT,KAAK,SAAS,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CAAC,UAAU;IAgBlB,OAAO,CAAC,aAAa;IAerB,OAAO,CAAC,OAAO;IASf,OAAO,CAAC,UAAU;IA+BlB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAqE9B;IAED,OAAO,CAAC,cAAc;IAetB,cAAc,IAAI,KAAK,CAEtB;CACD","sourcesContent":["import {\n\tContainer,\n\ttype Focusable,\n\tfuzzyFilter,\n\tgetKeybindings,\n\tInput,\n\tKey,\n\tmatchesKey,\n\tSpacer,\n\tText,\n} from \"@caupulican/pi-tui\";\nimport { decodeResourceSelection, encodeResourceSelection } from \"../../../core/profile-resource-selection.ts\";\nimport type { ResourceProfileKind, ResourceProfileSettings } from \"../../../core/settings-manager.ts\";\nimport { theme } from \"../theme/theme.ts\";\nimport { DynamicBorder } from \"./dynamic-border.ts\";\nimport { keyText } from \"./keybinding-hints.ts\";\n\nexport interface ProfileResourceEditorKind {\n\tkind: ResourceProfileKind; // \"tools\" | \"skills\" | \"extensions\" | \"agents\" | \"prompts\" | \"themes\"\n\tlabel: string; // display label, e.g. \"Tools\"\n\tallIds: string[]; // the full universe of selectable ids for this kind\n}\n\nexport interface ProfileResourceEditorOptions {\n\tprofileName: string;\n\tinitialResources: ResourceProfileSettings; // existing profile.resources; may be {}\n\tkinds: ProfileResourceEditorKind[]; // the six kinds, with their universes\n\tonSave: (resources: ResourceProfileSettings) => void; // called on ctrl+s with the encoded result\n\tonCancel: () => void; // called on esc\n}\n\ninterface ResourceItem {\n\tid: string;\n\tenabled: boolean;\n}\n\n/**\n * TUI component for editing per-kind resource toggles in a profile.\n * Shows a selectable list of resources for each kind (tools, skills, etc.),\n * with space-to-toggle, search filtering, and save/cancel callbacks.\n */\nexport class ProfileResourceEditorComponent extends Container implements Focusable {\n\tprivate profileName: string;\n\tprivate kinds: ProfileResourceEditorKind[];\n\tprivate enabledByKind: Map<ResourceProfileKind, Set<string>> = new Map();\n\tprivate currentKindIndex = 0;\n\n\tprivate filteredItems: ResourceItem[] = [];\n\tprivate selectedIndex = 0;\n\tprivate searchInput: Input;\n\tprivate kindHeaderText: Text;\n\tprivate listContainer: Container;\n\tprivate footerText: Text;\n\tprivate isDirty = false;\n\tprivate maxVisible = 8;\n\n\tprivate _focused = false;\n\n\tget focused(): boolean {\n\t\treturn this._focused;\n\t}\n\tset focused(value: boolean) {\n\t\tthis._focused = value;\n\t\tthis.searchInput.focused = value;\n\t}\n\n\tprivate onSave: (resources: ResourceProfileSettings) => void;\n\tprivate onCancel: () => void;\n\n\tconstructor(options: ProfileResourceEditorOptions) {\n\t\tsuper();\n\t\tthis.profileName = options.profileName;\n\t\tthis.kinds = options.kinds;\n\t\tthis.onSave = options.onSave;\n\t\tthis.onCancel = options.onCancel;\n\n\t\t// Initialize enabled sets for each kind via decoding\n\t\tfor (const kind of this.kinds) {\n\t\t\tconst filter = options.initialResources[kind.kind];\n\t\t\tconst enabledSet = decodeResourceSelection(filter, kind.allIds);\n\t\t\tthis.enabledByKind.set(kind.kind, enabledSet);\n\t\t}\n\n\t\t// Header\n\t\tthis.addChild(new DynamicBorder());\n\t\tthis.addChild(new Text(theme.fg(\"accent\", theme.bold(`Edit Resources: ${this.profileName}`)), 0, 0));\n\t\tthis.addChild(\n\t\t\tnew Text(\n\t\t\t\ttheme.fg(\n\t\t\t\t\t\"muted\",\n\t\t\t\t\t`Navigate kinds with ${keyText(\"tui.input.tab\")}. Toggle with ${keyText(\"tui.select.confirm\")}.`,\n\t\t\t\t),\n\t\t\t\t0,\n\t\t\t\t0,\n\t\t\t),\n\t\t);\n\t\tthis.addChild(new Spacer(1));\n\n\t\t// Kind selector header (shows current kind label and count)\n\t\tthis.kindHeaderText = new Text(this.getKindHeaderText(), 0, 0);\n\t\tthis.addChild(this.kindHeaderText);\n\t\tthis.addChild(new Spacer(1));\n\n\t\t// Search input\n\t\tthis.searchInput = new Input();\n\t\tthis.addChild(this.searchInput);\n\t\tthis.addChild(new Spacer(1));\n\n\t\t// List container\n\t\tthis.listContainer = new Container();\n\t\tthis.addChild(this.listContainer);\n\n\t\t// Footer hint\n\t\tthis.addChild(new Spacer(1));\n\t\tthis.footerText = new Text(this.getFooterText(), 0, 0);\n\t\tthis.addChild(this.footerText);\n\n\t\tthis.addChild(new DynamicBorder());\n\n\t\tthis.updateList();\n\t}\n\n\tprivate getKindHeaderText(): string {\n\t\tconst kind = this.kinds[this.currentKindIndex]!;\n\t\tconst enabledSet = this.enabledByKind.get(kind.kind)!;\n\t\tconst countText = `${enabledSet.size}/${kind.allIds.length} enabled`;\n\t\tconst kindIndicator = this.kinds\n\t\t\t.map((k, i) => {\n\t\t\t\tconst marker = i === this.currentKindIndex ? \"●\" : \"○\";\n\t\t\t\treturn theme.fg(i === this.currentKindIndex ? \"accent\" : \"muted\", `${marker} ${k.label}`);\n\t\t\t})\n\t\t\t.join(\" \");\n\t\treturn `${kindIndicator} ${theme.fg(\"muted\", countText)}`;\n\t}\n\n\tprivate getCurrentKind(): ProfileResourceEditorKind {\n\t\treturn this.kinds[this.currentKindIndex]!;\n\t}\n\n\tprivate getCurrentEnabledSet(): Set<string> {\n\t\tconst kind = this.getCurrentKind();\n\t\treturn this.enabledByKind.get(kind.kind)!;\n\t}\n\n\tprivate buildItems(): ResourceItem[] {\n\t\tconst kind = this.getCurrentKind();\n\t\tconst enabledSet = this.getCurrentEnabledSet();\n\t\t// Return items sorted: enabled first (in order), then disabled\n\t\tconst enabled: ResourceItem[] = [];\n\t\tconst disabled: ResourceItem[] = [];\n\t\tfor (const id of kind.allIds) {\n\t\t\tif (enabledSet.has(id)) {\n\t\t\t\tenabled.push({ id, enabled: true });\n\t\t\t} else {\n\t\t\t\tdisabled.push({ id, enabled: false });\n\t\t\t}\n\t\t}\n\t\treturn [...enabled, ...disabled];\n\t}\n\n\tprivate getFooterText(): string {\n\t\tconst kind = this.getCurrentKind();\n\t\tconst enabledSet = this.getCurrentEnabledSet();\n\t\tconst countText = `${enabledSet.size}/${kind.allIds.length} enabled`;\n\t\tconst parts = [\n\t\t\t`${keyText(\"tui.select.confirm\")} toggle`,\n\t\t\t`${keyText(\"tui.input.tab\")} kind`,\n\t\t\t`${keyText(\"app.models.save\")} save`,\n\t\t\tcountText,\n\t\t];\n\t\treturn this.isDirty\n\t\t\t? theme.fg(\"dim\", ` ${parts.join(\" · \")} `) + theme.fg(\"warning\", \"(unsaved)\")\n\t\t\t: theme.fg(\"dim\", ` ${parts.join(\" · \")}`);\n\t}\n\n\tprivate refresh(): void {\n\t\tconst query = this.searchInput.getValue();\n\t\tconst items = this.buildItems();\n\t\tthis.filteredItems = query ? fuzzyFilter(items, query, (i) => i.id) : items;\n\t\tthis.selectedIndex = Math.min(this.selectedIndex, Math.max(0, this.filteredItems.length - 1));\n\t\tthis.updateList();\n\t\tthis.footerText.setText(this.getFooterText());\n\t}\n\n\tprivate updateList(): void {\n\t\tthis.listContainer.clear();\n\n\t\tif (this.filteredItems.length === 0) {\n\t\t\tthis.listContainer.addChild(new Text(theme.fg(\"muted\", \" No matching resources\"), 0, 0));\n\t\t\treturn;\n\t\t}\n\n\t\tconst startIndex = Math.max(\n\t\t\t0,\n\t\t\tMath.min(this.selectedIndex - Math.floor(this.maxVisible / 2), this.filteredItems.length - this.maxVisible),\n\t\t);\n\t\tconst endIndex = Math.min(startIndex + this.maxVisible, this.filteredItems.length);\n\n\t\tfor (let i = startIndex; i < endIndex; i++) {\n\t\t\tconst item = this.filteredItems[i]!;\n\t\t\tconst isSelected = i === this.selectedIndex;\n\t\t\tconst prefix = isSelected ? theme.fg(\"accent\", \"→ \") : \" \";\n\t\t\tconst resourceText = isSelected ? theme.fg(\"accent\", item.id) : item.id;\n\t\t\tconst status = item.enabled ? theme.fg(\"success\", \" ✓\") : theme.fg(\"dim\", \" ✗\");\n\t\t\tthis.listContainer.addChild(new Text(`${prefix}${resourceText}${status}`, 0, 0));\n\t\t}\n\n\t\t// Add scroll indicator if needed\n\t\tif (startIndex > 0 || endIndex < this.filteredItems.length) {\n\t\t\tthis.listContainer.addChild(\n\t\t\t\tnew Text(theme.fg(\"muted\", ` (${this.selectedIndex + 1}/${this.filteredItems.length})`), 0, 0),\n\t\t\t);\n\t\t}\n\t}\n\n\thandleInput(data: string): void {\n\t\tconst kb = getKeybindings();\n\n\t\t// Navigation within list\n\t\tif (kb.matches(data, \"tui.select.up\")) {\n\t\t\tif (this.filteredItems.length === 0) return;\n\t\t\tthis.selectedIndex = this.selectedIndex === 0 ? this.filteredItems.length - 1 : this.selectedIndex - 1;\n\t\t\tthis.updateList();\n\t\t\treturn;\n\t\t}\n\t\tif (kb.matches(data, \"tui.select.down\")) {\n\t\t\tif (this.filteredItems.length === 0) return;\n\t\t\tthis.selectedIndex = this.selectedIndex === this.filteredItems.length - 1 ? 0 : this.selectedIndex + 1;\n\t\t\tthis.updateList();\n\t\t\treturn;\n\t\t}\n\n\t\t// Switch kind with Tab (cycles forward)\n\t\tif (kb.matches(data, \"tui.input.tab\")) {\n\t\t\tthis.currentKindIndex = (this.currentKindIndex + 1) % this.kinds.length;\n\t\t\tthis.selectedIndex = 0;\n\t\t\tthis.searchInput.setValue(\"\");\n\t\t\tthis.kindHeaderText.setText(this.getKindHeaderText());\n\t\t\tthis.refresh();\n\t\t\treturn;\n\t\t}\n\n\t\t// Toggle on space/enter\n\t\tif (kb.matches(data, \"tui.select.confirm\")) {\n\t\t\tconst item = this.filteredItems[this.selectedIndex];\n\t\t\tif (item) {\n\t\t\t\tconst enabledSet = this.getCurrentEnabledSet();\n\t\t\t\tif (enabledSet.has(item.id)) {\n\t\t\t\t\tenabledSet.delete(item.id);\n\t\t\t\t} else {\n\t\t\t\t\tenabledSet.add(item.id);\n\t\t\t\t}\n\t\t\t\tthis.isDirty = true;\n\t\t\t\tthis.refresh();\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\n\t\t// Save/persist to settings\n\t\tif (kb.matches(data, \"app.models.save\")) {\n\t\t\tthis.persistChanges();\n\t\t\treturn;\n\t\t}\n\n\t\t// Ctrl+C - clear search or cancel if empty\n\t\tif (matchesKey(data, Key.ctrl(\"c\"))) {\n\t\t\tif (this.searchInput.getValue()) {\n\t\t\t\tthis.searchInput.setValue(\"\");\n\t\t\t\tthis.refresh();\n\t\t\t} else {\n\t\t\t\tthis.onCancel();\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\n\t\t// Escape - cancel\n\t\tif (matchesKey(data, Key.escape)) {\n\t\t\tthis.onCancel();\n\t\t\treturn;\n\t\t}\n\n\t\t// Pass everything else to search input\n\t\tthis.searchInput.handleInput(data);\n\t\tthis.refresh();\n\t}\n\n\tprivate persistChanges(): void {\n\t\t// Encode each kind and build the result\n\t\tconst resources: ResourceProfileSettings = {};\n\t\tfor (const kind of this.kinds) {\n\t\t\tconst enabledSet = this.enabledByKind.get(kind.kind)!;\n\t\t\tconst encoded = encodeResourceSelection(enabledSet, kind.allIds);\n\t\t\tif (encoded !== undefined) {\n\t\t\t\tresources[kind.kind] = encoded;\n\t\t\t}\n\t\t}\n\t\tthis.onSave(resources);\n\t\tthis.isDirty = false;\n\t\tthis.footerText.setText(this.getFooterText());\n\t}\n\n\tgetSearchInput(): Input {\n\t\treturn this.searchInput;\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"profile-resource-editor.d.ts","sourceRoot":"","sources":["../../../../src/modes/interactive/components/profile-resource-editor.ts"],"names":[],"mappings":"AAGA,OAAO,EACN,SAAS,EACT,KAAK,SAAS,EAGd,KAAK,EAKL,MAAM,oBAAoB,CAAC;AAO5B,OAAO,KAAK,EAAE,mBAAmB,EAAE,uBAAuB,EAAE,MAAM,mCAAmC,CAAC;AAKtG,MAAM,WAAW,mBAAmB;IACnC,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,WAAW,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,yBAAyB;IACzC,IAAI,EAAE,mBAAmB,CAAC;IAC1B,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,mBAAmB,EAAE,CAAC;CAC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,CAAC,qBAAqB,CAAW;IAExC,OAAO,CAAC,aAAa,CAAsB;IAC3C,OAAO,CAAC,aAAa,CAAK;IAC1B,OAAO,CAAC,WAAW,CAAQ;IAC3B,OAAO,CAAC,cAAc,CAAO;IAC7B,OAAO,CAAC,aAAa,CAAY;IACjC,OAAO,CAAC,eAAe,CAAO;IAC9B,OAAO,CAAC,UAAU,CAAO;IACzB,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,UAAU,CAAK;IAEvB,OAAO,CAAC,QAAQ,CAAS;IAEzB,IAAI,OAAO,IAAI,OAAO,CAErB;IACD,IAAI,OAAO,CAAC,KAAK,EAAE,OAAO,EAGzB;IAED,OAAO,CAAC,MAAM,CAA+C;IAC7D,OAAO,CAAC,QAAQ,CAAa;IAC7B,OAAO,CAAC,aAAa,CAAC,CAAa;IACnC,OAAO,CAAC,MAAM,CAAC,CAAgE;IAE/E,YAAY,OAAO,EAAE,4BAA4B,EA+FhD;IAED,OAAO,CAAC,iBAAiB;IAezB,OAAO,CAAC,cAAc;IAItB,OAAO,CAAC,oBAAoB;IAK5B,OAAO,CAAC,UAAU;IAqDlB,OAAO,CAAC,aAAa;IAgBrB,OAAO,CAAC,OAAO;IASf,OAAO,CAAC,UAAU;IAoElB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CA2G9B;IAED,OAAO,CAAC,cAAc;IAgBtB,cAAc,IAAI,KAAK,CAEtB;CACD","sourcesContent":["import * as fs from \"node:fs\";\nimport * as path from \"node:path\";\nimport { isAbsolute, resolve } from \"node:path\";\nimport {\n\tContainer,\n\ttype Focusable,\n\tfuzzyFilter,\n\tgetKeybindings,\n\tInput,\n\tKey,\n\tmatchesKey,\n\tSpacer,\n\tText,\n} from \"@caupulican/pi-tui\";\nimport {\n\tdecodeResourceSelection,\n\tdetectResourceFraming,\n\tencodeResourceSelectionWithFraming,\n\ttype ResourceFraming,\n} from \"../../../core/profile-resource-selection.ts\";\nimport type { ResourceProfileKind, ResourceProfileSettings } from \"../../../core/settings-manager.ts\";\nimport { theme } from \"../theme/theme.ts\";\nimport { DynamicBorder } from \"./dynamic-border.ts\";\nimport { keyText } from \"./keybinding-hints.ts\";\n\nexport interface ProfileResourceItem {\n\tid: string;\n\tpath?: string;\n\tdescription?: string;\n}\n\nexport interface ProfileResourceEditorKind {\n\tkind: ResourceProfileKind; // \"tools\" | \"skills\" | \"extensions\" | \"agents\" | \"prompts\" | \"themes\"\n\tlabel: string; // display label, e.g. \"Tools\"\n\titems: ProfileResourceItem[]; // the available items of this kind\n}\n\nexport interface ProfileResourceEditorOptions {\n\tprofileName: string;\n\tprofileScope: string; // e.g. \"directory\" | \"project\" | \"global\" | \"session\" | \"reusable-file\"\n\tinitialResources: ResourceProfileSettings; // existing profile.resources; may be {}\n\tkinds: ProfileResourceEditorKind[]; // the six kinds, with their universes\n\tonSave: (resources: ResourceProfileSettings) => void; // called on ctrl+s with the encoded result\n\tonCancel: () => void; // called on esc\n\tonScopeChange?: () => void;\n\tonEdit?: (id: string, path: string, kind: ResourceProfileKind) => void;\n\tcwd?: string;\n\tagentDir?: string;\n\texternalResourceRoots?: string[];\n}\n\ninterface ResourceItem {\n\tid: string;\n\tenabled: boolean;\n\tpath?: string;\n\tdescription?: string;\n\tsourceLabel?: \"catalog\" | \"user\" | \"project\" | \"bundled\";\n\tisMissing?: boolean;\n}\n\nconst TOOL_DESCRIPTIONS: Record<string, string> = {\n\tread: \"Read files from the filesystem.\",\n\tbash: \"Execute arbitrary commands in the shell.\",\n\tedit: \"Edit files surgically.\",\n\twrite: \"Create new files or overwrite existing files.\",\n\tgrep: \"Search for text patterns using ripgrep.\",\n\tfind: \"Locate files matching a search query.\",\n\tls: \"List files and directories.\",\n\tskill_audit: \"Inspect and audit local skills.\",\n\tskillify: \"Convert a set of files/instructions into a skill.\",\n\textensionify: \"Package a tool or script as an extension.\",\n};\n\nexport function resolveResourceEditPath(\n\t_id: string,\n\tfilePath: string | undefined,\n\tkind: ResourceProfileKind,\n): string | undefined {\n\tif (kind === \"tools\") {\n\t\treturn undefined;\n\t}\n\n\tif (!filePath) {\n\t\treturn undefined;\n\t}\n\n\tif (kind === \"extensions\") {\n\t\ttry {\n\t\t\tconst stats = fs.statSync(filePath);\n\t\t\tif (stats.isDirectory()) {\n\t\t\t\tconst indexTs = path.join(filePath, \"index.ts\");\n\t\t\t\tif (fs.existsSync(indexTs)) {\n\t\t\t\t\treturn indexTs;\n\t\t\t\t}\n\t\t\t\tconst indexJs = path.join(filePath, \"index.js\");\n\t\t\t\tif (fs.existsSync(indexJs)) {\n\t\t\t\t\treturn indexJs;\n\t\t\t\t}\n\t\t\t\tconst pkgJsonPath = path.join(filePath, \"package.json\");\n\t\t\t\tif (fs.existsSync(pkgJsonPath)) {\n\t\t\t\t\ttry {\n\t\t\t\t\t\tconst pkg = JSON.parse(fs.readFileSync(pkgJsonPath, \"utf-8\"));\n\t\t\t\t\t\tif (typeof pkg.main === \"string\") {\n\t\t\t\t\t\t\tconst resolvedMain = path.resolve(filePath, pkg.main);\n\t\t\t\t\t\t\tif (fs.existsSync(resolvedMain)) {\n\t\t\t\t\t\t\t\treturn resolvedMain;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t} catch {}\n\t\t\t\t}\n\t\t\t\treturn indexTs;\n\t\t\t}\n\t\t} catch {}\n\t\treturn filePath;\n\t}\n\n\tif (kind === \"skills\") {\n\t\ttry {\n\t\t\tconst stats = fs.statSync(filePath);\n\t\t\tif (stats.isDirectory()) {\n\t\t\t\tconst skillMd = path.join(filePath, \"SKILL.md\");\n\t\t\t\tif (fs.existsSync(skillMd)) {\n\t\t\t\t\treturn skillMd;\n\t\t\t\t}\n\t\t\t}\n\t\t} catch {}\n\t\treturn filePath;\n\t}\n\n\treturn filePath;\n}\n\nexport function classifyResourceSource(\n\tfilePath: string | undefined,\n\tcwd: string,\n\tagentDir: string,\n\texternalRoots: string[],\n): \"catalog\" | \"user\" | \"project\" | \"bundled\" {\n\tif (!filePath) {\n\t\treturn \"bundled\";\n\t}\n\n\tconst absolutePath = isAbsolute(filePath) ? filePath : resolve(cwd, filePath);\n\tconst normPath = resolve(absolutePath);\n\tconst normCwd = resolve(cwd);\n\tconst normAgentDir = agentDir ? resolve(agentDir) : \"\";\n\n\tfor (const extRoot of externalRoots) {\n\t\tconst normExt = resolve(extRoot);\n\t\tif (normPath.startsWith(normExt)) {\n\t\t\treturn \"catalog\";\n\t\t}\n\t}\n\n\tif (normAgentDir && normPath.startsWith(normAgentDir)) {\n\t\treturn \"user\";\n\t}\n\n\tif (normPath.startsWith(normCwd)) {\n\t\treturn \"project\";\n\t}\n\n\tif (normPath.includes(\"node_modules\")) {\n\t\treturn \"bundled\";\n\t}\n\n\treturn \"bundled\";\n}\n\nexport class ProfileResourceEditorComponent extends Container implements Focusable {\n\tprivate profileName: string;\n\tprivate profileScope: string;\n\tprivate kinds: ProfileResourceEditorKind[];\n\tprivate enabledByKind: Map<ResourceProfileKind, Set<string>> = new Map();\n\tprivate framingByKind: Map<ResourceProfileKind, ResourceFraming> = new Map();\n\tprivate missingIdsByKind: Map<ResourceProfileKind, Set<string>> = new Map();\n\tprivate currentKindIndex = 0;\n\n\tprivate cwd: string;\n\tprivate agentDir: string;\n\tprivate externalResourceRoots: string[];\n\n\tprivate filteredItems: ResourceItem[] = [];\n\tprivate selectedIndex = 0;\n\tprivate searchInput: Input;\n\tprivate kindHeaderText: Text;\n\tprivate listContainer: Container;\n\tprivate descriptionText: Text;\n\tprivate footerText: Text;\n\tprivate isDirty = false;\n\tprivate maxVisible = 8;\n\n\tprivate _focused = false;\n\n\tget focused(): boolean {\n\t\treturn this._focused;\n\t}\n\tset focused(value: boolean) {\n\t\tthis._focused = value;\n\t\tthis.searchInput.focused = value;\n\t}\n\n\tprivate onSave: (resources: ResourceProfileSettings) => void;\n\tprivate onCancel: () => void;\n\tprivate onScopeChange?: () => void;\n\tprivate onEdit?: (id: string, path: string, kind: ResourceProfileKind) => void;\n\n\tconstructor(options: ProfileResourceEditorOptions) {\n\t\tsuper();\n\t\tthis.profileName = options.profileName;\n\t\tthis.profileScope = options.profileScope;\n\t\tthis.kinds = options.kinds;\n\t\tthis.onSave = options.onSave;\n\t\tthis.onCancel = options.onCancel;\n\t\tthis.onScopeChange = options.onScopeChange;\n\t\tthis.onEdit = options.onEdit;\n\t\tthis.cwd = options.cwd || process.cwd();\n\t\tthis.agentDir = options.agentDir || \"\";\n\t\tthis.externalResourceRoots = options.externalResourceRoots || [];\n\n\t\t// Initialize enabled, framing, and missing sets for each kind\n\t\tfor (const kind of this.kinds) {\n\t\t\tconst filter = options.initialResources[kind.kind];\n\t\t\tconst allIds = kind.items.map((item) => item.id);\n\t\t\tconst enabledSet = decodeResourceSelection(filter, allIds);\n\t\t\tthis.enabledByKind.set(kind.kind, enabledSet);\n\t\t\tthis.framingByKind.set(kind.kind, detectResourceFraming(filter));\n\n\t\t\t// Compute missing items\n\t\t\tconst mentionedIds = new Set<string>();\n\t\t\tif (filter) {\n\t\t\t\tif (filter.allow) {\n\t\t\t\t\tfor (const id of filter.allow) {\n\t\t\t\t\t\tmentionedIds.add(id);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif (filter.block) {\n\t\t\t\t\tfor (const id of filter.block) {\n\t\t\t\t\t\tif (id !== \"*\") {\n\t\t\t\t\t\t\tmentionedIds.add(id);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tconst availableIds = new Set(allIds);\n\t\t\tconst missingSet = new Set<string>();\n\t\t\tfor (const id of mentionedIds) {\n\t\t\t\tif (!availableIds.has(id)) {\n\t\t\t\t\tmissingSet.add(id);\n\t\t\t\t}\n\t\t\t}\n\t\t\tthis.missingIdsByKind.set(kind.kind, missingSet);\n\t\t}\n\n\t\t// Header\n\t\tthis.addChild(new DynamicBorder());\n\t\tthis.addChild(\n\t\t\tnew Text(\n\t\t\t\ttheme.fg(\"accent\", theme.bold(`Library — editing \"${this.profileName}\" (${this.profileScope})`)),\n\t\t\t\t0,\n\t\t\t\t0,\n\t\t\t),\n\t\t);\n\t\tthis.addChild(\n\t\t\tnew Text(\n\t\t\t\ttheme.fg(\n\t\t\t\t\t\"muted\",\n\t\t\t\t\t`Navigate kinds: ${keyText(\"tui.input.tab\")}. Toggle: ${keyText(\"tui.select.confirm\")}. Mode: ${theme.fg(\"accent\", \"a\")} allow / ${theme.fg(\"accent\", \"b\")} block. Scope: ${theme.fg(\"accent\", \"s\")} change. Edit: ${theme.fg(\"accent\", \"e\")}.`,\n\t\t\t\t),\n\t\t\t\t0,\n\t\t\t\t0,\n\t\t\t),\n\t\t);\n\t\tthis.addChild(new Spacer(1));\n\n\t\t// Kind selector header\n\t\tthis.kindHeaderText = new Text(this.getKindHeaderText(), 0, 0);\n\t\tthis.addChild(this.kindHeaderText);\n\t\tthis.addChild(new Spacer(1));\n\n\t\t// Search input\n\t\tthis.searchInput = new Input();\n\t\tthis.addChild(this.searchInput);\n\t\tthis.addChild(new Spacer(1));\n\n\t\t// List container\n\t\tthis.listContainer = new Container();\n\t\tthis.addChild(this.listContainer);\n\n\t\t// Description area\n\t\tthis.descriptionText = new Text(\"\", 0, 0);\n\t\tthis.addChild(new Spacer(1));\n\t\tthis.addChild(this.descriptionText);\n\n\t\t// Footer hint\n\t\tthis.addChild(new Spacer(1));\n\t\tthis.footerText = new Text(this.getFooterText(), 0, 0);\n\t\tthis.addChild(this.footerText);\n\n\t\tthis.addChild(new DynamicBorder());\n\n\t\tthis.refresh();\n\t}\n\n\tprivate getKindHeaderText(): string {\n\t\tconst kind = this.kinds[this.currentKindIndex]!;\n\t\tconst enabledSet = this.enabledByKind.get(kind.kind)!;\n\t\tconst framing = this.framingByKind.get(kind.kind)!;\n\t\tconst framingText = framing === \"allow\" ? \"allow-list\" : \"block-list\";\n\t\tconst countText = `${enabledSet.size}/${kind.items.length} enabled (${framingText})`;\n\t\tconst kindIndicator = this.kinds\n\t\t\t.map((k, i) => {\n\t\t\t\tconst marker = i === this.currentKindIndex ? \"●\" : \"○\";\n\t\t\t\treturn theme.fg(i === this.currentKindIndex ? \"accent\" : \"muted\", `${marker} ${k.label}`);\n\t\t\t})\n\t\t\t.join(\" \");\n\t\treturn `${kindIndicator} ${theme.fg(\"muted\", countText)}`;\n\t}\n\n\tprivate getCurrentKind(): ProfileResourceEditorKind {\n\t\treturn this.kinds[this.currentKindIndex]!;\n\t}\n\n\tprivate getCurrentEnabledSet(): Set<string> {\n\t\tconst kind = this.getCurrentKind();\n\t\treturn this.enabledByKind.get(kind.kind)!;\n\t}\n\n\tprivate buildItems(): ResourceItem[] {\n\t\tconst kind = this.getCurrentKind();\n\t\tconst enabledSet = this.getCurrentEnabledSet();\n\n\t\tconst items: ResourceItem[] = [];\n\n\t\t// Add all available items\n\t\tfor (const availableItem of kind.items) {\n\t\t\tconst isEnabled = enabledSet.has(availableItem.id);\n\t\t\tlet desc = availableItem.description;\n\t\t\tif (kind.kind === \"tools\" && !desc) {\n\t\t\t\tdesc = TOOL_DESCRIPTIONS[availableItem.id];\n\t\t\t}\n\t\t\titems.push({\n\t\t\t\tid: availableItem.id,\n\t\t\t\tenabled: isEnabled,\n\t\t\t\tpath: availableItem.path,\n\t\t\t\tdescription: desc,\n\t\t\t\tsourceLabel: classifyResourceSource(\n\t\t\t\t\tavailableItem.path,\n\t\t\t\t\tthis.cwd,\n\t\t\t\t\tthis.agentDir,\n\t\t\t\t\tthis.externalResourceRoots,\n\t\t\t\t),\n\t\t\t\tisMissing: false,\n\t\t\t});\n\t\t}\n\n\t\t// Add missing items\n\t\tconst missingSet = this.missingIdsByKind.get(kind.kind) || new Set<string>();\n\t\tfor (const missingId of missingSet) {\n\t\t\tconst isEnabled = enabledSet.has(missingId);\n\t\t\titems.push({\n\t\t\t\tid: missingId,\n\t\t\t\tenabled: isEnabled,\n\t\t\t\tisMissing: true,\n\t\t\t\tdescription: \"Referenced in profile but missing from available resources.\",\n\t\t\t});\n\t\t}\n\n\t\t// Sort: enabled first, then disabled\n\t\tconst enabled: ResourceItem[] = [];\n\t\tconst disabled: ResourceItem[] = [];\n\t\tfor (const item of items) {\n\t\t\tif (item.enabled) {\n\t\t\t\tenabled.push(item);\n\t\t\t} else {\n\t\t\t\tdisabled.push(item);\n\t\t\t}\n\t\t}\n\t\treturn [...enabled, ...disabled];\n\t}\n\n\tprivate getFooterText(): string {\n\t\tconst kind = this.getCurrentKind();\n\t\tconst enabledSet = this.getCurrentEnabledSet();\n\t\tconst countText = `${enabledSet.size}/${kind.items.length} enabled`;\n\t\tconst parts = [\n\t\t\t`${keyText(\"tui.select.confirm\")} toggle`,\n\t\t\t`${keyText(\"tui.input.tab\")} kind`,\n\t\t\t`${keyText(\"app.models.save\")} save`,\n\t\t\t`${theme.fg(\"accent\", \"e\")} edit`,\n\t\t\tcountText,\n\t\t];\n\t\treturn this.isDirty\n\t\t\t? theme.fg(\"dim\", ` ${parts.join(\" · \")} `) + theme.fg(\"warning\", \"(unsaved)\")\n\t\t\t: theme.fg(\"dim\", ` ${parts.join(\" · \")}`);\n\t}\n\n\tprivate refresh(): void {\n\t\tconst query = this.searchInput.getValue();\n\t\tconst items = this.buildItems();\n\t\tthis.filteredItems = query ? fuzzyFilter(items, query, (i) => `${i.id} ${i.description ?? \"\"}`) : items;\n\t\tthis.selectedIndex = Math.min(this.selectedIndex, Math.max(0, this.filteredItems.length - 1));\n\t\tthis.updateList();\n\t\tthis.footerText.setText(this.getFooterText());\n\t}\n\n\tprivate updateList(): void {\n\t\tthis.listContainer.clear();\n\n\t\tconst kind = this.getCurrentKind();\n\t\tconst missingSet = this.missingIdsByKind.get(kind.kind) || new Set<string>();\n\t\tconst totalAvailableCount = kind.items.length + missingSet.size;\n\n\t\tif (totalAvailableCount === 0) {\n\t\t\tthis.listContainer.addChild(\n\t\t\t\tnew Text(theme.fg(\"muted\", \" (none available — add a Source or install resources)\"), 0, 0),\n\t\t\t);\n\t\t\tthis.descriptionText.setText(theme.fg(\"muted\", \" No description available\"));\n\t\t\treturn;\n\t\t}\n\n\t\tif (this.filteredItems.length === 0) {\n\t\t\tthis.listContainer.addChild(new Text(theme.fg(\"muted\", \" No matching resources\"), 0, 0));\n\t\t\tthis.descriptionText.setText(theme.fg(\"muted\", \" No description available\"));\n\t\t\treturn;\n\t\t}\n\n\t\tconst startIndex = Math.max(\n\t\t\t0,\n\t\t\tMath.min(this.selectedIndex - Math.floor(this.maxVisible / 2), this.filteredItems.length - this.maxVisible),\n\t\t);\n\t\tconst endIndex = Math.min(startIndex + this.maxVisible, this.filteredItems.length);\n\n\t\tfor (let i = startIndex; i < endIndex; i++) {\n\t\t\tconst item = this.filteredItems[i]!;\n\t\t\tconst isSelected = i === this.selectedIndex;\n\t\t\tconst prefix = isSelected ? theme.fg(\"accent\", \"→ \") : \" \";\n\t\t\tlet resourceText = isSelected ? theme.fg(\"accent\", item.id) : item.id;\n\n\t\t\tif (item.isMissing) {\n\t\t\t\tresourceText = theme.fg(\"muted\", `${item.id} [missing]`);\n\t\t\t} else if (item.sourceLabel) {\n\t\t\t\tconst labelColor =\n\t\t\t\t\titem.sourceLabel === \"catalog\"\n\t\t\t\t\t\t? \"thinkingText\"\n\t\t\t\t\t\t: item.sourceLabel === \"project\"\n\t\t\t\t\t\t\t? \"success\"\n\t\t\t\t\t\t\t: item.sourceLabel === \"user\"\n\t\t\t\t\t\t\t\t? \"warning\"\n\t\t\t\t\t\t\t\t: \"muted\";\n\t\t\t\tconst labelText = theme.fg(labelColor, ` [${item.sourceLabel}]`);\n\t\t\t\tresourceText = `${resourceText}${labelText}`;\n\t\t\t}\n\n\t\t\tconst status = item.enabled ? theme.fg(\"success\", \" ✓\") : theme.fg(\"dim\", \" ✗\");\n\t\t\tthis.listContainer.addChild(new Text(`${prefix}${resourceText}${status}`, 0, 0));\n\t\t}\n\n\t\t// Add scroll indicator if needed\n\t\tif (startIndex > 0 || endIndex < this.filteredItems.length) {\n\t\t\tthis.listContainer.addChild(\n\t\t\t\tnew Text(theme.fg(\"muted\", ` (${this.selectedIndex + 1}/${this.filteredItems.length})`), 0, 0),\n\t\t\t);\n\t\t}\n\n\t\t// Update description area for current selection\n\t\tconst selectedItem = this.filteredItems[this.selectedIndex];\n\t\tif (selectedItem?.description) {\n\t\t\tthis.descriptionText.setText(theme.fg(\"muted\", ` Description: ${selectedItem.description}`));\n\t\t} else {\n\t\t\tthis.descriptionText.setText(theme.fg(\"muted\", \" No description available\"));\n\t\t}\n\t}\n\n\thandleInput(data: string): void {\n\t\tconst kb = getKeybindings();\n\n\t\t// Navigation within list\n\t\tif (kb.matches(data, \"tui.select.up\")) {\n\t\t\tif (this.filteredItems.length === 0) return;\n\t\t\tthis.selectedIndex = this.selectedIndex === 0 ? this.filteredItems.length - 1 : this.selectedIndex - 1;\n\t\t\tthis.updateList();\n\t\t\treturn;\n\t\t}\n\t\tif (kb.matches(data, \"tui.select.down\")) {\n\t\t\tif (this.filteredItems.length === 0) return;\n\t\t\tthis.selectedIndex = this.selectedIndex === this.filteredItems.length - 1 ? 0 : this.selectedIndex + 1;\n\t\t\tthis.updateList();\n\t\t\treturn;\n\t\t}\n\n\t\t// Switch kind with Tab (cycles forward)\n\t\tif (kb.matches(data, \"tui.input.tab\")) {\n\t\t\tthis.currentKindIndex = (this.currentKindIndex + 1) % this.kinds.length;\n\t\t\tthis.selectedIndex = 0;\n\t\t\tthis.searchInput.setValue(\"\");\n\t\t\tthis.kindHeaderText.setText(this.getKindHeaderText());\n\t\t\tthis.refresh();\n\t\t\treturn;\n\t\t}\n\n\t\t// Switch framing: Allow-list\n\t\tif (matchesKey(data, Key.ctrl(\"a\")) || (this.searchInput.getValue() === \"\" && data === \"a\")) {\n\t\t\tthis.framingByKind.set(this.getCurrentKind().kind, \"allow\");\n\t\t\tthis.isDirty = true;\n\t\t\tthis.kindHeaderText.setText(this.getKindHeaderText());\n\t\t\tthis.refresh();\n\t\t\treturn;\n\t\t}\n\n\t\t// Switch framing: Block-list\n\t\tif (matchesKey(data, Key.ctrl(\"b\")) || (this.searchInput.getValue() === \"\" && data === \"b\")) {\n\t\t\tthis.framingByKind.set(this.getCurrentKind().kind, \"block\");\n\t\t\tthis.isDirty = true;\n\t\t\tthis.kindHeaderText.setText(this.getKindHeaderText());\n\t\t\tthis.refresh();\n\t\t\treturn;\n\t\t}\n\n\t\t// Edit highlighted resource\n\t\tif (data === \"e\" && this.searchInput.getValue() === \"\") {\n\t\t\tconst item = this.filteredItems[this.selectedIndex];\n\t\t\tif (item && !item.isMissing && item.path) {\n\t\t\t\tconst kind = this.getCurrentKind().kind;\n\t\t\t\tif (this.onEdit) {\n\t\t\t\t\tthis.onEdit(item.id, item.path, kind);\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\n\t\t// Switch scope: Scope selector\n\t\tif (matchesKey(data, Key.ctrl(\"o\")) || (this.searchInput.getValue() === \"\" && data === \"s\")) {\n\t\t\tif (this.onScopeChange) {\n\t\t\t\tthis.onScopeChange();\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\n\t\t// Toggle on space/enter\n\t\tif (kb.matches(data, \"tui.select.confirm\")) {\n\t\t\tconst item = this.filteredItems[this.selectedIndex];\n\t\t\tif (item) {\n\t\t\t\tconst enabledSet = this.getCurrentEnabledSet();\n\t\t\t\tif (enabledSet.has(item.id)) {\n\t\t\t\t\tenabledSet.delete(item.id);\n\t\t\t\t} else {\n\t\t\t\t\tenabledSet.add(item.id);\n\t\t\t\t}\n\t\t\t\tthis.isDirty = true;\n\t\t\t\tthis.refresh();\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\n\t\t// Save/persist to settings\n\t\tif (kb.matches(data, \"app.models.save\")) {\n\t\t\tthis.persistChanges();\n\t\t\treturn;\n\t\t}\n\n\t\t// Ctrl+C - clear search or cancel if empty\n\t\tif (matchesKey(data, Key.ctrl(\"c\"))) {\n\t\t\tif (this.searchInput.getValue()) {\n\t\t\t\tthis.searchInput.setValue(\"\");\n\t\t\t\tthis.refresh();\n\t\t\t} else {\n\t\t\t\tthis.onCancel();\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\n\t\t// Escape - cancel\n\t\tif (matchesKey(data, Key.escape)) {\n\t\t\tthis.onCancel();\n\t\t\treturn;\n\t\t}\n\n\t\t// Pass everything else to search input\n\t\tthis.searchInput.handleInput(data);\n\t\tthis.refresh();\n\t}\n\n\tprivate persistChanges(): void {\n\t\tconst resources: ResourceProfileSettings = {};\n\t\tfor (const kind of this.kinds) {\n\t\t\tconst enabledSet = this.enabledByKind.get(kind.kind)!;\n\t\t\tconst framing = this.framingByKind.get(kind.kind)!;\n\t\t\tconst allIds = kind.items.map((item) => item.id);\n\t\t\tconst encoded = encodeResourceSelectionWithFraming(enabledSet, allIds, framing);\n\t\t\tif (encoded !== undefined) {\n\t\t\t\tresources[kind.kind] = encoded;\n\t\t\t}\n\t\t}\n\t\tthis.onSave(resources);\n\t\tthis.isDirty = false;\n\t\tthis.footerText.setText(this.getFooterText());\n\t}\n\n\tgetSearchInput(): Input {\n\t\treturn this.searchInput;\n\t}\n}\n"]}
|