@phren/cli 0.3.27 → 0.3.30
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/dist/bridge/codex-daemon.js +25 -1
- package/dist/bridge/hand-off-queue.d.ts +6 -0
- package/dist/bridge/hand-off-queue.js +29 -9
- package/dist/bridge/resources.d.ts +21 -0
- package/dist/bridge/resources.js +58 -2
- package/dist/bridge/server-launch.js +2 -1
- package/dist/bridge/server-routes.js +33 -2
- package/dist/bridge/simulators.d.ts +3 -1
- package/dist/bridge/simulators.js +40 -5
- package/dist/bridge/task-routes.d.ts +282 -0
- package/dist/bridge/task-routes.js +162 -0
- package/dist/bridge/uploads.d.ts +4 -0
- package/dist/bridge/uploads.js +15 -0
- package/dist/bridge-hook.mjs +4306 -2990
- package/dist/cli/namespaces-store.js +32 -1
- package/dist/cli/namespaces-tasks.d.ts +1 -0
- package/dist/cli/namespaces-tasks.js +55 -4
- package/dist/cli/ops.d.ts +2 -1
- package/dist/cli/ops.js +20 -4
- package/dist/cli-registry.js +5 -4
- package/dist/data/task-contract.d.ts +75 -0
- package/dist/data/task-contract.js +161 -0
- package/dist/data/task-format.d.ts +20 -0
- package/dist/data/task-format.js +55 -0
- package/dist/data/task-metadata.d.ts +10 -0
- package/dist/data/task-metadata.js +24 -0
- package/dist/data/task-store-directory.d.ts +21 -0
- package/dist/data/task-store-directory.js +37 -0
- package/dist/data/tasks.d.ts +38 -2
- package/dist/data/tasks.js +221 -28
- package/dist/modules/registry.js +3 -3
- package/dist/shell/input.js +49 -4
- package/dist/shell/state-store.d.ts +1 -0
- package/dist/shell/state-store.js +2 -0
- package/dist/shell/view.js +19 -3
- package/dist/store-registry.d.ts +12 -1
- package/dist/store-registry.js +52 -4
- package/dist/sync/task-claim.d.ts +1 -0
- package/dist/sync/task-claim.js +8 -1
- package/dist/sync/task-merge.d.ts +0 -9
- package/dist/sync/task-merge.js +48 -1
- package/dist/tools/tasks.js +31 -18
- package/dist/ui/page.js +1 -0
- package/dist/ui/scripts.js +64 -5
- package/dist/ui/server.js +18 -0
- package/package.json +1 -1
package/dist/modules/registry.js
CHANGED
|
@@ -59,8 +59,8 @@ export const BUILTIN_MODULES = [
|
|
|
59
59
|
...core(["get_tasks", "add_task", "manage_task"]),
|
|
60
60
|
...full(["complete_task", "remove_task", "update_task", "tidy_done_tasks", "pin_task", "claim_task"]),
|
|
61
61
|
],
|
|
62
|
-
cliCommands: ["task", "tasks", "config task-mode", "config proactivity.tasks"], agentHooks: [], hookRoutes: [], capabilities: ["tasks"],
|
|
63
|
-
storeFiles: ["<project>/tasks.md", ".sessions/checkpoint-*.json"], localFiles: [],
|
|
62
|
+
cliCommands: ["task", "tasks", "config task-mode", "config proactivity.tasks"], agentHooks: [], hookRoutes: [{ method: "GET", path: "/v1/tasks" }, { method: "GET", path: "/v1/tasks/stores" }, { method: "POST", path: "/v1/tasks/update" }, { method: "POST", path: "/v1/tasks/create" }, { method: "POST", path: "/v1/tasks/save" }, { method: "POST", path: "/v1/tasks/launch" }], capabilities: ["tasks", "taskDependencies", "taskWriterSafety", "taskAtomicCreate", "taskAtomicSave", "taskBoundLaunch"],
|
|
63
|
+
storeFiles: ["<project>/tasks.md", ".sessions/checkpoint-*.json", ".config/task-format.json", ".config/task-archive/*.md", "stores.yaml"], localFiles: [".runtime/task-dependencies.lock"],
|
|
64
64
|
phoneScreens: [{ screen: "TasksView", capability: "tasks" }], skills: [],
|
|
65
65
|
},
|
|
66
66
|
{
|
|
@@ -85,7 +85,7 @@ export const BUILTIN_MODULES = [
|
|
|
85
85
|
"/v1/subagents", "/v1/subagents/transcript", "/v1/subagents/messages",
|
|
86
86
|
]),
|
|
87
87
|
...routes("POST", [
|
|
88
|
-
"/v1/push/register", "/v1/push/answer", "/v1/push/target", "/v1/files", "/v1/projects/add", "/v1/simulators/action",
|
|
88
|
+
"/v1/push/register", "/v1/push/answer", "/v1/push/target", "/v1/files", "/v1/files/delete", "/v1/projects/add", "/v1/simulators/action",
|
|
89
89
|
"/v1/workspaces/launch", "/v1/workspaces/create", "/v1/workspaces/focus", "/v1/workspaces/rename",
|
|
90
90
|
"/v1/workspaces/close", "/v1/sessions/rename", "/v1/prompt", "/v1/prompt/status", "/v1/model", "/v1/settings", "/v1/agents/permission-mode", "/v1/side-question/dismiss", "/v1/keys", "/v1/secret", "/v1/upload",
|
|
91
91
|
"/v1/approvals/answer", "/v1/questions/answer", "/v1/subagents/resume", "/v1/subagents/archive-finished", "/v1/canary",
|
package/dist/shell/input.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { filterTaskDoc } from "../data/task-contract.js";
|
|
1
2
|
import { nonInteractiveGitEnv } from "../utils-helpers.js";
|
|
2
3
|
/**
|
|
3
4
|
* Command palette and input handling for the phren interactive shell.
|
|
@@ -152,6 +153,49 @@ export async function executePalette(host, input) {
|
|
|
152
153
|
host.setMessage(` ${resultMsg(addTask(host.phrenPath, project, text))}`);
|
|
153
154
|
return;
|
|
154
155
|
}
|
|
156
|
+
if (command === "lane") {
|
|
157
|
+
const value = (parts[1] ?? "").toLowerCase();
|
|
158
|
+
if (!["human", "agent", "all"].includes(value)) {
|
|
159
|
+
host.setMessage(" Usage: :lane human|agent|all");
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
host.state.taskResponsibility = value === "all" ? undefined : value;
|
|
163
|
+
saveShellState(host.phrenPath, host.state);
|
|
164
|
+
host.setView("Tasks");
|
|
165
|
+
host.setMessage(` Task responsibility: ${value}`);
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
if (command === "responsibility" || command === "depends") {
|
|
169
|
+
const project = host.ensureProjectSelected();
|
|
170
|
+
if (!project)
|
|
171
|
+
return;
|
|
172
|
+
const match = parts[1];
|
|
173
|
+
if (!match) {
|
|
174
|
+
host.setMessage(" Usage: :responsibility <id> human|agent or :depends <id> <JSON array>");
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
177
|
+
const value = parts.slice(2).join(" ");
|
|
178
|
+
let updates;
|
|
179
|
+
if (command === "responsibility") {
|
|
180
|
+
if (value !== "human" && value !== "agent") {
|
|
181
|
+
host.setMessage(" Responsibility must be human or agent.");
|
|
182
|
+
return;
|
|
183
|
+
}
|
|
184
|
+
updates = { responsibility: value };
|
|
185
|
+
}
|
|
186
|
+
else {
|
|
187
|
+
try {
|
|
188
|
+
updates = { dependencies: JSON.parse(value) };
|
|
189
|
+
}
|
|
190
|
+
catch {
|
|
191
|
+
host.setMessage(" Dependencies must be a JSON array.");
|
|
192
|
+
return;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
host.snapshotForUndo(command, taskFileForProject(host.phrenPath, project));
|
|
196
|
+
host.setMessage(` ${resultMsg(updateTask(host.phrenPath, project, match, updates))}`);
|
|
197
|
+
return;
|
|
198
|
+
}
|
|
155
199
|
if (command === "complete") {
|
|
156
200
|
const project = host.ensureProjectSelected();
|
|
157
201
|
if (!project)
|
|
@@ -513,7 +557,7 @@ function suggestCommand(input) {
|
|
|
513
557
|
}
|
|
514
558
|
export function completeInput(line, phrenPath, profile, state) {
|
|
515
559
|
const commands = [
|
|
516
|
-
":projects", ":tasks", ":task", ":findings", ":review queue", ":machines", ":health", ":graph",
|
|
560
|
+
":projects", ":tasks", ":task", ":lane", ":responsibility", ":depends", ":findings", ":review queue", ":machines", ":health", ":graph",
|
|
517
561
|
":open", ":search", ":add", ":complete", ":move", ":reprioritize", ":pin",
|
|
518
562
|
":unpin", ":context", ":work next", ":tidy", ":find add", ":find remove",
|
|
519
563
|
":machine map",
|
|
@@ -537,7 +581,7 @@ export function completeInput(line, phrenPath, profile, state) {
|
|
|
537
581
|
if (cmd === "open") {
|
|
538
582
|
return listProjectCards(phrenPath, profile).map((c) => `:open ${c.name}`);
|
|
539
583
|
}
|
|
540
|
-
if (["complete", "move", "reprioritize", "context", "pin", "unpin"].includes(cmd)) {
|
|
584
|
+
if (["complete", "move", "reprioritize", "context", "pin", "unpin", "responsibility", "depends"].includes(cmd)) {
|
|
541
585
|
const project = state.project;
|
|
542
586
|
if (!project)
|
|
543
587
|
return [];
|
|
@@ -576,8 +620,9 @@ export function getListItems(phrenPath, profile, state, healthLineCount) {
|
|
|
576
620
|
const result = readTasks(phrenPath, state.project);
|
|
577
621
|
if (!result.ok)
|
|
578
622
|
return [];
|
|
579
|
-
const
|
|
580
|
-
const
|
|
623
|
+
const filtered = filterTaskDoc(phrenPath, result.data, { responsibility: state.taskResponsibility });
|
|
624
|
+
const active = state.filter ? tasksByFilter(filtered.items.Active, state.filter) : filtered.items.Active;
|
|
625
|
+
const queue = state.filter ? tasksByFilter(filtered.items.Queue, state.filter) : filtered.items.Queue;
|
|
581
626
|
return [...active, ...queue];
|
|
582
627
|
}
|
|
583
628
|
case "Findings": {
|
|
@@ -4,6 +4,7 @@ export interface ShellState {
|
|
|
4
4
|
view: "Projects" | "Tasks" | "Findings" | "Review Queue" | "Skills" | "Hooks" | "Machines/Profiles" | "Health" | "Graph";
|
|
5
5
|
project?: string;
|
|
6
6
|
filter?: string;
|
|
7
|
+
taskResponsibility?: "human" | "agent";
|
|
7
8
|
page?: number;
|
|
8
9
|
perPage?: number;
|
|
9
10
|
introMode?: "always" | "once-per-version" | "off";
|
|
@@ -27,6 +27,7 @@ export function loadShellState(phrenPath) {
|
|
|
27
27
|
view: persistedView,
|
|
28
28
|
project: raw.project,
|
|
29
29
|
filter: raw.filter,
|
|
30
|
+
taskResponsibility: raw.taskResponsibility === "human" || raw.taskResponsibility === "agent" ? raw.taskResponsibility : undefined,
|
|
30
31
|
page: Number.isFinite(raw.page) ? Number(raw.page) : fallback.page,
|
|
31
32
|
perPage: Number.isFinite(raw.perPage) ? Number(raw.perPage) : fallback.perPage,
|
|
32
33
|
introMode: raw.introMode === "always" || raw.introMode === "off" ? raw.introMode : "once-per-version",
|
|
@@ -47,6 +48,7 @@ export function saveShellState(phrenPath, state) {
|
|
|
47
48
|
view: state.view,
|
|
48
49
|
project: state.project,
|
|
49
50
|
filter: state.filter,
|
|
51
|
+
taskResponsibility: state.taskResponsibility,
|
|
50
52
|
page: state.page,
|
|
51
53
|
perPage: state.perPage,
|
|
52
54
|
introMode: state.introMode,
|
package/dist/shell/view.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { taskReadiness, filterTaskDoc, taskCounts } from "../data/task-contract.js";
|
|
1
2
|
import { moduleEnabled } from "../modules/runtime.js";
|
|
2
3
|
/**
|
|
3
4
|
* View rendering functions for the phren interactive shell.
|
|
@@ -278,7 +279,9 @@ function renderTaskView(ctx, cursor, height, subsectionsCache) {
|
|
|
278
279
|
const result = readTasks(storePath, project);
|
|
279
280
|
if (!result.ok)
|
|
280
281
|
return { lines: [result.error], subsectionsCache };
|
|
281
|
-
const parsed = result.data;
|
|
282
|
+
const parsed = filterTaskDoc(ctx.phrenPath, result.data, { responsibility: ctx.state.taskResponsibility });
|
|
283
|
+
const counts = taskCounts(ctx.phrenPath, result.data);
|
|
284
|
+
const laneHeader = ` ${ctx.state.taskResponsibility ?? "Human + Agent"} · Human ${counts.human} · Agent ready ${counts.agentReady} · Waiting ${counts.agentWaitingOnHuman + counts.agentWaitingOnTask} (:lane human|agent|all)`;
|
|
282
285
|
const warnings = parsed.issues.length
|
|
283
286
|
? [` ${style.yellow("⚠")} ${style.yellow(parsed.issues.join("; "))}`, ""]
|
|
284
287
|
: [];
|
|
@@ -298,7 +301,7 @@ function renderTaskView(ctx, cursor, height, subsectionsCache) {
|
|
|
298
301
|
}
|
|
299
302
|
const queueStart = active.length;
|
|
300
303
|
const doneStart = active.length + queue.length;
|
|
301
|
-
const allLines = [];
|
|
304
|
+
const allLines = [style.dim(laneHeader)];
|
|
302
305
|
let cursorFirstLine = 0;
|
|
303
306
|
let cursorLastLine = 0;
|
|
304
307
|
let lastSection = "";
|
|
@@ -331,11 +334,24 @@ function renderTaskView(ctx, cursor, height, subsectionsCache) {
|
|
|
331
334
|
: "";
|
|
332
335
|
const lineText = isDone ? style.dim(item.line) : item.line;
|
|
333
336
|
const idStr = style.dim(item.id.padEnd(3));
|
|
334
|
-
|
|
337
|
+
const ready = taskReadiness(ctx.phrenPath, result.data, item);
|
|
338
|
+
const laneTag = ` [${ready.responsibility} · ${ready.readiness}]`;
|
|
339
|
+
let row = ` ${prioIcon} ${statusIcon} ${idStr} ${lineText}${pinTag}${ghTag}${laneTag}`;
|
|
335
340
|
row = isSelected && !isDone
|
|
336
341
|
? formatSelectableLine(row, cols, true)
|
|
337
342
|
: truncateLine(row, cols);
|
|
338
343
|
allLines.push(row);
|
|
344
|
+
for (const prerequisite of ready.prerequisites) {
|
|
345
|
+
const responsibility = prerequisite.missing ? "Unknown responsibility" : prerequisite.responsibility === "human" ? "Human" : "Agent";
|
|
346
|
+
allLines.push(truncateLine(` ${prerequisite.missing ? "Unavailable" : prerequisite.completed ? "✓" : "Waiting on"} [${responsibility}] ${prerequisite.title}`, cols));
|
|
347
|
+
// Identity components are validated ASCII. Wrap rather than truncate so
|
|
348
|
+
// similarly titled cross-store tasks stay distinguishable in narrow panes.
|
|
349
|
+
const identity = `${prerequisite.storeId}/${prerequisite.project}/${prerequisite.stableId}`;
|
|
350
|
+
const indent = " ".repeat(Math.min(14, Math.max(0, cols - 1)));
|
|
351
|
+
const width = Math.max(1, cols - indent.length);
|
|
352
|
+
for (let start = 0; start < identity.length; start += width)
|
|
353
|
+
allLines.push(indent + identity.slice(start, start + width));
|
|
354
|
+
}
|
|
339
355
|
if (item.context) {
|
|
340
356
|
const ctxLine = ` ${style.dimItalic("→ " + item.context)}`;
|
|
341
357
|
allLines.push(isSelected && !isDone ? formatSelectableLine(ctxLine, cols, true) : truncateLine(ctxLine, cols));
|
package/dist/store-registry.d.ts
CHANGED
|
@@ -61,7 +61,15 @@ export interface RegistryReadResult {
|
|
|
61
61
|
problems: string[];
|
|
62
62
|
lossy: boolean;
|
|
63
63
|
}
|
|
64
|
-
export declare function readStoreRegistryDetailed(phrenPath: string
|
|
64
|
+
export declare function readStoreRegistryDetailed(phrenPath: string, options?: {
|
|
65
|
+
migrateAttachments?: boolean;
|
|
66
|
+
}): RegistryReadResult;
|
|
67
|
+
/** Identity carried by the store itself, never an attachment ID or path hash.
|
|
68
|
+
* Reading identity must not migrate this machine's attachments. */
|
|
69
|
+
export declare function registeredStoreIdentity(phrenPath: string): string | undefined;
|
|
70
|
+
/** Explicit, idempotent registration for legacy stores. Callers enforce the
|
|
71
|
+
* existing manage_config permission. No task or attachment is rewritten. */
|
|
72
|
+
export declare function registerStoreIdentity(phrenPath: string): string;
|
|
65
73
|
export declare function readStoreRegistry(phrenPath: string): StoreRegistry | null;
|
|
66
74
|
/**
|
|
67
75
|
* Writes this machine's view of the stores: the primary entry to the synced
|
|
@@ -85,6 +93,9 @@ export declare function storePathExists(storePath: string): boolean;
|
|
|
85
93
|
* deciding what to do, otherwise its writes would land in the primary store.
|
|
86
94
|
*/
|
|
87
95
|
export declare function resolveAllStores(phrenPath: string): StoreEntry[];
|
|
96
|
+
/** Task discovery must neither migrate attachments nor treat a partial registry
|
|
97
|
+
* as proof of an unambiguous task identity. No writes or warnings on this path. */
|
|
98
|
+
export declare function readTaskStoreEntries(phrenPath: string): StoreEntry[];
|
|
88
99
|
/**
|
|
89
100
|
* Non-primary entries in the synced stores.yaml that this machine does not use:
|
|
90
101
|
* joined on another machine with an older phren. Attached ones were moved into
|
package/dist/store-registry.js
CHANGED
|
@@ -40,9 +40,9 @@ export function generateStoreId() {
|
|
|
40
40
|
function deterministicIdFromPath(storePath) {
|
|
41
41
|
return crypto.createHash("sha256").update(storePath).digest("hex").slice(0, 8);
|
|
42
42
|
}
|
|
43
|
-
export function readStoreRegistryDetailed(phrenPath) {
|
|
43
|
+
export function readStoreRegistryDetailed(phrenPath, options = {}) {
|
|
44
44
|
const synced = readSyncedRegistry(phrenPath);
|
|
45
|
-
const attached = readAttachedStores(phrenPath, synced.registry);
|
|
45
|
+
const attached = readAttachedStores(phrenPath, synced.registry, options.migrateAttachments !== false);
|
|
46
46
|
const problems = [...synced.problems, ...attached.problems];
|
|
47
47
|
const lossy = synced.lossy || attached.lossy;
|
|
48
48
|
if (!synced.registry && attached.stores.length === 0)
|
|
@@ -75,10 +75,36 @@ function readSyncedRegistry(phrenPath) {
|
|
|
75
75
|
}
|
|
76
76
|
return { registry, problems, lossy: skippedEntries > 0 };
|
|
77
77
|
}
|
|
78
|
-
|
|
78
|
+
/** Identity carried by the store itself, never an attachment ID or path hash.
|
|
79
|
+
* Reading identity must not migrate this machine's attachments. */
|
|
80
|
+
export function registeredStoreIdentity(phrenPath) {
|
|
81
|
+
const result = readSyncedRegistry(phrenPath);
|
|
82
|
+
const id = result.lossy ? undefined : result.registry?.stores.find(s => s.role === "primary")?.id;
|
|
83
|
+
return id && /^[a-f0-9]{8}$/.test(id) ? id : undefined;
|
|
84
|
+
}
|
|
85
|
+
/** Explicit, idempotent registration for legacy stores. Callers enforce the
|
|
86
|
+
* existing manage_config permission. No task or attachment is rewritten. */
|
|
87
|
+
export function registerStoreIdentity(phrenPath) {
|
|
88
|
+
return withFileLock(registryLockPath(phrenPath), () => {
|
|
89
|
+
const result = readSyncedRegistry(phrenPath);
|
|
90
|
+
if (result.lossy)
|
|
91
|
+
throw new Error(`Cannot register store identity: ${result.problems.join(" | ")}`);
|
|
92
|
+
const existing = result.registry?.stores.find(s => s.role === "primary");
|
|
93
|
+
if (existing) {
|
|
94
|
+
if (!/^[a-f0-9]{8}$/.test(existing.id))
|
|
95
|
+
throw new Error("Existing store identity is not a canonical eight-hex ID. Review the registry; identity registration cannot replace an immutable ID.");
|
|
96
|
+
return existing.id;
|
|
97
|
+
}
|
|
98
|
+
const primary = { ...implicitPrimaryStore(phrenPath), id: generateStoreId() };
|
|
99
|
+
writeSyncedPrimary(phrenPath, primary);
|
|
100
|
+
return primary.id;
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
function readAttachedStores(phrenPath, synced, migrate = true) {
|
|
79
104
|
const parsed = readYamlFile(attachedStoresFilePath(phrenPath), ATTACHED_STORES_FILENAME);
|
|
80
105
|
if (!parsed.exists)
|
|
81
|
-
return { stores: migrateSyncedAttachments(phrenPath, synced)
|
|
106
|
+
return { stores: migrate ? migrateSyncedAttachments(phrenPath, synced)
|
|
107
|
+
: (synced?.stores.filter(s => s.role !== "primary" && storePathExists(s.path)) ?? []), problems: [], lossy: false };
|
|
82
108
|
if (parsed.problems.length > 0)
|
|
83
109
|
return { stores: [], problems: parsed.problems, lossy: true };
|
|
84
110
|
const problems = [];
|
|
@@ -213,6 +239,28 @@ export function storePathExists(storePath) {
|
|
|
213
239
|
*/
|
|
214
240
|
export function resolveAllStores(phrenPath) {
|
|
215
241
|
const registry = readStoreRegistry(phrenPath);
|
|
242
|
+
return resolveStoreEntries(phrenPath, registry);
|
|
243
|
+
}
|
|
244
|
+
/** Task discovery must neither migrate attachments nor treat a partial registry
|
|
245
|
+
* as proof of an unambiguous task identity. No writes or warnings on this path. */
|
|
246
|
+
export function readTaskStoreEntries(phrenPath) {
|
|
247
|
+
const result = readStoreRegistryDetailed(phrenPath, { migrateAttachments: false });
|
|
248
|
+
if (result.lossy)
|
|
249
|
+
return [];
|
|
250
|
+
// The legacy registry normalizer tolerates bad subscription members by
|
|
251
|
+
// dropping them. For task access that could turn an invalid list into "all
|
|
252
|
+
// projects", so validate the original evidence before using that view.
|
|
253
|
+
for (const [file, label] of [[storesFilePath(phrenPath), STORES_FILENAME], [attachedStoresFilePath(phrenPath), ATTACHED_STORES_FILENAME]]) {
|
|
254
|
+
const raw = readYamlFile(file, label);
|
|
255
|
+
if (raw.exists && (!isRecord(raw.value) || !Array.isArray(raw.value.stores)
|
|
256
|
+
|| raw.value.stores.some(store => !isRecord(store) || (store.projects !== undefined
|
|
257
|
+
&& (!Array.isArray(store.projects) || store.projects.some(project => typeof project !== "string" || !/^[A-Za-z0-9][A-Za-z0-9_-]{0,99}$/.test(project)))))))
|
|
258
|
+
return [];
|
|
259
|
+
}
|
|
260
|
+
const registry = result.registry && { ...result.registry, stores: result.registry.stores.map(store => store.role === "primary" ? { ...store, path: path.resolve(phrenPath) } : store) };
|
|
261
|
+
return resolveStoreEntries(phrenPath, registry);
|
|
262
|
+
}
|
|
263
|
+
function resolveStoreEntries(phrenPath, registry) {
|
|
216
264
|
const stores = registry ? [...registry.stores] : [implicitPrimaryStore(phrenPath)];
|
|
217
265
|
// Append PHREN_FEDERATION_PATHS entries that aren't already in the registry
|
|
218
266
|
const knownPaths = new Set(stores.map((s) => s.path));
|
package/dist/sync/task-claim.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { runBestEffortGit } from "../cli/session-git.js";
|
|
2
|
-
import { claimTask, resolveTaskItem } from "../data/tasks.js";
|
|
2
|
+
import { claimTask, readTasks, resolveTaskItem } from "../data/tasks.js";
|
|
3
|
+
import { taskReadiness } from "../data/task-contract.js";
|
|
3
4
|
import { withFileLock } from "../governance/locks.js";
|
|
4
5
|
import { runtimeFile } from "../phren-paths.js";
|
|
5
6
|
import { trackTaskWriteCommits } from "../data/task-receipts.js";
|
|
@@ -40,6 +41,12 @@ export async function claimTaskSynced(phrenPath, project, match, claim, opts = {
|
|
|
40
41
|
if (!opts.release && now?.claim && now.claim.computer !== claim.computer) {
|
|
41
42
|
return { claimed: false, item: now, heldBy: now.claim, synced: pushed.ok, detail: `${now.claim.computer} claimed this task first.` };
|
|
42
43
|
}
|
|
44
|
+
const doc = readTasks(phrenPath, project);
|
|
45
|
+
if (!opts.release && (!now || now.section !== "Active" || now.checked || now.claim?.computer !== claim.computer || !doc.ok
|
|
46
|
+
|| taskReadiness(opts.graphRoot ?? phrenPath, doc.data, now).readiness !== "ready")) {
|
|
47
|
+
return { claimed: false, ...(now ? { item: now } : {}), synced: pushed.ok,
|
|
48
|
+
detail: "The task changed while syncing; this computer no longer holds a ready agent task." };
|
|
49
|
+
}
|
|
43
50
|
return { claimed: !opts.release, item: now ?? written.data, synced: pushed.ok,
|
|
44
51
|
detail: pushed.ok ? "Pushed to the store's remote." : `Committed but not pushed: ${pushed.error ?? "push failed"}` };
|
|
45
52
|
});
|
|
@@ -1,12 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Three-way merge of a tasks.md file by task id, for store sync conflicts.
|
|
3
|
-
*
|
|
4
|
-
* Each task is keyed by its `bid:` comment (or its normalized text when it has
|
|
5
|
-
* none) and compared across the merge base, the local side and the incoming
|
|
6
|
-
* side. The side that changed a task wins; when both changed it, a completed
|
|
7
|
-
* side wins, then an edit beats a removal, then the incoming side wins. The
|
|
8
|
-
* result keeps the incoming file's layout and section order.
|
|
9
|
-
*/
|
|
10
1
|
interface TaskEntry {
|
|
11
2
|
key: string;
|
|
12
3
|
section: string;
|
package/dist/sync/task-merge.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { parseTaskMetadata } from "../data/task-metadata.js";
|
|
1
2
|
/**
|
|
2
3
|
* Three-way merge of a tasks.md file by task id, for store sync conflicts.
|
|
3
4
|
*
|
|
@@ -67,6 +68,38 @@ export function pickTask(base, ours, theirs) {
|
|
|
67
68
|
return ours;
|
|
68
69
|
return theirs;
|
|
69
70
|
}
|
|
71
|
+
/** Merge independent responsibility/dependency edits and retain both histories.
|
|
72
|
+
* Ordinary task conflict precedence still controls title, claim and section. */
|
|
73
|
+
function mergeContract(base, ours, theirs, winner) {
|
|
74
|
+
const read = (entry) => {
|
|
75
|
+
const records = entry?.lines.filter(line => line.trimStart().startsWith("Task:")) ?? [];
|
|
76
|
+
if (!records.length)
|
|
77
|
+
return { value: { version: 1, responsibility: "agent", dependencies: [], history: [] } };
|
|
78
|
+
if (records.length !== 1)
|
|
79
|
+
return { raw: records.join("\n") };
|
|
80
|
+
return { raw: records[0], value: parseTaskMetadata(records[0].trim().slice(5).trim()) };
|
|
81
|
+
};
|
|
82
|
+
const b = read(base), o = read(ours), t = read(theirs);
|
|
83
|
+
if (o.raw === undefined && t.raw === undefined)
|
|
84
|
+
return winner;
|
|
85
|
+
if (!b.value || !o.value || !t.value)
|
|
86
|
+
return winner;
|
|
87
|
+
const baseValue = b.value, ourValue = o.value, theirValue = t.value;
|
|
88
|
+
const pick = (field) => JSON.stringify(theirValue[field]) === JSON.stringify(baseValue[field]) ? ourValue[field] : theirValue[field];
|
|
89
|
+
const history = [...new Map([...o.value.history, ...t.value.history].map(h => [JSON.stringify(h), h])).values()];
|
|
90
|
+
const contract = { version: 1, responsibility: pick("responsibility"), dependencies: pick("dependencies"), history };
|
|
91
|
+
let lines = winner.lines.filter(line => !line.trimStart().startsWith("Task:"));
|
|
92
|
+
if (contract.responsibility === "human") {
|
|
93
|
+
lines = lines.filter(line => {
|
|
94
|
+
const claim = /^Claimed:\s+([A-Za-z0-9][A-Za-z0-9._-]{0,252})\s+(\d{4}-\d{2}-\d{2}T[0-9:.]+Z)(?:\s+session:[A-Za-z0-9._:-]{1,128})?$/.exec(line.trim());
|
|
95
|
+
if (!claim)
|
|
96
|
+
return true;
|
|
97
|
+
history.push({ at: history.at(-1)?.at ?? claim[2], change: `released claim by ${claim[1]} during human responsibility merge` });
|
|
98
|
+
return false;
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
return { ...winner, lines: [...lines, ` Task: ${JSON.stringify(contract)}`] };
|
|
102
|
+
}
|
|
70
103
|
/**
|
|
71
104
|
* Merges three versions of a tasks.md. `base` is empty when the file was
|
|
72
105
|
* added on both sides.
|
|
@@ -77,11 +110,25 @@ export function mergeTasksByBid(base, ours, theirs) {
|
|
|
77
110
|
const b = index(parse(base));
|
|
78
111
|
const o = index(oursSections);
|
|
79
112
|
const t = index(theirsSections);
|
|
113
|
+
// A duplicated identity cannot be reconciled by first-win indexing. Leave
|
|
114
|
+
// the sync conflict unresolved, retaining both original files for repair.
|
|
115
|
+
for (const sections of [parse(base), oursSections, theirsSections]) {
|
|
116
|
+
const seen = new Set();
|
|
117
|
+
for (const section of sections)
|
|
118
|
+
for (const row of section.rows) {
|
|
119
|
+
if (row.kind !== "task" || !row.entry.key.startsWith("bid:"))
|
|
120
|
+
continue;
|
|
121
|
+
if (seen.has(row.entry.key) || [...row.entry.lines[0].matchAll(/<!--\s*bid:([a-f0-9]{8})\b[^>]*-->/g)].length !== 1) {
|
|
122
|
+
throw new Error("Task merge requires unique, unambiguous stable IDs; repair the conflicting records first.");
|
|
123
|
+
}
|
|
124
|
+
seen.add(row.entry.key);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
80
127
|
const chosen = new Map();
|
|
81
128
|
for (const key of new Set([...b.keys(), ...o.keys(), ...t.keys()])) {
|
|
82
129
|
const winner = pickTask(b.get(key), o.get(key), t.get(key));
|
|
83
130
|
if (winner)
|
|
84
|
-
chosen.set(key, winner);
|
|
131
|
+
chosen.set(key, mergeContract(b.get(key), o.get(key), t.get(key), winner));
|
|
85
132
|
}
|
|
86
133
|
// Local order, per section, so a task only the local side placed there lands after its local predecessor.
|
|
87
134
|
const localOrder = new Map();
|
package/dist/tools/tasks.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { taskView, taskCounts, filterTaskDoc } from "../data/task-contract.js";
|
|
1
2
|
import { mcpResponse, resolveStoreForProject } from "./types.js";
|
|
2
3
|
import { z } from "zod";
|
|
3
4
|
import * as fs from "fs";
|
|
@@ -71,8 +72,9 @@ function buildTaskView(doc, status, limit, doneLimit, offset) {
|
|
|
71
72
|
truncated,
|
|
72
73
|
};
|
|
73
74
|
}
|
|
74
|
-
function buildTaskSummary(doc, includedSections) {
|
|
75
|
-
const
|
|
75
|
+
function buildTaskSummary(doc, includedSections, base, original = doc) {
|
|
76
|
+
const counts = taskCounts(base, original);
|
|
77
|
+
const lines = [`## ${doc.project}`, `Human: ${counts.human}; Agent ready: ${counts.agentReady}; Agent waiting on human: ${counts.agentWaitingOnHuman}; Agent waiting on task: ${counts.agentWaitingOnTask}.`];
|
|
76
78
|
for (const section of includedSections) {
|
|
77
79
|
const items = doc.items[section];
|
|
78
80
|
const highCount = items.filter(i => i.priority === "high").length;
|
|
@@ -108,13 +110,15 @@ export function register(server, ctx) {
|
|
|
108
110
|
project: z.string().optional().describe("Project name. Omit to get all projects."),
|
|
109
111
|
id: z.string().optional().describe("Task ID like A1, Q3, D2. Requires project."),
|
|
110
112
|
item: z.string().optional().describe("Exact task text. Requires project."),
|
|
113
|
+
responsibility: z.enum(["human", "agent"]).optional().describe("Independent responsibility lane filter."),
|
|
114
|
+
readiness: z.enum(["ready", "waiting-on-human", "waiting-on-task"]).optional().describe("Derived readiness filter; does not change task section."),
|
|
111
115
|
status: z.enum(["all", "active", "queue", "done", "active+queue"]).optional().describe("Which task sections to include. Defaults to 'active+queue'."),
|
|
112
116
|
limit: z.number().int().min(1).max(200).optional().describe("Max items per Active/Queue section to return. Default 20."),
|
|
113
117
|
done_limit: z.number().int().min(1).max(200).optional().describe("Max Done items to return (most recent). Default 5. Done sections are capped tightly to avoid large responses."),
|
|
114
118
|
offset: z.number().int().min(0).optional().describe("Skip the first N items in each section before applying limit. Use with limit for pagination (e.g. offset:20, limit:20 for page 2)."),
|
|
115
119
|
summary: z.boolean().optional().describe("If true, return counts and titles only (no full content). Reduces token usage."),
|
|
116
120
|
}),
|
|
117
|
-
}, async ({ project, id, item, status, limit, done_limit, offset, summary }) => {
|
|
121
|
+
}, async ({ project, id, item, status, responsibility, readiness, limit, done_limit, offset, summary }) => {
|
|
118
122
|
// Single item lookup
|
|
119
123
|
if (id || item) {
|
|
120
124
|
if (!project)
|
|
@@ -127,16 +131,20 @@ export function register(server, ctx) {
|
|
|
127
131
|
return mcpResponse({ ok: false, error: result.error });
|
|
128
132
|
const doc = result.data;
|
|
129
133
|
const all = [...doc.items.Active, ...doc.items.Queue, ...doc.items.Done];
|
|
130
|
-
const bidLookup = id &&
|
|
131
|
-
const
|
|
134
|
+
const bidLookup = id && /^(?:bid:)?[a-f0-9]{8}$/.test(id) ? id.replace(/^bid:/, "") : null;
|
|
135
|
+
const matches = all.filter((entry) => (bidLookup && entry.stableId === bidLookup) ||
|
|
132
136
|
(id && !bidLookup && entry.id.toLowerCase() === id.toLowerCase()) ||
|
|
133
137
|
(item && entry.line.trim() === item.trim()));
|
|
138
|
+
if (matches.length > 1)
|
|
139
|
+
return mcpResponse({ ok: false, error: "Task identity is ambiguous." });
|
|
140
|
+
const match = matches[0];
|
|
134
141
|
if (!match)
|
|
135
142
|
return mcpResponse({ ok: false, error: `No task found in ${project} for ${id ? `id=${id}` : `item="${item}"`}.` });
|
|
136
143
|
return mcpResponse({
|
|
137
144
|
ok: true,
|
|
138
145
|
message: `${match.id}: ${match.line} (${match.section})`,
|
|
139
146
|
data: {
|
|
147
|
+
...taskView(phrenPath, doc, match),
|
|
140
148
|
project,
|
|
141
149
|
id: match.id,
|
|
142
150
|
stableId: match.stableId || null,
|
|
@@ -159,19 +167,19 @@ export function register(server, ctx) {
|
|
|
159
167
|
if (!result.ok)
|
|
160
168
|
return mcpResponse({ ok: false, error: result.error });
|
|
161
169
|
const doc = result.data;
|
|
162
|
-
const view = buildTaskView(doc, status, limit, done_limit, offset);
|
|
170
|
+
const view = buildTaskView(filterTaskDoc(phrenPath, doc, { responsibility, readiness }), status, limit, done_limit, offset);
|
|
163
171
|
if (!fs.existsSync(doc.path)) {
|
|
164
172
|
return mcpResponse({
|
|
165
173
|
ok: true,
|
|
166
174
|
message: `No tasks found for "${project}".`,
|
|
167
|
-
data: { project, items: view.doc.items, includedSections: view.includedSections, totalItems: view.totalItems },
|
|
175
|
+
data: { project, counts: taskCounts(phrenPath, doc), items: Object.fromEntries(TASK_SECTION_ORDER.map(section => [section, view.doc.items[section].map(entry => taskView(phrenPath, doc, entry))])), includedSections: view.includedSections, totalItems: view.totalItems },
|
|
168
176
|
});
|
|
169
177
|
}
|
|
170
178
|
if (summary) {
|
|
171
179
|
return mcpResponse({
|
|
172
180
|
ok: true,
|
|
173
|
-
message: buildTaskSummary(view.doc, view.includedSections),
|
|
174
|
-
data: { project, includedSections: view.includedSections, totalItems: view.totalItems, summary: true },
|
|
181
|
+
message: buildTaskSummary(view.doc, view.includedSections, phrenPath, doc),
|
|
182
|
+
data: { project, counts: taskCounts(phrenPath, doc), includedSections: view.includedSections, totalItems: view.totalItems, summary: true },
|
|
175
183
|
});
|
|
176
184
|
}
|
|
177
185
|
const sectionCounts = view.includedSections
|
|
@@ -183,26 +191,27 @@ export function register(server, ctx) {
|
|
|
183
191
|
return mcpResponse({
|
|
184
192
|
ok: true,
|
|
185
193
|
message: `## ${project}\n${taskMarkdown(view.doc)}${paginationNote}`,
|
|
186
|
-
data: { project, items: view.doc.items, issues: doc.issues, includedSections: view.includedSections, totalItems: view.totalItems, totalUnpaged: view.totalUnpaged, offset: offset ?? 0, truncated: view.truncated },
|
|
194
|
+
data: { project, counts: taskCounts(phrenPath, doc), items: Object.fromEntries(TASK_SECTION_ORDER.map(section => [section, view.doc.items[section].map(entry => taskView(phrenPath, doc, entry))])), issues: doc.issues, includedSections: view.includedSections, totalItems: view.totalItems, totalUnpaged: view.totalUnpaged, offset: offset ?? 0, truncated: view.truncated },
|
|
187
195
|
});
|
|
188
196
|
}
|
|
189
197
|
// All projects
|
|
190
198
|
const docs = readTasksAcrossProjects(phrenPath, profile);
|
|
191
199
|
if (!docs.length)
|
|
192
200
|
return mcpResponse({ ok: true, message: "No tasks found.", data: { projects: [] } });
|
|
193
|
-
const views = docs.map((doc) => ({ project: doc.project, doc, view: buildTaskView(doc, status, limit, done_limit, offset), issues: doc.issues }));
|
|
201
|
+
const views = docs.map((doc) => ({ project: doc.project, doc, view: buildTaskView(filterTaskDoc(phrenPath, doc, { responsibility, readiness }), status, limit, done_limit, offset), issues: doc.issues }));
|
|
194
202
|
const anyTruncated = views.some(({ view }) => view.truncated);
|
|
195
203
|
let parts;
|
|
196
204
|
if (summary) {
|
|
197
|
-
parts = views.map(({ view }) => buildTaskSummary(view.doc, view.includedSections));
|
|
205
|
+
parts = views.map(({ view, doc }) => buildTaskSummary(view.doc, view.includedSections, phrenPath, doc));
|
|
198
206
|
}
|
|
199
207
|
else {
|
|
200
208
|
parts = views.map(({ project, view }) => `## ${project}\n${taskMarkdown(view.doc)}`);
|
|
201
209
|
}
|
|
202
210
|
const truncationNote = anyTruncated && !summary ? `\n\n_Results capped (Active/Queue: ${limit ?? DEFAULT_TASK_LIMIT}, Done: ${done_limit ?? DEFAULT_DONE_LIMIT}). Pass limit/done_limit to see more._` : "";
|
|
203
|
-
const projectData = views.map(({ project, view, issues }) => ({
|
|
211
|
+
const projectData = views.map(({ project, doc, view, issues }) => ({
|
|
204
212
|
project,
|
|
205
|
-
|
|
213
|
+
counts: taskCounts(phrenPath, doc),
|
|
214
|
+
items: Object.fromEntries(TASK_SECTION_ORDER.map(section => [section, view.doc.items[section].map(entry => taskView(phrenPath, doc, entry))])),
|
|
206
215
|
issues,
|
|
207
216
|
includedSections: view.includedSections,
|
|
208
217
|
totalItems: view.totalItems,
|
|
@@ -373,6 +382,8 @@ export function register(server, ctx) {
|
|
|
373
382
|
priority: z.enum(["high", "medium", "low"]).optional().describe("New priority tag: high, medium, or low."),
|
|
374
383
|
context: z.string().optional().describe("Text to set on the Context: line below the task."),
|
|
375
384
|
replace_context: z.boolean().optional().describe("If true, replace the existing Context: value instead of appending."),
|
|
385
|
+
responsibility: z.enum(["human", "agent"]).optional().describe("Who must act; independent of task section. Legacy tasks default to agent."),
|
|
386
|
+
dependencies: z.array(z.object({ storeId: z.string().regex(/^[a-f0-9]{8}$/), project: z.string().regex(/^[A-Za-z0-9][A-Za-z0-9_-]{0,99}$/), stableId: z.string().regex(/^[a-f0-9]{8}$/) }).strict()).max(100).optional().describe("Replace prerequisites with immutable store/project/task identities; [] clears. Rejects self-links, cycles and missing targets."),
|
|
376
387
|
section: z.enum(["queue", "active", "done", "Queue", "Active", "Done"]).optional().describe("Move item to this section: Queue, Active, or Done."),
|
|
377
388
|
github_issue: z.union([z.number().int().positive(), z.string()]).optional().describe("GitHub issue number (for example 14 or '#14')."),
|
|
378
389
|
github_url: z.string().optional().describe("GitHub issue URL to associate with the task item."),
|
|
@@ -417,6 +428,8 @@ export function register(server, ctx) {
|
|
|
417
428
|
updates.move_to_active,
|
|
418
429
|
updates.work_next,
|
|
419
430
|
updates.replace_context,
|
|
431
|
+
updates.responsibility,
|
|
432
|
+
updates.dependencies,
|
|
420
433
|
].some((value) => value !== undefined);
|
|
421
434
|
if (extraUpdates) {
|
|
422
435
|
return mcpResponse({ ok: false, error: "create_issue must be used by itself." });
|
|
@@ -437,7 +450,7 @@ export function register(server, ctx) {
|
|
|
437
450
|
return withWriteQueue(async () => {
|
|
438
451
|
// Handle work_next: pick highest-priority Queue item, move to Active
|
|
439
452
|
if (updates.work_next) {
|
|
440
|
-
const result = workNextTask(targetPath, project);
|
|
453
|
+
const result = workNextTask(targetPath, project, phrenPath);
|
|
441
454
|
if (!result.ok)
|
|
442
455
|
return mcpResponse({ ok: false, error: result.error });
|
|
443
456
|
refreshTaskIndex(updateFileInIndex, targetPath, project);
|
|
@@ -503,7 +516,7 @@ export function register(server, ctx) {
|
|
|
503
516
|
});
|
|
504
517
|
}
|
|
505
518
|
// Handle github issue linking via update_task when github_issue or github_url is set (and no other field updates)
|
|
506
|
-
if ((updates.github_issue !== undefined || updates.github_url || updates.unlink_github) && !updates.text && !updates.priority && !updates.context && !updates.section) {
|
|
519
|
+
if ((updates.github_issue !== undefined || updates.github_url || updates.unlink_github) && !updates.text && !updates.priority && !updates.context && !updates.section && updates.responsibility === undefined && updates.dependencies === undefined) {
|
|
507
520
|
if (updates.unlink_github && (updates.github_issue !== undefined || updates.github_url)) {
|
|
508
521
|
return mcpResponse({ ok: false, error: "Use either unlink_github=true or github_issue/github_url, not both." });
|
|
509
522
|
}
|
|
@@ -530,7 +543,7 @@ export function register(server, ctx) {
|
|
|
530
543
|
});
|
|
531
544
|
}
|
|
532
545
|
// Standard update path
|
|
533
|
-
const result = updateTaskStore(targetPath, project, item, updates);
|
|
546
|
+
const result = updateTaskStore(targetPath, project, item, updates, phrenPath);
|
|
534
547
|
if (!result.ok)
|
|
535
548
|
return mcpResponse({ ok: false, error: result.error });
|
|
536
549
|
refreshTaskIndex(updateFileInIndex, targetPath, project);
|
|
@@ -586,7 +599,7 @@ export function register(server, ctx) {
|
|
|
586
599
|
// The Claimed line takes a plain token; a name with spaces would never parse back.
|
|
587
600
|
const computer = getMachineName().replace(/[^A-Za-z0-9._-]+/g, "-").replace(/^[^A-Za-z0-9]+/, "") || "computer";
|
|
588
601
|
const claim = { computer, at: new Date().toISOString().replace(/\.\d{3}Z$/, "Z"), ...(session ? { session } : {}) };
|
|
589
|
-
const outcome = await claimTaskSynced(targetPath, project, item, claim, { release, force });
|
|
602
|
+
const outcome = await claimTaskSynced(targetPath, project, item, claim, { release, force, graphRoot: phrenPath });
|
|
590
603
|
if (outcome.error)
|
|
591
604
|
return mcpResponse({ ok: false, error: outcome.error });
|
|
592
605
|
refreshTaskIndex(updateFileInIndex, targetPath, project);
|
package/dist/ui/page.js
CHANGED
|
@@ -293,6 +293,7 @@ ${NOTES_UI_STYLES}
|
|
|
293
293
|
<option value="Queue">Queue only</option>
|
|
294
294
|
<option value="Done">Completed</option>
|
|
295
295
|
</select>
|
|
296
|
+
<select id="tasks-filter-responsibility" class="task-filter-select" aria-label="Task responsibility"><option value="">Human + Agent</option><option value="human">Human</option><option value="agent">Agent</option></select>
|
|
296
297
|
<span id="tasks-count" class="task-count-label"></span>
|
|
297
298
|
</div>
|
|
298
299
|
<div id="tasks-list">
|