bb-plugin-goal 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/README.md +95 -2
- package/app.tsx +805 -0
- package/components/ui/button.tsx +60 -0
- package/components/ui/coarse-pointer-sizing.ts +76 -0
- package/components/ui/input.tsx +31 -0
- package/components/ui/motion.ts +21 -0
- package/dist/app.css +2 -0
- package/dist/app.js +1 -0
- package/dist/app.meta.json +19 -0
- package/dist/package.json +1 -0
- package/dist/server.js +442 -0
- package/dist/server.js.map +6 -0
- package/dist/server.meta.json +11 -0
- package/lib/utils.ts +24 -0
- package/package.json +72 -4
- package/server.ts +1758 -0
- package/src/coordinator.ts +892 -0
- package/src/domain.ts +407 -0
- package/src/failure.ts +202 -0
- package/src/history-cursor.ts +46 -0
- package/src/progress.ts +167 -0
- package/src/repository.ts +1735 -0
- package/src/runtime.ts +189 -0
- package/src/usage-wait.ts +21 -0
package/src/progress.ts
ADDED
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import type { GoalProgressSignalKind } from "./domain";
|
|
3
|
+
|
|
4
|
+
export interface GoalStructuredEventRow {
|
|
5
|
+
readonly id: string;
|
|
6
|
+
readonly seq: number;
|
|
7
|
+
readonly createdAt: number;
|
|
8
|
+
readonly scope: { readonly kind: "thread" } | { readonly kind: "turn"; readonly turnId: string };
|
|
9
|
+
readonly type: string;
|
|
10
|
+
readonly data: unknown;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface GoalSettledContinuationObservation {
|
|
14
|
+
readonly requestEventId: string;
|
|
15
|
+
readonly requestSeq: number;
|
|
16
|
+
readonly requestId: string;
|
|
17
|
+
readonly acceptedEventId: string;
|
|
18
|
+
readonly acceptedSeq: number;
|
|
19
|
+
readonly turnId: string;
|
|
20
|
+
readonly terminalEventId: string;
|
|
21
|
+
readonly terminalSeq: number;
|
|
22
|
+
readonly signals: readonly Exclude<GoalProgressSignalKind, "changed-assistant-result">[];
|
|
23
|
+
readonly assistantResultFingerprint: string | null;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function record(value: unknown): Record<string, unknown> | null {
|
|
27
|
+
return typeof value === "object" && value !== null
|
|
28
|
+
? (value as Record<string, unknown>)
|
|
29
|
+
: null;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function markerIsInInput(data: unknown, marker: string): boolean {
|
|
33
|
+
const input = record(data)?.input;
|
|
34
|
+
return (
|
|
35
|
+
Array.isArray(input) &&
|
|
36
|
+
input.some((part) => {
|
|
37
|
+
const item = record(part);
|
|
38
|
+
return (
|
|
39
|
+
item?.type === "text" &&
|
|
40
|
+
typeof item.text === "string" &&
|
|
41
|
+
item.text.includes(marker)
|
|
42
|
+
);
|
|
43
|
+
})
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export function continuationPrompt(deliveryMarker: string): string {
|
|
48
|
+
return (
|
|
49
|
+
"Continue working toward the active BB Goal. Re-read the objective and make the next meaningful step. Do not stop unless the Goal is complete or genuinely blocked. " +
|
|
50
|
+
`Internal delivery marker: ${deliveryMarker}`
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export function fingerprintAssistantResult(text: string): string {
|
|
55
|
+
const normalized = text.normalize("NFKC").trim().replace(/\s+/g, " ");
|
|
56
|
+
return createHash("sha256").update(normalized).digest("hex");
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export function observeSettledContinuation(
|
|
60
|
+
rows: readonly GoalStructuredEventRow[],
|
|
61
|
+
deliveryMarker: string,
|
|
62
|
+
): GoalSettledContinuationObservation | null {
|
|
63
|
+
const ordered = [...rows].sort((left, right) => left.seq - right.seq);
|
|
64
|
+
const request = ordered.find((row) => {
|
|
65
|
+
if (row.type !== "client/turn/requested") return false;
|
|
66
|
+
const data = record(row.data);
|
|
67
|
+
const target = record(data?.target);
|
|
68
|
+
return (
|
|
69
|
+
data?.initiator === "system" &&
|
|
70
|
+
target?.kind === "auto" &&
|
|
71
|
+
typeof data.requestId === "string" &&
|
|
72
|
+
markerIsInInput(data, deliveryMarker)
|
|
73
|
+
);
|
|
74
|
+
});
|
|
75
|
+
if (request === undefined) return null;
|
|
76
|
+
const requestId = record(request.data)?.requestId;
|
|
77
|
+
if (typeof requestId !== "string") return null;
|
|
78
|
+
|
|
79
|
+
const accepted = ordered.find((row) => {
|
|
80
|
+
const data = record(row.data);
|
|
81
|
+
return (
|
|
82
|
+
row.seq > request.seq &&
|
|
83
|
+
row.type === "turn/input/accepted" &&
|
|
84
|
+
row.scope.kind === "turn" &&
|
|
85
|
+
data?.clientRequestId === requestId
|
|
86
|
+
);
|
|
87
|
+
});
|
|
88
|
+
if (accepted === undefined || accepted.scope.kind !== "turn") return null;
|
|
89
|
+
const turnId = accepted.scope.turnId;
|
|
90
|
+
const terminal = ordered.find((row) => {
|
|
91
|
+
const data = record(row.data);
|
|
92
|
+
return (
|
|
93
|
+
row.seq > accepted.seq &&
|
|
94
|
+
row.type === "turn/completed" &&
|
|
95
|
+
row.scope.kind === "turn" &&
|
|
96
|
+
row.scope.turnId === turnId &&
|
|
97
|
+
data?.status === "completed"
|
|
98
|
+
);
|
|
99
|
+
});
|
|
100
|
+
if (terminal === undefined) return null;
|
|
101
|
+
|
|
102
|
+
const turnRows = ordered.filter(
|
|
103
|
+
(row) =>
|
|
104
|
+
row.seq > accepted.seq &&
|
|
105
|
+
row.seq < terminal.seq &&
|
|
106
|
+
row.scope.kind === "turn" &&
|
|
107
|
+
row.scope.turnId === turnId,
|
|
108
|
+
);
|
|
109
|
+
const signals = new Set<Exclude<GoalProgressSignalKind, "changed-assistant-result">>();
|
|
110
|
+
let assistantResultFingerprint: string | null = null;
|
|
111
|
+
for (const row of turnRows) {
|
|
112
|
+
const data = record(row.data);
|
|
113
|
+
const item = record(data?.item);
|
|
114
|
+
if (
|
|
115
|
+
(row.type === "item/started" || row.type === "item/completed") &&
|
|
116
|
+
(item?.type === "commandExecution" || item?.type === "toolCall")
|
|
117
|
+
) {
|
|
118
|
+
signals.add("tool-call");
|
|
119
|
+
}
|
|
120
|
+
if (
|
|
121
|
+
((row.type === "item/started" || row.type === "item/completed") &&
|
|
122
|
+
item?.type === "fileChange" &&
|
|
123
|
+
Array.isArray(item.changes) &&
|
|
124
|
+
item.changes.length > 0) ||
|
|
125
|
+
(row.type === "turn/diff/updated" &&
|
|
126
|
+
typeof data?.diff === "string" &&
|
|
127
|
+
data.diff.length > 0)
|
|
128
|
+
) {
|
|
129
|
+
signals.add("file-mutation");
|
|
130
|
+
}
|
|
131
|
+
if (
|
|
132
|
+
(row.type === "item/started" || row.type === "item/completed") &&
|
|
133
|
+
["webSearch", "webFetch", "imageView", "backgroundTask"].includes(
|
|
134
|
+
String(item?.type),
|
|
135
|
+
)
|
|
136
|
+
) {
|
|
137
|
+
signals.add("external-action");
|
|
138
|
+
}
|
|
139
|
+
if (
|
|
140
|
+
(row.type === "system/permissionGrant/lifecycle" ||
|
|
141
|
+
row.type === "system/userQuestion/lifecycle") &&
|
|
142
|
+
data?.status === "pending"
|
|
143
|
+
) {
|
|
144
|
+
signals.add("pending-interaction");
|
|
145
|
+
}
|
|
146
|
+
if (
|
|
147
|
+
row.type === "item/completed" &&
|
|
148
|
+
item?.type === "agentMessage" &&
|
|
149
|
+
typeof item.text === "string"
|
|
150
|
+
) {
|
|
151
|
+
assistantResultFingerprint = fingerprintAssistantResult(item.text);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
return {
|
|
156
|
+
requestEventId: request.id,
|
|
157
|
+
requestSeq: request.seq,
|
|
158
|
+
requestId,
|
|
159
|
+
acceptedEventId: accepted.id,
|
|
160
|
+
acceptedSeq: accepted.seq,
|
|
161
|
+
turnId,
|
|
162
|
+
terminalEventId: terminal.id,
|
|
163
|
+
terminalSeq: terminal.seq,
|
|
164
|
+
signals: [...signals],
|
|
165
|
+
assistantResultFingerprint,
|
|
166
|
+
};
|
|
167
|
+
}
|