@phren/cli 0.3.28 → 0.3.31
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/agent-hooks.d.ts +5 -55
- package/dist/bridge/agent-hooks.js +22 -155
- package/dist/bridge/codex-servers.d.ts +12 -0
- package/dist/bridge/codex-servers.js +35 -3
- package/dist/bridge/codex-thread-origin.d.ts +12 -0
- package/dist/bridge/codex-thread-origin.js +31 -0
- package/dist/bridge/hand-off-queue.d.ts +16 -0
- package/dist/bridge/hand-off-queue.js +62 -19
- package/dist/bridge/hook-main.js +12 -2
- package/dist/bridge/prompt-deliveries.d.ts +99 -0
- package/dist/bridge/prompt-deliveries.js +327 -0
- package/dist/bridge/prompt-once.d.ts +2 -0
- package/dist/bridge/prompt-once.js +2 -0
- 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-pane-routes.js +72 -34
- package/dist/bridge/server-routes.d.ts +1 -0
- package/dist/bridge/server-routes.js +34 -3
- package/dist/bridge/server-stream.js +4 -2
- package/dist/bridge/server.js +12 -3
- package/dist/bridge/simulators.d.ts +3 -1
- package/dist/bridge/simulators.js +40 -5
- package/dist/bridge/sudo.d.ts +1 -1
- package/dist/bridge/sudo.js +51 -17
- 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 +18218 -15566
- 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/generated/memory-ui-graph.browser.js +328 -333
- package/dist/init/setup.js +2 -2
- package/dist/memory-ui-graph.runtime.js +328 -333
- 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 +8 -8
|
@@ -4,13 +4,15 @@ import * as path from "path";
|
|
|
4
4
|
import { execFileSync } from "child_process";
|
|
5
5
|
import { getPhrenPath } from "../shared.js";
|
|
6
6
|
import { isValidProjectName, errorMessage, getOptionValue } from "../utils.js";
|
|
7
|
-
import { resolveAllStores, addStoreToRegistry, removeStoreFromRegistry, generateStoreId, getStoreProjectDirs, readTeamBootstrap, } from "../store-registry.js";
|
|
7
|
+
import { resolveAllStores, addStoreToRegistry, removeStoreFromRegistry, generateStoreId, getStoreProjectDirs, readTeamBootstrap, registeredStoreIdentity, registerStoreIdentity, } from "../store-registry.js";
|
|
8
8
|
import { mergeStoreUpstream } from "../sync/store-merge.js";
|
|
9
9
|
import { aheadBehind, logSyncOutcome } from "../sync/outcome.js";
|
|
10
10
|
import { getRuntimeHealth, updateRuntimeHealth } from "../shared/governance.js";
|
|
11
|
+
import { permissionDeniedError } from "../governance/rbac.js";
|
|
11
12
|
function printStoreUsage() {
|
|
12
13
|
console.log("Usage:");
|
|
13
14
|
console.log(" phren store list List registered stores");
|
|
15
|
+
console.log(" phren store identity [--create] Read or explicitly register this store's portable identity");
|
|
14
16
|
console.log(" phren store add <name> --remote <url> Add a team store");
|
|
15
17
|
console.log(" phren store remove <name> Remove a store (local only)");
|
|
16
18
|
console.log(" phren store sync Pull and push all stores");
|
|
@@ -106,6 +108,35 @@ export async function handleStoreNamespace(args) {
|
|
|
106
108
|
return;
|
|
107
109
|
}
|
|
108
110
|
const phrenPath = getPhrenPath();
|
|
111
|
+
if (subcommand === "identity") {
|
|
112
|
+
if (args.length > 2 || (args[1] !== undefined && args[1] !== "--create")) {
|
|
113
|
+
console.error("Usage: phren store identity [--create]");
|
|
114
|
+
process.exitCode = 1;
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
try {
|
|
118
|
+
if (args[1] === "--create") {
|
|
119
|
+
const denied = permissionDeniedError(phrenPath, "manage_config");
|
|
120
|
+
if (denied)
|
|
121
|
+
throw new Error(denied);
|
|
122
|
+
console.log(registerStoreIdentity(phrenPath));
|
|
123
|
+
}
|
|
124
|
+
else {
|
|
125
|
+
const id = registeredStoreIdentity(phrenPath);
|
|
126
|
+
if (id)
|
|
127
|
+
console.log(id);
|
|
128
|
+
else {
|
|
129
|
+
console.error("No portable store identity. An owner can register one with phren store identity --create, then distribute stores.yaml through the existing store sync workflow.");
|
|
130
|
+
process.exitCode = 1;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
catch (error) {
|
|
135
|
+
console.error(errorMessage(error));
|
|
136
|
+
process.exitCode = 1;
|
|
137
|
+
}
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
109
140
|
if (subcommand === "list") {
|
|
110
141
|
const stores = resolveAllStores(phrenPath);
|
|
111
142
|
if (stores.length === 0) {
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import { getPhrenPath } from "../shared.js";
|
|
2
|
+
import { enableTaskFormat, taskFormatStatus, taskFormatMigrationHint } from "../data/task-format.js";
|
|
2
3
|
import { addTask, completeTask, updateTask, reorderTask, pinTask, removeTask, workNextTask, tidyDoneTasks, linkTaskIssue, promoteTask, resolveTaskItem } from "../data/tasks.js";
|
|
3
4
|
import { buildTaskIssueBody, createGithubIssueForTask, parseGithubIssueUrl, resolveProjectGithubRepo } from "../task/github.js";
|
|
4
5
|
function printTaskUsage() {
|
|
5
6
|
console.log("Usage:");
|
|
7
|
+
console.log(' phren task list [profile] [--responsibility=human|agent] [--readiness=ready|waiting-on-human|waiting-on-task]');
|
|
8
|
+
console.log(' phren task format [enable --all-writers-compatible]');
|
|
6
9
|
console.log(' phren task add <project> "<text>"');
|
|
7
10
|
console.log(' phren task complete <project> "<text>"');
|
|
8
11
|
console.log(' phren task remove <project> "<text>"');
|
|
@@ -12,7 +15,7 @@ function printTaskUsage() {
|
|
|
12
15
|
console.log(' phren task link <project> "<text>" --issue <number> [--url <url>]');
|
|
13
16
|
console.log(' phren task link <project> "<text>" --unlink');
|
|
14
17
|
console.log(' phren task create-issue <project> "<text>" [--repo <owner/name>] [--title "<title>"] [--done]');
|
|
15
|
-
console.log(' phren task update <project> "<text>" [--priority=high|medium|low] [--section=Active|Queue|Done] [--context="..."]');
|
|
18
|
+
console.log(' phren task update <project> "<text>" [--priority=high|medium|low] [--section=Active|Queue|Done] [--context="..."] [--responsibility=human|agent] [--dependencies=JSON]');
|
|
16
19
|
console.log(' phren task pin <project> "<text>"');
|
|
17
20
|
console.log(' phren task reorder <project> "<text>" --rank=<n>');
|
|
18
21
|
}
|
|
@@ -24,8 +27,28 @@ export async function handleTaskNamespace(args) {
|
|
|
24
27
|
}
|
|
25
28
|
if (subcommand === "list") {
|
|
26
29
|
// Delegate to the cross-project task view (same as `phren tasks`)
|
|
27
|
-
|
|
28
|
-
|
|
30
|
+
return handleTaskListArgs(args.slice(1), "default");
|
|
31
|
+
}
|
|
32
|
+
if (subcommand === "format") {
|
|
33
|
+
const base = getPhrenPath();
|
|
34
|
+
if (args.length === 1) {
|
|
35
|
+
console.log(JSON.stringify(taskFormatStatus(base)));
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
if (args.length !== 3 || args[1] !== "enable" || args[2] !== "--all-writers-compatible") {
|
|
39
|
+
console.error(taskFormatMigrationHint);
|
|
40
|
+
process.exitCode = 1;
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
try {
|
|
44
|
+
enableTaskFormat(base, true);
|
|
45
|
+
console.log("Task metadata enabled for this store. Your acknowledgement covers every CLI, MCP, Hook, sync and app writer; old binaries must no longer write this store.");
|
|
46
|
+
}
|
|
47
|
+
catch (error) {
|
|
48
|
+
console.error(error instanceof Error ? error.message : String(error));
|
|
49
|
+
process.exitCode = 1;
|
|
50
|
+
}
|
|
51
|
+
return;
|
|
29
52
|
}
|
|
30
53
|
if (subcommand === "add") {
|
|
31
54
|
const project = args[1];
|
|
@@ -67,7 +90,24 @@ export async function handleTaskNamespace(args) {
|
|
|
67
90
|
const positional = [];
|
|
68
91
|
const updates = {};
|
|
69
92
|
for (const arg of args.slice(2)) {
|
|
70
|
-
if (arg.startsWith("--
|
|
93
|
+
if (arg.startsWith("--responsibility=")) {
|
|
94
|
+
const value = arg.slice(17);
|
|
95
|
+
if (value !== "human" && value !== "agent") {
|
|
96
|
+
console.error("Responsibility must be human or agent.");
|
|
97
|
+
process.exit(1);
|
|
98
|
+
}
|
|
99
|
+
updates.responsibility = value;
|
|
100
|
+
}
|
|
101
|
+
else if (arg.startsWith("--dependencies=")) {
|
|
102
|
+
try {
|
|
103
|
+
updates.dependencies = JSON.parse(arg.slice(15));
|
|
104
|
+
}
|
|
105
|
+
catch {
|
|
106
|
+
console.error("Dependencies must be a JSON array of storeId/project/stableId objects.");
|
|
107
|
+
process.exit(1);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
else if (arg.startsWith("--priority=")) {
|
|
71
111
|
updates.priority = arg.slice("--priority=".length);
|
|
72
112
|
}
|
|
73
113
|
else if (arg.startsWith("--section=")) {
|
|
@@ -367,3 +407,14 @@ export async function handleTaskNamespace(args) {
|
|
|
367
407
|
printTaskUsage();
|
|
368
408
|
process.exit(1);
|
|
369
409
|
}
|
|
410
|
+
export async function handleTaskListArgs(args, defaultProfile) {
|
|
411
|
+
const { handleTaskView } = await import("./ops.js");
|
|
412
|
+
const { z } = await import("zod");
|
|
413
|
+
const filter = z.object({ responsibility: z.enum(["human", "agent"]).optional(), readiness: z.enum(["ready", "waiting-on-human", "waiting-on-task"]).optional() }).strict().safeParse(Object.fromEntries(args.filter(a => a.startsWith("--")).map(a => a.slice(2).split("="))));
|
|
414
|
+
if (!filter.success)
|
|
415
|
+
throw new Error("Invalid task responsibility/readiness filter; use --responsibility=human|agent or --readiness=ready|waiting-on-human|waiting-on-task.");
|
|
416
|
+
const profiles = args.filter(a => !a.startsWith("--"));
|
|
417
|
+
if (profiles.length > 1)
|
|
418
|
+
throw new Error("Pass at most one task profile.");
|
|
419
|
+
return handleTaskView(profiles[0] || defaultProfile, filter.data);
|
|
420
|
+
}
|
package/dist/cli/ops.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
import { type TaskFilter } from "../data/task-contract.js";
|
|
2
|
+
export declare function handleTaskView(profile: string, filter?: TaskFilter): void;
|
|
2
3
|
export declare function handleSessionsView(args: string[]): Promise<void>;
|
|
3
4
|
export declare function handleQuickstart(): Promise<void>;
|
|
4
5
|
export declare function handleDebugInjection(args: string[], profile: string): Promise<void>;
|
package/dist/cli/ops.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { taskReadiness, filterTaskDoc, taskCounts } from "../data/task-contract.js";
|
|
1
2
|
import * as fs from "fs";
|
|
2
3
|
import * as path from "path";
|
|
3
4
|
import { execFileSync } from "child_process";
|
|
@@ -8,7 +9,7 @@ import { applyGravity } from "../data/tasks.js";
|
|
|
8
9
|
import { buildIndex, queryRows } from "../shared/index.js";
|
|
9
10
|
import { resolveSubprocessArgs } from "./hooks.js";
|
|
10
11
|
import { listAllSessions, getSessionArtifacts } from "../tools/session.js";
|
|
11
|
-
export function handleTaskView(profile) {
|
|
12
|
+
export function handleTaskView(profile, filter = {}) {
|
|
12
13
|
const docs = readTasksAcrossProjects(getPhrenPath(), profile);
|
|
13
14
|
if (!docs.length) {
|
|
14
15
|
console.log("No tasks found.");
|
|
@@ -16,7 +17,8 @@ export function handleTaskView(profile) {
|
|
|
16
17
|
}
|
|
17
18
|
let totalActive = 0;
|
|
18
19
|
let totalQueue = 0;
|
|
19
|
-
for (const
|
|
20
|
+
for (const original of docs) {
|
|
21
|
+
const doc = filterTaskDoc(getPhrenPath(), original, filter);
|
|
20
22
|
const activeCount = doc.items.Active.length;
|
|
21
23
|
const queueCount = doc.items.Queue.length;
|
|
22
24
|
if (activeCount === 0 && queueCount === 0)
|
|
@@ -24,13 +26,21 @@ export function handleTaskView(profile) {
|
|
|
24
26
|
totalActive += activeCount;
|
|
25
27
|
totalQueue += queueCount;
|
|
26
28
|
console.log(`\n## ${doc.project}`);
|
|
29
|
+
const counts = taskCounts(getPhrenPath(), original);
|
|
30
|
+
console.log(` Human: ${counts.human}; Agent ready: ${counts.agentReady}; waiting on human: ${counts.agentWaitingOnHuman}; waiting on task: ${counts.agentWaitingOnTask}.`);
|
|
27
31
|
if (activeCount > 0) {
|
|
28
32
|
console.log(" Active:");
|
|
29
33
|
const activeWithGravity = applyGravity(doc.items.Active).sort((a, b) => (a.rank ?? 0) - (b.rank ?? 0));
|
|
30
34
|
for (const item of activeWithGravity) {
|
|
31
35
|
const rankTag = item.rank !== undefined ? ` [#${item.rank}]` : "";
|
|
32
36
|
const github = item.githubIssue ? ` [gh:#${item.githubIssue}]` : item.githubUrl ? " [gh]" : "";
|
|
33
|
-
|
|
37
|
+
const ready = taskReadiness(getPhrenPath(), original, item);
|
|
38
|
+
console.log(` - ${item.line}${rankTag}${github} [${ready.responsibility} · ${ready.readiness}]`);
|
|
39
|
+
for (const prerequisite of ready.prerequisites) {
|
|
40
|
+
const responsibility = prerequisite.missing ? "Unknown responsibility" : prerequisite.responsibility === "human" ? "Human" : "Agent";
|
|
41
|
+
console.log(` ${prerequisite.missing ? "Unavailable" : prerequisite.completed ? "✓" : "Waiting on"} [${responsibility}] ${prerequisite.title}`);
|
|
42
|
+
console.log(` ${prerequisite.storeId}/${prerequisite.project}/${prerequisite.stableId}`);
|
|
43
|
+
}
|
|
34
44
|
}
|
|
35
45
|
}
|
|
36
46
|
if (queueCount > 0) {
|
|
@@ -39,7 +49,13 @@ export function handleTaskView(profile) {
|
|
|
39
49
|
for (const item of queueWithGravity) {
|
|
40
50
|
const rankTag = item.rank !== undefined ? ` [#${item.rank}]` : "";
|
|
41
51
|
const github = item.githubIssue ? ` [gh:#${item.githubIssue}]` : item.githubUrl ? " [gh]" : "";
|
|
42
|
-
|
|
52
|
+
const ready = taskReadiness(getPhrenPath(), original, item);
|
|
53
|
+
console.log(` - ${item.line}${rankTag}${github} [${ready.responsibility} · ${ready.readiness}]`);
|
|
54
|
+
for (const prerequisite of ready.prerequisites) {
|
|
55
|
+
const responsibility = prerequisite.missing ? "Unknown responsibility" : prerequisite.responsibility === "human" ? "Human" : "Agent";
|
|
56
|
+
console.log(` ${prerequisite.missing ? "Unavailable" : prerequisite.completed ? "✓" : "Waiting on"} [${responsibility}] ${prerequisite.title}`);
|
|
57
|
+
console.log(` ${prerequisite.storeId}/${prerequisite.project}/${prerequisite.stableId}`);
|
|
58
|
+
}
|
|
43
59
|
}
|
|
44
60
|
}
|
|
45
61
|
}
|
package/dist/cli-registry.js
CHANGED
|
@@ -119,6 +119,7 @@ const MAINTAIN_SUBCOMMANDS = [
|
|
|
119
119
|
];
|
|
120
120
|
const STORE_SUBCOMMANDS = [
|
|
121
121
|
{ name: "list", usage: "phren store list", summary: "List registered stores" },
|
|
122
|
+
{ name: "identity", usage: "phren store identity [--create]", summary: "Read or explicitly register this store's portable identity" },
|
|
122
123
|
{ name: "add", usage: "phren store add <name> --remote <url>", summary: "Add a team store" },
|
|
123
124
|
{ name: "remove", usage: "phren store remove <name>", summary: "Remove a store (local only)" },
|
|
124
125
|
{ name: "sync", usage: "phren store sync", summary: "Pull and push all stores" },
|
|
@@ -329,12 +330,12 @@ export const REGISTRY = [
|
|
|
329
330
|
{
|
|
330
331
|
name: "tasks",
|
|
331
332
|
topic: "core",
|
|
332
|
-
usage: "phren tasks",
|
|
333
|
+
usage: "phren tasks [profile] [--responsibility=human|agent] [--readiness=ready|waiting-on-human|waiting-on-task]",
|
|
333
334
|
summary: "Cross-project task view",
|
|
334
335
|
featured: true,
|
|
335
|
-
run: async (
|
|
336
|
-
const {
|
|
337
|
-
await
|
|
336
|
+
run: async (args, ctx) => {
|
|
337
|
+
const { handleTaskListArgs } = await import("./cli/namespaces-tasks.js");
|
|
338
|
+
await handleTaskListArgs(args, ctx.profile());
|
|
338
339
|
},
|
|
339
340
|
},
|
|
340
341
|
{
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import type { PhrenResult } from "../shared.js";
|
|
2
|
+
export { taskStores, taskStoreHasProject } from "./task-store-directory.js";
|
|
3
|
+
import { type TaskDoc, type TaskItem } from "./tasks.js";
|
|
4
|
+
export type TaskResponsibility = "human" | "agent";
|
|
5
|
+
export interface TaskDependency {
|
|
6
|
+
storeId: string;
|
|
7
|
+
project: string;
|
|
8
|
+
stableId: string;
|
|
9
|
+
}
|
|
10
|
+
export interface TaskChange {
|
|
11
|
+
at: string;
|
|
12
|
+
change: string;
|
|
13
|
+
}
|
|
14
|
+
export interface TaskPrerequisite extends TaskDependency {
|
|
15
|
+
title: string;
|
|
16
|
+
responsibility: TaskResponsibility;
|
|
17
|
+
completed: boolean;
|
|
18
|
+
missing: boolean;
|
|
19
|
+
}
|
|
20
|
+
export interface TaskReadiness {
|
|
21
|
+
responsibility: TaskResponsibility;
|
|
22
|
+
readiness: "ready" | "waiting-on-human" | "waiting-on-task";
|
|
23
|
+
prerequisites: TaskPrerequisite[];
|
|
24
|
+
}
|
|
25
|
+
/** Writers that can create cycles lock every writable attached store in path order.
|
|
26
|
+
* Reciprocal links edited from different store roots serialize on the same locks. */
|
|
27
|
+
export declare function withTaskGraphLock<T>(base: string, fn: () => PhrenResult<T>): PhrenResult<T>;
|
|
28
|
+
export declare function taskIdentity(phrenPath: string, doc: TaskDoc, item: TaskItem): TaskDependency | undefined;
|
|
29
|
+
/** Derived, never persisted. Missing or unknown metadata blocks autonomous selection. */
|
|
30
|
+
export declare function taskReadiness(phrenPath: string, doc: TaskDoc, item: TaskItem): TaskReadiness;
|
|
31
|
+
export declare function taskView(phrenPath: string, doc: TaskDoc, item: TaskItem): {
|
|
32
|
+
responsibility: TaskResponsibility;
|
|
33
|
+
readiness: "ready" | "waiting-on-human" | "waiting-on-task";
|
|
34
|
+
prerequisites: TaskPrerequisite[];
|
|
35
|
+
identity: TaskDependency | null;
|
|
36
|
+
id: string;
|
|
37
|
+
stableId?: string;
|
|
38
|
+
identityAmbiguous?: boolean;
|
|
39
|
+
section: import("./tasks.js").TaskSection;
|
|
40
|
+
line: string;
|
|
41
|
+
checked: boolean;
|
|
42
|
+
priority?: "high" | "medium" | "low";
|
|
43
|
+
context?: string;
|
|
44
|
+
pinned?: boolean;
|
|
45
|
+
githubIssue?: number;
|
|
46
|
+
githubUrl?: string;
|
|
47
|
+
claim?: import("./tasks.js").TaskClaim;
|
|
48
|
+
rank?: number;
|
|
49
|
+
lastActivity?: string;
|
|
50
|
+
createdAt?: string;
|
|
51
|
+
sessionId?: string;
|
|
52
|
+
scope?: string;
|
|
53
|
+
childFindings?: string[];
|
|
54
|
+
speculative?: boolean;
|
|
55
|
+
parentFinding?: string;
|
|
56
|
+
dependencies?: TaskDependency[];
|
|
57
|
+
history?: TaskChange[];
|
|
58
|
+
taskContractRaw?: string;
|
|
59
|
+
taskContractRecords?: string[];
|
|
60
|
+
taskContractLines?: string[];
|
|
61
|
+
opaqueContinuationLines?: string[];
|
|
62
|
+
};
|
|
63
|
+
export declare function validateTaskDependencies(phrenPath: string, doc: TaskDoc, item: TaskItem, refs: TaskDependency[]): string | undefined;
|
|
64
|
+
export interface TaskFilter {
|
|
65
|
+
responsibility?: TaskResponsibility;
|
|
66
|
+
readiness?: TaskReadiness["readiness"];
|
|
67
|
+
}
|
|
68
|
+
export declare function filterTaskDoc(base: string, doc: TaskDoc, filter: TaskFilter): TaskDoc;
|
|
69
|
+
export declare function taskCounts(base: string, doc: TaskDoc): {
|
|
70
|
+
human: number;
|
|
71
|
+
agentReady: number;
|
|
72
|
+
agentWaitingOnHuman: number;
|
|
73
|
+
agentWaitingOnTask: number;
|
|
74
|
+
done: number;
|
|
75
|
+
};
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
import * as path from "node:path";
|
|
2
|
+
import * as fs from "node:fs";
|
|
3
|
+
import { withSafeLock } from "../shared/data-utils.js";
|
|
4
|
+
import { taskStores, taskStoreHasProject } from "./task-store-directory.js";
|
|
5
|
+
import { isTaskDependency } from "./task-metadata.js";
|
|
6
|
+
export { taskStores, taskStoreHasProject } from "./task-store-directory.js";
|
|
7
|
+
import { readTasks, stripBid, parseTaskContent } from "./tasks.js";
|
|
8
|
+
/** Writers that can create cycles lock every writable attached store in path order.
|
|
9
|
+
* Reciprocal links edited from different store roots serialize on the same locks. */
|
|
10
|
+
export function withTaskGraphLock(base, fn) {
|
|
11
|
+
const roots = [...new Set(taskStores(base).filter(s => s.role !== "readonly" && s.available !== false).map(s => path.resolve(s.path)))].sort();
|
|
12
|
+
const lock = (at) => at === roots.length ? fn() : withSafeLock(path.join(roots[at], ".runtime", "task-dependencies"), () => lock(at + 1));
|
|
13
|
+
return lock(0);
|
|
14
|
+
}
|
|
15
|
+
const key = (ref) => `${ref.storeId}/${ref.project}/${ref.stableId}`;
|
|
16
|
+
export function taskIdentity(phrenPath, doc, item) {
|
|
17
|
+
const stores = taskStores(phrenPath);
|
|
18
|
+
const owner = stores.filter(s => path.resolve(s.path) === path.dirname(path.dirname(path.resolve(doc.path))));
|
|
19
|
+
const matches = [...doc.items.Active, ...doc.items.Queue, ...doc.items.Done].filter(i => i.stableId === item.stableId);
|
|
20
|
+
if (owner.length !== 1 || !item.stableId || !/^[a-f0-9]{8}$/.test(item.stableId) || item.identityAmbiguous || matches.length !== 1
|
|
21
|
+
|| !owner[0].taskStoreId || !taskStoreHasProject(owner[0], doc.project))
|
|
22
|
+
return undefined;
|
|
23
|
+
const storeId = owner[0].taskStoreId;
|
|
24
|
+
return stores.filter(s => s.taskStoreId === storeId).length === 1 ? { storeId, project: doc.project, stableId: item.stableId } : undefined;
|
|
25
|
+
}
|
|
26
|
+
function resolver(phrenPath, current) {
|
|
27
|
+
const stores = taskStores(phrenPath);
|
|
28
|
+
const cache = new Map();
|
|
29
|
+
return (ref) => {
|
|
30
|
+
const owners = stores.filter(s => s.taskStoreId === ref.storeId);
|
|
31
|
+
if (owners.length !== 1 || owners[0].available === false || !/^[A-Za-z0-9][A-Za-z0-9_-]{0,99}$/.test(ref.project))
|
|
32
|
+
return undefined;
|
|
33
|
+
if (!taskStoreHasProject(owners[0], ref.project))
|
|
34
|
+
return undefined;
|
|
35
|
+
const file = path.join(owners[0].path, ref.project, "tasks.md");
|
|
36
|
+
let doc;
|
|
37
|
+
if (current && path.resolve(current.path) === path.resolve(file))
|
|
38
|
+
doc = current;
|
|
39
|
+
else {
|
|
40
|
+
if (!cache.has(file)) {
|
|
41
|
+
const result = readTasks(owners[0].path, ref.project);
|
|
42
|
+
cache.set(file, result.ok && path.resolve(result.data.path) === path.resolve(file) ? result.data : undefined);
|
|
43
|
+
}
|
|
44
|
+
doc = cache.get(file);
|
|
45
|
+
}
|
|
46
|
+
const matches = doc ? [...doc.items.Active, ...doc.items.Queue, ...doc.items.Done].filter(i => i.stableId === ref.stableId) : [];
|
|
47
|
+
if (matches.length === 1)
|
|
48
|
+
return matches[0].identityAmbiguous ? undefined : matches[0];
|
|
49
|
+
if (matches.length > 1)
|
|
50
|
+
return undefined;
|
|
51
|
+
// Completed prerequisites remain satisfied after tidy archives their history.
|
|
52
|
+
const archive = path.join(owners[0].path, ".config", "task-archive", `${ref.project}.md`);
|
|
53
|
+
try {
|
|
54
|
+
const source = fs.readFileSync(archive, "utf8").replace(/\r\n/g, "\n").split("\n"), records = [];
|
|
55
|
+
for (let i = 0; i < source.length; i++) {
|
|
56
|
+
if (!source[i].startsWith("- "))
|
|
57
|
+
continue;
|
|
58
|
+
const comments = [...source[i].matchAll(/<!--\s*bid:([a-f0-9]{8})\b[^>]*-->/g)];
|
|
59
|
+
if (!comments.some(comment => comment[1] === ref.stableId))
|
|
60
|
+
continue;
|
|
61
|
+
if (comments.length !== 1)
|
|
62
|
+
return undefined;
|
|
63
|
+
if (stripBid(source[i]).bid !== ref.stableId)
|
|
64
|
+
continue;
|
|
65
|
+
const lines = [source[i]];
|
|
66
|
+
while (source[i + 1]?.startsWith(" "))
|
|
67
|
+
lines.push(source[++i]);
|
|
68
|
+
records.push(lines);
|
|
69
|
+
}
|
|
70
|
+
if (records.length === 1 && /^- \[[xX]\]\s/.test(records[0][0]))
|
|
71
|
+
return parseTaskContent(ref.project, archive, `# Archive\n\n## Done\n\n${records[0].join("\n")}`).items.Done[0];
|
|
72
|
+
}
|
|
73
|
+
catch { /* An absent archive is not completion evidence. */ }
|
|
74
|
+
return undefined;
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
/** Derived, never persisted. Missing or unknown metadata blocks autonomous selection. */
|
|
78
|
+
export function taskReadiness(phrenPath, doc, item) {
|
|
79
|
+
const resolve = resolver(phrenPath, doc);
|
|
80
|
+
const prerequisites = (item.dependencies ?? []).map(ref => {
|
|
81
|
+
const target = resolve(ref);
|
|
82
|
+
return { ...ref, title: target?.line ?? `Unavailable prerequisite ${key(ref)}`, responsibility: target?.responsibility ?? "agent", completed: target?.section === "Done" || target?.checked === true, missing: !target };
|
|
83
|
+
});
|
|
84
|
+
const responsibility = item.responsibility ?? "agent";
|
|
85
|
+
const waiting = prerequisites.filter(p => !p.completed);
|
|
86
|
+
const ambiguous = item.identityAmbiguous || (item.stableId && [...doc.items.Active, ...doc.items.Queue, ...doc.items.Done].filter(i => i.stableId === item.stableId).length !== 1);
|
|
87
|
+
const invalid = item.dependencies?.length ? validateTaskDependencies(phrenPath, doc, item, item.dependencies) : undefined;
|
|
88
|
+
const readiness = responsibility === "human" || waiting.some(p => p.responsibility === "human") ? "waiting-on-human"
|
|
89
|
+
: item.taskContractRaw !== undefined || ambiguous || invalid || waiting.length ? "waiting-on-task" : "ready";
|
|
90
|
+
return { responsibility, readiness, prerequisites };
|
|
91
|
+
}
|
|
92
|
+
export function taskView(phrenPath, doc, item) {
|
|
93
|
+
return { ...item, ...taskReadiness(phrenPath, doc, item), identity: taskIdentity(phrenPath, doc, item) ?? null };
|
|
94
|
+
}
|
|
95
|
+
export function validateTaskDependencies(phrenPath, doc, item, refs) {
|
|
96
|
+
if (!Array.isArray(refs) || refs.length > 100 || refs.some(r => !isTaskDependency(r)))
|
|
97
|
+
return "Dependencies require storeId, project and stableId (at most 100).";
|
|
98
|
+
const own = taskIdentity(phrenPath, doc, item);
|
|
99
|
+
if (!own)
|
|
100
|
+
return "The task needs an unambiguous store identity and stable ID.";
|
|
101
|
+
const resolve = resolver(phrenPath, doc);
|
|
102
|
+
const complete = new Set();
|
|
103
|
+
const visiting = new Set([key(own)]);
|
|
104
|
+
let visited = 0;
|
|
105
|
+
const visit = (ref) => {
|
|
106
|
+
const id = key(ref);
|
|
107
|
+
if (visiting.has(id))
|
|
108
|
+
return "Task dependencies cannot contain self-links or cycles.";
|
|
109
|
+
if (complete.has(id))
|
|
110
|
+
return undefined;
|
|
111
|
+
if (++visited > 10000 || visiting.size > 200)
|
|
112
|
+
return "Dependency graph is too large to validate safely.";
|
|
113
|
+
const target = resolve(ref);
|
|
114
|
+
if (!target)
|
|
115
|
+
return `Prerequisite ${id} is missing, unavailable or ambiguous.`;
|
|
116
|
+
if (target.taskContractRaw !== undefined)
|
|
117
|
+
return `Prerequisite ${id} has unsupported task metadata.`;
|
|
118
|
+
if (new Set((target.dependencies ?? []).map(key)).size !== (target.dependencies ?? []).length)
|
|
119
|
+
return `Prerequisite ${id} has duplicate dependencies.`;
|
|
120
|
+
visiting.add(id);
|
|
121
|
+
for (const child of target.dependencies ?? []) {
|
|
122
|
+
const error = visit(child);
|
|
123
|
+
if (error)
|
|
124
|
+
return error;
|
|
125
|
+
}
|
|
126
|
+
visiting.delete(id);
|
|
127
|
+
complete.add(id);
|
|
128
|
+
return undefined;
|
|
129
|
+
};
|
|
130
|
+
if (new Set(refs.map(key)).size !== refs.length)
|
|
131
|
+
return "Duplicate task dependencies are not allowed.";
|
|
132
|
+
for (const ref of refs) {
|
|
133
|
+
const error = visit(ref);
|
|
134
|
+
if (error)
|
|
135
|
+
return error;
|
|
136
|
+
}
|
|
137
|
+
return undefined;
|
|
138
|
+
}
|
|
139
|
+
export function filterTaskDoc(base, doc, filter) {
|
|
140
|
+
if (!filter.responsibility && !filter.readiness)
|
|
141
|
+
return doc;
|
|
142
|
+
return { ...doc, items: Object.fromEntries(Object.entries(doc.items).map(([section, items]) => [section, items.filter(item => {
|
|
143
|
+
const ready = taskReadiness(base, doc, item);
|
|
144
|
+
return (!filter.responsibility || ready.responsibility === filter.responsibility) && (!filter.readiness || ready.readiness === filter.readiness);
|
|
145
|
+
})])) };
|
|
146
|
+
}
|
|
147
|
+
export function taskCounts(base, doc) {
|
|
148
|
+
const counts = { human: 0, agentReady: 0, agentWaitingOnHuman: 0, agentWaitingOnTask: 0, done: doc.items.Done.length };
|
|
149
|
+
for (const item of [...doc.items.Active, ...doc.items.Queue]) {
|
|
150
|
+
const ready = taskReadiness(base, doc, item);
|
|
151
|
+
if (ready.responsibility === "human")
|
|
152
|
+
counts.human++;
|
|
153
|
+
else if (ready.readiness === "ready")
|
|
154
|
+
counts.agentReady++;
|
|
155
|
+
else if (ready.readiness === "waiting-on-human")
|
|
156
|
+
counts.agentWaitingOnHuman++;
|
|
157
|
+
else
|
|
158
|
+
counts.agentWaitingOnTask++;
|
|
159
|
+
}
|
|
160
|
+
return counts;
|
|
161
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export declare const taskFormatMigrationHint = "Task metadata is not enabled for this store. Upgrade every CLI, MCP, Hook, sync and app writer first; an owner can then run phren task format enable --all-writers-compatible. Existing writers must be replaced through the coordinated adoption workflow.";
|
|
2
|
+
/** An explicit store-owner acknowledgement, not inferred from one serving Hook.
|
|
3
|
+
* It cannot fence an old binary that ignores this file: coordinated adoption of
|
|
4
|
+
* every writer remains a prerequisite, and is stated at the activation boundary. */
|
|
5
|
+
export declare function taskFormatStatus(base: string): {
|
|
6
|
+
enabled: boolean;
|
|
7
|
+
version: 1;
|
|
8
|
+
acknowledgedAt?: string;
|
|
9
|
+
};
|
|
10
|
+
/** Wire status describes admission, never proof that old filesystem/Git writers
|
|
11
|
+
* have been upgraded. Such writers do not consult our activation file. */
|
|
12
|
+
export declare function taskWriterSafety(base: string): {
|
|
13
|
+
version: 1;
|
|
14
|
+
metadataVersion: 1;
|
|
15
|
+
activation: "disabled" | "owner-acknowledged";
|
|
16
|
+
requiresCoordinatedAdoption: true;
|
|
17
|
+
legacyWritersFenced: false;
|
|
18
|
+
acknowledgedAt?: string | undefined;
|
|
19
|
+
};
|
|
20
|
+
export declare function enableTaskFormat(base: string, allWritersCompatible: boolean): void;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import * as fs from "node:fs";
|
|
2
|
+
import * as path from "node:path";
|
|
3
|
+
import { atomicWriteText } from "../phren-paths.js";
|
|
4
|
+
import { withFileLock } from "../governance/locks.js";
|
|
5
|
+
import { permissionDeniedError } from "../governance/rbac.js";
|
|
6
|
+
import { registeredStoreIdentity } from "../store-registry.js";
|
|
7
|
+
const file = (base) => path.join(base, ".config", "task-format.json");
|
|
8
|
+
export const taskFormatMigrationHint = "Task metadata is not enabled for this store. Upgrade every CLI, MCP, Hook, sync and app writer first; an owner can then run phren task format enable --all-writers-compatible. Existing writers must be replaced through the coordinated adoption workflow.";
|
|
9
|
+
/** An explicit store-owner acknowledgement, not inferred from one serving Hook.
|
|
10
|
+
* It cannot fence an old binary that ignores this file: coordinated adoption of
|
|
11
|
+
* every writer remains a prerequisite, and is stated at the activation boundary. */
|
|
12
|
+
export function taskFormatStatus(base) {
|
|
13
|
+
try {
|
|
14
|
+
const value = JSON.parse(fs.readFileSync(file(base), "utf8"));
|
|
15
|
+
if (value?.version === 1 && value.allWritersCompatible === true && typeof value.storeId === "string"
|
|
16
|
+
&& value.storeId === registeredStoreIdentity(base) && typeof value.acknowledgedAt === "string"
|
|
17
|
+
&& Number.isFinite(Date.parse(value.acknowledgedAt))) {
|
|
18
|
+
return { enabled: true, version: 1, acknowledgedAt: value.acknowledgedAt };
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
catch { /* Missing, malformed or unsupported activation remains disabled. */ }
|
|
22
|
+
return { enabled: false, version: 1 };
|
|
23
|
+
}
|
|
24
|
+
/** Wire status describes admission, never proof that old filesystem/Git writers
|
|
25
|
+
* have been upgraded. Such writers do not consult our activation file. */
|
|
26
|
+
export function taskWriterSafety(base) {
|
|
27
|
+
const status = taskFormatStatus(base);
|
|
28
|
+
return {
|
|
29
|
+
version: 1,
|
|
30
|
+
metadataVersion: 1,
|
|
31
|
+
activation: status.enabled ? "owner-acknowledged" : "disabled",
|
|
32
|
+
requiresCoordinatedAdoption: true,
|
|
33
|
+
legacyWritersFenced: false,
|
|
34
|
+
...(status.acknowledgedAt ? { acknowledgedAt: status.acknowledgedAt } : {}),
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
export function enableTaskFormat(base, allWritersCompatible) {
|
|
38
|
+
const denied = permissionDeniedError(base, "manage_config");
|
|
39
|
+
if (denied)
|
|
40
|
+
throw new Error(denied);
|
|
41
|
+
if (allWritersCompatible !== true)
|
|
42
|
+
throw new Error(taskFormatMigrationHint);
|
|
43
|
+
const storeId = registeredStoreIdentity(base);
|
|
44
|
+
if (!storeId)
|
|
45
|
+
throw new Error("Register a portable store identity with phren store identity --create before enabling task metadata.");
|
|
46
|
+
fs.mkdirSync(path.dirname(file(base)), { recursive: true });
|
|
47
|
+
withFileLock(file(base), () => {
|
|
48
|
+
if (taskFormatStatus(base).enabled)
|
|
49
|
+
return;
|
|
50
|
+
// A future-format or malformed file is evidence, not permission to replace it.
|
|
51
|
+
if (fs.existsSync(file(base)))
|
|
52
|
+
throw new Error("Existing task-format.json is unsupported or belongs to another store. Review it before enabling metadata.");
|
|
53
|
+
atomicWriteText(file(base), JSON.stringify({ version: 1, storeId, allWritersCompatible: true, acknowledgedAt: new Date().toISOString() }, null, 2) + "\n");
|
|
54
|
+
});
|
|
55
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/** Strict, side-effect-free validator shared by task parsing and three-way sync. */
|
|
2
|
+
import type { TaskChange, TaskDependency, TaskResponsibility } from "./task-contract.js";
|
|
3
|
+
export interface TaskMetadata {
|
|
4
|
+
version: 1;
|
|
5
|
+
responsibility: TaskResponsibility;
|
|
6
|
+
dependencies: TaskDependency[];
|
|
7
|
+
history: TaskChange[];
|
|
8
|
+
}
|
|
9
|
+
export declare function isTaskDependency(value: unknown): value is TaskDependency;
|
|
10
|
+
export declare function parseTaskMetadata(raw: string): TaskMetadata | undefined;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
const record = (value) => !!value && typeof value === "object" && !Array.isArray(value);
|
|
2
|
+
const keys = (value, allowed) => Object.keys(value).every(key => allowed.includes(key));
|
|
3
|
+
export function isTaskDependency(value) {
|
|
4
|
+
return record(value) && keys(value, ["storeId", "project", "stableId"])
|
|
5
|
+
&& typeof value.storeId === "string" && /^[a-f0-9]{8}$/.test(value.storeId)
|
|
6
|
+
&& typeof value.stableId === "string" && /^[a-f0-9]{8}$/.test(value.stableId)
|
|
7
|
+
&& typeof value.project === "string" && /^[A-Za-z0-9][A-Za-z0-9_-]{0,99}$/.test(value.project);
|
|
8
|
+
}
|
|
9
|
+
export function parseTaskMetadata(raw) {
|
|
10
|
+
try {
|
|
11
|
+
const value = JSON.parse(raw);
|
|
12
|
+
if (!record(value) || !keys(value, ["version", "responsibility", "dependencies", "history"]) || value.version !== 1
|
|
13
|
+
|| (value.responsibility !== "human" && value.responsibility !== "agent"))
|
|
14
|
+
return undefined;
|
|
15
|
+
if (!Array.isArray(value.dependencies) || value.dependencies.length > 100 || value.dependencies.some(dep => !isTaskDependency(dep)))
|
|
16
|
+
return undefined;
|
|
17
|
+
if (!Array.isArray(value.history) || value.history.some(change => !record(change) || !keys(change, ["at", "change"]) || typeof change.at !== "string" || typeof change.change !== "string"))
|
|
18
|
+
return undefined;
|
|
19
|
+
return value;
|
|
20
|
+
}
|
|
21
|
+
catch {
|
|
22
|
+
return undefined;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/** Local attachment roles/subscriptions authorize access; only the target's
|
|
2
|
+
* synced primary ID identifies a task store on another machine. */
|
|
3
|
+
export declare function taskStores(base: string): {
|
|
4
|
+
id: string;
|
|
5
|
+
name: string;
|
|
6
|
+
path: string;
|
|
7
|
+
role: import("../store-registry.js").StoreRole;
|
|
8
|
+
remote?: string;
|
|
9
|
+
sync: import("../store-registry.js").StoreSyncMode;
|
|
10
|
+
projects?: string[];
|
|
11
|
+
available?: boolean;
|
|
12
|
+
taskStoreId: string | undefined;
|
|
13
|
+
}[];
|
|
14
|
+
export declare function taskStoreProjects(store: ReturnType<typeof taskStores>[number]): string[];
|
|
15
|
+
export declare function taskStoreHasProject(store: ReturnType<typeof taskStores>[number], project: string): boolean;
|
|
16
|
+
/** The directory never snapshots Git or returns its stderr/remote/path. Only
|
|
17
|
+
* bounded, read-only Git queries and the existing credential-stripping parser. */
|
|
18
|
+
export declare function taskStoreRepositoryIdentity(store: string): Promise<{
|
|
19
|
+
repository: string;
|
|
20
|
+
branch: string;
|
|
21
|
+
} | undefined>;
|