khala-cli 0.4.7 → 0.4.9
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/README.md +20 -3
- package/dist/THIRD_PARTY_NOTICES.txt +781 -0
- package/dist/{chunk-SU6362YU.mjs → chunk-3KDOTR54.mjs} +4 -2
- package/dist/{chunk-K6EJSZYO.mjs → chunk-3R6HFSLL.mjs} +149 -40
- package/dist/{chunk-OAFYPBCP.mjs → chunk-47XNLAJG.mjs} +5 -1
- package/dist/chunk-6BO3JSUP.mjs +33 -0
- package/dist/chunk-7R3EIDGR.mjs +58 -0
- package/dist/{chunk-YIHRHD7W.mjs → chunk-ANSR4IAW.mjs} +5 -1
- package/dist/chunk-BEO7WIIM.mjs +153 -0
- package/dist/chunk-BLCRVRIK.mjs +1000 -0
- package/dist/{chunk-LNG3ZZBK.mjs → chunk-BV45NK7K.mjs} +5 -1
- package/dist/{chunk-6YEYXZZB.mjs → chunk-DJM23SIU.mjs} +8 -8
- package/dist/{chunk-25AX7UMF.mjs → chunk-FO5GXCST.mjs} +24 -10
- package/dist/{chunk-IG2NU5J6.mjs → chunk-FZEH2IXZ.mjs} +95 -15
- package/dist/{chunk-TOBQUAPD.mjs → chunk-GSZADJMW.mjs} +253 -73
- package/dist/chunk-ITFD3JZS.mjs +1137 -0
- package/dist/chunk-K7V7X6WU.mjs +207 -0
- package/dist/chunk-KMLXOPBQ.mjs +20 -0
- package/dist/chunk-LBT47HLZ.mjs +19 -0
- package/dist/{chunk-3OFKVYOX.mjs → chunk-NGSYOVQ4.mjs} +12 -1
- package/dist/chunk-NIX5F4LT.mjs +863 -0
- package/dist/chunk-NPSQNCOY.mjs +590 -0
- package/dist/chunk-P3YIN7G7.mjs +26 -0
- package/dist/chunk-PAJ4JJPV.mjs +9827 -0
- package/dist/{chunk-ODTSGEID.mjs → chunk-PDZ5Z5ZE.mjs} +9 -6
- package/dist/chunk-QKWEZXR3.mjs +52 -0
- package/dist/chunk-SSO5RFOX.mjs +7 -0
- package/dist/{chunk-W5HS2PQO.mjs → chunk-T7IL7V7Q.mjs} +11 -9
- package/dist/{chunk-OP2HZ7EM.mjs → chunk-TANCKTDK.mjs} +24 -5
- package/dist/chunk-TEFOQXBK.mjs +44 -0
- package/dist/{chunk-7V2YQIRI.mjs → chunk-UK5GJO4Y.mjs} +22 -9
- package/dist/{chunk-C5SMOUTO.mjs → chunk-V4F3SYKW.mjs} +38 -11
- package/dist/{chunk-L7L6UNXN.mjs → chunk-WDOHRV3D.mjs} +31 -19
- package/dist/chunk-XBQDIKB5.mjs +18 -0
- package/dist/chunk-XUCWSYVS.mjs +148 -0
- package/dist/khala.mjs +20 -13
- package/dist/web/assets/local-CFzRHZpB.js +9 -0
- package/dist/web/assets/{local-OwDq47O4.css → local-ciypUFoK.css} +1 -1
- package/dist/web/index.html +2 -2
- package/package.json +5 -3
- package/dist/chunk-4LSCOWWN.mjs +0 -237
- package/dist/chunk-5GLTKWJ5.mjs +0 -1
- package/dist/chunk-5RGEO5HN.mjs +0 -142
- package/dist/chunk-APIWKRKG.mjs +0 -8
- package/dist/chunk-JEI32DEA.mjs +0 -634
- package/dist/chunk-S3FX7VCY.mjs +0 -386
- package/dist/chunk-U3MKSPRO.mjs +0 -227
- package/dist/chunk-WNOIHCCC.mjs +0 -191
- package/dist/web/assets/local-BQl2KrE1.js +0 -9
package/dist/chunk-5RGEO5HN.mjs
DELETED
|
@@ -1,142 +0,0 @@
|
|
|
1
|
-
import { createRequire as __khalaCreateRequire } from 'node:module'; const require = __khalaCreateRequire(import.meta.url);
|
|
2
|
-
import {
|
|
3
|
-
SESSION_ID_PATTERN,
|
|
4
|
-
ensureStateDir,
|
|
5
|
-
readJson,
|
|
6
|
-
stateRoot,
|
|
7
|
-
writeJsonAtomic
|
|
8
|
-
} from "./chunk-WNOIHCCC.mjs";
|
|
9
|
-
|
|
10
|
-
// src/harness/session-sources.ts
|
|
11
|
-
import path from "node:path";
|
|
12
|
-
|
|
13
|
-
// src/harness/proc.ts
|
|
14
|
-
import { execFile } from "node:child_process";
|
|
15
|
-
import { readFile } from "node:fs/promises";
|
|
16
|
-
import { promisify } from "node:util";
|
|
17
|
-
var execFileAsync = promisify(execFile);
|
|
18
|
-
var validPid = (pid) => Number.isSafeInteger(pid) && pid > 0;
|
|
19
|
-
function startToken(value) {
|
|
20
|
-
return value.trim().replace(/[^a-zA-Z0-9_-]+/g, "-");
|
|
21
|
-
}
|
|
22
|
-
function parseLinuxStat(pid, text) {
|
|
23
|
-
const open = text.indexOf("(");
|
|
24
|
-
const close = text.lastIndexOf(")");
|
|
25
|
-
if (!validPid(pid) || open < 0 || close < open || Number(text.slice(0, open).trim()) !== pid) return null;
|
|
26
|
-
const fields = text.slice(close + 1).trim().split(/\s+/);
|
|
27
|
-
const ppid = Number(fields[1]);
|
|
28
|
-
const startTime = fields[19];
|
|
29
|
-
if (!Number.isSafeInteger(ppid) || ppid < 0 || !startTime || !/^\d+$/.test(startTime)) return null;
|
|
30
|
-
return { pid, ppid, startTime, command: text.slice(open + 1, close) };
|
|
31
|
-
}
|
|
32
|
-
function parseDarwinPs(pid, text) {
|
|
33
|
-
const match = text.trim().match(/^(\d+)\s+([A-Za-z]{3}\s+[A-Za-z]{3}\s+\d{1,2}\s+\d{2}:\d{2}:\d{2}\s+\d{4})\s+(.+)$/);
|
|
34
|
-
if (!validPid(pid) || !match) return null;
|
|
35
|
-
return { pid, ppid: Number(match[1]), startTime: startToken(match[2]), command: match[3] };
|
|
36
|
-
}
|
|
37
|
-
function csvFields(line) {
|
|
38
|
-
const fields = [];
|
|
39
|
-
let value = "";
|
|
40
|
-
let quoted = false;
|
|
41
|
-
for (let i = 0; i < line.length; i++) {
|
|
42
|
-
const char = line[i];
|
|
43
|
-
if (char === '"') {
|
|
44
|
-
if (quoted && line[i + 1] === '"') {
|
|
45
|
-
value += '"';
|
|
46
|
-
i++;
|
|
47
|
-
} else quoted = !quoted;
|
|
48
|
-
} else if (char === "," && !quoted) {
|
|
49
|
-
fields.push(value);
|
|
50
|
-
value = "";
|
|
51
|
-
} else value += char;
|
|
52
|
-
}
|
|
53
|
-
if (quoted) return null;
|
|
54
|
-
fields.push(value);
|
|
55
|
-
return fields;
|
|
56
|
-
}
|
|
57
|
-
function parseWindowsCsv(text, pid) {
|
|
58
|
-
if (!validPid(pid)) return null;
|
|
59
|
-
const lines = text.replace(/^\uFEFF/, "").split(/\r?\n/).filter((line) => line.trim() && !line.startsWith("#"));
|
|
60
|
-
const headers = csvFields(lines[0] ?? "");
|
|
61
|
-
if (!headers) return null;
|
|
62
|
-
for (const line of lines.slice(1)) {
|
|
63
|
-
const values = csvFields(line);
|
|
64
|
-
if (!values) continue;
|
|
65
|
-
const field = (name) => values[headers.indexOf(name)] ?? "";
|
|
66
|
-
if (Number(field("ProcessId")) !== pid) continue;
|
|
67
|
-
const ppid = Number(field("ParentProcessId"));
|
|
68
|
-
const startTime = startToken(field("CreationDate"));
|
|
69
|
-
const command = field("Name");
|
|
70
|
-
if (!field("ParentProcessId") || !Number.isSafeInteger(ppid) || ppid < 0 || !startTime || !command) return null;
|
|
71
|
-
return { pid, ppid, startTime, command };
|
|
72
|
-
}
|
|
73
|
-
return null;
|
|
74
|
-
}
|
|
75
|
-
async function readProcess(pid) {
|
|
76
|
-
if (!validPid(pid)) return null;
|
|
77
|
-
try {
|
|
78
|
-
if (process.platform === "linux") return parseLinuxStat(pid, await readFile(`/proc/${pid}/stat`, "utf8"));
|
|
79
|
-
if (process.platform === "darwin") {
|
|
80
|
-
const { stdout } = await execFileAsync("ps", ["-o", "ppid=,lstart=,comm=", "-p", String(pid)], { env: { ...process.env, LC_ALL: "C" }, timeout: 5e3 });
|
|
81
|
-
return parseDarwinPs(pid, stdout);
|
|
82
|
-
}
|
|
83
|
-
if (process.platform === "win32") {
|
|
84
|
-
const script = `Get-CimInstance Win32_Process -Filter 'ProcessId = ${pid}' | Select-Object ProcessId,ParentProcessId,@{Name='CreationDate';Expression={$_.CreationDate.ToUniversalTime().ToString('o')}},Name | ConvertTo-Csv -NoTypeInformation`;
|
|
85
|
-
const { stdout } = await execFileAsync("powershell.exe", ["-NoProfile", "-NonInteractive", "-Command", script], { timeout: 5e3 });
|
|
86
|
-
return parseWindowsCsv(stdout, pid);
|
|
87
|
-
}
|
|
88
|
-
} catch {
|
|
89
|
-
}
|
|
90
|
-
return null;
|
|
91
|
-
}
|
|
92
|
-
async function* walkAncestors(pid, read = readProcess) {
|
|
93
|
-
const seen = /* @__PURE__ */ new Set([pid]);
|
|
94
|
-
let current = await read(pid);
|
|
95
|
-
while (current && validPid(current.ppid) && !seen.has(current.ppid)) {
|
|
96
|
-
seen.add(current.ppid);
|
|
97
|
-
current = await read(current.ppid);
|
|
98
|
-
if (current) yield current;
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
async function nearestNonShellAncestor(pid, read = readProcess) {
|
|
102
|
-
for await (const ancestor of walkAncestors(pid, read)) {
|
|
103
|
-
const name = ancestor.command.split(/[\\/]/).pop()?.replace(/^-/, "").toLowerCase() ?? "";
|
|
104
|
-
if (!/^(?:sh|bash|dash|zsh|fish|ksh|csh|tcsh|ash|cmd(?:\.exe)?|powershell(?:\.exe)?|pwsh(?:\.exe)?)$/.test(name)) return ancestor;
|
|
105
|
-
}
|
|
106
|
-
return null;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
// src/harness/session-sources.ts
|
|
110
|
-
var SESSION_UNKNOWN_HINT = "Send the agent one message first, then retry.";
|
|
111
|
-
var mappingDir = (harness, env) => path.join(stateRoot(env), harness, ".by-pid");
|
|
112
|
-
async function recordHookSession(harness, sessionId, env, options = {}) {
|
|
113
|
-
if (!SESSION_ID_PATTERN.test(sessionId)) return;
|
|
114
|
-
const parent = await nearestNonShellAncestor(options.pid ?? process.pid, options.readProcess ?? readProcess);
|
|
115
|
-
if (!parent) return;
|
|
116
|
-
const dir = mappingDir(harness, env);
|
|
117
|
-
await ensureStateDir(dir);
|
|
118
|
-
const file = path.join(dir, `${parent.pid}.json`);
|
|
119
|
-
const at = (options.now ?? (() => /* @__PURE__ */ new Date()))().toISOString();
|
|
120
|
-
const previous = await readJson(file);
|
|
121
|
-
if (previous?.startTime === parent.startTime && typeof previous.at === "string" && previous.at > at) return;
|
|
122
|
-
await writeJsonAtomic(file, {
|
|
123
|
-
sessionId,
|
|
124
|
-
startTime: parent.startTime,
|
|
125
|
-
at,
|
|
126
|
-
...options.workspace !== void 0 ? { workspace: options.workspace } : {}
|
|
127
|
-
});
|
|
128
|
-
}
|
|
129
|
-
async function resolveSources(sources, meta, env, context) {
|
|
130
|
-
for (const source of sources) {
|
|
131
|
-
const value = await source.resolve(meta, env, context);
|
|
132
|
-
if (value === void 0 || value === null) continue;
|
|
133
|
-
return typeof value === "string" && SESSION_ID_PATTERN.test(value) ? { sessionId: value, rejoinable: source.rejoinable(value) } : null;
|
|
134
|
-
}
|
|
135
|
-
return null;
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
export {
|
|
139
|
-
SESSION_UNKNOWN_HINT,
|
|
140
|
-
recordHookSession,
|
|
141
|
-
resolveSources
|
|
142
|
-
};
|
package/dist/chunk-APIWKRKG.mjs
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { createRequire as __khalaCreateRequire } from 'node:module'; const require = __khalaCreateRequire(import.meta.url);
|
|
2
|
-
|
|
3
|
-
// <define:__KHALA_BUNDLE__>
|
|
4
|
-
var define_KHALA_BUNDLE_default = { name: "khala-cli", version: "0.4.7" };
|
|
5
|
-
|
|
6
|
-
export {
|
|
7
|
-
define_KHALA_BUNDLE_default
|
|
8
|
-
};
|