@dev-sergeev/datalab-kit 0.1.6 → 0.1.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/README.md +8 -8
- package/THIRD_PARTY_NOTICES.md +1 -1
- package/dist/extension.js +2 -2
- package/dist/install.d.ts +2 -2
- package/dist/install.js +14 -12
- package/docs/adr/0002-package-delivery.md +5 -5
- package/node_modules/node-addon-api/common 2.gypi +21 -0
- package/node_modules/node-addon-api/except 2.gypi +25 -0
- package/node_modules/node-addon-api/napi 2.h +3463 -0
- package/node_modules/node-addon-api/napi-inl 2.h +7250 -0
- package/node_modules/node-addon-api/napi-inl.deprecated 2.h +186 -0
- package/node_modules/node-addon-api/node_addon_api 2.gyp +42 -0
- package/node_modules/node-addon-api/node_api 2.gyp +9 -0
- package/node_modules/node-addon-api/noexcept 2.gypi +26 -0
- package/node_modules/node-addon-api/nothing 2.c +0 -0
- package/node_modules/pi-toggle-skills/toggle-skills 2.ts +316 -0
- package/node_modules/pi-toggle-skills/vitest.config 2.ts +15 -0
- package/node_modules/sprintf-js/.npmignore 2 +1 -0
- package/node_modules/sprintf-js/LICENSE 2 +24 -0
- package/node_modules/sprintf-js/README 2.md +88 -0
- package/node_modules/sprintf-js/bower 2.json +14 -0
- package/node_modules/sprintf-js/gruntfile 2.js +36 -0
- package/node_modules/sprintf-js/package 2.json +22 -0
- package/node_modules/tree-sitter-bash/tree-sitter-bash 2.wasm +0 -0
- package/node_modules/typebox/license 2 +23 -0
- package/node_modules/typebox/package 2.json +87 -0
- package/node_modules/typebox/readme 2.md +370 -0
- package/node_modules/zod/compile 2.cjs +96 -0
- package/node_modules/zod/compile 2.js +52 -0
- package/node_modules/zod/index 2.cjs +52 -0
- package/node_modules/zod/index 2.js +7 -0
- package/package.json +5 -5
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
#ifndef SRC_NAPI_INL_DEPRECATED_H_
|
|
2
|
+
#define SRC_NAPI_INL_DEPRECATED_H_
|
|
3
|
+
|
|
4
|
+
////////////////////////////////////////////////////////////////////////////////
|
|
5
|
+
// PropertyDescriptor class
|
|
6
|
+
////////////////////////////////////////////////////////////////////////////////
|
|
7
|
+
|
|
8
|
+
template <typename Getter>
|
|
9
|
+
inline PropertyDescriptor PropertyDescriptor::Accessor(
|
|
10
|
+
const char* utf8name,
|
|
11
|
+
Getter getter,
|
|
12
|
+
napi_property_attributes attributes,
|
|
13
|
+
void* /*data*/) {
|
|
14
|
+
using CbData = details::CallbackData<Getter, Napi::Value>;
|
|
15
|
+
// TODO: Delete when the function is destroyed
|
|
16
|
+
auto callbackData = new CbData({getter, nullptr});
|
|
17
|
+
|
|
18
|
+
return PropertyDescriptor({utf8name,
|
|
19
|
+
nullptr,
|
|
20
|
+
nullptr,
|
|
21
|
+
CbData::Wrapper,
|
|
22
|
+
nullptr,
|
|
23
|
+
nullptr,
|
|
24
|
+
attributes,
|
|
25
|
+
callbackData});
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
template <typename Getter>
|
|
29
|
+
inline PropertyDescriptor PropertyDescriptor::Accessor(
|
|
30
|
+
const std::string& utf8name,
|
|
31
|
+
Getter getter,
|
|
32
|
+
napi_property_attributes attributes,
|
|
33
|
+
void* data) {
|
|
34
|
+
return Accessor(utf8name.c_str(), getter, attributes, data);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
template <typename Getter>
|
|
38
|
+
inline PropertyDescriptor PropertyDescriptor::Accessor(
|
|
39
|
+
napi_value name,
|
|
40
|
+
Getter getter,
|
|
41
|
+
napi_property_attributes attributes,
|
|
42
|
+
void* /*data*/) {
|
|
43
|
+
using CbData = details::CallbackData<Getter, Napi::Value>;
|
|
44
|
+
// TODO: Delete when the function is destroyed
|
|
45
|
+
auto callbackData = new CbData({getter, nullptr});
|
|
46
|
+
|
|
47
|
+
return PropertyDescriptor({nullptr,
|
|
48
|
+
name,
|
|
49
|
+
nullptr,
|
|
50
|
+
CbData::Wrapper,
|
|
51
|
+
nullptr,
|
|
52
|
+
nullptr,
|
|
53
|
+
attributes,
|
|
54
|
+
callbackData});
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
template <typename Getter>
|
|
58
|
+
inline PropertyDescriptor PropertyDescriptor::Accessor(
|
|
59
|
+
Name name, Getter getter, napi_property_attributes attributes, void* data) {
|
|
60
|
+
napi_value nameValue = name;
|
|
61
|
+
return PropertyDescriptor::Accessor(nameValue, getter, attributes, data);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
template <typename Getter, typename Setter>
|
|
65
|
+
inline PropertyDescriptor PropertyDescriptor::Accessor(
|
|
66
|
+
const char* utf8name,
|
|
67
|
+
Getter getter,
|
|
68
|
+
Setter setter,
|
|
69
|
+
napi_property_attributes attributes,
|
|
70
|
+
void* /*data*/) {
|
|
71
|
+
using CbData = details::AccessorCallbackData<Getter, Setter>;
|
|
72
|
+
// TODO: Delete when the function is destroyed
|
|
73
|
+
auto callbackData = new CbData({getter, setter, nullptr});
|
|
74
|
+
|
|
75
|
+
return PropertyDescriptor({utf8name,
|
|
76
|
+
nullptr,
|
|
77
|
+
nullptr,
|
|
78
|
+
CbData::GetterWrapper,
|
|
79
|
+
CbData::SetterWrapper,
|
|
80
|
+
nullptr,
|
|
81
|
+
attributes,
|
|
82
|
+
callbackData});
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
template <typename Getter, typename Setter>
|
|
86
|
+
inline PropertyDescriptor PropertyDescriptor::Accessor(
|
|
87
|
+
const std::string& utf8name,
|
|
88
|
+
Getter getter,
|
|
89
|
+
Setter setter,
|
|
90
|
+
napi_property_attributes attributes,
|
|
91
|
+
void* data) {
|
|
92
|
+
return Accessor(utf8name.c_str(), getter, setter, attributes, data);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
template <typename Getter, typename Setter>
|
|
96
|
+
inline PropertyDescriptor PropertyDescriptor::Accessor(
|
|
97
|
+
napi_value name,
|
|
98
|
+
Getter getter,
|
|
99
|
+
Setter setter,
|
|
100
|
+
napi_property_attributes attributes,
|
|
101
|
+
void* /*data*/) {
|
|
102
|
+
using CbData = details::AccessorCallbackData<Getter, Setter>;
|
|
103
|
+
// TODO: Delete when the function is destroyed
|
|
104
|
+
auto callbackData = new CbData({getter, setter, nullptr});
|
|
105
|
+
|
|
106
|
+
return PropertyDescriptor({nullptr,
|
|
107
|
+
name,
|
|
108
|
+
nullptr,
|
|
109
|
+
CbData::GetterWrapper,
|
|
110
|
+
CbData::SetterWrapper,
|
|
111
|
+
nullptr,
|
|
112
|
+
attributes,
|
|
113
|
+
callbackData});
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
template <typename Getter, typename Setter>
|
|
117
|
+
inline PropertyDescriptor PropertyDescriptor::Accessor(
|
|
118
|
+
Name name,
|
|
119
|
+
Getter getter,
|
|
120
|
+
Setter setter,
|
|
121
|
+
napi_property_attributes attributes,
|
|
122
|
+
void* data) {
|
|
123
|
+
napi_value nameValue = name;
|
|
124
|
+
return PropertyDescriptor::Accessor(
|
|
125
|
+
nameValue, getter, setter, attributes, data);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
template <typename Callable>
|
|
129
|
+
inline PropertyDescriptor PropertyDescriptor::Function(
|
|
130
|
+
const char* utf8name,
|
|
131
|
+
Callable cb,
|
|
132
|
+
napi_property_attributes attributes,
|
|
133
|
+
void* /*data*/) {
|
|
134
|
+
using ReturnType = decltype(cb(CallbackInfo(nullptr, nullptr)));
|
|
135
|
+
using CbData = details::CallbackData<Callable, ReturnType>;
|
|
136
|
+
// TODO: Delete when the function is destroyed
|
|
137
|
+
auto callbackData = new CbData({cb, nullptr});
|
|
138
|
+
|
|
139
|
+
return PropertyDescriptor({utf8name,
|
|
140
|
+
nullptr,
|
|
141
|
+
CbData::Wrapper,
|
|
142
|
+
nullptr,
|
|
143
|
+
nullptr,
|
|
144
|
+
nullptr,
|
|
145
|
+
attributes,
|
|
146
|
+
callbackData});
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
template <typename Callable>
|
|
150
|
+
inline PropertyDescriptor PropertyDescriptor::Function(
|
|
151
|
+
const std::string& utf8name,
|
|
152
|
+
Callable cb,
|
|
153
|
+
napi_property_attributes attributes,
|
|
154
|
+
void* data) {
|
|
155
|
+
return Function(utf8name.c_str(), cb, attributes, data);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
template <typename Callable>
|
|
159
|
+
inline PropertyDescriptor PropertyDescriptor::Function(
|
|
160
|
+
napi_value name,
|
|
161
|
+
Callable cb,
|
|
162
|
+
napi_property_attributes attributes,
|
|
163
|
+
void* /*data*/) {
|
|
164
|
+
using ReturnType = decltype(cb(CallbackInfo(nullptr, nullptr)));
|
|
165
|
+
using CbData = details::CallbackData<Callable, ReturnType>;
|
|
166
|
+
// TODO: Delete when the function is destroyed
|
|
167
|
+
auto callbackData = new CbData({cb, nullptr});
|
|
168
|
+
|
|
169
|
+
return PropertyDescriptor({nullptr,
|
|
170
|
+
name,
|
|
171
|
+
CbData::Wrapper,
|
|
172
|
+
nullptr,
|
|
173
|
+
nullptr,
|
|
174
|
+
nullptr,
|
|
175
|
+
attributes,
|
|
176
|
+
callbackData});
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
template <typename Callable>
|
|
180
|
+
inline PropertyDescriptor PropertyDescriptor::Function(
|
|
181
|
+
Name name, Callable cb, napi_property_attributes attributes, void* data) {
|
|
182
|
+
napi_value nameValue = name;
|
|
183
|
+
return PropertyDescriptor::Function(nameValue, cb, attributes, data);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
#endif // !SRC_NAPI_INL_DEPRECATED_H_
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
{
|
|
2
|
+
'targets': [
|
|
3
|
+
{
|
|
4
|
+
'target_name': 'node_addon_api',
|
|
5
|
+
'type': 'none',
|
|
6
|
+
'sources': [ 'napi.h', 'napi-inl.h' ],
|
|
7
|
+
'direct_dependent_settings': {
|
|
8
|
+
'include_dirs': [ '.' ],
|
|
9
|
+
'includes': ['noexcept.gypi'],
|
|
10
|
+
}
|
|
11
|
+
},
|
|
12
|
+
{
|
|
13
|
+
'target_name': 'node_addon_api_except',
|
|
14
|
+
'type': 'none',
|
|
15
|
+
'sources': [ 'napi.h', 'napi-inl.h' ],
|
|
16
|
+
'direct_dependent_settings': {
|
|
17
|
+
'include_dirs': [ '.' ],
|
|
18
|
+
'includes': ['except.gypi'],
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
'target_name': 'node_addon_api_except_all',
|
|
23
|
+
'type': 'none',
|
|
24
|
+
'sources': [ 'napi.h', 'napi-inl.h' ],
|
|
25
|
+
'direct_dependent_settings': {
|
|
26
|
+
'include_dirs': [ '.' ],
|
|
27
|
+
'includes': ['except.gypi'],
|
|
28
|
+
'defines': [ 'NODE_ADDON_API_CPP_EXCEPTIONS_ALL' ]
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
'target_name': 'node_addon_api_maybe',
|
|
33
|
+
'type': 'none',
|
|
34
|
+
'sources': [ 'napi.h', 'napi-inl.h' ],
|
|
35
|
+
'direct_dependent_settings': {
|
|
36
|
+
'include_dirs': [ '.' ],
|
|
37
|
+
'includes': ['noexcept.gypi'],
|
|
38
|
+
'defines': ['NODE_ADDON_API_ENABLE_MAYBE']
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
]
|
|
42
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
{
|
|
2
|
+
'defines': [ 'NODE_ADDON_API_DISABLE_CPP_EXCEPTIONS' ],
|
|
3
|
+
'cflags': [ '-fno-exceptions' ],
|
|
4
|
+
'cflags_cc': [ '-fno-exceptions' ],
|
|
5
|
+
'conditions': [
|
|
6
|
+
["OS=='win'", {
|
|
7
|
+
# _HAS_EXCEPTIONS is already defined and set to 0 in common.gypi
|
|
8
|
+
#"defines": [
|
|
9
|
+
# "_HAS_EXCEPTIONS=0"
|
|
10
|
+
#],
|
|
11
|
+
"msvs_settings": {
|
|
12
|
+
"VCCLCompilerTool": {
|
|
13
|
+
'ExceptionHandling': 0,
|
|
14
|
+
'EnablePREfast': 'true',
|
|
15
|
+
},
|
|
16
|
+
},
|
|
17
|
+
}],
|
|
18
|
+
["OS=='mac'", {
|
|
19
|
+
'xcode_settings': {
|
|
20
|
+
'CLANG_CXX_LIBRARY': 'libc++',
|
|
21
|
+
'MACOSX_DEPLOYMENT_TARGET': '10.7',
|
|
22
|
+
'GCC_ENABLE_CPP_EXCEPTIONS': 'NO',
|
|
23
|
+
},
|
|
24
|
+
}],
|
|
25
|
+
],
|
|
26
|
+
}
|
|
File without changes
|
|
@@ -0,0 +1,316 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* pi-toggle-skills — toggle skill visibility in pi's system prompt.
|
|
3
|
+
*
|
|
4
|
+
* Toggles `disable-model-invocation` in SKILL.md frontmatter to control
|
|
5
|
+
* whether a skill appears in the model's available skills list.
|
|
6
|
+
*
|
|
7
|
+
* When a skill has `disable-model-invocation: true`, pi excludes it from
|
|
8
|
+
* the system prompt entirely. Users can still invoke it explicitly via
|
|
9
|
+
* /skill:name commands.
|
|
10
|
+
*
|
|
11
|
+
* This extension modifies SKILL.md files on disk. Changes require a /reload
|
|
12
|
+
* to take effect.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import type { ExtensionAPI, ExtensionCommandContext } from "@earendil-works/pi-coding-agent";
|
|
16
|
+
import {
|
|
17
|
+
TOGGLE_COMMAND_DESCRIPTION,
|
|
18
|
+
type ToggleSkill,
|
|
19
|
+
computeChanges,
|
|
20
|
+
} from "./src/index.js";
|
|
21
|
+
import {
|
|
22
|
+
discoverSkills,
|
|
23
|
+
toggleSkillInvocation,
|
|
24
|
+
applyChanges,
|
|
25
|
+
} from "./src/skill-discovery.js";
|
|
26
|
+
import { ToggleSkillSelectorComponent, type ToggleSkillSelectorResult } from "./src/skill-selector.js";
|
|
27
|
+
|
|
28
|
+
export default function (pi: ExtensionAPI) {
|
|
29
|
+
let currentSkills: ToggleSkill[] = [];
|
|
30
|
+
|
|
31
|
+
pi.on("session_start", async (_event, ctx) => {
|
|
32
|
+
currentSkills = discoverSkills(ctx.cwd);
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
pi.registerCommand("toggle-skills", {
|
|
36
|
+
description: TOGGLE_COMMAND_DESCRIPTION,
|
|
37
|
+
getArgumentCompletions(prefix: string) {
|
|
38
|
+
const subcommands = ["status", "enable", "disable", "list", "help"];
|
|
39
|
+
const matches = subcommands.filter((s) => s.startsWith(prefix));
|
|
40
|
+
return matches.length > 0 ? matches.map((s) => ({ value: s, label: s })) : null;
|
|
41
|
+
},
|
|
42
|
+
handler: async (args, ctx) => {
|
|
43
|
+
await handleToggleCommand(ctx, args.trim(), currentSkills, (skills) => {
|
|
44
|
+
currentSkills = skills;
|
|
45
|
+
});
|
|
46
|
+
},
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
async function handleToggleCommand(
|
|
51
|
+
ctx: ExtensionCommandContext,
|
|
52
|
+
args: string,
|
|
53
|
+
currentSkills: ToggleSkill[],
|
|
54
|
+
setSkills: (skills: ToggleSkill[]) => void,
|
|
55
|
+
): Promise<void> {
|
|
56
|
+
const parts = args.split(/\s+/);
|
|
57
|
+
const subcommand = parts[0]?.toLowerCase() ?? "";
|
|
58
|
+
const rest = parts.slice(1).join(" ");
|
|
59
|
+
|
|
60
|
+
// /toggle-skills — open interactive TUI selector (default)
|
|
61
|
+
if (!subcommand) {
|
|
62
|
+
await showToggleSelector(ctx, currentSkills, setSkills);
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// /toggle-skills list — show skills and their status
|
|
67
|
+
if (subcommand === "list") {
|
|
68
|
+
showStatus(ctx, currentSkills);
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// /toggle-skills status — same as list
|
|
73
|
+
if (subcommand === "status") {
|
|
74
|
+
showStatus(ctx, currentSkills);
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// /toggle-skills disable <name> — hide a skill from the system prompt
|
|
79
|
+
if (subcommand === "disable") {
|
|
80
|
+
if (!rest) {
|
|
81
|
+
ctx.ui.notify(
|
|
82
|
+
"Usage: /toggle-skills disable <skill-name>",
|
|
83
|
+
"warning",
|
|
84
|
+
);
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
const skill = findSkillByName(currentSkills, rest);
|
|
89
|
+
if (!skill) {
|
|
90
|
+
ctx.ui.notify(`Skill not found: "${rest}". Use /toggle-skills list to see available skills.`, "warning");
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
if (skill.disabled) {
|
|
95
|
+
ctx.ui.notify(`Skill "${skill.name}" is already hidden.`, "info");
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
if (toggleSkillInvocation(skill.filePath, true)) {
|
|
100
|
+
skill.disabled = true;
|
|
101
|
+
ctx.ui.notify(
|
|
102
|
+
`Disabled: "${skill.name}" — hidden from system prompt. Run /reload to apply.`,
|
|
103
|
+
"info",
|
|
104
|
+
);
|
|
105
|
+
} else {
|
|
106
|
+
ctx.ui.notify(`Failed to toggle skill "${skill.name}". Check file permissions.`, "error");
|
|
107
|
+
}
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
// /toggle-skills enable <name> — show a skill in the system prompt
|
|
112
|
+
if (subcommand === "enable") {
|
|
113
|
+
if (!rest) {
|
|
114
|
+
ctx.ui.notify(
|
|
115
|
+
"Usage: /toggle-skills enable <skill-name>",
|
|
116
|
+
"warning",
|
|
117
|
+
);
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
const skill = findSkillByName(currentSkills, rest);
|
|
122
|
+
if (!skill) {
|
|
123
|
+
ctx.ui.notify(`Skill not found: "${rest}". Use /toggle-skills list to see available skills.`, "warning");
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
if (!skill.disabled) {
|
|
128
|
+
ctx.ui.notify(`Skill "${skill.name}" is already visible.`, "info");
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
if (toggleSkillInvocation(skill.filePath, false)) {
|
|
133
|
+
skill.disabled = false;
|
|
134
|
+
ctx.ui.notify(
|
|
135
|
+
`Enabled: "${skill.name}" — visible in system prompt. Run /reload to apply.`,
|
|
136
|
+
"info",
|
|
137
|
+
);
|
|
138
|
+
} else {
|
|
139
|
+
ctx.ui.notify(`Failed to toggle skill "${skill.name}". Check file permissions.`, "error");
|
|
140
|
+
}
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
// /toggle-skills help
|
|
145
|
+
if (subcommand === "help") {
|
|
146
|
+
ctx.ui.notify(
|
|
147
|
+
[
|
|
148
|
+
"pi-toggle-skills commands:",
|
|
149
|
+
" /toggle-skills Open interactive TUI to toggle skill visibility",
|
|
150
|
+
" /toggle-skills status Show current skills and their visibility",
|
|
151
|
+
" /toggle-skills list Same as /toggle-skills status",
|
|
152
|
+
" /toggle-skills disable <n> Hide a skill from the system prompt",
|
|
153
|
+
" /toggle-skills enable <n> Show a skill in the system prompt",
|
|
154
|
+
" /toggle-skills help This message",
|
|
155
|
+
"",
|
|
156
|
+
"Mechanism: toggles disable-model-invocation in SKILL.md frontmatter.",
|
|
157
|
+
" When true, the skill is excluded from the system prompt.",
|
|
158
|
+
" Users can still invoke hidden skills via /skill:name commands.",
|
|
159
|
+
" Changes require /reload to take effect.",
|
|
160
|
+
].join("\n"),
|
|
161
|
+
"info",
|
|
162
|
+
);
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
ctx.ui.notify(
|
|
167
|
+
`Unknown subcommand: "${subcommand}". Use /toggle-skills help for usage.`,
|
|
168
|
+
"warning",
|
|
169
|
+
);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
// Open the interactive TUI selector.
|
|
173
|
+
async function showToggleSelector(
|
|
174
|
+
ctx: ExtensionCommandContext,
|
|
175
|
+
currentSkills: ToggleSkill[],
|
|
176
|
+
setSkills: (skills: ToggleSkill[]) => void,
|
|
177
|
+
): Promise<void> {
|
|
178
|
+
if (currentSkills.length === 0) {
|
|
179
|
+
ctx.ui.notify("No skills found. Add skills to ~/.pi/agent/skills/ or .pi/skills/ first.", "warning");
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
if (ctx.mode !== "tui") {
|
|
184
|
+
if (!ctx.hasUI) {
|
|
185
|
+
ctx.ui.notify("/toggle-skills requires a UI (TUI or GUI).", "error");
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
const items = currentSkills.map((s) => `${s.name}: ${s.disabled ? "disabled" : "enabled"}`);
|
|
189
|
+
const pick = await ctx.ui.select("Toggle skill \u2014 pick a skill to flip", items);
|
|
190
|
+
if (pick === undefined) return;
|
|
191
|
+
const idx = items.indexOf(pick);
|
|
192
|
+
if (idx < 0) return;
|
|
193
|
+
const skill = currentSkills[idx];
|
|
194
|
+
if (!skill) return;
|
|
195
|
+
const newDisabled = !skill.disabled;
|
|
196
|
+
const written = applyChanges(currentSkills, [{ filePath: skill.filePath, newDisabled }]);
|
|
197
|
+
if (written.length === 0) {
|
|
198
|
+
ctx.ui.notify("No files were written. Check file permissions.", "warning");
|
|
199
|
+
return;
|
|
200
|
+
}
|
|
201
|
+
setSkills(
|
|
202
|
+
currentSkills.map((s) => (s.filePath === skill.filePath ? { ...s, disabled: newDisabled } : s)),
|
|
203
|
+
);
|
|
204
|
+
ctx.ui.notify(
|
|
205
|
+
`Skill ${skill.name} ${newDisabled ? "disabled" : "enabled"}. /reload to take effect. Run /toggle-skills again for more.`,
|
|
206
|
+
"info",
|
|
207
|
+
);
|
|
208
|
+
return;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
const result = await ctx.ui.custom<ToggleSkillSelectorResult>(
|
|
212
|
+
(tui, theme, _kb, done) => {
|
|
213
|
+
const selector = new ToggleSkillSelectorComponent(
|
|
214
|
+
theme,
|
|
215
|
+
currentSkills,
|
|
216
|
+
(result) => done(result),
|
|
217
|
+
);
|
|
218
|
+
|
|
219
|
+
return {
|
|
220
|
+
get focused() { return selector.focused; },
|
|
221
|
+
set focused(value: boolean) { selector.focused = value; },
|
|
222
|
+
render(width: number) {
|
|
223
|
+
return selector.render(width);
|
|
224
|
+
},
|
|
225
|
+
invalidate() {
|
|
226
|
+
selector.invalidate();
|
|
227
|
+
},
|
|
228
|
+
handleInput(data: string) {
|
|
229
|
+
selector.handleInput(data);
|
|
230
|
+
tui.requestRender();
|
|
231
|
+
},
|
|
232
|
+
};
|
|
233
|
+
},
|
|
234
|
+
);
|
|
235
|
+
|
|
236
|
+
if (!result || result.cancelled) {
|
|
237
|
+
ctx.ui.notify("Toggle selector cancelled.", "info");
|
|
238
|
+
return;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
// Compute what changed
|
|
242
|
+
const changes = computeChanges(currentSkills, result.skills);
|
|
243
|
+
if (changes.length === 0) {
|
|
244
|
+
ctx.ui.notify("No changes to apply.", "info");
|
|
245
|
+
return;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
// Write changes to disk
|
|
249
|
+
const written = applyChanges(currentSkills, changes);
|
|
250
|
+
if (written.length === 0) {
|
|
251
|
+
ctx.ui.notify("No files were written. Check file permissions.", "warning");
|
|
252
|
+
return;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
setSkills(result.skills);
|
|
256
|
+
|
|
257
|
+
// Summarize what changed
|
|
258
|
+
const disabled = changes.filter((c) => c.newDisabled).length;
|
|
259
|
+
const enabled = changes.length - disabled;
|
|
260
|
+
const parts: string[] = [];
|
|
261
|
+
if (enabled > 0) parts.push(`${enabled} enabled`);
|
|
262
|
+
if (disabled > 0) parts.push(`${disabled} disabled`);
|
|
263
|
+
const summary = parts.join(", ");
|
|
264
|
+
|
|
265
|
+
ctx.ui.notify(
|
|
266
|
+
`Skills updated: ${summary}. Run /reload to apply.`,
|
|
267
|
+
"info",
|
|
268
|
+
);
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
function findSkillByName(skills: ReadonlyArray<ToggleSkill>, name: string): ToggleSkill | undefined {
|
|
272
|
+
// Exact match first
|
|
273
|
+
const exact = skills.find((s) => s.name === name);
|
|
274
|
+
if (exact) return exact;
|
|
275
|
+
|
|
276
|
+
// Prefix match
|
|
277
|
+
const prefix = skills.find((s) => s.name.startsWith(name));
|
|
278
|
+
if (prefix) return prefix;
|
|
279
|
+
|
|
280
|
+
// Fuzzy: contains
|
|
281
|
+
const fuzzy = skills.find((s) => s.name.includes(name));
|
|
282
|
+
return fuzzy;
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
function showStatus(
|
|
286
|
+
ctx: ExtensionCommandContext,
|
|
287
|
+
skills: ReadonlyArray<ToggleSkill>,
|
|
288
|
+
): void {
|
|
289
|
+
const lines: string[] = [];
|
|
290
|
+
|
|
291
|
+
if (skills.length === 0) {
|
|
292
|
+
lines.push("No skills found. Add skills to ~/.pi/agent/skills/ or .pi/skills/.");
|
|
293
|
+
} else {
|
|
294
|
+
const visible = skills.filter((s) => !s.disabled);
|
|
295
|
+
const hidden = skills.filter((s) => s.disabled);
|
|
296
|
+
|
|
297
|
+
if (hidden.length > 0) {
|
|
298
|
+
lines.push(`Visible skills (${visible.length}):`);
|
|
299
|
+
for (const skill of visible) {
|
|
300
|
+
lines.push(` ✓ ${skill.name}`);
|
|
301
|
+
}
|
|
302
|
+
lines.push("");
|
|
303
|
+
lines.push(`Hidden skills (${hidden.length}):`);
|
|
304
|
+
for (const skill of hidden) {
|
|
305
|
+
lines.push(` ✗ ${skill.name}`);
|
|
306
|
+
}
|
|
307
|
+
} else {
|
|
308
|
+
lines.push(`All skills visible (${skills.length}):`);
|
|
309
|
+
for (const skill of skills) {
|
|
310
|
+
lines.push(` ✓ ${skill.name}`);
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
ctx.ui.notify(lines.join("\n"), "info");
|
|
316
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { defineConfig } from "vitest/config";
|
|
2
|
+
|
|
3
|
+
export default defineConfig({
|
|
4
|
+
test: {
|
|
5
|
+
globals: true,
|
|
6
|
+
environment: "node",
|
|
7
|
+
include: ["__tests__/**/*.test.ts"],
|
|
8
|
+
exclude: ["node_modules", "dist", ".idea", ".git", ".cache"],
|
|
9
|
+
coverage: {
|
|
10
|
+
provider: "v8",
|
|
11
|
+
reporter: ["text", "json", "html"],
|
|
12
|
+
exclude: ["node_modules/", "**/*.d.ts", "**/*.test.ts"],
|
|
13
|
+
},
|
|
14
|
+
},
|
|
15
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
/node_modules/
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
Copyright (c) 2007-2014, Alexandru Marasteanu <hello [at) alexei (dot] ro>
|
|
2
|
+
All rights reserved.
|
|
3
|
+
|
|
4
|
+
Redistribution and use in source and binary forms, with or without
|
|
5
|
+
modification, are permitted provided that the following conditions are met:
|
|
6
|
+
* Redistributions of source code must retain the above copyright
|
|
7
|
+
notice, this list of conditions and the following disclaimer.
|
|
8
|
+
* Redistributions in binary form must reproduce the above copyright
|
|
9
|
+
notice, this list of conditions and the following disclaimer in the
|
|
10
|
+
documentation and/or other materials provided with the distribution.
|
|
11
|
+
* Neither the name of this software nor the names of its contributors may be
|
|
12
|
+
used to endorse or promote products derived from this software without
|
|
13
|
+
specific prior written permission.
|
|
14
|
+
|
|
15
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
16
|
+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
17
|
+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
18
|
+
DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
|
|
19
|
+
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
20
|
+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
21
|
+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
|
22
|
+
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
23
|
+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
24
|
+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|