@wrongstack/tools 0.313.0 → 0.316.1
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/dist/_edit-match.d.ts +3 -2
- package/dist/_output-spool.d.ts +4 -3
- package/dist/_shell-pick.d.ts +2 -1
- package/dist/_spawn-stream.d.ts +2 -1
- package/dist/_syntax-check.d.ts +2 -1
- package/dist/audit.js +10 -4055
- package/dist/bash-kill-guard.d.ts +3 -6
- package/dist/bash.js +9 -2308
- package/dist/batch-tool-use.js +2 -187
- package/dist/browser/index.js +25 -1339
- package/dist/browser/network-guard-proxy.d.ts +2 -1
- package/dist/builtin.js +69 -33949
- package/dist/chunk-22B7GE5T.js +260 -0
- package/dist/chunk-2VSZC6QM.js +113 -0
- package/dist/chunk-3PVYQFRQ.js +472 -0
- package/dist/chunk-42BHI7TN.js +337 -0
- package/dist/chunk-4BHUSMNL.js +104 -0
- package/dist/chunk-4I4LWFOO.js +431 -0
- package/dist/chunk-4UESMQDP.js +122 -0
- package/dist/chunk-553IQUMO.js +478 -0
- package/dist/chunk-5H4GSJAI.js +223 -0
- package/dist/chunk-6RNIFLG4.js +305 -0
- package/dist/chunk-7EY5DCRO.js +434 -0
- package/dist/chunk-A6BRWIXN.js +317 -0
- package/dist/chunk-AHHDWNXC.js +200 -0
- package/dist/chunk-BSLVR56S.js +199 -0
- package/dist/chunk-BTSFTGIL.js +7 -0
- package/dist/chunk-D33S4RQG.js +222 -0
- package/dist/chunk-DA4KNE2H.js +4412 -0
- package/dist/chunk-DR7JOQTC.js +520 -0
- package/dist/chunk-EEOFQDT6.js +898 -0
- package/dist/chunk-EJWSCQ6D.js +137 -0
- package/dist/chunk-EMRGN4KM.js +170 -0
- package/dist/chunk-FQZOHLG3.js +89 -0
- package/dist/chunk-GOIZNNOA.js +221 -0
- package/dist/chunk-HFXSNKCV.js +196 -0
- package/dist/chunk-HYX2TZ7O.js +1272 -0
- package/dist/chunk-I64BS3VC.js +15 -0
- package/dist/chunk-IVWV2UM6.js +955 -0
- package/dist/chunk-IXMNTNW5.js +238 -0
- package/dist/chunk-IYK7XGDZ.js +892 -0
- package/dist/chunk-J5SKD6LN.js +235 -0
- package/dist/chunk-JNNVRHMV.js +2111 -0
- package/dist/chunk-JOHXDF3D.js +295 -0
- package/dist/chunk-JRJJX3L5.js +424 -0
- package/dist/chunk-K3WNSHUF.js +1371 -0
- package/dist/chunk-L25CVUVR.js +2830 -0
- package/dist/chunk-LIJQMYYX.js +59 -0
- package/dist/chunk-LWKUTMD5.js +197 -0
- package/dist/chunk-MQX2KXVW.js +54 -0
- package/dist/chunk-MZZN7VCD.js +359 -0
- package/dist/chunk-NBDZMMG2.js +169 -0
- package/dist/chunk-NKJW5GFO.js +366 -0
- package/dist/chunk-NKNOBUBU.js +522 -0
- package/dist/chunk-O4MBV4AX.js +134 -0
- package/dist/chunk-OUBDL3WH.js +3515 -0
- package/dist/chunk-PQKK5JH7.js +101 -0
- package/dist/chunk-PY2IOS7C.js +1000 -0
- package/dist/chunk-Q5JPPCZC.js +12 -0
- package/dist/chunk-QBV725YG.js +128 -0
- package/dist/chunk-QZQSPUBF.js +315 -0
- package/dist/chunk-RGISBZBD.js +231 -0
- package/dist/chunk-RJZQWEMS.js +84 -0
- package/dist/chunk-RXISBFR5.js +315 -0
- package/dist/chunk-S5CCLZL3.js +99 -0
- package/dist/chunk-SDLVH5RZ.js +178 -0
- package/dist/chunk-T2F4S7U4.js +1723 -0
- package/dist/chunk-TEBQ4VPZ.js +163 -0
- package/dist/chunk-U4D5S3VQ.js +21 -0
- package/dist/chunk-U4VAATKP.js +193 -0
- package/dist/chunk-UCYQTZ7F.js +113 -0
- package/dist/chunk-UKU2ZX4C.js +203 -0
- package/dist/chunk-UNSKG6DC.js +159 -0
- package/dist/chunk-V43EQ6VR.js +68 -0
- package/dist/chunk-VB3MJGCV.js +610 -0
- package/dist/chunk-VFKPWSOX.js +154 -0
- package/dist/chunk-VJNHFZ7J.js +190 -0
- package/dist/chunk-VXECAJJ7.js +1091 -0
- package/dist/chunk-WHIIIREL.js +223 -0
- package/dist/chunk-Z6DAKQ3U.js +1 -0
- package/dist/chunk-ZJQ4IGXK.js +474 -0
- package/dist/chunk-ZLTFLC25.js +385 -0
- package/dist/circuit-breaker.js +3 -191
- package/dist/codebase-index/ast-invariant-engine.d.ts +5 -4
- package/dist/codebase-index/binary-frame.d.ts +0 -2
- package/dist/codebase-index/bm25.d.ts +1 -1
- package/dist/codebase-index/circuit-breaker.d.ts +2 -1
- package/dist/codebase-index/codebase-ast-replace-tool.d.ts +3 -2
- package/dist/codebase-index/codebase-impact-analysis-tool.d.ts +4 -3
- package/dist/codebase-index/codebase-invariant-check-tool.d.ts +3 -2
- package/dist/codebase-index/codebase-repo-map-tool.d.ts +3 -2
- package/dist/codebase-index/codebase-skeleton-tool.d.ts +3 -2
- package/dist/codebase-index/codebase-targeted-test-tool.d.ts +3 -2
- package/dist/codebase-index/content-hash.d.ts +0 -2
- package/dist/codebase-index/import-extractor.d.ts +0 -13
- package/dist/codebase-index/index-service.d.ts +1 -1
- package/dist/codebase-index/index.js +84 -13688
- package/dist/codebase-index/languages.d.ts +2 -1
- package/dist/codebase-index/module-roots.d.ts +3 -2
- package/dist/codebase-index/parser-batch.d.ts +0 -5
- package/dist/codebase-index/parser-dispatch.d.ts +2 -1
- package/dist/codebase-index/parser-output.d.ts +4 -3
- package/dist/codebase-index/parser-worker-pool.d.ts +0 -2
- package/dist/codebase-index/parser-worker-script.d.ts +1 -16
- package/dist/codebase-index/parser-worker-script.js +8 -3995
- package/dist/codebase-index/project-server-client-state.d.ts +2 -2
- package/dist/codebase-index/project-server-endpoint.d.ts +0 -15
- package/dist/codebase-index/project-server.js +60 -8548
- package/dist/codebase-index/tree-sitter/visitor.d.ts +2 -1
- package/dist/codebase-index/tree-sitter-parser.d.ts +0 -2
- package/dist/codebase-index/ts-parser.d.ts +1 -1
- package/dist/codebase-index/vector-search.d.ts +2 -1
- package/dist/codebase-index/wal-maintenance.d.ts +3 -2
- package/dist/codebase-index/worker.js +20 -8416
- package/dist/codebase-index/writer-admin.d.ts +0 -1
- package/dist/codebase-index/writer-search.d.ts +0 -9
- package/dist/design.js +2 -299
- package/dist/diff.js +4 -256
- package/dist/document.js +4 -222
- package/dist/e2e.js +5 -476
- package/dist/edit.js +14 -10200
- package/dist/exec.js +16 -3131
- package/dist/fetch.js +8 -398
- package/dist/format.js +10 -3750
- package/dist/generic-parser-VUXDIAOZ.js +13 -0
- package/dist/git.js +4 -380
- package/dist/glob.js +6 -280
- package/dist/go-parser-JXYKJHRC.js +469 -0
- package/dist/grep.js +7 -604
- package/dist/index.js +318 -35387
- package/dist/install.js +10 -4091
- package/dist/json-parser-IBHZ4BZC.js +213 -0
- package/dist/json.js +4 -665
- package/dist/kanban-contract-actions.d.ts +1 -1
- package/dist/kanban-detail-actions.d.ts +2 -1
- package/dist/kanban-presence.d.ts +2 -1
- package/dist/kanban-serializer.d.ts +0 -8
- package/dist/kanban-split-task-handler.d.ts +2 -2
- package/dist/kanban-tool-types.d.ts +2 -1
- package/dist/kanban.js +3 -2096
- package/dist/languages/diagnostics.d.ts +2 -1
- package/dist/languages/index.js +23 -4664
- package/dist/languages/legacy-bridge.d.ts +3 -2
- package/dist/languages/types.d.ts +2 -1
- package/dist/legacy-bridge-7M6QLUQN.js +18 -0
- package/dist/lint.js +10 -3706
- package/dist/logs.js +4 -287
- package/dist/memory.js +6 -215
- package/dist/mode.js +3 -99
- package/dist/outdated.js +4 -5170
- package/dist/pack.js +65 -33897
- package/dist/parser-dispatch-QH4XPGG6.js +14 -0
- package/dist/patch.js +13 -9935
- package/dist/plan.js +5 -3286
- package/dist/process-registry.js +8 -651
- package/dist/ps-slash.js +12 -1439
- package/dist/pwsh.d.ts +0 -1
- package/dist/py-parser-IS4HKYMF.js +16 -0
- package/dist/read.js +13 -9816
- package/dist/replace.js +15 -10014
- package/dist/rs-parser-XHUUO2KZ.js +81 -0
- package/dist/scaffold.js +4 -253
- package/dist/search.js +5 -585
- package/dist/session-kanban-sync.d.ts +0 -6
- package/dist/session-kanban.js +30 -972
- package/dist/skill.js +2 -215
- package/dist/spawn-background.d.ts +1 -1
- package/dist/task.js +5 -3410
- package/dist/test.js +10 -3773
- package/dist/todo.js +4 -2891
- package/dist/tool-help.js +3 -123
- package/dist/tool-search.js +3 -79
- package/dist/tool-tier.js +68 -33984
- package/dist/tool-use.js +2 -93
- package/dist/tree-sitter-parser-AIERW3YI.js +15 -0
- package/dist/tree.js +4 -288
- package/dist/ts-parser-RCTYKSVI.js +232 -0
- package/dist/typecheck.js +10 -3753
- package/dist/win32.js +6 -60
- package/dist/write.js +14 -9882
- package/dist/yaml-parser-4SAXV3PL.js +157 -0
- package/package.json +5 -5
|
@@ -0,0 +1,337 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getPersistentProcessRegistry
|
|
3
|
+
} from "./chunk-NKNOBUBU.js";
|
|
4
|
+
|
|
5
|
+
// src/ps-slash.ts
|
|
6
|
+
import * as os from "node:os";
|
|
7
|
+
var IDLE_THRESHOLD_MS = 2 * 6e4;
|
|
8
|
+
var STALE_THRESHOLD_MS = 5 * 6e4;
|
|
9
|
+
function now() {
|
|
10
|
+
return Date.now();
|
|
11
|
+
}
|
|
12
|
+
function formatAge(ms) {
|
|
13
|
+
if (ms < 1e3) return "0s";
|
|
14
|
+
const seconds = Math.floor(ms / 1e3);
|
|
15
|
+
if (seconds < 60) return `${seconds}s`;
|
|
16
|
+
const minutes = Math.floor(seconds / 60);
|
|
17
|
+
if (minutes < 60) return `${minutes}m`;
|
|
18
|
+
const hours = Math.floor(minutes / 60);
|
|
19
|
+
if (hours < 24) return `${hours}h`;
|
|
20
|
+
const days = Math.floor(hours / 24);
|
|
21
|
+
return `${days}d`;
|
|
22
|
+
}
|
|
23
|
+
function formatUptime(ms) {
|
|
24
|
+
return formatAge(ms);
|
|
25
|
+
}
|
|
26
|
+
function matchGlob(pattern, value) {
|
|
27
|
+
const regexPattern = pattern.replace(/[.+^${}()|[\]\\]/g, "\\$&").replace(/\*/g, ".*").replace(/\?/g, ".");
|
|
28
|
+
try {
|
|
29
|
+
const regex = new RegExp(`^${regexPattern}$`, "i");
|
|
30
|
+
return regex.test(value);
|
|
31
|
+
} catch {
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
async function listInstances(options = {}) {
|
|
36
|
+
const { includeStale = false, hostname: hostname2, status } = options;
|
|
37
|
+
const timestamp = now();
|
|
38
|
+
const registry = getPersistentProcessRegistry();
|
|
39
|
+
const globalStatus = await registry.getGlobalStatus();
|
|
40
|
+
const instances = [];
|
|
41
|
+
const instanceMap = globalStatus.instances;
|
|
42
|
+
for (const [instanceId, processes] of instanceMap) {
|
|
43
|
+
if (processes.length === 0) continue;
|
|
44
|
+
const mainProc = processes.find((p) => p.spawnMode === "main");
|
|
45
|
+
const firstProc = processes.at(0);
|
|
46
|
+
const mainPid = mainProc?.pid ?? firstProc?.pid ?? 0;
|
|
47
|
+
const hostname_ = firstProc?.hostname ?? os.hostname();
|
|
48
|
+
const startedAt = Math.min(...processes.map((p) => p.startedAt));
|
|
49
|
+
const lastActivity = Math.max(...processes.map((p) => p.lastHeartbeat));
|
|
50
|
+
const age = timestamp - lastActivity;
|
|
51
|
+
let instanceStatus = "stale";
|
|
52
|
+
if (age < IDLE_THRESHOLD_MS) instanceStatus = "active";
|
|
53
|
+
else if (age < STALE_THRESHOLD_MS) instanceStatus = "idle";
|
|
54
|
+
const sessionIds = /* @__PURE__ */ new Set();
|
|
55
|
+
for (const proc of processes) {
|
|
56
|
+
if (proc.sessionId) {
|
|
57
|
+
sessionIds.add(proc.sessionId);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
if (!includeStale && instanceStatus === "stale") continue;
|
|
61
|
+
if (hostname2 && !matchGlob(hostname2, hostname_)) continue;
|
|
62
|
+
if (status && status !== "all" && instanceStatus !== status) continue;
|
|
63
|
+
instances.push({
|
|
64
|
+
instanceId,
|
|
65
|
+
hostname: hostname_,
|
|
66
|
+
mainPid,
|
|
67
|
+
startedAt,
|
|
68
|
+
lastActivity,
|
|
69
|
+
status: instanceStatus,
|
|
70
|
+
processCount: processes.length,
|
|
71
|
+
processes,
|
|
72
|
+
sessionIds
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
instances.sort((a, b) => b.lastActivity - a.lastActivity);
|
|
76
|
+
return instances;
|
|
77
|
+
}
|
|
78
|
+
async function getInstanceCount() {
|
|
79
|
+
const instances = await listInstances({ includeStale: true });
|
|
80
|
+
const byHostname = /* @__PURE__ */ new Map();
|
|
81
|
+
let active = 0;
|
|
82
|
+
let idle = 0;
|
|
83
|
+
let stale = 0;
|
|
84
|
+
for (const inst of instances) {
|
|
85
|
+
const current = byHostname.get(inst.hostname) ?? 0;
|
|
86
|
+
byHostname.set(inst.hostname, current + 1);
|
|
87
|
+
switch (inst.status) {
|
|
88
|
+
case "active":
|
|
89
|
+
active++;
|
|
90
|
+
break;
|
|
91
|
+
case "idle":
|
|
92
|
+
idle++;
|
|
93
|
+
break;
|
|
94
|
+
case "stale":
|
|
95
|
+
stale++;
|
|
96
|
+
break;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
return {
|
|
100
|
+
total: instances.length,
|
|
101
|
+
active,
|
|
102
|
+
idle,
|
|
103
|
+
stale,
|
|
104
|
+
byHostname
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
async function getGlobalProcessStatus() {
|
|
108
|
+
const timestamp = now();
|
|
109
|
+
const registry = getPersistentProcessRegistry();
|
|
110
|
+
const globalStatus = await registry.getGlobalStatus();
|
|
111
|
+
const instances = await listInstances({ includeStale: true });
|
|
112
|
+
const localInstanceId = registry.getInstanceId();
|
|
113
|
+
const localInstance = instances.find((i) => i.instanceId === localInstanceId);
|
|
114
|
+
let localProtectedCount = 0;
|
|
115
|
+
if (localInstance) {
|
|
116
|
+
localProtectedCount = localInstance.processes.filter((p) => p.protected).length;
|
|
117
|
+
}
|
|
118
|
+
let activeInstanceCount = 0;
|
|
119
|
+
for (const inst of instances) {
|
|
120
|
+
if (inst.status === "active") activeInstanceCount++;
|
|
121
|
+
}
|
|
122
|
+
return {
|
|
123
|
+
localInstance: localInstance ? {
|
|
124
|
+
instanceId: localInstance.instanceId,
|
|
125
|
+
mainPid: localInstance.mainPid,
|
|
126
|
+
protectedCount: localProtectedCount,
|
|
127
|
+
platform: process.platform,
|
|
128
|
+
hostname: localInstance.hostname,
|
|
129
|
+
uptime: timestamp - localInstance.startedAt
|
|
130
|
+
} : {
|
|
131
|
+
instanceId: localInstanceId,
|
|
132
|
+
mainPid: process.pid,
|
|
133
|
+
protectedCount: 0,
|
|
134
|
+
platform: process.platform,
|
|
135
|
+
hostname: os.hostname(),
|
|
136
|
+
uptime: 0
|
|
137
|
+
},
|
|
138
|
+
allInstances: instances.map((inst) => ({
|
|
139
|
+
instanceId: inst.instanceId,
|
|
140
|
+
hostname: inst.hostname,
|
|
141
|
+
mainPid: inst.mainPid,
|
|
142
|
+
processes: inst.processes,
|
|
143
|
+
startedAt: inst.startedAt,
|
|
144
|
+
lastActivity: inst.lastActivity
|
|
145
|
+
})),
|
|
146
|
+
summary: {
|
|
147
|
+
totalProcesses: globalStatus.totalProcesses,
|
|
148
|
+
protectedCount: globalStatus.protectedCount,
|
|
149
|
+
staleCount: globalStatus.staleCount,
|
|
150
|
+
instanceCount: instances.length,
|
|
151
|
+
activeInstanceCount
|
|
152
|
+
},
|
|
153
|
+
timestamp
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
async function formatGlobalStatus() {
|
|
157
|
+
const status = await getGlobalProcessStatus();
|
|
158
|
+
const lines = [];
|
|
159
|
+
lines.push("=== WrongStack Global Process Status ===");
|
|
160
|
+
lines.push(`Updated: ${new Date(status.timestamp).toISOString()}`);
|
|
161
|
+
lines.push("");
|
|
162
|
+
lines.push("Summary:");
|
|
163
|
+
lines.push(` Total processes: ${status.summary.totalProcesses}`);
|
|
164
|
+
lines.push(` Protected: ${status.summary.protectedCount}`);
|
|
165
|
+
lines.push(` Stale entries: ${status.summary.staleCount}`);
|
|
166
|
+
lines.push(
|
|
167
|
+
` Instances: ${status.summary.instanceCount} (${status.summary.activeInstanceCount} active)`
|
|
168
|
+
);
|
|
169
|
+
lines.push("");
|
|
170
|
+
lines.push(`This instance (${status.localInstance.instanceId}):`);
|
|
171
|
+
lines.push(` Main PID: ${status.localInstance.mainPid}`);
|
|
172
|
+
lines.push(` Protected processes: ${status.localInstance.protectedCount}`);
|
|
173
|
+
lines.push(` Platform: ${status.localInstance.platform} (${status.localInstance.hostname})`);
|
|
174
|
+
lines.push(` Uptime: ${formatUptime(status.localInstance.uptime)}`);
|
|
175
|
+
lines.push("");
|
|
176
|
+
for (const instance of status.allInstances) {
|
|
177
|
+
if (instance.instanceId === status.localInstance.instanceId) continue;
|
|
178
|
+
const age = Math.round((status.timestamp - instance.lastActivity) / 1e3);
|
|
179
|
+
lines.push(`Instance ${instance.instanceId} (${instance.hostname}):`);
|
|
180
|
+
for (const proc of instance.processes) {
|
|
181
|
+
const procAge = formatAge(status.timestamp - proc.startedAt);
|
|
182
|
+
const heartbeatAge = formatAge(status.timestamp - proc.lastHeartbeat);
|
|
183
|
+
const protected_ = proc.protected ? "[P]" : " ";
|
|
184
|
+
lines.push(
|
|
185
|
+
` ${protected_} ${String(proc.pid).padStart(6)} ${proc.name.padEnd(20)} started ${procAge.padStart(8)} heartbeat ${heartbeatAge.padStart(6)} ${proc.spawnMode}`
|
|
186
|
+
);
|
|
187
|
+
}
|
|
188
|
+
lines.push(` Last activity: ${age}s ago`);
|
|
189
|
+
lines.push("");
|
|
190
|
+
}
|
|
191
|
+
lines.push("Legend:");
|
|
192
|
+
lines.push(" [P] = Protected (cannot be killed via bash)");
|
|
193
|
+
lines.push(" main = Main WrongStack process");
|
|
194
|
+
lines.push(" spawn = Spawned child process");
|
|
195
|
+
lines.push(" fork = Forked process (e.g., worker threads)");
|
|
196
|
+
return lines.join("\n");
|
|
197
|
+
}
|
|
198
|
+
async function formatInstanceList(options = {}) {
|
|
199
|
+
const instances = await listInstances(options);
|
|
200
|
+
const count = await getInstanceCount();
|
|
201
|
+
const lines = [];
|
|
202
|
+
lines.push("=== WrongStack Instances ===");
|
|
203
|
+
lines.push(
|
|
204
|
+
`Total: ${count.total} instances (${count.active} active, ${count.idle} idle, ${count.stale} stale)`
|
|
205
|
+
);
|
|
206
|
+
lines.push("");
|
|
207
|
+
if (count.byHostname.size > 1) {
|
|
208
|
+
lines.push("By hostname:");
|
|
209
|
+
for (const [host, num] of count.byHostname) {
|
|
210
|
+
lines.push(` ${host}: ${num} instance${num !== 1 ? "s" : ""}`);
|
|
211
|
+
}
|
|
212
|
+
lines.push("");
|
|
213
|
+
}
|
|
214
|
+
if (instances.length === 0) {
|
|
215
|
+
lines.push("No instances found matching the filter.");
|
|
216
|
+
return lines.join("\n");
|
|
217
|
+
}
|
|
218
|
+
lines.push("INSTANCES:");
|
|
219
|
+
lines.push(
|
|
220
|
+
" " + [
|
|
221
|
+
"STATUS".padEnd(7),
|
|
222
|
+
"HOSTNAME".padEnd(16),
|
|
223
|
+
"MAIN PID".padEnd(9),
|
|
224
|
+
"PROCS".padEnd(6),
|
|
225
|
+
"SESSIONS".padEnd(8),
|
|
226
|
+
"UPTIME".padEnd(8),
|
|
227
|
+
"LAST ACTIVITY"
|
|
228
|
+
].join(" ")
|
|
229
|
+
);
|
|
230
|
+
lines.push(" " + "-".repeat(80));
|
|
231
|
+
for (const inst of instances) {
|
|
232
|
+
const uptime = formatAge(Date.now() - inst.startedAt);
|
|
233
|
+
const lastAct = formatAge(Date.now() - inst.lastActivity);
|
|
234
|
+
const statusIcon = inst.status === "active" ? "[*]" : inst.status === "idle" ? "[-]" : "[ ]";
|
|
235
|
+
lines.push(
|
|
236
|
+
" " + [
|
|
237
|
+
`${statusIcon} ${inst.status}`.padEnd(7),
|
|
238
|
+
inst.hostname.padEnd(16),
|
|
239
|
+
String(inst.mainPid).padEnd(9),
|
|
240
|
+
String(inst.processCount).padEnd(6),
|
|
241
|
+
String(inst.sessionIds.size).padEnd(8),
|
|
242
|
+
uptime.padEnd(8),
|
|
243
|
+
`${lastAct} ago`
|
|
244
|
+
].join(" ")
|
|
245
|
+
);
|
|
246
|
+
}
|
|
247
|
+
lines.push("");
|
|
248
|
+
lines.push("Use /ps full for detailed process listing per instance.");
|
|
249
|
+
return lines.join("\n");
|
|
250
|
+
}
|
|
251
|
+
async function formatInstanceSummary() {
|
|
252
|
+
const count = await getInstanceCount();
|
|
253
|
+
const instances = await listInstances({ includeStale: false });
|
|
254
|
+
if (instances.length === 0) {
|
|
255
|
+
return "No active WrongStack instances.";
|
|
256
|
+
}
|
|
257
|
+
const lines = [];
|
|
258
|
+
lines.push(`${count.total} instance${count.total !== 1 ? "s" : ""}`);
|
|
259
|
+
const byStatus = /* @__PURE__ */ new Map();
|
|
260
|
+
for (const inst of instances) {
|
|
261
|
+
byStatus.set(inst.status, (byStatus.get(inst.status) ?? 0) + 1);
|
|
262
|
+
}
|
|
263
|
+
const parts = [];
|
|
264
|
+
if (byStatus.get("active")) parts.push(`${byStatus.get("active")} active`);
|
|
265
|
+
if (byStatus.get("idle")) parts.push(`${byStatus.get("idle")} idle`);
|
|
266
|
+
if (byStatus.get("stale")) parts.push(`${byStatus.get("stale")} stale`);
|
|
267
|
+
lines.push(`(${parts.join(", ")})`);
|
|
268
|
+
const totalProcs = instances.reduce((sum, inst) => sum + inst.processCount, 0);
|
|
269
|
+
lines.push(`${totalProcs} total processes`);
|
|
270
|
+
return lines.join(" ");
|
|
271
|
+
}
|
|
272
|
+
function createGlobalPsSlashCommand() {
|
|
273
|
+
return {
|
|
274
|
+
name: "ps",
|
|
275
|
+
description: "List all WrongStack instances and their processes",
|
|
276
|
+
async handler(input) {
|
|
277
|
+
try {
|
|
278
|
+
const trimmed = input.trim();
|
|
279
|
+
const parts = trimmed.split(/\s+/);
|
|
280
|
+
const sub = parts[0]?.toLowerCase() ?? "";
|
|
281
|
+
if (sub === "list" || sub === "ls" || sub === "") {
|
|
282
|
+
const output = await formatInstanceList();
|
|
283
|
+
return { message: output };
|
|
284
|
+
}
|
|
285
|
+
if (sub === "summary" || sub === "sum") {
|
|
286
|
+
const output = await formatInstanceSummary();
|
|
287
|
+
return { message: output };
|
|
288
|
+
}
|
|
289
|
+
if (sub === "full" || sub === "detail") {
|
|
290
|
+
const output = await formatGlobalStatus();
|
|
291
|
+
return { message: output };
|
|
292
|
+
}
|
|
293
|
+
if (sub === "count" || sub === "num") {
|
|
294
|
+
const count = await getInstanceCount();
|
|
295
|
+
return {
|
|
296
|
+
message: `${count.total} instance${count.total !== 1 ? "s" : ""} (${count.active} active, ${count.idle} idle, ${count.stale} stale)`
|
|
297
|
+
};
|
|
298
|
+
}
|
|
299
|
+
if (sub === "hostname" || sub === "host") {
|
|
300
|
+
const pattern = parts.slice(1).join(" ");
|
|
301
|
+
if (!pattern) {
|
|
302
|
+
return { message: "Usage: /ps hostname <pattern> (e.g., /ps hostname workstation*)" };
|
|
303
|
+
}
|
|
304
|
+
const output = await formatInstanceList({ hostname: pattern });
|
|
305
|
+
return { message: output };
|
|
306
|
+
}
|
|
307
|
+
if (sub === "status" || sub === "state") {
|
|
308
|
+
const filterStatus = parts[1]?.toLowerCase();
|
|
309
|
+
if (!["active", "idle", "stale", "all"].includes(filterStatus ?? "")) {
|
|
310
|
+
return { message: "Usage: /ps status <active|idle|stale|all>" };
|
|
311
|
+
}
|
|
312
|
+
const output = await formatInstanceList({
|
|
313
|
+
status: filterStatus
|
|
314
|
+
});
|
|
315
|
+
return { message: output };
|
|
316
|
+
}
|
|
317
|
+
return {
|
|
318
|
+
message: "Usage: /ps [list|summary|count|full|hostname <pattern>|status <state>]"
|
|
319
|
+
};
|
|
320
|
+
} catch (err) {
|
|
321
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
322
|
+
return { message: `Error getting process status: ${message}` };
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
};
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
export {
|
|
329
|
+
listInstances,
|
|
330
|
+
getInstanceCount,
|
|
331
|
+
getGlobalProcessStatus,
|
|
332
|
+
formatGlobalStatus,
|
|
333
|
+
formatInstanceList,
|
|
334
|
+
formatInstanceSummary,
|
|
335
|
+
createGlobalPsSlashCommand
|
|
336
|
+
};
|
|
337
|
+
//# sourceMappingURL=chunk-42BHI7TN.js.map
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
// src/mode.ts
|
|
2
|
+
function modeFamily(mode) {
|
|
3
|
+
if (mode.tags?.includes("lite")) return "lite";
|
|
4
|
+
if (mode.tags?.includes("deep")) return "deep";
|
|
5
|
+
if (mode.tags?.includes("balanced") || mode.id === "default") return "balanced";
|
|
6
|
+
return "custom";
|
|
7
|
+
}
|
|
8
|
+
function createModeTool(modeStore) {
|
|
9
|
+
return {
|
|
10
|
+
name: "mode",
|
|
11
|
+
category: "Session",
|
|
12
|
+
description: "Manage agent operating modes. Modes change the agent's behavior, personality, and system prompt for different workflows (e.g. coding, security review, planning).",
|
|
13
|
+
usageHint: "POWERFUL BEHAVIOR CONTROL TOOL:\n\n- Use `list` to see available modes.\n- Use `set <modeId>` to switch the agent into a specific role/mode.\n- Use `get` to check current mode.\n- Use `clear` to return to default behavior.\nSwitching modes is very effective for specialized tasks. The mode change affects how the agent reasons and which guidelines it follows.",
|
|
14
|
+
permission: "confirm",
|
|
15
|
+
// WS-046: gives permission decisions something to key on — the mode being
|
|
16
|
+
// activated. Permission semantics are unchanged.
|
|
17
|
+
subjectKey: "mode",
|
|
18
|
+
mutating: true,
|
|
19
|
+
timeoutMs: 5e3,
|
|
20
|
+
capabilities: ["session.mode"],
|
|
21
|
+
icon: "settings",
|
|
22
|
+
inputSchema: {
|
|
23
|
+
type: "object",
|
|
24
|
+
properties: {
|
|
25
|
+
action: {
|
|
26
|
+
type: "string",
|
|
27
|
+
enum: ["get", "list", "set", "clear"],
|
|
28
|
+
description: "The mode operation to perform."
|
|
29
|
+
},
|
|
30
|
+
mode: {
|
|
31
|
+
type: "string",
|
|
32
|
+
description: "The mode identifier to activate (only required when action=set)."
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
required: ["action"]
|
|
36
|
+
},
|
|
37
|
+
async execute(input) {
|
|
38
|
+
switch (input.action) {
|
|
39
|
+
case "get": {
|
|
40
|
+
const mode = await modeStore.getActiveMode();
|
|
41
|
+
return {
|
|
42
|
+
action: "get",
|
|
43
|
+
currentMode: mode?.id,
|
|
44
|
+
success: true,
|
|
45
|
+
message: mode ? `Current mode: ${mode.name} \u2014 ${mode.description}` : "No mode set (using default)"
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
case "list": {
|
|
49
|
+
const modes = await modeStore.listModes();
|
|
50
|
+
const lines = modes.map((m) => ` ${m.id.padEnd(20)} [${modeFamily(m)}] ${m.name} \u2014 ${m.description}`).join("\n");
|
|
51
|
+
return {
|
|
52
|
+
action: "list",
|
|
53
|
+
modes: modes.map((m) => ({
|
|
54
|
+
id: m.id,
|
|
55
|
+
name: m.name,
|
|
56
|
+
description: m.description,
|
|
57
|
+
family: modeFamily(m),
|
|
58
|
+
tags: m.tags ?? []
|
|
59
|
+
})),
|
|
60
|
+
success: true,
|
|
61
|
+
message: lines
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
case "set": {
|
|
65
|
+
if (!input.mode) {
|
|
66
|
+
return { action: "set", success: false, message: "mode is required for action=set" };
|
|
67
|
+
}
|
|
68
|
+
const mode = await modeStore.getMode(input.mode);
|
|
69
|
+
if (!mode) {
|
|
70
|
+
return { action: "set", success: false, message: `Mode "${input.mode}" not found` };
|
|
71
|
+
}
|
|
72
|
+
await modeStore.setActiveMode(input.mode);
|
|
73
|
+
return {
|
|
74
|
+
action: "set",
|
|
75
|
+
currentMode: mode.id,
|
|
76
|
+
success: true,
|
|
77
|
+
message: `Switched to mode: ${mode.name}
|
|
78
|
+
|
|
79
|
+
${mode.description}`
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
case "clear": {
|
|
83
|
+
await modeStore.setActiveMode(null);
|
|
84
|
+
return {
|
|
85
|
+
action: "clear",
|
|
86
|
+
success: true,
|
|
87
|
+
message: "Mode cleared \u2014 using default mode"
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
default:
|
|
91
|
+
return {
|
|
92
|
+
action: input.action,
|
|
93
|
+
success: false,
|
|
94
|
+
message: `Unknown action "${input.action}"`
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export {
|
|
102
|
+
createModeTool
|
|
103
|
+
};
|
|
104
|
+
//# sourceMappingURL=chunk-4BHUSMNL.js.map
|