@wrongstack/tools 0.310.1 → 0.313.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/_shell-pick.d.ts +5 -10
- package/dist/audit.js +10 -4055
- package/dist/bash.js +9 -2332
- package/dist/batch-tool-use.js +2 -187
- package/dist/browser/index.js +25 -1339
- package/dist/builtin.js +69 -33985
- package/dist/chunk-2CTB3UK5.js +197 -0
- package/dist/chunk-2ME7ZWDD.js +1272 -0
- package/dist/chunk-2TFQDEPU.js +113 -0
- package/dist/chunk-2ZCJNKFE.js +315 -0
- package/dist/chunk-3PVYQFRQ.js +472 -0
- package/dist/chunk-3QMQBO5Z.js +89 -0
- package/dist/chunk-42AKKX7O.js +385 -0
- package/dist/chunk-42SKEETB.js +113 -0
- package/dist/chunk-4BHUSMNL.js +104 -0
- package/dist/chunk-4I4LWFOO.js +431 -0
- package/dist/chunk-553IQUMO.js +478 -0
- package/dist/chunk-55KF77OK.js +1944 -0
- package/dist/chunk-6HLZK37X.js +359 -0
- package/dist/chunk-6RNIFLG4.js +305 -0
- package/dist/chunk-A6BRWIXN.js +317 -0
- package/dist/chunk-AHHDWNXC.js +200 -0
- package/dist/chunk-B2CIOKWP.js +899 -0
- package/dist/chunk-BTSFTGIL.js +7 -0
- package/dist/chunk-D33S4RQG.js +222 -0
- package/dist/chunk-DIJKHSUO.js +134 -0
- package/dist/chunk-DPL47QGS.js +3515 -0
- package/dist/chunk-EMRGN4KM.js +170 -0
- package/dist/chunk-FGOABE4Z.js +955 -0
- package/dist/chunk-FW65TP4G.js +520 -0
- package/dist/chunk-GOIZNNOA.js +221 -0
- package/dist/chunk-H5MJUAA6.js +295 -0
- package/dist/chunk-H5OHH6F4.js +223 -0
- package/dist/chunk-HC5RM4WY.js +199 -0
- package/dist/chunk-HEQFMLZ7.js +190 -0
- package/dist/chunk-HFXSNKCV.js +196 -0
- package/dist/chunk-HXSBQ2SE.js +1723 -0
- package/dist/chunk-ILESNGNM.js +163 -0
- package/dist/chunk-INF5CGAO.js +137 -0
- package/dist/chunk-IWDFZ6XR.js +337 -0
- package/dist/chunk-IXMNTNW5.js +238 -0
- package/dist/chunk-J4SRJKBW.js +428 -0
- package/dist/chunk-J5SKD6LN.js +235 -0
- package/dist/chunk-JRJJX3L5.js +424 -0
- package/dist/chunk-KXNDHMUB.js +366 -0
- package/dist/chunk-LIJQMYYX.js +59 -0
- package/dist/chunk-MAN26PZ5.js +260 -0
- package/dist/chunk-MKRQMLZA.js +474 -0
- package/dist/chunk-NBDZMMG2.js +169 -0
- package/dist/chunk-NHA6BEIH.js +101 -0
- package/dist/chunk-OA6YJIWL.js +4412 -0
- package/dist/chunk-OZC255IC.js +2830 -0
- package/dist/chunk-PUR6WU2B.js +154 -0
- package/dist/chunk-Q5JPPCZC.js +12 -0
- package/dist/chunk-QBV725YG.js +128 -0
- package/dist/chunk-QHVW4AAM.js +892 -0
- package/dist/chunk-QNJ7AQ4B.js +1000 -0
- package/dist/chunk-RGISBZBD.js +231 -0
- package/dist/chunk-RJZQWEMS.js +84 -0
- package/dist/chunk-RP2ZA47V.js +15 -0
- package/dist/chunk-RXISBFR5.js +315 -0
- package/dist/chunk-S5CCLZL3.js +99 -0
- package/dist/chunk-TVTCSBJF.js +122 -0
- package/dist/chunk-U4D5S3VQ.js +21 -0
- package/dist/chunk-U4VAATKP.js +193 -0
- package/dist/chunk-UKU2ZX4C.js +203 -0
- package/dist/chunk-UNSKG6DC.js +159 -0
- package/dist/chunk-URFKEIHM.js +1091 -0
- package/dist/chunk-UTV7YAW7.js +178 -0
- package/dist/chunk-V43EQ6VR.js +68 -0
- package/dist/chunk-VB3MJGCV.js +610 -0
- package/dist/chunk-WHIIIREL.js +223 -0
- package/dist/chunk-XMIFYKUT.js +1371 -0
- package/dist/chunk-YF2RSV34.js +54 -0
- package/dist/chunk-Z6DAKQ3U.js +1 -0
- package/dist/chunk-ZIGAZFWE.js +522 -0
- package/dist/circuit-breaker.js +3 -191
- package/dist/codebase-index/index.js +84 -13688
- package/dist/codebase-index/parser-worker-script.js +8 -3995
- package/dist/codebase-index/project-server.js +60 -8548
- package/dist/codebase-index/worker.js +20 -8416
- 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-6CA77WZ4.js +469 -0
- package/dist/grep.js +7 -604
- package/dist/index.js +318 -35423
- package/dist/install.js +10 -4091
- package/dist/json-parser-7YMDJSBJ.js +213 -0
- package/dist/json.js +4 -665
- package/dist/kanban.js +3 -2096
- package/dist/languages/index.js +23 -4664
- package/dist/legacy-bridge-7UKZT46G.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 -33933
- package/dist/parser-dispatch-VPOFDO2U.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/py-parser-GPM5VYRG.js +16 -0
- package/dist/read.js +13 -9816
- package/dist/replace.js +15 -10014
- package/dist/rs-parser-WVQ4KYCX.js +81 -0
- package/dist/scaffold.js +4 -253
- package/dist/search.js +5 -585
- package/dist/session-kanban.js +30 -972
- package/dist/skill.js +2 -215
- 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 -34020
- package/dist/tool-use.js +2 -93
- package/dist/tree-sitter-parser-YCILHGZD.js +17 -0
- package/dist/tree.js +4 -288
- package/dist/ts-parser-YH4ZMWMH.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-GFAOKV53.js +157 -0
- package/package.json +5 -5
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
// src/codebase-index/languages.ts
|
|
2
|
+
import * as path from "node:path";
|
|
3
|
+
var EXT_TO_LANG = {
|
|
4
|
+
// TypeScript / JavaScript (first-class TS compiler API)
|
|
5
|
+
".ts": "ts",
|
|
6
|
+
".mts": "ts",
|
|
7
|
+
".cts": "ts",
|
|
8
|
+
".tsx": "tsx",
|
|
9
|
+
".js": "js",
|
|
10
|
+
".mjs": "js",
|
|
11
|
+
".cjs": "js",
|
|
12
|
+
".jsx": "jsx",
|
|
13
|
+
// First-class native/spawn parsers (+ regex fallback)
|
|
14
|
+
".go": "go",
|
|
15
|
+
".py": "py",
|
|
16
|
+
".pyi": "py",
|
|
17
|
+
".pyw": "py",
|
|
18
|
+
".rs": "rs",
|
|
19
|
+
".json": "json",
|
|
20
|
+
".jsonc": "json",
|
|
21
|
+
".yaml": "yaml",
|
|
22
|
+
".yml": "yaml",
|
|
23
|
+
// C family
|
|
24
|
+
".c": "c",
|
|
25
|
+
".h": "c",
|
|
26
|
+
".cc": "cpp",
|
|
27
|
+
".cpp": "cpp",
|
|
28
|
+
".cxx": "cpp",
|
|
29
|
+
".hh": "cpp",
|
|
30
|
+
".hpp": "cpp",
|
|
31
|
+
".hxx": "cpp",
|
|
32
|
+
// JVM / .NET
|
|
33
|
+
".java": "java",
|
|
34
|
+
".cs": "csharp",
|
|
35
|
+
".kt": "kotlin",
|
|
36
|
+
".kts": "kotlin",
|
|
37
|
+
".scala": "scala",
|
|
38
|
+
".sc": "scala",
|
|
39
|
+
// Scripting
|
|
40
|
+
".php": "php",
|
|
41
|
+
".rb": "ruby",
|
|
42
|
+
".swift": "swift",
|
|
43
|
+
".dart": "dart",
|
|
44
|
+
".lua": "lua",
|
|
45
|
+
".r": "r",
|
|
46
|
+
".R": "r",
|
|
47
|
+
".pl": "other",
|
|
48
|
+
".pm": "other",
|
|
49
|
+
// Systems / functional
|
|
50
|
+
".zig": "zig",
|
|
51
|
+
".ex": "elixir",
|
|
52
|
+
".exs": "elixir",
|
|
53
|
+
".hs": "haskell",
|
|
54
|
+
".lhs": "haskell",
|
|
55
|
+
// Shell / data / docs / web
|
|
56
|
+
".sh": "shell",
|
|
57
|
+
".bash": "shell",
|
|
58
|
+
".zsh": "shell",
|
|
59
|
+
".ps1": "shell",
|
|
60
|
+
".sql": "sql",
|
|
61
|
+
".md": "md",
|
|
62
|
+
".mdx": "md",
|
|
63
|
+
".toml": "toml",
|
|
64
|
+
".html": "html",
|
|
65
|
+
".htm": "html",
|
|
66
|
+
".css": "css",
|
|
67
|
+
".scss": "css",
|
|
68
|
+
".less": "css",
|
|
69
|
+
".vue": "vue",
|
|
70
|
+
".svelte": "svelte",
|
|
71
|
+
".proto": "proto",
|
|
72
|
+
".graphql": "graphql",
|
|
73
|
+
".gql": "graphql"
|
|
74
|
+
};
|
|
75
|
+
var INDEXABLE_EXTENSIONS = Object.freeze(
|
|
76
|
+
[...new Set(Object.keys(EXT_TO_LANG).map((e) => e.toLowerCase()))].sort()
|
|
77
|
+
);
|
|
78
|
+
var SPECIAL_FILENAMES = {
|
|
79
|
+
makefile: "other",
|
|
80
|
+
gnumakefile: "other",
|
|
81
|
+
dockerfile: "other",
|
|
82
|
+
"docker-compose.yml": "yaml",
|
|
83
|
+
"docker-compose.yaml": "yaml",
|
|
84
|
+
"cmakelists.txt": "other",
|
|
85
|
+
gemfile: "ruby",
|
|
86
|
+
rakefile: "ruby",
|
|
87
|
+
procfile: "other",
|
|
88
|
+
justfile: "other"
|
|
89
|
+
};
|
|
90
|
+
function detectLang(file) {
|
|
91
|
+
const base = path.basename(file);
|
|
92
|
+
const lowerBase = base.toLowerCase();
|
|
93
|
+
if (lowerBase.endsWith(".d.ts") || lowerBase.endsWith(".d.mts") || lowerBase.endsWith(".d.cts")) {
|
|
94
|
+
return "ts";
|
|
95
|
+
}
|
|
96
|
+
const special = SPECIAL_FILENAMES[lowerBase];
|
|
97
|
+
if (special) return special;
|
|
98
|
+
const ext = path.extname(base).toLowerCase();
|
|
99
|
+
if (!ext) return null;
|
|
100
|
+
return EXT_TO_LANG[ext] ?? null;
|
|
101
|
+
}
|
|
102
|
+
function isIndexablePath(file) {
|
|
103
|
+
return detectLang(file) !== null;
|
|
104
|
+
}
|
|
105
|
+
var LANG_FAMILY = {
|
|
106
|
+
// Single-compilation-unit family: a .vue/.svelte script block is JS/TS and
|
|
107
|
+
// imports from — and is imported by — plain .ts files.
|
|
108
|
+
ts: "js",
|
|
109
|
+
tsx: "js",
|
|
110
|
+
js: "js",
|
|
111
|
+
jsx: "js",
|
|
112
|
+
vue: "js",
|
|
113
|
+
svelte: "js",
|
|
114
|
+
go: "go",
|
|
115
|
+
py: "py",
|
|
116
|
+
rs: "rs",
|
|
117
|
+
// The JVM resolves across languages: Kotlin and Scala call Java directly.
|
|
118
|
+
java: "jvm",
|
|
119
|
+
kotlin: "jvm",
|
|
120
|
+
scala: "jvm",
|
|
121
|
+
csharp: "dotnet",
|
|
122
|
+
// A .h header is consumed by both C and C++ translation units.
|
|
123
|
+
c: "c",
|
|
124
|
+
cpp: "c",
|
|
125
|
+
ruby: "ruby",
|
|
126
|
+
php: "php",
|
|
127
|
+
swift: "swift",
|
|
128
|
+
dart: "dart",
|
|
129
|
+
elixir: "elixir",
|
|
130
|
+
haskell: "haskell",
|
|
131
|
+
zig: "zig",
|
|
132
|
+
lua: "lua",
|
|
133
|
+
r: "r",
|
|
134
|
+
shell: "shell",
|
|
135
|
+
sql: "sql",
|
|
136
|
+
json: "data",
|
|
137
|
+
yaml: "data",
|
|
138
|
+
toml: "data",
|
|
139
|
+
html: "web",
|
|
140
|
+
css: "web",
|
|
141
|
+
proto: "proto",
|
|
142
|
+
graphql: "graphql",
|
|
143
|
+
md: "other",
|
|
144
|
+
other: "other"
|
|
145
|
+
};
|
|
146
|
+
var LANG_FAMILY_ENTRIES = Object.freeze(
|
|
147
|
+
Object.entries(LANG_FAMILY).map(
|
|
148
|
+
([lang, family]) => Object.freeze([lang, family])
|
|
149
|
+
)
|
|
150
|
+
);
|
|
151
|
+
function languageFamily(lang) {
|
|
152
|
+
return LANG_FAMILY[lang] ?? "other";
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
export {
|
|
156
|
+
EXT_TO_LANG,
|
|
157
|
+
INDEXABLE_EXTENSIONS,
|
|
158
|
+
detectLang,
|
|
159
|
+
isIndexablePath,
|
|
160
|
+
LANG_FAMILY_ENTRIES,
|
|
161
|
+
languageFamily
|
|
162
|
+
};
|
|
163
|
+
//# sourceMappingURL=chunk-ILESNGNM.js.map
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import {
|
|
2
|
+
tryLegacyCodeOperation
|
|
3
|
+
} from "./chunk-NHA6BEIH.js";
|
|
4
|
+
import {
|
|
5
|
+
spawnStream
|
|
6
|
+
} from "./chunk-MAN26PZ5.js";
|
|
7
|
+
import {
|
|
8
|
+
detectPackageManager,
|
|
9
|
+
normalizeCommandOutput,
|
|
10
|
+
safeResolveReal
|
|
11
|
+
} from "./chunk-D33S4RQG.js";
|
|
12
|
+
|
|
13
|
+
// src/typecheck.ts
|
|
14
|
+
import * as path from "node:path";
|
|
15
|
+
var typecheckTool = {
|
|
16
|
+
name: "typecheck",
|
|
17
|
+
category: "Code Quality",
|
|
18
|
+
description: "Run the project's TypeScript type checker (`tsc --noEmit` or equivalent). Essential for verifying type safety before making changes or committing.",
|
|
19
|
+
usageHint: "ALWAYS RUN BEFORE CONSIDERING WORK COMPLETE:\n\n- Use this to catch type errors early.\n- In monorepos, `all: true` will check every package.\n- This is one of the most important quality gates in this project.\nNever claim a task is done without a clean typecheck (unless the user explicitly says otherwise).",
|
|
20
|
+
permission: "confirm",
|
|
21
|
+
mutating: false,
|
|
22
|
+
timeoutMs: 12e4,
|
|
23
|
+
capabilities: ["shell.restricted"],
|
|
24
|
+
icon: "code",
|
|
25
|
+
inputSchema: {
|
|
26
|
+
type: "object",
|
|
27
|
+
properties: {
|
|
28
|
+
project: { type: "string", description: "Path to tsconfig.json (default: auto-detect)" },
|
|
29
|
+
cwd: { type: "string", description: "Working directory (default: cwd)" },
|
|
30
|
+
strict: {
|
|
31
|
+
type: "boolean",
|
|
32
|
+
description: "Add --strict flag for maximum type checking (default: false)"
|
|
33
|
+
},
|
|
34
|
+
all: {
|
|
35
|
+
type: "boolean",
|
|
36
|
+
description: "Type-check all workspace packages (pnpm workspaces run `pnpm -r exec tsc --noEmit`; other setups run a single `tsc --noEmit` at cwd) (default: false)"
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
async execute(input, ctx, opts) {
|
|
41
|
+
let final;
|
|
42
|
+
const executeStream = typecheckTool.executeStream;
|
|
43
|
+
if (!executeStream) throw new Error("typecheckTool: stream execution unavailable");
|
|
44
|
+
for await (const ev of executeStream(input, ctx, opts)) {
|
|
45
|
+
if (ev.type === "final") final = ev.output;
|
|
46
|
+
}
|
|
47
|
+
if (!final) throw new Error("typecheck: stream ended without final event");
|
|
48
|
+
return final;
|
|
49
|
+
},
|
|
50
|
+
async *executeStream(input, ctx, opts) {
|
|
51
|
+
const cwd = input.cwd ? await safeResolveReal(input.cwd, ctx) : ctx.cwd;
|
|
52
|
+
const bridge = await tryLegacyCodeOperation("semantic", {
|
|
53
|
+
cwd,
|
|
54
|
+
projectRoot: ctx.projectRoot,
|
|
55
|
+
signal: opts.signal
|
|
56
|
+
});
|
|
57
|
+
if (bridge?.run) {
|
|
58
|
+
const run = bridge.run;
|
|
59
|
+
yield {
|
|
60
|
+
type: "final",
|
|
61
|
+
output: {
|
|
62
|
+
project: `${bridge.language} workspace`,
|
|
63
|
+
exit_code: run.exitCode ?? 0,
|
|
64
|
+
errors: run.summary.errors,
|
|
65
|
+
warnings: run.summary.warnings,
|
|
66
|
+
output: normalizeCommandOutput(run.output || run.error || ""),
|
|
67
|
+
truncated: run.truncated
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
let cmd;
|
|
73
|
+
let cmdArgs;
|
|
74
|
+
let project;
|
|
75
|
+
if (input.all) {
|
|
76
|
+
project = "workspace";
|
|
77
|
+
const tscArgs = ["--noEmit"];
|
|
78
|
+
if (input.strict) tscArgs.push("--strict");
|
|
79
|
+
const manager = await detectPackageManager(cwd, ctx.projectRoot);
|
|
80
|
+
if (manager === "pnpm") {
|
|
81
|
+
cmd = "pnpm";
|
|
82
|
+
cmdArgs = ["-r", "--no-bail", "exec", "tsc", ...tscArgs];
|
|
83
|
+
} else {
|
|
84
|
+
cmd = "npx";
|
|
85
|
+
cmdArgs = ["tsc", ...tscArgs];
|
|
86
|
+
}
|
|
87
|
+
} else {
|
|
88
|
+
const tsconfig = input.project ? await safeResolveReal(input.project, ctx) : await findTsConfig(cwd);
|
|
89
|
+
const tscArgs = ["--noEmit"];
|
|
90
|
+
if (input.strict) tscArgs.push("--strict");
|
|
91
|
+
if (tsconfig) tscArgs.push("--project", tsconfig);
|
|
92
|
+
project = tsconfig ?? "default";
|
|
93
|
+
cmd = "npx";
|
|
94
|
+
cmdArgs = ["tsc", ...tscArgs];
|
|
95
|
+
}
|
|
96
|
+
yield { type: "log", text: `${cmd} ${cmdArgs.join(" ")}`, data: { project } };
|
|
97
|
+
const result = yield* spawnStream({
|
|
98
|
+
cmd,
|
|
99
|
+
args: cmdArgs,
|
|
100
|
+
cwd,
|
|
101
|
+
signal: opts.signal,
|
|
102
|
+
maxBytes: 2e5
|
|
103
|
+
});
|
|
104
|
+
const combined = `${result.stdout}
|
|
105
|
+
${result.stderr}`;
|
|
106
|
+
const errors = [...combined.matchAll(/^.*\berror TS\d+:/gm)].length;
|
|
107
|
+
const warnings = [...combined.matchAll(/^.*\bwarning TS\d+:/gm)].length;
|
|
108
|
+
yield {
|
|
109
|
+
type: "final",
|
|
110
|
+
output: {
|
|
111
|
+
project,
|
|
112
|
+
exit_code: result.exitCode,
|
|
113
|
+
errors,
|
|
114
|
+
warnings,
|
|
115
|
+
output: normalizeCommandOutput(result.stdout || result.stderr || result.error || ""),
|
|
116
|
+
truncated: result.truncated
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
async function findTsConfig(cwd) {
|
|
122
|
+
const { stat } = await import("node:fs/promises");
|
|
123
|
+
const candidates = ["tsconfig.json", "tsconfig.base.json"];
|
|
124
|
+
for (const f of candidates) {
|
|
125
|
+
try {
|
|
126
|
+
const s = await stat(path.join(cwd, f));
|
|
127
|
+
if (s.isFile()) return path.join(cwd, f);
|
|
128
|
+
} catch {
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
return null;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
export {
|
|
135
|
+
typecheckTool
|
|
136
|
+
};
|
|
137
|
+
//# sourceMappingURL=chunk-INF5CGAO.js.map
|
|
@@ -0,0 +1,337 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getPersistentProcessRegistry
|
|
3
|
+
} from "./chunk-ZIGAZFWE.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-IWDFZ6XR.js.map
|