@fractaal/pi-goal-x 0.20.0 → 0.28.0
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 +38 -293
- package/dist/goal-auditor.d.ts +7 -61
- package/dist/goal-auditor.js +98 -300
- package/dist/goal-auditor.js.map +1 -1
- package/dist/goal-contract.d.ts +205 -0
- package/dist/goal-contract.js +135 -0
- package/dist/goal-contract.js.map +1 -0
- package/dist/goal-transcript-events.d.ts +54 -0
- package/dist/goal-transcript-events.js +177 -0
- package/dist/goal-transcript-events.js.map +1 -0
- package/dist/goal-widget.d.ts +13 -0
- package/dist/goal-widget.js +45 -0
- package/dist/goal-widget.js.map +1 -0
- package/dist/goal.d.ts +8 -49
- package/dist/goal.js +582 -3644
- package/dist/goal.js.map +1 -1
- package/dist/legacy-migration.d.ts +61 -0
- package/dist/legacy-migration.js +306 -0
- package/dist/legacy-migration.js.map +1 -0
- package/docs/architecture.md +14 -232
- package/extensions/goal-auditor.ts +108 -363
- package/extensions/goal-contract.ts +149 -0
- package/extensions/goal-transcript-events.ts +194 -0
- package/extensions/goal-widget.ts +50 -0
- package/extensions/goal.ts +602 -3916
- package/extensions/legacy-migration.ts +340 -0
- package/package.json +46 -21
- package/dist/goal-compaction.d.ts +0 -10
- package/dist/goal-compaction.js +0 -104
- package/dist/goal-compaction.js.map +0 -1
- package/dist/goal-core.d.ts +0 -19
- package/dist/goal-core.js +0 -66
- package/dist/goal-core.js.map +0 -1
- package/dist/goal-draft.d.ts +0 -71
- package/dist/goal-draft.js +0 -201
- package/dist/goal-draft.js.map +0 -1
- package/dist/goal-ledger.d.ts +0 -139
- package/dist/goal-ledger.js +0 -306
- package/dist/goal-ledger.js.map +0 -1
- package/dist/goal-policy.d.ts +0 -127
- package/dist/goal-policy.js +0 -359
- package/dist/goal-policy.js.map +0 -1
- package/dist/goal-pool.d.ts +0 -17
- package/dist/goal-pool.js +0 -85
- package/dist/goal-pool.js.map +0 -1
- package/dist/goal-questionnaire.d.ts +0 -56
- package/dist/goal-questionnaire.js +0 -733
- package/dist/goal-questionnaire.js.map +0 -1
- package/dist/goal-record.d.ts +0 -94
- package/dist/goal-record.js +0 -155
- package/dist/goal-record.js.map +0 -1
- package/dist/goal-settings.d.ts +0 -56
- package/dist/goal-settings.js +0 -184
- package/dist/goal-settings.js.map +0 -1
- package/dist/goal-tool-names.d.ts +0 -20
- package/dist/goal-tool-names.js +0 -69
- package/dist/goal-tool-names.js.map +0 -1
- package/dist/prompts/goal-prompts.d.ts +0 -17
- package/dist/prompts/goal-prompts.js +0 -304
- package/dist/prompts/goal-prompts.js.map +0 -1
- package/dist/storage/goal-files.d.ts +0 -40
- package/dist/storage/goal-files.js +0 -320
- package/dist/storage/goal-files.js.map +0 -1
- package/dist/widgets/goal-escape-dialog.d.ts +0 -15
- package/dist/widgets/goal-escape-dialog.js +0 -118
- package/dist/widgets/goal-escape-dialog.js.map +0 -1
- package/dist/widgets/goal-notifications.d.ts +0 -5
- package/dist/widgets/goal-notifications.js +0 -9
- package/dist/widgets/goal-notifications.js.map +0 -1
- package/dist/widgets/goal-widget.d.ts +0 -58
- package/dist/widgets/goal-widget.js +0 -282
- package/dist/widgets/goal-widget.js.map +0 -1
- package/dist/widgets/task-list-overlay.d.ts +0 -8
- package/dist/widgets/task-list-overlay.js +0 -321
- package/dist/widgets/task-list-overlay.js.map +0 -1
- package/docs/agent-flow-design.md +0 -432
- package/docs/agentic-runtime-prd.md +0 -764
- package/docs/goal-ts-refactor-test-strategy.md +0 -82
- package/docs/pi-autoresearch-survey.md +0 -45
- package/extensions/goal-compaction.ts +0 -133
- package/extensions/goal-core.ts +0 -77
- package/extensions/goal-draft.ts +0 -263
- package/extensions/goal-ledger.ts +0 -354
- package/extensions/goal-policy.ts +0 -389
- package/extensions/goal-pool.ts +0 -98
- package/extensions/goal-questionnaire.ts +0 -779
- package/extensions/goal-record.ts +0 -256
- package/extensions/goal-settings.ts +0 -181
- package/extensions/goal-tool-names.ts +0 -76
- package/extensions/prompts/goal-prompts.ts +0 -308
- package/extensions/storage/goal-files.ts +0 -352
- package/extensions/widgets/goal-escape-dialog.ts +0 -146
- package/extensions/widgets/goal-notifications.ts +0 -9
- package/extensions/widgets/goal-widget.ts +0 -378
- package/extensions/widgets/task-list-overlay.ts +0 -389
|
@@ -0,0 +1,340 @@
|
|
|
1
|
+
import * as fs from "node:fs";
|
|
2
|
+
import * as path from "node:path";
|
|
3
|
+
import type { ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
4
|
+
import {
|
|
5
|
+
GOAL_SCHEMA_VERSION,
|
|
6
|
+
GOAL_STATE_ENTRY,
|
|
7
|
+
isGoalState,
|
|
8
|
+
type Goal,
|
|
9
|
+
type GoalState,
|
|
10
|
+
} from "./goal-contract.ts";
|
|
11
|
+
|
|
12
|
+
export const LEGACY_MIGRATION_ENTRY = "pi-goal-todo-migration-v1";
|
|
13
|
+
export const LEGACY_MIGRATION_EVENT = "pi-goal-todo:migrated";
|
|
14
|
+
export const TODO_STATE_ENTRY = "pi-todo-state-v1";
|
|
15
|
+
// The migration package remains installable without Todo, so its one-time
|
|
16
|
+
// adapter mirrors the exported Todo producer bounds and is covered by parity tests.
|
|
17
|
+
const TODO_MAX_TASKS = 200;
|
|
18
|
+
const TODO_TASK_KEY_MAX_LENGTH = 256;
|
|
19
|
+
const TODO_TASK_SUBJECT_MAX_LENGTH = 2_048;
|
|
20
|
+
const TODO_TASK_DESCRIPTION_MAX_LENGTH = 16_384;
|
|
21
|
+
const TODO_TASK_MAX_DEPENDENCIES = 100;
|
|
22
|
+
const TODO_PLAN_MAX_BYTES = 16 * 1024;
|
|
23
|
+
const utf8Encoder = new TextEncoder();
|
|
24
|
+
|
|
25
|
+
interface LegacyTask {
|
|
26
|
+
id: string;
|
|
27
|
+
title: string;
|
|
28
|
+
status: "pending" | "complete" | "skipped";
|
|
29
|
+
verificationContract?: string;
|
|
30
|
+
subtasks?: LegacyTask[];
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export interface LegacyGoalCandidate {
|
|
34
|
+
id: string;
|
|
35
|
+
objective: string;
|
|
36
|
+
status: "active" | "paused" | "complete";
|
|
37
|
+
autoContinue: boolean;
|
|
38
|
+
createdAt: string;
|
|
39
|
+
updatedAt: string;
|
|
40
|
+
pauseReason?: string;
|
|
41
|
+
pauseSuggestedAction?: string;
|
|
42
|
+
tasks: LegacyTask[];
|
|
43
|
+
source: "session" | "file";
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export interface LegacyTodoState {
|
|
47
|
+
schemaVersion: 1;
|
|
48
|
+
revision: number;
|
|
49
|
+
tasks: Array<{
|
|
50
|
+
key: string;
|
|
51
|
+
subject: string;
|
|
52
|
+
description?: string;
|
|
53
|
+
status: "pending" | "completed";
|
|
54
|
+
dependsOn?: string[];
|
|
55
|
+
}>;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export type LegacyMigrationPlan =
|
|
59
|
+
| { kind: "none" }
|
|
60
|
+
| { kind: "ambiguous"; candidates: LegacyGoalCandidate[] }
|
|
61
|
+
| { kind: "migrate"; candidate: LegacyGoalCandidate; goal: GoalState; todo: LegacyTodoState | null };
|
|
62
|
+
|
|
63
|
+
function record(value: unknown): Record<string, unknown> | null {
|
|
64
|
+
return value !== null && typeof value === "object" && !Array.isArray(value)
|
|
65
|
+
? value as Record<string, unknown>
|
|
66
|
+
: null;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function text(value: unknown): string | undefined {
|
|
70
|
+
return typeof value === "string" && value.trim() ? value.trim() : undefined;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function legacyTask(value: unknown): LegacyTask | null {
|
|
74
|
+
const raw = record(value);
|
|
75
|
+
const id = text(raw?.id);
|
|
76
|
+
const title = text(raw?.title);
|
|
77
|
+
if (!raw || !id || !title) return null;
|
|
78
|
+
const subtasks = Array.isArray(raw.subtasks)
|
|
79
|
+
? raw.subtasks.map(legacyTask).filter((task): task is LegacyTask => task !== null)
|
|
80
|
+
: undefined;
|
|
81
|
+
return {
|
|
82
|
+
id,
|
|
83
|
+
title,
|
|
84
|
+
status: raw.status === "complete" ? "complete" : raw.status === "skipped" ? "skipped" : "pending",
|
|
85
|
+
...(text(raw.verificationContract) ? { verificationContract: text(raw.verificationContract) } : {}),
|
|
86
|
+
...(subtasks?.length ? { subtasks } : {}),
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function candidate(value: unknown, source: LegacyGoalCandidate["source"]): LegacyGoalCandidate | null {
|
|
91
|
+
const raw = record(value);
|
|
92
|
+
const id = text(raw?.id);
|
|
93
|
+
const objective = text(raw?.objective);
|
|
94
|
+
if (!raw || !id || !objective) return null;
|
|
95
|
+
const taskList = record(raw.taskList);
|
|
96
|
+
const tasks = Array.isArray(taskList?.tasks)
|
|
97
|
+
? taskList.tasks.map(legacyTask).filter((task): task is LegacyTask => task !== null)
|
|
98
|
+
: [];
|
|
99
|
+
return {
|
|
100
|
+
id,
|
|
101
|
+
objective,
|
|
102
|
+
status: raw.status === "complete" ? "complete" : raw.status === "paused" || raw.status === "blocked" || raw.status === "budget_limited" ? "paused" : "active",
|
|
103
|
+
autoContinue: raw.autoContinue !== false,
|
|
104
|
+
createdAt: text(raw.createdAt) ?? new Date().toISOString(),
|
|
105
|
+
updatedAt: text(raw.updatedAt) ?? text(raw.createdAt) ?? new Date().toISOString(),
|
|
106
|
+
...(text(raw.pauseReason) ? { pauseReason: text(raw.pauseReason) } : {}),
|
|
107
|
+
...(text(raw.pauseSuggestedAction) ? { pauseSuggestedAction: text(raw.pauseSuggestedAction) } : {}),
|
|
108
|
+
tasks,
|
|
109
|
+
source,
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
function jsonObjectEnd(content: string): number {
|
|
114
|
+
let depth = 0;
|
|
115
|
+
let quoted = false;
|
|
116
|
+
let escaped = false;
|
|
117
|
+
for (let index = 0; index < content.length; index += 1) {
|
|
118
|
+
const character = content[index];
|
|
119
|
+
if (quoted) {
|
|
120
|
+
if (escaped) escaped = false;
|
|
121
|
+
else if (character === "\\") escaped = true;
|
|
122
|
+
else if (character === "\"") quoted = false;
|
|
123
|
+
continue;
|
|
124
|
+
}
|
|
125
|
+
if (character === "\"") quoted = true;
|
|
126
|
+
else if (character === "{") depth += 1;
|
|
127
|
+
else if (character === "}" && --depth === 0) return index;
|
|
128
|
+
}
|
|
129
|
+
return -1;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
function readLegacyGoalFile(file: string): LegacyGoalCandidate | null {
|
|
133
|
+
try {
|
|
134
|
+
if (fs.lstatSync(file).isSymbolicLink()) return null;
|
|
135
|
+
const content = fs.readFileSync(file, "utf8");
|
|
136
|
+
const end = jsonObjectEnd(content);
|
|
137
|
+
if (end < 0) return null;
|
|
138
|
+
return candidate(JSON.parse(content.slice(0, end + 1)), "file");
|
|
139
|
+
} catch {
|
|
140
|
+
return null;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
function readLegacyGoalDirectories(ctx: ExtensionContext): LegacyGoalCandidate[] {
|
|
145
|
+
const sessionId = ctx.sessionManager.getSessionId();
|
|
146
|
+
const directories = [
|
|
147
|
+
path.join(ctx.cwd, ".pi", "goals", "sessions", sessionId),
|
|
148
|
+
path.join(ctx.cwd, ".pi", "goals"),
|
|
149
|
+
];
|
|
150
|
+
const candidates: LegacyGoalCandidate[] = [];
|
|
151
|
+
for (const directory of directories) {
|
|
152
|
+
try {
|
|
153
|
+
if (fs.lstatSync(directory).isSymbolicLink()) continue;
|
|
154
|
+
for (const name of fs.readdirSync(directory).sort()) {
|
|
155
|
+
if (!/^active_goal_.*\.md$/.test(name)) continue;
|
|
156
|
+
const parsed = readLegacyGoalFile(path.join(directory, name));
|
|
157
|
+
if (parsed && parsed.status !== "complete") candidates.push(parsed);
|
|
158
|
+
}
|
|
159
|
+
} catch {
|
|
160
|
+
// Missing legacy directories are normal.
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
return candidates;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
export function findLegacyGoalCandidates(ctx: ExtensionContext): { focusedId: string | null; candidates: LegacyGoalCandidate[] } {
|
|
167
|
+
const branch = ctx.sessionManager.getBranch();
|
|
168
|
+
let focusedId: string | null = null;
|
|
169
|
+
let sessionCandidate: LegacyGoalCandidate | null = null;
|
|
170
|
+
let sawFocusEntry = false;
|
|
171
|
+
let sawStateEntry = false;
|
|
172
|
+
for (let index = branch.length - 1; index >= 0; index -= 1) {
|
|
173
|
+
const entry = branch[index] as { type?: string; customType?: string; data?: unknown };
|
|
174
|
+
if (entry.type !== "custom") continue;
|
|
175
|
+
if (!sawFocusEntry && entry.customType === "pi-goal-focus") {
|
|
176
|
+
sawFocusEntry = true;
|
|
177
|
+
focusedId = text(record(entry.data)?.focusedGoalId) ?? null;
|
|
178
|
+
}
|
|
179
|
+
if (!sawStateEntry && entry.customType === "pi-goal-state") {
|
|
180
|
+
sawStateEntry = true;
|
|
181
|
+
sessionCandidate = candidate(record(entry.data)?.goal, "session");
|
|
182
|
+
if (sessionCandidate?.status === "complete") sessionCandidate = null;
|
|
183
|
+
}
|
|
184
|
+
if (sawFocusEntry && sawStateEntry) break;
|
|
185
|
+
}
|
|
186
|
+
if (!sawFocusEntry && sessionCandidate) focusedId = sessionCandidate.id;
|
|
187
|
+
|
|
188
|
+
const byId = new Map<string, LegacyGoalCandidate>();
|
|
189
|
+
for (const item of readLegacyGoalDirectories(ctx)) byId.set(item.id, item);
|
|
190
|
+
if (sessionCandidate) byId.set(sessionCandidate.id, sessionCandidate);
|
|
191
|
+
return { focusedId, candidates: [...byId.values()] };
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
function uniqueKey(raw: string, used: Set<string>): string {
|
|
195
|
+
const base = raw.trim().replace(/[^a-zA-Z0-9_-]+/g, "-").replace(/^-+|-+$/g, "") || "task";
|
|
196
|
+
let key = base;
|
|
197
|
+
let suffix = 2;
|
|
198
|
+
while (used.has(key)) key = `${base}-${suffix++}`;
|
|
199
|
+
used.add(key);
|
|
200
|
+
return key;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
function validLegacyTodoState(state: LegacyTodoState): boolean {
|
|
204
|
+
return state.tasks.length <= TODO_MAX_TASKS
|
|
205
|
+
&& state.tasks.every((task) => task.key.trim().length > 0 && task.key.length <= TODO_TASK_KEY_MAX_LENGTH
|
|
206
|
+
&& task.subject.trim().length > 0 && task.subject.length <= TODO_TASK_SUBJECT_MAX_LENGTH
|
|
207
|
+
&& (task.description === undefined || (task.description.trim().length > 0 && task.description.length <= TODO_TASK_DESCRIPTION_MAX_LENGTH))
|
|
208
|
+
&& (task.status === "pending" || task.status === "completed")
|
|
209
|
+
&& (task.dependsOn === undefined || (task.dependsOn.length <= TODO_TASK_MAX_DEPENDENCIES
|
|
210
|
+
&& task.dependsOn.every((dependency) => dependency.trim().length > 0 && dependency.length <= TODO_TASK_KEY_MAX_LENGTH)))
|
|
211
|
+
)
|
|
212
|
+
&& utf8Encoder.encode(JSON.stringify(state)).byteLength <= TODO_PLAN_MAX_BYTES;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
export function migrateLegacyTasks(tasks: readonly LegacyTask[]): LegacyTodoState | null {
|
|
216
|
+
const migrated: LegacyTodoState["tasks"] = [];
|
|
217
|
+
const used = new Set<string>();
|
|
218
|
+
|
|
219
|
+
function addSiblings(items: readonly LegacyTask[], parentPath: string[]): void {
|
|
220
|
+
let previous: LegacyTodoState["tasks"][number] | null = null;
|
|
221
|
+
for (const item of items) {
|
|
222
|
+
if (item.status === "skipped") continue;
|
|
223
|
+
const key = uniqueKey(item.id, used);
|
|
224
|
+
const status = item.status === "complete" ? "completed" as const : "pending" as const;
|
|
225
|
+
const safeDependency = previous && (status === "pending" || previous.status === "completed") ? [previous.key] : undefined;
|
|
226
|
+
const descriptionParts = [
|
|
227
|
+
parentPath.length ? `Legacy path: ${[...parentPath, item.title].join(" > ")}.` : undefined,
|
|
228
|
+
item.verificationContract ? `Verification guidance: ${item.verificationContract}` : undefined,
|
|
229
|
+
].filter((part): part is string => !!part);
|
|
230
|
+
const migratedTask: LegacyTodoState["tasks"][number] = {
|
|
231
|
+
key,
|
|
232
|
+
subject: item.title,
|
|
233
|
+
status,
|
|
234
|
+
...(descriptionParts.length ? { description: descriptionParts.join(" ") } : {}),
|
|
235
|
+
...(safeDependency ? { dependsOn: safeDependency } : {}),
|
|
236
|
+
};
|
|
237
|
+
migrated.push(migratedTask);
|
|
238
|
+
previous = migratedTask;
|
|
239
|
+
if (item.subtasks?.length) addSiblings(item.subtasks, [...parentPath, item.title]);
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
addSiblings(tasks, []);
|
|
244
|
+
if (migrated.length === 0) return null;
|
|
245
|
+
const state: LegacyTodoState = { schemaVersion: 1, revision: 1, tasks: migrated };
|
|
246
|
+
if (utf8Encoder.encode(JSON.stringify(state)).byteLength > TODO_PLAN_MAX_BYTES) {
|
|
247
|
+
throw new Error(`Migrated Todo plan exceeds the ${TODO_PLAN_MAX_BYTES}-byte serialized UTF-8 byte budget; migration refused without writing new state.`);
|
|
248
|
+
}
|
|
249
|
+
if (!validLegacyTodoState(state)) {
|
|
250
|
+
throw new Error("Migrated Todo plan exceeds the exported producer state bounds; migration refused without writing new state.");
|
|
251
|
+
}
|
|
252
|
+
return state;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
function branchHasGoalState(ctx: ExtensionContext): boolean {
|
|
256
|
+
return ctx.sessionManager.getBranch().some((item) => {
|
|
257
|
+
const entry = item as { type?: string; customType?: string; data?: unknown };
|
|
258
|
+
const data = record(entry.data);
|
|
259
|
+
return entry.type === "custom"
|
|
260
|
+
&& entry.customType === GOAL_STATE_ENTRY
|
|
261
|
+
&& data?.schemaVersion === GOAL_SCHEMA_VERSION
|
|
262
|
+
&& typeof data.revision === "number"
|
|
263
|
+
&& Object.hasOwn(data, "goal");
|
|
264
|
+
});
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
function branchHasTodoState(ctx: ExtensionContext): boolean {
|
|
268
|
+
return ctx.sessionManager.getBranch().some((item) => {
|
|
269
|
+
const entry = item as { type?: string; customType?: string; data?: unknown };
|
|
270
|
+
const data = record(entry.data);
|
|
271
|
+
return entry.type === "custom"
|
|
272
|
+
&& entry.customType === TODO_STATE_ENTRY
|
|
273
|
+
&& data?.schemaVersion === 1
|
|
274
|
+
&& Array.isArray(data.tasks);
|
|
275
|
+
});
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
export function planLegacyMigration(ctx: ExtensionContext, selectedGoalId?: string): LegacyMigrationPlan {
|
|
279
|
+
if (branchHasGoalState(ctx)) return { kind: "none" };
|
|
280
|
+
const { focusedId, candidates } = findLegacyGoalCandidates(ctx);
|
|
281
|
+
if (candidates.length === 0) return { kind: "none" };
|
|
282
|
+
let selected = selectedGoalId ? candidates.find((item) => item.id === selectedGoalId) : undefined;
|
|
283
|
+
if (!selected && !selectedGoalId && focusedId) selected = candidates.find((item) => item.id === focusedId);
|
|
284
|
+
if (!selected && !selectedGoalId && candidates.length === 1) selected = candidates[0];
|
|
285
|
+
if (!selected) return { kind: "ambiguous", candidates };
|
|
286
|
+
|
|
287
|
+
const migratePaused = selected.status === "paused" || !selected.autoContinue;
|
|
288
|
+
const common = {
|
|
289
|
+
id: selected.id,
|
|
290
|
+
objective: selected.objective,
|
|
291
|
+
usage: { tokensUsed: 0, activeSeconds: 0 },
|
|
292
|
+
createdAt: selected.createdAt,
|
|
293
|
+
updatedAt: selected.updatedAt,
|
|
294
|
+
};
|
|
295
|
+
const goal: Goal = migratePaused
|
|
296
|
+
? {
|
|
297
|
+
...common,
|
|
298
|
+
status: "paused",
|
|
299
|
+
autoContinue: false,
|
|
300
|
+
pause: {
|
|
301
|
+
reason: selected.status === "paused"
|
|
302
|
+
? selected.pauseReason ?? "Paused in the legacy Goal runtime."
|
|
303
|
+
: "Legacy autonomous continuation was disabled; migrated paused to avoid surprising work.",
|
|
304
|
+
...(selected.pauseSuggestedAction ? { suggestedAction: selected.pauseSuggestedAction } : {}),
|
|
305
|
+
},
|
|
306
|
+
}
|
|
307
|
+
: { ...common, status: "active", autoContinue: true };
|
|
308
|
+
const goalState: GoalState = { schemaVersion: GOAL_SCHEMA_VERSION, revision: 1, goal };
|
|
309
|
+
if (!isGoalState(goalState)) {
|
|
310
|
+
throw new Error("Migrated Goal exceeds the exported producer state bounds; migration refused without writing new state.");
|
|
311
|
+
}
|
|
312
|
+
return {
|
|
313
|
+
kind: "migrate",
|
|
314
|
+
candidate: selected,
|
|
315
|
+
goal: goalState,
|
|
316
|
+
todo: branchHasTodoState(ctx) ? null : migrateLegacyTasks(selected.tasks),
|
|
317
|
+
};
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
export function writeLegacyMigration(pi: { appendEntry: (type: string, data: unknown) => void; events: { emit: (channel: string, data: unknown) => void } }, plan: Extract<LegacyMigrationPlan, { kind: "migrate" }>): void {
|
|
321
|
+
if (!isGoalState(plan.goal)) {
|
|
322
|
+
throw new Error("Migrated Goal exceeds the exported producer state bounds; migration refused without writing new state.");
|
|
323
|
+
}
|
|
324
|
+
if (plan.todo && utf8Encoder.encode(JSON.stringify(plan.todo)).byteLength > TODO_PLAN_MAX_BYTES) {
|
|
325
|
+
throw new Error(`Migrated Todo plan exceeds the ${TODO_PLAN_MAX_BYTES}-byte serialized UTF-8 byte budget; migration refused without writing new state.`);
|
|
326
|
+
}
|
|
327
|
+
if (plan.todo && !validLegacyTodoState(plan.todo)) {
|
|
328
|
+
throw new Error("Migrated Todo plan exceeds the exported producer state bounds; migration refused without writing new state.");
|
|
329
|
+
}
|
|
330
|
+
pi.appendEntry(GOAL_STATE_ENTRY, plan.goal);
|
|
331
|
+
if (plan.todo) pi.appendEntry(TODO_STATE_ENTRY, plan.todo);
|
|
332
|
+
pi.appendEntry(LEGACY_MIGRATION_ENTRY, {
|
|
333
|
+
schemaVersion: 1,
|
|
334
|
+
status: "complete",
|
|
335
|
+
selectedLegacyGoalId: plan.candidate.id,
|
|
336
|
+
migratedAt: new Date().toISOString(),
|
|
337
|
+
sourcePreserved: true,
|
|
338
|
+
});
|
|
339
|
+
pi.events.emit(LEGACY_MIGRATION_EVENT, { goal: plan.goal, todo: plan.todo });
|
|
340
|
+
}
|
package/package.json
CHANGED
|
@@ -1,27 +1,32 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fractaal/pi-goal-x",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.28.0",
|
|
4
|
+
"description": "Portable single-goal runtime for Pi",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"author": "pi-goal-x contributors",
|
|
7
|
+
"type": "module",
|
|
4
8
|
"main": "./dist/goal.js",
|
|
5
9
|
"types": "./dist/goal.d.ts",
|
|
6
10
|
"exports": {
|
|
7
11
|
".": {
|
|
8
12
|
"types": "./dist/goal.d.ts",
|
|
9
13
|
"default": "./dist/goal.js"
|
|
14
|
+
},
|
|
15
|
+
"./contracts": {
|
|
16
|
+
"types": "./dist/goal-contract.d.ts",
|
|
17
|
+
"default": "./dist/goal-contract.js"
|
|
18
|
+
},
|
|
19
|
+
"./transcript-events": {
|
|
20
|
+
"types": "./dist/goal-transcript-events.d.ts",
|
|
21
|
+
"default": "./dist/goal-transcript-events.js"
|
|
10
22
|
}
|
|
11
23
|
},
|
|
12
|
-
"description": "Goal mode extension for pi: persistent long-running objectives, /goal-set drafting, Sisyphus prompt style, autoContinue, and an above-editor status overlay. Fork of @capyup/pi-goal.",
|
|
13
|
-
"license": "MIT",
|
|
14
|
-
"author": "pi-goal-x contributors",
|
|
15
|
-
"type": "module",
|
|
16
24
|
"keywords": [
|
|
17
25
|
"pi-package",
|
|
18
26
|
"pi",
|
|
19
27
|
"pi-extension",
|
|
20
28
|
"goal",
|
|
21
|
-
"
|
|
22
|
-
"autoresearch",
|
|
23
|
-
"agent-loop",
|
|
24
|
-
"long-running"
|
|
29
|
+
"agent-loop"
|
|
25
30
|
],
|
|
26
31
|
"repository": {
|
|
27
32
|
"type": "git",
|
|
@@ -35,20 +40,24 @@
|
|
|
35
40
|
"dist",
|
|
36
41
|
"extensions",
|
|
37
42
|
"README.md",
|
|
38
|
-
"
|
|
39
|
-
"
|
|
43
|
+
"LICENSE",
|
|
44
|
+
"docs/architecture.md"
|
|
40
45
|
],
|
|
41
46
|
"pi": {
|
|
42
47
|
"extensions": [
|
|
43
48
|
"extensions/goal.ts"
|
|
44
|
-
]
|
|
45
|
-
"image": "https://github.com/tmonk/pi-goal-x/raw/main/screenshot.png"
|
|
49
|
+
]
|
|
46
50
|
},
|
|
47
51
|
"scripts": {
|
|
48
52
|
"check": "tsc --noEmit",
|
|
49
|
-
"build": "tsc -p tsconfig.build.json",
|
|
50
|
-
"
|
|
51
|
-
"
|
|
53
|
+
"build:goal": "tsc -p tsconfig.build.json",
|
|
54
|
+
"build:todo": "tsc -p packages/todo/tsconfig.build.json",
|
|
55
|
+
"build": "npm run build:goal && npm run build:todo",
|
|
56
|
+
"prepack": "npm run build:goal",
|
|
57
|
+
"test": "node --experimental-strip-types --test tests/*.test.ts",
|
|
58
|
+
"test:installed": "node tests/installed-package-acceptance.mjs",
|
|
59
|
+
"test:all": "npm test && npm run test:installed",
|
|
60
|
+
"lint": "eslint extensions packages/todo/extensions tests"
|
|
52
61
|
},
|
|
53
62
|
"peerDependencies": {
|
|
54
63
|
"@earendil-works/pi-ai": "*",
|
|
@@ -57,13 +66,29 @@
|
|
|
57
66
|
"typebox": "*"
|
|
58
67
|
},
|
|
59
68
|
"devDependencies": {
|
|
60
|
-
"@earendil-works/pi-ai": "^0.
|
|
61
|
-
"@earendil-works/pi-coding-agent": "^0.
|
|
62
|
-
"@earendil-works/pi-tui": "^0.
|
|
63
|
-
"
|
|
64
|
-
"
|
|
69
|
+
"@earendil-works/pi-ai": "^0.84.1",
|
|
70
|
+
"@earendil-works/pi-coding-agent": "^0.84.1",
|
|
71
|
+
"@earendil-works/pi-tui": "^0.84.1",
|
|
72
|
+
"@eslint/js": "^9.39.5",
|
|
73
|
+
"eslint": "^9.39.5",
|
|
74
|
+
"globals": "^15.15.0",
|
|
75
|
+
"typebox": "^1.3.11",
|
|
76
|
+
"typescript": "^5.9.3",
|
|
77
|
+
"typescript-eslint": "^8.66.0"
|
|
65
78
|
},
|
|
66
79
|
"publishConfig": {
|
|
67
80
|
"access": "public"
|
|
81
|
+
},
|
|
82
|
+
"overrides": {
|
|
83
|
+
"@earendil-works/pi-coding-agent": {
|
|
84
|
+
"undici": "8.10.0",
|
|
85
|
+
"minimatch": "10.2.6"
|
|
86
|
+
},
|
|
87
|
+
"minimatch": {
|
|
88
|
+
"brace-expansion": "5.0.9"
|
|
89
|
+
}
|
|
90
|
+
},
|
|
91
|
+
"engines": {
|
|
92
|
+
"node": ">=22.15.0"
|
|
68
93
|
}
|
|
69
94
|
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { type GoalLedgerEvent } from "./goal-ledger.ts";
|
|
2
|
-
import { type GoalRecord } from "./goal-record.ts";
|
|
3
|
-
export declare function buildGoalCompactSummary(goal: GoalRecord, events: GoalLedgerEvent[]): string;
|
|
4
|
-
export declare function buildCompactionSummary(args: {
|
|
5
|
-
goalsById: Map<string, GoalRecord>;
|
|
6
|
-
focusedGoalId: string | null;
|
|
7
|
-
ledgerEvents: GoalLedgerEvent[];
|
|
8
|
-
capOpenGoals?: number;
|
|
9
|
-
capEventsPerGoal?: number;
|
|
10
|
-
}): string;
|
package/dist/goal-compaction.js
DELETED
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
import { formatDuration, formatTokenValue, statusLabel, truncateText, } from "./goal-core.js";
|
|
2
|
-
import { latestAuditorResultForGoal, latestEventsForGoal, reconstructGoalLedger, } from "./goal-ledger.js";
|
|
3
|
-
export function buildGoalCompactSummary(goal, events) {
|
|
4
|
-
const lines = [];
|
|
5
|
-
lines.push(`Goal ${goal.id} — ${statusLabel(goal)}`);
|
|
6
|
-
lines.push(` Objective: ${truncateText(goal.objective, 200)}`);
|
|
7
|
-
if (goal.usage.tokensUsed > 0) {
|
|
8
|
-
lines.push(` Usage: ${formatTokenValue(goal.usage.tokensUsed)}`);
|
|
9
|
-
}
|
|
10
|
-
if (goal.usage.activeSeconds > 0) {
|
|
11
|
-
lines.push(` Time: ${formatDuration(goal.usage.activeSeconds)}`);
|
|
12
|
-
}
|
|
13
|
-
const recent = latestEventsForGoal(events, goal.id, 5);
|
|
14
|
-
if (recent.length > 0) {
|
|
15
|
-
lines.push(" Recent events:");
|
|
16
|
-
for (const event of recent) {
|
|
17
|
-
switch (event.type) {
|
|
18
|
-
case "goal_paused":
|
|
19
|
-
lines.push(` - paused: ${event.reason}`);
|
|
20
|
-
break;
|
|
21
|
-
case "goal_resumed":
|
|
22
|
-
lines.push(` - resumed: ${event.reason}`);
|
|
23
|
-
break;
|
|
24
|
-
case "goal_tweaked":
|
|
25
|
-
lines.push(` - tweaked: ${event.changeSummary}`);
|
|
26
|
-
break;
|
|
27
|
-
case "completion_requested":
|
|
28
|
-
lines.push(` - completion requested${event.summary ? `: ${truncateText(event.summary, 80)}` : ""}`);
|
|
29
|
-
break;
|
|
30
|
-
case "audit_result":
|
|
31
|
-
lines.push(` - auditor ${event.verdict}${event.verdict === "disapproved" ? `: ${truncateText(event.report, 80)}` : ""}`);
|
|
32
|
-
break;
|
|
33
|
-
case "goal_completed":
|
|
34
|
-
lines.push(" - completed");
|
|
35
|
-
break;
|
|
36
|
-
case "task_list_set":
|
|
37
|
-
lines.push(` - task list set: ${event.taskCount} tasks${event.blockCompletion ? " (blocking)" : ""}`);
|
|
38
|
-
break;
|
|
39
|
-
case "task_complete":
|
|
40
|
-
lines.push(` - task complete: ${event.taskId}${event.evidence ? ` — ${truncateText(event.evidence, 60)}` : ""}`);
|
|
41
|
-
break;
|
|
42
|
-
case "task_skipped":
|
|
43
|
-
lines.push(` - task skipped: ${event.taskId} — ${truncateText(event.reason, 60)}`);
|
|
44
|
-
break;
|
|
45
|
-
case "goal_aborted":
|
|
46
|
-
lines.push(` - aborted: ${event.reason}`);
|
|
47
|
-
break;
|
|
48
|
-
default:
|
|
49
|
-
break;
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
const auditor = latestAuditorResultForGoal(events, goal.id);
|
|
54
|
-
if (auditor && auditor.verdict === "disapproved") {
|
|
55
|
-
lines.push(` Auditor rejection (latest): ${truncateText(auditor.report, 120)}`);
|
|
56
|
-
}
|
|
57
|
-
if (goal.pauseReason) {
|
|
58
|
-
lines.push(` Pause reason: ${goal.pauseReason}`);
|
|
59
|
-
}
|
|
60
|
-
if (goal.pauseSuggestedAction) {
|
|
61
|
-
lines.push(` Suggested action: ${goal.pauseSuggestedAction}`);
|
|
62
|
-
}
|
|
63
|
-
return lines.join("\n");
|
|
64
|
-
}
|
|
65
|
-
export function buildCompactionSummary(args) {
|
|
66
|
-
const { goalsById, focusedGoalId, ledgerEvents, capOpenGoals = 20, capEventsPerGoal = 5 } = args;
|
|
67
|
-
const lines = [];
|
|
68
|
-
const openGoals = Array.from(goalsById.values()).filter((g) => g.status !== "complete");
|
|
69
|
-
const reconstructed = reconstructGoalLedger(ledgerEvents);
|
|
70
|
-
if (focusedGoalId && goalsById.has(focusedGoalId)) {
|
|
71
|
-
const focused = goalsById.get(focusedGoalId);
|
|
72
|
-
lines.push(`[FOCUSED GOAL]`);
|
|
73
|
-
lines.push(buildGoalCompactSummary(focused, latestEventsForGoal(ledgerEvents, focusedGoalId, capEventsPerGoal)));
|
|
74
|
-
lines.push("");
|
|
75
|
-
}
|
|
76
|
-
const otherOpen = openGoals.filter((g) => g.id !== focusedGoalId);
|
|
77
|
-
if (otherOpen.length > 0) {
|
|
78
|
-
lines.push(`[OTHER OPEN GOALS — ${otherOpen.length} total]`);
|
|
79
|
-
for (const goal of otherOpen.slice(0, capOpenGoals)) {
|
|
80
|
-
lines.push(`- ${goal.id} — ${statusLabel(goal)} — ${truncateText(goal.objective, 120)}`);
|
|
81
|
-
}
|
|
82
|
-
if (otherOpen.length > capOpenGoals) {
|
|
83
|
-
lines.push(`... and ${otherOpen.length - capOpenGoals} more`);
|
|
84
|
-
}
|
|
85
|
-
lines.push("");
|
|
86
|
-
}
|
|
87
|
-
if (reconstructed.terminalGoals.size > 0) {
|
|
88
|
-
lines.push(`[TERMINAL GOALS — ${reconstructed.terminalGoals.size} completed or aborted]`);
|
|
89
|
-
for (const [goalId, state] of reconstructed.terminalGoals) {
|
|
90
|
-
const label = state.latestStatus === "complete" ? "completed" : "aborted";
|
|
91
|
-
lines.push(`- ${goalId} — ${label}${state.completedAt ? ` at ${state.completedAt}` : ""}${state.abortedAt ? ` at ${state.abortedAt}` : ""}`);
|
|
92
|
-
}
|
|
93
|
-
lines.push("");
|
|
94
|
-
}
|
|
95
|
-
if (openGoals.length === 0 && reconstructed.terminalGoals.size === 0) {
|
|
96
|
-
lines.push("[NO GOALS]");
|
|
97
|
-
lines.push("No open or terminal goals recorded in this session.");
|
|
98
|
-
}
|
|
99
|
-
lines.push("[INSTRUCTION]");
|
|
100
|
-
lines.push("Continue from the focused goal above, or ask the user to run /goals, /goals-set, or /goal-focus.");
|
|
101
|
-
lines.push("Do not rely on chat memory for goal state; use the facts above.");
|
|
102
|
-
return lines.join("\n");
|
|
103
|
-
}
|
|
104
|
-
//# sourceMappingURL=goal-compaction.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"goal-compaction.js","sourceRoot":"","sources":["../extensions/goal-compaction.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EACd,gBAAgB,EAChB,WAAW,EACX,YAAY,GACb,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACL,0BAA0B,EAC1B,mBAAmB,EACnB,qBAAqB,GAEtB,MAAM,kBAAkB,CAAC;AAG1B,MAAM,UAAU,uBAAuB,CAAC,IAAgB,EAAE,MAAyB;IACjF,MAAM,KAAK,GAAa,EAAE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,CAAC;YAC1E,KAAK,CAAC,IAAI,CAAC,KAAK,MAAM,MAAM,KAAK,GAAG,KAAK,CAAC,WAAW,CAAC,CAAC,CAAC,OAAO,KAAK,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,EAAE,GAAG,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC,OAAO,KAAK,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;QAC/I,CAAC;QACD,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACjB,CAAC;IAED,IAAI,SAAS,CAAC,MAAM,KAAK,CAAC,IAAI,aAAa,CAAC,aAAa,CAAC,IAAI,KAAK,CAAC,EAAE,CAAC;QACrE,KAAK,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;QACzB,KAAK,CAAC,IAAI,CAAC,qDAAqD,CAAC,CAAC;IACpE,CAAC;IAED,KAAK,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC;IAC5B,KAAK,CAAC,IAAI,CAAC,kGAAkG,CAAC,CAAC;IAC/G,KAAK,CAAC,IAAI,CAAC,iEAAiE,CAAC,CAAC;IAE9E,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC1B,CAAC"}
|
package/dist/goal-core.d.ts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
export interface GoalUsageLike {
|
|
2
|
-
tokensUsed: number;
|
|
3
|
-
activeSeconds: number;
|
|
4
|
-
}
|
|
5
|
-
export interface GoalDisplayRecordLike {
|
|
6
|
-
objective: string;
|
|
7
|
-
status: "active" | "paused" | "complete";
|
|
8
|
-
autoContinue: boolean;
|
|
9
|
-
usage: GoalUsageLike;
|
|
10
|
-
sisyphus: boolean;
|
|
11
|
-
stopReason?: "user" | "agent";
|
|
12
|
-
}
|
|
13
|
-
export { isQuestionLikeToolName } from "./goal-tool-names.ts";
|
|
14
|
-
export declare function truncateText(value: string, max?: number): string;
|
|
15
|
-
export declare function displayObjectiveTitle(objective: string): string;
|
|
16
|
-
export declare function formatTokenValue(value: number): string;
|
|
17
|
-
export declare function formatDuration(seconds: number): string;
|
|
18
|
-
export declare function statusLabel(goal: Pick<GoalDisplayRecordLike, "sisyphus" | "status" | "autoContinue" | "stopReason">): string;
|
|
19
|
-
export declare function footerStatus(goal: GoalDisplayRecordLike): string;
|
package/dist/goal-core.js
DELETED
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
export { isQuestionLikeToolName } from "./goal-tool-names.js";
|
|
2
|
-
export function truncateText(value, max = 120) {
|
|
3
|
-
const oneLine = value.replace(/\s+/g, " ").trim();
|
|
4
|
-
return oneLine.length > max ? `${oneLine.slice(0, max - 3)}...` : oneLine;
|
|
5
|
-
}
|
|
6
|
-
export function displayObjectiveTitle(objective) {
|
|
7
|
-
const lines = objective.replace(/\r/g, "").split("\n").map((line) => line.trim()).filter(Boolean);
|
|
8
|
-
const sectionHeader = /^(success criteria|boundaries|constraints|steps|order rules|don'ts|if blocked|if blocked \/ unclear \/ failing|sisyphus reminder)\s*[::]/i;
|
|
9
|
-
for (const line of lines) {
|
|
10
|
-
if (/^=+\s*(?:sisyphus\s+)?goal\s*=+$/i.test(line))
|
|
11
|
-
continue;
|
|
12
|
-
const objectiveMatch = line.match(/^(?:objective|目标)\s*[::]\s*(.+)$/i);
|
|
13
|
-
if (objectiveMatch?.[1])
|
|
14
|
-
return objectiveMatch[1].trim();
|
|
15
|
-
if (sectionHeader.test(line))
|
|
16
|
-
continue;
|
|
17
|
-
return line;
|
|
18
|
-
}
|
|
19
|
-
return truncateText(objective);
|
|
20
|
-
}
|
|
21
|
-
export function formatTokenValue(value) {
|
|
22
|
-
const safe = Math.max(0, Math.floor(value));
|
|
23
|
-
const compact = safe >= 1_000_000_000
|
|
24
|
-
? `${(safe / 1_000_000_000).toFixed(safe >= 10_000_000_000 ? 0 : 1).replace(/\.0$/, "")}B`
|
|
25
|
-
: safe >= 1_000_000
|
|
26
|
-
? `${(safe / 1_000_000).toFixed(safe >= 10_000_000 ? 0 : 1).replace(/\.0$/, "")}M`
|
|
27
|
-
: safe >= 10_000
|
|
28
|
-
? `${(safe / 1_000).toFixed(0)}K`
|
|
29
|
-
: safe >= 1_000
|
|
30
|
-
? `${(safe / 1_000).toFixed(1).replace(/\.0$/, "")}K`
|
|
31
|
-
: String(safe);
|
|
32
|
-
const exact = safe.toLocaleString("en-US");
|
|
33
|
-
if (compact === exact)
|
|
34
|
-
return `${exact} tokens`;
|
|
35
|
-
return `${compact} (${exact}) tokens`;
|
|
36
|
-
}
|
|
37
|
-
export function formatDuration(seconds) {
|
|
38
|
-
const total = Math.max(0, Math.floor(seconds));
|
|
39
|
-
const hours = Math.floor(total / 3600);
|
|
40
|
-
const minutes = Math.floor((total % 3600) / 60);
|
|
41
|
-
const secs = total % 60;
|
|
42
|
-
if (hours > 0)
|
|
43
|
-
return `${hours}h${minutes.toString().padStart(2, "0")}m${secs.toString().padStart(2, "0")}s`;
|
|
44
|
-
if (minutes > 0)
|
|
45
|
-
return `${minutes}m${secs.toString().padStart(2, "0")}s`;
|
|
46
|
-
return `${secs}s`;
|
|
47
|
-
}
|
|
48
|
-
export function statusLabel(goal) {
|
|
49
|
-
const prefix = goal.sisyphus ? "sisyphus " : "";
|
|
50
|
-
if (goal.status === "active" && goal.autoContinue)
|
|
51
|
-
return `${prefix}running`;
|
|
52
|
-
if (goal.status === "paused" && goal.stopReason === "agent")
|
|
53
|
-
return `${prefix}paused (agent)`;
|
|
54
|
-
return `${prefix}${goal.status}`;
|
|
55
|
-
}
|
|
56
|
-
export function footerStatus(goal) {
|
|
57
|
-
const usageBits = [];
|
|
58
|
-
if (goal.usage.activeSeconds > 0)
|
|
59
|
-
usageBits.push(formatDuration(goal.usage.activeSeconds));
|
|
60
|
-
if (goal.usage.tokensUsed > 0)
|
|
61
|
-
usageBits.push(formatTokenValue(goal.usage.tokensUsed).split(" ")[0]);
|
|
62
|
-
const usage = usageBits.length > 0 ? ` [${usageBits.join(" ")}]` : "";
|
|
63
|
-
const prefix = goal.sisyphus ? "goal✊" : "goal";
|
|
64
|
-
return `${prefix}: ${statusLabel(goal)}${usage} - ${truncateText(goal.objective, 60)}`;
|
|
65
|
-
}
|
|
66
|
-
//# sourceMappingURL=goal-core.js.map
|
package/dist/goal-core.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"goal-core.js","sourceRoot":"","sources":["../extensions/goal-core.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,sBAAsB,EAAE,MAAM,sBAAsB,CAAC;AAG9D,MAAM,UAAU,YAAY,CAAC,KAAa,EAAE,GAAG,GAAG,GAAG;IACpD,MAAM,OAAO,GAAG,KAAK,CAAC,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC;IAClD,OAAO,OAAO,CAAC,MAAM,GAAG,GAAG,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,OAAO,CAAC;AAC3E,CAAC;AAED,MAAM,UAAU,qBAAqB,CAAC,SAAiB;IACtD,MAAM,KAAK,GAAG,SAAS,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IAClG,MAAM,aAAa,GAAG,2IAA2I,CAAC;IAClK,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QAC1B,IAAI,mCAAmC,CAAC,IAAI,CAAC,IAAI,CAAC;YAAE,SAAS;QAC7D,MAAM,cAAc,GAAG,IAAI,CAAC,KAAK,CAAC,mCAAmC,CAAC,CAAC;QACvE,IAAI,cAAc,EAAE,CAAC,CAAC,CAAC;YAAE,OAAO,cAAc,CAAC,CAAC,CAAC,C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