@cmgmyr/hive 1.11.2 → 1.11.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.
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { atom, read, update } from 'claude-code'
|
|
2
2
|
import type { EngineInterface, Register } from 'claude-code'
|
|
3
3
|
|
|
4
|
-
import { REFRESH_MS, buildCrewView, failedView,
|
|
4
|
+
import { REFRESH_MS, buildCrewView, failedView, pollCrew } from '../model.mjs'
|
|
5
5
|
import type { CrewView } from '../types'
|
|
6
6
|
|
|
7
7
|
const PANE = 'hive-crew'
|
|
@@ -12,13 +12,14 @@ let polling = false
|
|
|
12
12
|
async function startPolling($: EngineInterface) {
|
|
13
13
|
if (polling) return
|
|
14
14
|
polling = true
|
|
15
|
-
const
|
|
15
|
+
const state = { cwd: await $.session.cwd() }
|
|
16
|
+
const isDir = (dir: string) => $.fs.stat(dir).then(s => s.kind === 'dir', () => false)
|
|
16
17
|
let busy = false
|
|
17
18
|
const refresh = async () => {
|
|
18
19
|
if (busy) return
|
|
19
20
|
busy = true
|
|
20
21
|
try {
|
|
21
|
-
const snapshot = await
|
|
22
|
+
const snapshot = await pollCrew((argv, init) => $.process.run(argv, init), isDir, state, [() => $.session.cwd(), () => $.session.root()])
|
|
22
23
|
await update($, crew, prev => buildCrewView(snapshot, prev, Date.now()))
|
|
23
24
|
} catch (err) {
|
|
24
25
|
await update($, crew, prev => failedView(prev, String(err instanceof Error ? err.message : err)))
|
|
@@ -9,12 +9,33 @@ export function ago(seconds) {
|
|
|
9
9
|
return `${Math.floor(s / 3600)}h${Math.floor((s % 3600) / 60)}m`;
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
+
export async function resolveCwd(isDir, candidates) {
|
|
13
|
+
const tried = [];
|
|
14
|
+
for (const candidate of candidates) {
|
|
15
|
+
let dir;
|
|
16
|
+
try {
|
|
17
|
+
dir = await candidate();
|
|
18
|
+
} catch {
|
|
19
|
+
continue;
|
|
20
|
+
}
|
|
21
|
+
if (typeof dir !== "string" || dir === "" || tried.includes(dir)) continue;
|
|
22
|
+
tried.push(dir);
|
|
23
|
+
if (await isDir(dir)) return dir;
|
|
24
|
+
}
|
|
25
|
+
throw new Error(`hive crew has no directory to run in (tried ${tried.join(", ") || "none"})`);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export async function pollCrew(run, isDir, state, fallbacks) {
|
|
29
|
+
state.cwd = await resolveCwd(isDir, [() => state.cwd, ...fallbacks]);
|
|
30
|
+
return readCrew(run, state.cwd);
|
|
31
|
+
}
|
|
32
|
+
|
|
12
33
|
export async function readCrew(run, cwd) {
|
|
13
34
|
let res;
|
|
14
35
|
try {
|
|
15
36
|
res = await run(["hive", "crew", "--json"], { cwd, timeoutMs: TIMEOUT_MS });
|
|
16
37
|
} catch (err) {
|
|
17
|
-
throw new Error(`hive crew did not answer: ${String(err instanceof Error ? err.message : err).slice(0, 100)}`);
|
|
38
|
+
throw new Error(`hive crew --json in ${cwd} did not answer: ${String(err instanceof Error ? err.message : err).slice(0, 100)}`);
|
|
18
39
|
}
|
|
19
40
|
if (res.exitCode !== 0) {
|
|
20
41
|
const line = String(res.stderr ?? "").split("\n").map((l) => l.trim()).find((l) => l !== "");
|
package/dist/build-info.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":"1.11.
|
|
1
|
+
{"version":"1.11.3","sha":"959b92c","dirty":false,"build_id":"9ec08cbe1418fce5591b6a2d0373e6bd5173810edd4f572aa06bdd23e49bdd11"}
|
package/dist/tools/agents.js
CHANGED
|
@@ -77,6 +77,23 @@ export function findAgent(projectId, ref) {
|
|
|
77
77
|
const candidates = partial.map((r) => `${r.name} (agent_id ${r.id})`).join(", ");
|
|
78
78
|
throw new Error(`"${ref.name}" matches ${partial.length} running agents: ${candidates}. Use the full name or agent_id.`);
|
|
79
79
|
}
|
|
80
|
+
if (/^\d+$/.test(ref.name)) {
|
|
81
|
+
const id = Number(ref.name);
|
|
82
|
+
if (Number.isSafeInteger(id)) {
|
|
83
|
+
const byId = db
|
|
84
|
+
.prepare("SELECT * FROM agents WHERE project_id = ? AND id = ? AND status = 'running'")
|
|
85
|
+
.get(projectId, id);
|
|
86
|
+
if (byId)
|
|
87
|
+
return byId;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
else if (/^[a-z]+:\d+$/i.test(ref.name)) {
|
|
91
|
+
const byActorId = db
|
|
92
|
+
.prepare("SELECT * FROM agents WHERE project_id = ? AND actor_id = ? AND status = 'running'")
|
|
93
|
+
.get(projectId, ref.name);
|
|
94
|
+
if (byActorId)
|
|
95
|
+
return byActorId;
|
|
96
|
+
}
|
|
80
97
|
throw new Error(`No running agent matching "${ref.name}" in project ${projectId}. Call agent_list.`);
|
|
81
98
|
}
|
|
82
99
|
throw new Error("Pass agent_id or name.");
|
package/package.json
CHANGED