@polderlabs/bizar-plugin 0.5.4
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/LICENSE +21 -0
- package/README.md +448 -0
- package/bun.lock +88 -0
- package/index.ts +1113 -0
- package/package.json +42 -0
- package/scripts/check-forbidden-imports.sh +33 -0
- package/src/background-state.ts +463 -0
- package/src/background.ts +964 -0
- package/src/commands-impl.ts +369 -0
- package/src/commands.ts +880 -0
- package/src/event-stream.ts +574 -0
- package/src/fingerprint.ts +120 -0
- package/src/handoff.ts +79 -0
- package/src/http-client.ts +467 -0
- package/src/logger.ts +144 -0
- package/src/loop.ts +176 -0
- package/src/options.ts +421 -0
- package/src/plan-fs.ts +323 -0
- package/src/report.ts +178 -0
- package/src/research-prompt.ts +35 -0
- package/src/serve.ts +476 -0
- package/src/settings.ts +349 -0
- package/src/state.ts +298 -0
- package/src/tools/bg-collect.ts +104 -0
- package/src/tools/bg-get-comments.ts +239 -0
- package/src/tools/bg-kill.ts +87 -0
- package/src/tools/bg-spawn.ts +263 -0
- package/src/tools/bg-status.ts +99 -0
- package/src/tools/plan-action.ts +767 -0
- package/src/tools/wait-for-feedback.ts +402 -0
- package/tests/attach-handler-bug.test.ts +166 -0
- package/tests/background-state.test.ts +277 -0
- package/tests/background.test.ts +402 -0
- package/tests/block.test.ts +193 -0
- package/tests/canonical-key-order.test.ts +71 -0
- package/tests/commands-impl.test.ts +442 -0
- package/tests/commands.test.ts +548 -0
- package/tests/config.test.ts +122 -0
- package/tests/dispose.test.ts +336 -0
- package/tests/event-stream.test.ts +409 -0
- package/tests/event.test.ts +262 -0
- package/tests/fingerprint.test.ts +161 -0
- package/tests/http-client.test.ts +403 -0
- package/tests/init-helpers.test.ts +203 -0
- package/tests/integration/slash-command.test.ts +348 -0
- package/tests/integration/tool-routing.test.ts +314 -0
- package/tests/loop.test.ts +397 -0
- package/tests/options.test.ts +274 -0
- package/tests/serve.test.ts +335 -0
- package/tests/settings.test.ts +351 -0
- package/tests/stall-think.test.ts +749 -0
- package/tests/state.test.ts +275 -0
- package/tests/tools/bg-collect.test.ts +337 -0
- package/tests/tools/bg-get-comments.test.ts +485 -0
- package/tests/tools/bg-kill.test.ts +231 -0
- package/tests/tools/bg-spawn.test.ts +311 -0
- package/tests/tools/bg-status.test.ts +216 -0
- package/tests/tools/plan-action.test.ts +599 -0
- package/tests/tools/wait-for-feedback.test.ts +390 -0
- package/tsconfig.json +29 -0
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* bg-status.ts
|
|
3
|
+
*
|
|
4
|
+
* `bizar_status` tool (v0.4.2 spec §7.1).
|
|
5
|
+
*
|
|
6
|
+
* Read-only — available to ALL agents (Vör, Frigg, Quick, Odin) per
|
|
7
|
+
* §6.3. Returns a snapshot of the in-memory instance list, optionally
|
|
8
|
+
* filtered by `instanceId`. The result is the `InstanceView` shape
|
|
9
|
+
* (subset of `BackgroundState`); see `background.ts` for the type.
|
|
10
|
+
*
|
|
11
|
+
* Returns:
|
|
12
|
+
* `Array<{ instanceId, agent, status, startedAt, toolCallCount,
|
|
13
|
+
* promptPreview, resultPreview?, error?, parentAgent,
|
|
14
|
+
* parentInstanceId? }>`
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import { tool } from "@opencode-ai/plugin";
|
|
18
|
+
import { z } from "zod";
|
|
19
|
+
|
|
20
|
+
import type { InstanceManager, InstanceView } from "../background.js";
|
|
21
|
+
import type { Logger } from "../logger.js";
|
|
22
|
+
|
|
23
|
+
export interface BgStatusDeps {
|
|
24
|
+
instanceManager: InstanceManager;
|
|
25
|
+
logger: Logger;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Build the `bizar_status` tool. The plugin wires the result into
|
|
30
|
+
* `Hooks.tool`. The `deps` closure carries the InstanceManager.
|
|
31
|
+
*/
|
|
32
|
+
export function createBgStatusTool(deps: BgStatusDeps) {
|
|
33
|
+
return tool({
|
|
34
|
+
description:
|
|
35
|
+
"List background instances. Read-only; available to all agents. " +
|
|
36
|
+
"Pass an instanceId to inspect one instance.",
|
|
37
|
+
args: {
|
|
38
|
+
instanceId: z
|
|
39
|
+
.string()
|
|
40
|
+
.optional()
|
|
41
|
+
.describe("Optional instanceId. If omitted, all instances are returned."),
|
|
42
|
+
},
|
|
43
|
+
execute: async (rawArgs) => {
|
|
44
|
+
const args = rawArgs as { instanceId?: string };
|
|
45
|
+
try {
|
|
46
|
+
if (args.instanceId) {
|
|
47
|
+
const inst = await deps.instanceManager.get(args.instanceId);
|
|
48
|
+
if (!inst) {
|
|
49
|
+
return {
|
|
50
|
+
output: JSON.stringify({ error: `instance not found`, instanceId: args.instanceId }),
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
const view: InstanceView = toViewShape(inst);
|
|
54
|
+
return { output: JSON.stringify([view]) };
|
|
55
|
+
}
|
|
56
|
+
const list = await deps.instanceManager.list();
|
|
57
|
+
return { output: JSON.stringify(list) };
|
|
58
|
+
} catch (err: unknown) {
|
|
59
|
+
deps.logger.warn(
|
|
60
|
+
`bizar: status failed: ${err instanceof Error ? err.message : String(err)}`,
|
|
61
|
+
);
|
|
62
|
+
return {
|
|
63
|
+
output: JSON.stringify({ error: `status failed: ${err instanceof Error ? err.message : String(err)}` }),
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
},
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// --- Helpers --------------------------------------------------------------
|
|
71
|
+
|
|
72
|
+
function toViewShape(inst: import("../background-state.js").BackgroundState): InstanceView {
|
|
73
|
+
const v: InstanceView = {
|
|
74
|
+
instanceId: inst.instanceId,
|
|
75
|
+
agent: inst.agent,
|
|
76
|
+
status: inst.status,
|
|
77
|
+
startedAt: inst.startedAt,
|
|
78
|
+
toolCallCount: inst.toolCallCount,
|
|
79
|
+
promptPreview: inst.promptPreview,
|
|
80
|
+
parentAgent: inst.parentAgent,
|
|
81
|
+
sessionId: inst.sessionId,
|
|
82
|
+
// v0.3.0 — always surface lastEventAt so callers can compute the
|
|
83
|
+
// current "freshness" of an instance (now - lastEventAt).
|
|
84
|
+
lastEventAt: inst.lastEventAt,
|
|
85
|
+
};
|
|
86
|
+
if (inst.completedAt !== undefined) v.completedAt = inst.completedAt;
|
|
87
|
+
if (inst.resultPreview !== undefined) v.resultPreview = inst.resultPreview;
|
|
88
|
+
if (inst.error !== undefined) v.error = inst.error;
|
|
89
|
+
if (inst.parentInstanceId !== undefined) v.parentInstanceId = inst.parentInstanceId;
|
|
90
|
+
// v0.3.0 — only surface intervention metadata when at least one
|
|
91
|
+
// intervention has actually been sent.
|
|
92
|
+
const interventionCount = inst.interventionCount ?? 0;
|
|
93
|
+
if (interventionCount > 0) {
|
|
94
|
+
v.interventionCount = interventionCount;
|
|
95
|
+
if (inst.interventionAt !== undefined) v.interventionAt = inst.interventionAt;
|
|
96
|
+
if (inst.interventionReason !== undefined) v.interventionReason = inst.interventionReason;
|
|
97
|
+
}
|
|
98
|
+
return v;
|
|
99
|
+
}
|