@islamihab/kds 0.2.2 → 0.2.3
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/index.js +101 -24
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -14383,6 +14383,9 @@ config(en_default());
|
|
|
14383
14383
|
// ../../packages/env/src/cli.ts
|
|
14384
14384
|
var env = createEnv({
|
|
14385
14385
|
server: {
|
|
14386
|
+
KDS_ACTOR: exports_external.enum(["agent", "human"]).optional(),
|
|
14387
|
+
KDS_HARNESS: exports_external.string().optional(),
|
|
14388
|
+
KDS_MODEL: exports_external.string().optional(),
|
|
14386
14389
|
KDS_CONFIG_DIR: exports_external.string().optional(),
|
|
14387
14390
|
KDS_NO_UPDATE_CHECK: exports_external.string().optional(),
|
|
14388
14391
|
KDS_SERVER_URL: exports_external.url().optional()
|
|
@@ -14594,7 +14597,7 @@ import { join } from "path";
|
|
|
14594
14597
|
// package.json
|
|
14595
14598
|
var package_default = {
|
|
14596
14599
|
name: "cli",
|
|
14597
|
-
version: "0.2.
|
|
14600
|
+
version: "0.2.3",
|
|
14598
14601
|
private: true,
|
|
14599
14602
|
type: "module",
|
|
14600
14603
|
bin: {
|
|
@@ -17623,7 +17626,62 @@ function forwardErrorData(errorData, error51) {
|
|
|
17623
17626
|
error51.data = jsonToConvex(errorData);
|
|
17624
17627
|
return error51;
|
|
17625
17628
|
}
|
|
17629
|
+
// src/lib/actor.ts
|
|
17630
|
+
import { homedir as homedir2 } from "os";
|
|
17631
|
+
import { join as join2 } from "path";
|
|
17632
|
+
var HARNESSES = [
|
|
17633
|
+
{ env: "CLAUDECODE", label: "Claude Code" },
|
|
17634
|
+
{ env: "CLAUDE_CODE_ENTRYPOINT", label: "Claude Code" },
|
|
17635
|
+
{ env: "CODEX_SANDBOX", label: "Codex" },
|
|
17636
|
+
{ env: "CURSOR_AGENT", label: "Cursor" },
|
|
17637
|
+
{ env: "AI_AGENT", label: undefined }
|
|
17638
|
+
];
|
|
17639
|
+
var readEnv = (name) => {
|
|
17640
|
+
const value = process.env[name]?.trim();
|
|
17641
|
+
return value ? value : undefined;
|
|
17642
|
+
};
|
|
17643
|
+
var detectHarness = () => {
|
|
17644
|
+
if (env.KDS_HARNESS)
|
|
17645
|
+
return env.KDS_HARNESS;
|
|
17646
|
+
for (const { env: name, label } of HARNESSES) {
|
|
17647
|
+
const value = readEnv(name);
|
|
17648
|
+
if (value)
|
|
17649
|
+
return label ?? value;
|
|
17650
|
+
}
|
|
17651
|
+
return;
|
|
17652
|
+
};
|
|
17653
|
+
var TRANSCRIPT_TAIL_BYTES = 64 * 1024;
|
|
17654
|
+
var claudeCodeModel = async () => {
|
|
17655
|
+
const sessionId = readEnv("CLAUDE_CODE_SESSION_ID");
|
|
17656
|
+
if (!sessionId)
|
|
17657
|
+
return;
|
|
17658
|
+
try {
|
|
17659
|
+
const projects = join2(homedir2(), ".claude", "projects");
|
|
17660
|
+
const glob = new Bun.Glob(`*/${sessionId}.jsonl`);
|
|
17661
|
+
for await (const match of glob.scan({ cwd: projects, absolute: true })) {
|
|
17662
|
+
const file2 = Bun.file(match);
|
|
17663
|
+
const tail = await file2.slice(Math.max(0, file2.size - TRANSCRIPT_TAIL_BYTES)).text();
|
|
17664
|
+
const models = [...tail.matchAll(/"model"\s*:\s*"([^"]+)"/g)];
|
|
17665
|
+
return models.at(-1)?.[1];
|
|
17666
|
+
}
|
|
17667
|
+
} catch {}
|
|
17668
|
+
return;
|
|
17669
|
+
};
|
|
17670
|
+
var detectModel = async () => env.KDS_MODEL ?? readEnv("ANTHROPIC_MODEL") ?? await claudeCodeModel();
|
|
17671
|
+
var detectAgent = async () => {
|
|
17672
|
+
if (env.KDS_ACTOR === "human")
|
|
17673
|
+
return;
|
|
17674
|
+
const harness = detectHarness();
|
|
17675
|
+
if (!harness && env.KDS_ACTOR !== "agent")
|
|
17676
|
+
return;
|
|
17677
|
+
const model = await detectModel();
|
|
17678
|
+
return { harness: harness ?? "unidentified harness", ...model ? { model } : {} };
|
|
17679
|
+
};
|
|
17680
|
+
var claim;
|
|
17681
|
+
var agentClaim = () => claim ??= detectAgent();
|
|
17682
|
+
|
|
17626
17683
|
// src/lib/backend.ts
|
|
17684
|
+
var attributed = (args, agent) => agent === undefined ? args : { ...args, agent };
|
|
17627
17685
|
var backendClient = async () => {
|
|
17628
17686
|
const config2 = await loadConfig();
|
|
17629
17687
|
if (!config2)
|
|
@@ -17641,7 +17699,17 @@ var backendClient = async () => {
|
|
|
17641
17699
|
throw new Error("The auth server returned no Convex token");
|
|
17642
17700
|
client3.setAuth(data.token);
|
|
17643
17701
|
}
|
|
17644
|
-
return
|
|
17702
|
+
return {
|
|
17703
|
+
query: (reference, ...args) => client3.query(reference, ...args),
|
|
17704
|
+
mutation: async (reference, args) => {
|
|
17705
|
+
const widened = reference;
|
|
17706
|
+
return await client3.mutation(widened, attributed(args, await agentClaim()));
|
|
17707
|
+
},
|
|
17708
|
+
action: async (reference, args) => {
|
|
17709
|
+
const widened = reference;
|
|
17710
|
+
return await client3.action(widened, attributed(args, await agentClaim()));
|
|
17711
|
+
}
|
|
17712
|
+
};
|
|
17645
17713
|
};
|
|
17646
17714
|
|
|
17647
17715
|
// src/lib/prompt.ts
|
|
@@ -17804,27 +17872,14 @@ var logout = command({
|
|
|
17804
17872
|
}
|
|
17805
17873
|
});
|
|
17806
17874
|
|
|
17807
|
-
// src/commands/auth/status.ts
|
|
17808
|
-
var status = command({
|
|
17809
|
-
name: "status",
|
|
17810
|
-
description: "Show the signed-in user",
|
|
17811
|
-
run: async () => {
|
|
17812
|
-
const user = await (await backendClient()).query(api2.auth.getCurrentUser, {});
|
|
17813
|
-
if (!user)
|
|
17814
|
-
return console.log("Not signed in.");
|
|
17815
|
-
console.log(`Signed in as ${user.name} <${user.email}>`);
|
|
17816
|
-
}
|
|
17817
|
-
});
|
|
17818
|
-
|
|
17819
|
-
// src/commands/auth/index.ts
|
|
17820
|
-
var auth = group({
|
|
17821
|
-
name: "auth",
|
|
17822
|
-
description: "Manage backend authentication",
|
|
17823
|
-
commands: [login, logout, status]
|
|
17824
|
-
});
|
|
17825
|
-
|
|
17826
17875
|
// src/lib/activity.ts
|
|
17827
|
-
var SOURCE_LABELS = { github: "GitHub" };
|
|
17876
|
+
var SOURCE_LABELS = { github: "GitHub", agent: "Agent" };
|
|
17877
|
+
var actorLabel = (via, agent) => {
|
|
17878
|
+
if (via === undefined)
|
|
17879
|
+
return "You";
|
|
17880
|
+
const named = [agent?.model, agent?.harness].filter(Boolean).join(" \xB7 ");
|
|
17881
|
+
return named ? `${SOURCE_LABELS[via]} (${named})` : SOURCE_LABELS[via];
|
|
17882
|
+
};
|
|
17828
17883
|
var issueActivityLine = (detail) => {
|
|
17829
17884
|
const label = detail.kind.replaceAll("_", " ");
|
|
17830
17885
|
switch (detail.kind) {
|
|
@@ -17883,6 +17938,28 @@ var projectActivityLine = (detail) => {
|
|
|
17883
17938
|
}
|
|
17884
17939
|
};
|
|
17885
17940
|
|
|
17941
|
+
// src/commands/auth/status.ts
|
|
17942
|
+
var status = command({
|
|
17943
|
+
name: "status",
|
|
17944
|
+
description: "Show the signed-in user",
|
|
17945
|
+
run: async () => {
|
|
17946
|
+
const user = await (await backendClient()).query(api2.auth.getCurrentUser, {});
|
|
17947
|
+
if (!user)
|
|
17948
|
+
return console.log("Not signed in.");
|
|
17949
|
+
console.log(`Signed in as ${user.name} <${user.email}>`);
|
|
17950
|
+
const agent = await agentClaim();
|
|
17951
|
+
if (agent)
|
|
17952
|
+
console.log(`Acting as ${actorLabel("agent", agent)}; changes will show in the inbox.`);
|
|
17953
|
+
}
|
|
17954
|
+
});
|
|
17955
|
+
|
|
17956
|
+
// src/commands/auth/index.ts
|
|
17957
|
+
var auth = group({
|
|
17958
|
+
name: "auth",
|
|
17959
|
+
description: "Manage backend authentication",
|
|
17960
|
+
commands: [login, logout, status]
|
|
17961
|
+
});
|
|
17962
|
+
|
|
17886
17963
|
// src/lib/output.ts
|
|
17887
17964
|
var printTable = (rows) => {
|
|
17888
17965
|
if (rows.length === 0)
|
|
@@ -17922,7 +17999,7 @@ var runInbox = async (options) => {
|
|
|
17922
17999
|
["WHEN", "ACTOR", "WHERE", "EVENT"],
|
|
17923
18000
|
...events.map((event) => [
|
|
17924
18001
|
new Date(event.at).toISOString().slice(0, 16).replace("T", " "),
|
|
17925
|
-
|
|
18002
|
+
actorLabel(event.via, event.agent),
|
|
17926
18003
|
event.type === "issue" ? event.issue.identifier : event.project.name,
|
|
17927
18004
|
event.type === "issue" ? issueActivityLine(event.detail) : projectActivityLine(event.detail)
|
|
17928
18005
|
])
|
|
@@ -18275,7 +18352,7 @@ Feed:`);
|
|
|
18275
18352
|
for (const event of feed.events) {
|
|
18276
18353
|
const at = new Date(event.at).toISOString().slice(0, 16).replace("T", " ");
|
|
18277
18354
|
if (event.type === "activity") {
|
|
18278
|
-
const via = event.via === undefined ? "" : `
|
|
18355
|
+
const via = event.via === undefined ? "" : ` \u2014 ${actorLabel(event.via, event.agent)}`;
|
|
18279
18356
|
console.log(`${at} ${issueActivityLine(event.detail)}${via}`);
|
|
18280
18357
|
} else {
|
|
18281
18358
|
console.log(`${at} comment${event.editedAt ? " (edited)" : ""}:`);
|