@phren/cli 0.3.71 → 0.3.73
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.js +11 -1
- package/dist/bridge/browser-env.d.ts +5 -0
- package/dist/bridge/browser-env.js +110 -0
- package/dist/bridge/browser-protocol.d.ts +120 -0
- package/dist/bridge/browser-protocol.js +70 -0
- package/dist/bridge/browser-recordings.d.ts +63 -0
- package/dist/bridge/browser-recordings.js +148 -0
- package/dist/bridge/browser-registry.d.ts +64 -0
- package/dist/bridge/browser-registry.js +262 -0
- package/dist/bridge/browser-routes.d.ts +4 -0
- package/dist/bridge/browser-routes.js +39 -0
- package/dist/bridge/browser-shim/phren-playwright.cjs +184 -0
- package/dist/bridge/browser-socket.d.ts +2 -0
- package/dist/bridge/browser-socket.js +10 -0
- package/dist/bridge/browser-stream.d.ts +3 -0
- package/dist/bridge/browser-stream.js +129 -0
- package/dist/bridge/browser-watch.d.ts +12 -0
- package/dist/bridge/browser-watch.js +83 -0
- package/dist/bridge/claude-account-setup.js +3 -1
- package/dist/bridge/claude-accounts.d.ts +5 -1
- package/dist/bridge/claude-accounts.js +36 -6
- package/dist/bridge/codex-servers.d.ts +2 -0
- package/dist/bridge/codex-servers.js +1 -1
- package/dist/bridge/command.js +24 -5
- package/dist/bridge/dispatch-clone.d.ts +33 -0
- package/dist/bridge/dispatch-clone.js +176 -0
- package/dist/bridge/dispatch-command.d.ts +14 -0
- package/dist/bridge/dispatch-command.js +98 -13
- package/dist/bridge/dispatch-idempotency.d.ts +85 -0
- package/dist/bridge/dispatch-idempotency.js +235 -0
- package/dist/bridge/dispatch-returns.d.ts +6 -0
- package/dist/bridge/dispatch-returns.js +131 -1
- package/dist/bridge/dispatch-wait.d.ts +32 -0
- package/dist/bridge/dispatch-wait.js +177 -0
- package/dist/bridge/dispatch.d.ts +78 -2
- package/dist/bridge/dispatch.js +841 -25
- package/dist/bridge/dream-schedule.d.ts +133 -0
- package/dist/bridge/dream-schedule.js +322 -0
- package/dist/bridge/fanouts.js +20 -3
- package/dist/bridge/files.d.ts +1 -1
- package/dist/bridge/git-credential.d.ts +44 -0
- package/dist/bridge/git-credential.js +113 -0
- package/dist/bridge/git-host-auth.d.ts +9 -1
- package/dist/bridge/git-host-auth.js +18 -5
- package/dist/bridge/git-host-gitboy.js +8 -1
- package/dist/bridge/git-hosts.d.ts +12 -1
- package/dist/bridge/git-publish.js +3 -2
- package/dist/bridge/herdr.d.ts +4 -0
- package/dist/bridge/herdr.js +44 -9
- package/dist/bridge/install.d.ts +1 -1
- package/dist/bridge/install.js +12 -4
- package/dist/bridge/launch-brief.d.ts +11 -0
- package/dist/bridge/launch-brief.js +22 -0
- package/dist/bridge/launch-worktree.d.ts +2 -0
- package/dist/bridge/launch-worktree.js +5 -1
- package/dist/bridge/pane-status.js +1 -1
- package/dist/bridge/protocol.d.ts +7 -0
- package/dist/bridge/schedule-watch.js +13 -2
- package/dist/bridge/server-launch.d.ts +2 -0
- package/dist/bridge/server-launch.js +251 -145
- package/dist/bridge/server-routes.d.ts +3 -0
- package/dist/bridge/server-routes.js +33 -17
- package/dist/bridge/server-stream.d.ts +4 -0
- package/dist/bridge/server-stream.js +24 -5
- package/dist/bridge/server.js +35 -4
- package/dist/bridge/session-move.d.ts +10 -4
- package/dist/bridge/session-move.js +65 -34
- package/dist/bridge/simulator-stream.d.ts +2 -0
- package/dist/bridge/simulator-stream.js +2 -0
- package/dist/bridge/status-line-fast.d.ts +9 -0
- package/dist/bridge/status-line-fast.js +56 -0
- package/dist/bridge/tab-activity.d.ts +2 -0
- package/dist/bridge/tab-activity.js +15 -2
- package/dist/bridge/task-routes.d.ts +20 -16
- package/dist/bridge/task-routes.js +1 -1
- package/dist/bridge/terminal-herdr.d.ts +5 -1
- package/dist/bridge/terminal-herdr.js +67 -2
- package/dist/bridge/terminal-tmux.d.ts +2 -0
- package/dist/bridge/terminal-tmux.js +29 -7
- package/dist/bridge/terminal.d.ts +5 -1
- package/dist/bridge/transcript-claude.js +192 -112
- package/dist/bridge/transcript-preview.d.ts +2 -1
- package/dist/bridge/transcript-preview.js +85 -3
- package/dist/bridge/transcripts.js +17 -11
- package/dist/bridge/turn-records.js +16 -4
- package/dist/bridge/usage.d.ts +7 -1
- package/dist/bridge/usage.js +47 -31
- package/dist/bridge/worker-close.d.ts +15 -0
- package/dist/bridge/worker-close.js +304 -3
- package/dist/bridge/worker-identity.d.ts +51 -0
- package/dist/bridge/worker-identity.js +289 -0
- package/dist/bridge/worker-reports.js +15 -3
- package/dist/bridge-hook.mjs +39990 -36152
- package/dist/capabilities/mcp.js +1 -1
- package/dist/cli/browser-hint.d.ts +2 -0
- package/dist/cli/browser-hint.js +21 -0
- package/dist/cli/config-dreaming.d.ts +7 -0
- package/dist/cli/config-dreaming.js +72 -0
- package/dist/cli/config.js +6 -0
- package/dist/cli/dream.d.ts +59 -0
- package/dist/cli/dream.js +315 -0
- package/dist/cli/hooks-context.d.ts +2 -2
- package/dist/cli/hooks-context.js +3 -3
- package/dist/cli/hooks.js +20 -11
- package/dist/cli/namespaces-tasks.js +14 -0
- package/dist/cli-registry.js +28 -3
- package/dist/config/dreaming.d.ts +82 -0
- package/dist/config/dreaming.js +195 -0
- package/dist/config/resolve.js +11 -0
- package/dist/config/schema.d.ts +4 -4
- package/dist/config/schema.js +157 -1
- package/dist/content/citation-freshness.js +6 -0
- package/dist/content/learning.d.ts +1 -0
- package/dist/content/learning.js +2 -0
- package/dist/data/access.d.ts +1 -1
- package/dist/data/access.js +3 -1
- package/dist/data/task-contract.d.ts +5 -4
- package/dist/data/tasks.d.ts +5 -0
- package/dist/data/tasks.js +28 -2
- package/dist/dream/apply.d.ts +69 -0
- package/dist/dream/apply.js +372 -0
- package/dist/dream/budget.d.ts +78 -0
- package/dist/dream/budget.js +180 -0
- package/dist/dream/collect.d.ts +86 -0
- package/dist/dream/collect.js +449 -0
- package/dist/dream/eval/dream-adapter.d.ts +16 -0
- package/dist/dream/eval/dream-adapter.js +21 -0
- package/dist/dream/eval/fixture.d.ts +53 -0
- package/dist/dream/eval/fixture.js +172 -0
- package/dist/dream/eval/index.d.ts +40 -0
- package/dist/dream/eval/index.js +78 -0
- package/dist/dream/eval/score.d.ts +34 -0
- package/dist/dream/eval/score.js +99 -0
- package/dist/dream/eval/scripted-model.d.ts +19 -0
- package/dist/dream/eval/scripted-model.js +70 -0
- package/dist/dream/pages.d.ts +68 -0
- package/dist/dream/pages.js +220 -0
- package/dist/dream/privacy.d.ts +3 -0
- package/dist/dream/privacy.js +18 -0
- package/dist/dream/prompt.d.ts +13 -0
- package/dist/dream/prompt.js +84 -0
- package/dist/dream/run.d.ts +98 -0
- package/dist/dream/run.js +317 -0
- package/dist/dream/types.d.ts +74 -0
- package/dist/dream/types.js +4 -0
- package/dist/finding/lifecycle.d.ts +2 -2
- package/dist/finding/lifecycle.js +5 -2
- package/dist/finding/versions.d.ts +4 -0
- package/dist/finding/versions.js +28 -0
- package/dist/index.js +1 -0
- package/dist/modules/registry.js +10 -8
- package/dist/project-config.d.ts +3 -0
- package/dist/task/merge-links.d.ts +38 -0
- package/dist/task/merge-links.js +45 -0
- package/dist/task/reconcile.d.ts +39 -0
- package/dist/task/reconcile.js +201 -0
- package/dist/task/report-links.d.ts +10 -0
- package/dist/task/report-links.js +47 -0
- package/dist/tools/config.js +46 -4
- package/dist/tools/dispatch.js +2 -1
- package/dist/tools/dream.d.ts +3 -0
- package/dist/tools/dream.js +123 -0
- package/dist/tools/tasks.js +4 -1
- package/package.json +1 -1
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/** Private-store links only. Never encode a task identity in Git or forge data. */
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
export const mergeTaskIdentitySchema = 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();
|
|
4
|
+
const repo = z.string().max(200).regex(/^[A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+$/);
|
|
5
|
+
export const branchLinkSchema = z.object({ repo, name: z.string().min(1).max(200).refine(s => !/[\s\x00-\x1f\x7f~^:?*\[\\]/.test(s) && !s.startsWith("-") && !s.includes("..")) }).strict();
|
|
6
|
+
export const prLinkSchema = z.object({ repo, number: z.number().int().positive().max(Number.MAX_SAFE_INTEGER) }).strict();
|
|
7
|
+
export const taskLinksSchema = z.object({
|
|
8
|
+
version: z.literal(1), branches: z.array(branchLinkSchema).max(32), prs: z.array(prLinkSchema).max(32),
|
|
9
|
+
review: z.enum(["closed, review", "merged, verify"]).optional(),
|
|
10
|
+
evidence: z.array(z.string().max(1000).refine(s => !/[\x00-\x1f\x7f]/.test(s))).max(32).optional(),
|
|
11
|
+
}).strict();
|
|
12
|
+
export function prUrl(pr) { return `https://github.com/${pr.repo}/pull/${pr.number}`; }
|
|
13
|
+
export function parsePrLink(value) {
|
|
14
|
+
const match = value.match(/^https:\/\/github\.com\/([A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+)\/pull\/([1-9]\d*)(?:[/?#][^\s]*)?$/)
|
|
15
|
+
?? value.match(/^([A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+)#([1-9]\d*)$/);
|
|
16
|
+
if (!match)
|
|
17
|
+
return undefined;
|
|
18
|
+
const result = prLinkSchema.safeParse({ repo: match[1], number: Number(match[2]) });
|
|
19
|
+
return result.success ? result.data : undefined;
|
|
20
|
+
}
|
|
21
|
+
export function uniqueLinks(links) { return [...new Map(links.map(link => [JSON.stringify(link), link])).values()]; }
|
|
22
|
+
/** Bare #N is deliberately ignored. Bare branch names need a trusted project repo. */
|
|
23
|
+
export function linksFromContext(context, projectRepo) {
|
|
24
|
+
const prs = uniqueLinks([...context.matchAll(/[A-Za-z][A-Za-z0-9+.-]*:\/\/\S+|(?<![\w./:@-])[A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+#[1-9]\d*(?![\w])/g)]
|
|
25
|
+
.flatMap(m => { const pr = parsePrLink(m[0].replace(/[.,;`'")>\]]+$/, "")); return pr ? [pr] : []; }));
|
|
26
|
+
const inferredRepo = projectRepo ?? (new Set(prs.map(p => p.repo)).size === 1 ? prs[0]?.repo : undefined);
|
|
27
|
+
const branches = [];
|
|
28
|
+
for (const match of context.matchAll(/\bbranch(?:\s*[:=]\s*|\s+)(?:`([^`]+)`|"([^"]+)"|'([^']+)'|(\S+))/gi)) {
|
|
29
|
+
const token = match[1] ?? match[2] ?? match[3] ?? match[4];
|
|
30
|
+
// Punctuation in bare tokens is ambiguous with prose separators. Require
|
|
31
|
+
// quoting instead of ever shortening a valid Git branch name.
|
|
32
|
+
if (match[4] && /[;(),`"']/.test(token))
|
|
33
|
+
continue;
|
|
34
|
+
const at = token.indexOf("@");
|
|
35
|
+
const [qualified, name] = at >= 0 ? [token.slice(0, at), token.slice(at + 1)] : [inferredRepo, token];
|
|
36
|
+
const parsed = branchLinkSchema.safeParse({ repo: qualified, name });
|
|
37
|
+
if (parsed.success)
|
|
38
|
+
branches.push(parsed.data);
|
|
39
|
+
}
|
|
40
|
+
const distinctBranches = uniqueLinks(branches);
|
|
41
|
+
// Truncation could hide an unmerged prerequisite. Oversized context needs an explicit link update.
|
|
42
|
+
if (prs.length > 32 || distinctBranches.length > 32)
|
|
43
|
+
return { version: 1, prs: [], branches: [] };
|
|
44
|
+
return { version: 1, prs, branches: distinctBranches };
|
|
45
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { type TaskItem } from "../data/tasks.js";
|
|
3
|
+
declare const prStateSchema: z.ZodObject<{
|
|
4
|
+
number: z.ZodNumber;
|
|
5
|
+
url: z.ZodString;
|
|
6
|
+
state: z.ZodEnum<{
|
|
7
|
+
CLOSED: "CLOSED";
|
|
8
|
+
MERGED: "MERGED";
|
|
9
|
+
OPEN: "OPEN";
|
|
10
|
+
}>;
|
|
11
|
+
mergedAt: z.ZodNullable<z.ZodString>;
|
|
12
|
+
mergeCommit: z.ZodNullable<z.ZodObject<{
|
|
13
|
+
oid: z.ZodString;
|
|
14
|
+
}, z.core.$strip>>;
|
|
15
|
+
headRefName: z.ZodOptional<z.ZodString>;
|
|
16
|
+
headRepository: z.ZodOptional<z.ZodNullable<z.ZodObject<{
|
|
17
|
+
nameWithOwner: z.ZodString;
|
|
18
|
+
}, z.core.$strip>>>;
|
|
19
|
+
}, z.core.$strip>;
|
|
20
|
+
export type PrState = z.infer<typeof prStateSchema>;
|
|
21
|
+
/** Unknown acceptance prose is intentionally conservative; a human can finish it. */
|
|
22
|
+
export declare function mergeDecision(item: TaskItem, states: PrState[]): "done" | "merged, verify" | "closed, review" | undefined;
|
|
23
|
+
export interface ReconcileSummary {
|
|
24
|
+
dryRun: boolean;
|
|
25
|
+
checked: number;
|
|
26
|
+
done: number;
|
|
27
|
+
review: number;
|
|
28
|
+
linked: number;
|
|
29
|
+
skipped: number;
|
|
30
|
+
errors: number;
|
|
31
|
+
requests: number;
|
|
32
|
+
}
|
|
33
|
+
/** Read-only GitHub queries; all writes stay in the selected private stores. */
|
|
34
|
+
export declare function reconcileTasks(base: string, options?: {
|
|
35
|
+
dryRun?: boolean;
|
|
36
|
+
apply?: boolean;
|
|
37
|
+
project?: string;
|
|
38
|
+
}): Promise<ReconcileSummary>;
|
|
39
|
+
export {};
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
import * as fs from "node:fs";
|
|
2
|
+
import * as path from "node:path";
|
|
3
|
+
import { execFile } from "node:child_process";
|
|
4
|
+
import { promisify } from "node:util";
|
|
5
|
+
import { z } from "zod";
|
|
6
|
+
import { readTasks, updateTask } from "../data/tasks.js";
|
|
7
|
+
import { taskStores } from "../data/task-store-directory.js";
|
|
8
|
+
import { getStoreProjectDirs } from "../store-registry.js";
|
|
9
|
+
import { withFileLock } from "../governance/locks.js";
|
|
10
|
+
import { permissionDeniedError } from "../governance/rbac.js";
|
|
11
|
+
import { renameOverSync } from "../phren-paths.js";
|
|
12
|
+
import { resolveProjectGithubRepo } from "./github.js";
|
|
13
|
+
import { linksFromContext, parsePrLink, prUrl, uniqueLinks } from "./merge-links.js";
|
|
14
|
+
const exec = promisify(execFile);
|
|
15
|
+
const prStateSchema = z.object({ number: z.number().int().positive(), url: z.string(), state: z.enum(["OPEN", "CLOSED", "MERGED"]),
|
|
16
|
+
mergedAt: z.string().nullable(), mergeCommit: z.object({ oid: z.string() }).nullable(), headRefName: z.string().optional(), headRepository: z.object({ nameWithOwner: z.string() }).nullable().optional() });
|
|
17
|
+
const fields = "number,url,state,mergedAt,mergeCommit,headRefName,headRepository";
|
|
18
|
+
const cacheSchema = z.record(z.string(), z.object({ at: z.number(), value: z.array(prStateSchema).optional() }));
|
|
19
|
+
const TTL = 15 * 60 * 1000;
|
|
20
|
+
/** Unknown acceptance prose is intentionally conservative; a human can finish it. */
|
|
21
|
+
export function mergeDecision(item, states) {
|
|
22
|
+
if (!states.length)
|
|
23
|
+
return undefined;
|
|
24
|
+
if (states.some(pr => pr.state === "CLOSED"))
|
|
25
|
+
return "closed, review";
|
|
26
|
+
if (states.some(pr => pr.state !== "MERGED" || !pr.mergedAt || !Number.isFinite(Date.parse(pr.mergedAt)) || !/^[a-f0-9]{40,64}$/.test(pr.mergeCommit?.oid ?? "")))
|
|
27
|
+
return undefined;
|
|
28
|
+
const text = [item.line, item.context, ...(item.opaqueContinuationLines ?? [])].join("\n");
|
|
29
|
+
const acceptance = [...text.matchAll(/(?:acceptance|accepts?|done when)\s*:\s*([^\n]+)/gi)].map(m => m[1].trim());
|
|
30
|
+
const mergeOnly = /^(?:PR\s+)?(?:is\s+)?merged?(?:\s+(?:to|into)\s+(?:main|master))?[.!]?$/i;
|
|
31
|
+
return item.responsibility === "human" || item.dependencies?.length || item.taskContractRaw !== undefined
|
|
32
|
+
|| acceptance.some(value => !mergeOnly.test(value))
|
|
33
|
+
|| /\b(?:verify|verification|on.device|testflight|deploy|release|publish|ship|rollout|monitor|owner|manual|acceptance|done\s+when|smoke\s+test)\b/i.test(text.replace(/(?:acceptance|accepts?|done when)\s*:\s*(?:PR\s+)?(?:is\s+)?merged?(?:\s+(?:to|into)\s+(?:main|master))?[.!]?/gi, ""))
|
|
34
|
+
? "merged, verify" : "done";
|
|
35
|
+
}
|
|
36
|
+
function saveJson(file, value) {
|
|
37
|
+
fs.mkdirSync(path.dirname(file), { recursive: true });
|
|
38
|
+
const temp = `${file}.${process.pid}.tmp`;
|
|
39
|
+
fs.writeFileSync(temp, JSON.stringify(value), { mode: 0o600 });
|
|
40
|
+
renameOverSync(temp, file);
|
|
41
|
+
}
|
|
42
|
+
function readJson(file) { try {
|
|
43
|
+
return JSON.parse(fs.readFileSync(file, "utf8"));
|
|
44
|
+
}
|
|
45
|
+
catch {
|
|
46
|
+
return undefined;
|
|
47
|
+
} }
|
|
48
|
+
/** Read-only GitHub queries; all writes stay in the selected private stores. */
|
|
49
|
+
export async function reconcileTasks(base, options = {}) {
|
|
50
|
+
const runtime = path.join(base, ".runtime", "task-reconcile");
|
|
51
|
+
return withFileLock(runtime, async () => {
|
|
52
|
+
const config = path.join(base, ".config", "task-reconcile.json");
|
|
53
|
+
const enabled = readJson(config)?.enabled === true;
|
|
54
|
+
const dryRun = options.dryRun === true || (!options.apply && !enabled);
|
|
55
|
+
const summary = { dryRun, checked: 0, done: 0, review: 0, linked: 0, skipped: 0, errors: 0, requests: 0 };
|
|
56
|
+
const cacheFile = `${runtime}.json`;
|
|
57
|
+
const parsed = cacheSchema.safeParse(readJson(cacheFile));
|
|
58
|
+
const cache = parsed.success ? parsed.data : {};
|
|
59
|
+
let offline = !!cache.offline && Date.now() - cache.offline.at < TTL;
|
|
60
|
+
const query = async (key, args) => {
|
|
61
|
+
const hit = cache[key];
|
|
62
|
+
if (hit && Date.now() >= hit.at && Date.now() - hit.at < TTL)
|
|
63
|
+
return hit.value;
|
|
64
|
+
if (offline || summary.requests >= 100)
|
|
65
|
+
return undefined;
|
|
66
|
+
summary.requests++;
|
|
67
|
+
try {
|
|
68
|
+
const { stdout } = await exec("gh", args, { encoding: "utf8", timeout: 10000, maxBuffer: 1024 * 1024, env: { ...process.env, GH_PROMPT_DISABLED: "1" }, windowsHide: true });
|
|
69
|
+
const raw = JSON.parse(stdout);
|
|
70
|
+
const result = z.array(prStateSchema).parse(Array.isArray(raw) ? raw : [raw]);
|
|
71
|
+
cache[key] = { at: Date.now(), value: result };
|
|
72
|
+
return result;
|
|
73
|
+
}
|
|
74
|
+
catch {
|
|
75
|
+
// Stop after any failure (offline, auth, rate limit, missing/deleted PR).
|
|
76
|
+
// Failure entries provide backoff, never completion evidence.
|
|
77
|
+
offline = true;
|
|
78
|
+
summary.errors++;
|
|
79
|
+
cache[key] = { at: Date.now() };
|
|
80
|
+
cache.offline = { at: Date.now() };
|
|
81
|
+
return undefined;
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
const work = [];
|
|
85
|
+
for (const store of taskStores(base)) {
|
|
86
|
+
if (store.role === "readonly" || store.available === false)
|
|
87
|
+
continue;
|
|
88
|
+
for (const directory of getStoreProjectDirs(store)) {
|
|
89
|
+
const project = path.basename(directory);
|
|
90
|
+
if (options.project && options.project !== project)
|
|
91
|
+
continue;
|
|
92
|
+
if (permissionDeniedError(store.path, "update_task", project))
|
|
93
|
+
continue;
|
|
94
|
+
const doc = readTasks(store.path, project);
|
|
95
|
+
if (!doc.ok || path.resolve(doc.data.path) !== path.join(path.resolve(store.path), project, "tasks.md"))
|
|
96
|
+
continue;
|
|
97
|
+
const repo = resolveProjectGithubRepo(store.path, project);
|
|
98
|
+
for (const snapshot of [...doc.data.items.Active, ...doc.data.items.Queue])
|
|
99
|
+
work.push({ store, project, snapshot, repo });
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
const progressFile = `${runtime}-progress.json`;
|
|
103
|
+
const progress = readJson(progressFile);
|
|
104
|
+
const scope = options.project ?? "*";
|
|
105
|
+
const offsets = progress?.offsets ?? {};
|
|
106
|
+
const offset = Number.isSafeInteger(offsets[scope]) && offsets[scope] >= 0 ? offsets[scope] % Math.max(work.length, 1) : 0;
|
|
107
|
+
let resume = 0;
|
|
108
|
+
for (let at = 0; at < work.length; at++) {
|
|
109
|
+
const index = (offset + at) % work.length;
|
|
110
|
+
if (summary.requests >= 100) {
|
|
111
|
+
resume = index;
|
|
112
|
+
break;
|
|
113
|
+
}
|
|
114
|
+
const { store, project, snapshot, repo } = work[index];
|
|
115
|
+
// Re-read before each task: earlier completions change the document revision.
|
|
116
|
+
const fresh = readTasks(store.path, project);
|
|
117
|
+
if (!fresh.ok) {
|
|
118
|
+
summary.errors++;
|
|
119
|
+
continue;
|
|
120
|
+
}
|
|
121
|
+
const candidates = [...fresh.data.items.Active, ...fresh.data.items.Queue].filter(i => snapshot.stableId ? i.stableId === snapshot.stableId : i.line === snapshot.line);
|
|
122
|
+
if (candidates.length !== 1) {
|
|
123
|
+
summary.skipped++;
|
|
124
|
+
continue;
|
|
125
|
+
}
|
|
126
|
+
const item = candidates[0];
|
|
127
|
+
const match = item.stableId ? `bid:${item.stableId}` : item.id;
|
|
128
|
+
if (item.checked || item.identityAmbiguous || /\[needs owner\]/i.test(item.line) || /\bneeds owner\b/i.test(item.context ?? "")
|
|
129
|
+
|| item.opaqueContinuationLines?.some(line => line.trim().startsWith("Links:"))) {
|
|
130
|
+
summary.skipped++;
|
|
131
|
+
continue;
|
|
132
|
+
}
|
|
133
|
+
const links = item.links ?? linksFromContext(item.context ?? "", repo);
|
|
134
|
+
if (!links.prs.length && !links.branches.length) {
|
|
135
|
+
summary.skipped++;
|
|
136
|
+
continue;
|
|
137
|
+
}
|
|
138
|
+
summary.checked++;
|
|
139
|
+
const prs = [...links.prs];
|
|
140
|
+
let uncertain = false;
|
|
141
|
+
// A branch-only link must resolve to exactly one PR. Deleted branches,
|
|
142
|
+
// reused names and truncated results cannot prove a task is complete.
|
|
143
|
+
if (!links.prs.length)
|
|
144
|
+
for (const branch of links.branches) {
|
|
145
|
+
const states = await query(`branch:${branch.repo}@${branch.name}`, ["pr", "list", "--repo", branch.repo, "--head", branch.name, "--state", "all", "--limit", "100", "--json", fields]);
|
|
146
|
+
const ref = states?.length === 1 ? parsePrLink(states[0].url) : undefined;
|
|
147
|
+
if (!ref || ref.repo.toLowerCase() !== branch.repo.toLowerCase() || states?.[0].headRefName !== branch.name
|
|
148
|
+
|| states?.[0].headRepository?.nameWithOwner.toLowerCase() !== branch.repo.toLowerCase())
|
|
149
|
+
uncertain = true;
|
|
150
|
+
else
|
|
151
|
+
prs.push(ref);
|
|
152
|
+
}
|
|
153
|
+
const states = [];
|
|
154
|
+
for (const pr of uniqueLinks(prs)) {
|
|
155
|
+
const found = await query(`pr:${pr.repo}#${pr.number}`, ["pr", "view", String(pr.number), "--repo", pr.repo, "--json", fields]);
|
|
156
|
+
if (found?.length !== 1 || found[0].number !== pr.number || found[0].url.toLowerCase() !== prUrl(pr).toLowerCase())
|
|
157
|
+
uncertain = true;
|
|
158
|
+
else
|
|
159
|
+
states.push(found[0]);
|
|
160
|
+
}
|
|
161
|
+
// Resume this task next sweep if the budget expired mid-task.
|
|
162
|
+
if (uncertain && summary.requests >= 100) {
|
|
163
|
+
resume = index;
|
|
164
|
+
break;
|
|
165
|
+
}
|
|
166
|
+
const decision = uncertain ? undefined : mergeDecision(item, states);
|
|
167
|
+
const next = { ...links, prs: uncertain ? links.prs : uniqueLinks(prs) };
|
|
168
|
+
if (decision) {
|
|
169
|
+
next.review = decision === "done" ? undefined : decision;
|
|
170
|
+
next.evidence = states.filter(pr => pr.state !== "OPEN").map(pr => pr.state === "MERGED"
|
|
171
|
+
? `Merged ${pr.url} ${pr.mergeCommit?.oid} ${pr.mergedAt}` : `Closed unmerged ${pr.url}`);
|
|
172
|
+
}
|
|
173
|
+
const changed = JSON.stringify(item.links) !== JSON.stringify(next);
|
|
174
|
+
if (!changed && decision !== "done")
|
|
175
|
+
continue;
|
|
176
|
+
if (!dryRun) {
|
|
177
|
+
if (decision === "done" && permissionDeniedError(store.path, "complete_task", project)) {
|
|
178
|
+
summary.skipped++;
|
|
179
|
+
continue;
|
|
180
|
+
}
|
|
181
|
+
const result = updateTask(store.path, project, match, { links: next, ...(decision === "done" ? { section: "Done" } : {}) }, base, fresh.data.revision);
|
|
182
|
+
if (!result.ok) {
|
|
183
|
+
summary.errors++;
|
|
184
|
+
continue;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
if (!item.links)
|
|
188
|
+
summary.linked++;
|
|
189
|
+
if (decision === "done")
|
|
190
|
+
summary.done++;
|
|
191
|
+
else if (decision)
|
|
192
|
+
summary.review++;
|
|
193
|
+
}
|
|
194
|
+
saveJson(progressFile, { offsets: { ...offsets, [scope]: resume } });
|
|
195
|
+
// Runtime cache is bounded and local; a dry run never changes task files or opts in.
|
|
196
|
+
saveJson(cacheFile, Object.fromEntries(Object.entries(cache).filter(([, value]) => Date.now() - value.at < TTL).slice(-2000)));
|
|
197
|
+
if (options.apply && !options.dryRun)
|
|
198
|
+
saveJson(config, { enabled: true });
|
|
199
|
+
return summary;
|
|
200
|
+
});
|
|
201
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { TaskDependency } from "../data/task-contract.js";
|
|
2
|
+
/** Record reports in the private task store. No Git/forge writes or fuzzy title matching. */
|
|
3
|
+
export declare function recordTaskPrs(base: string, reports: {
|
|
4
|
+
url: string;
|
|
5
|
+
repo: string;
|
|
6
|
+
branch: string;
|
|
7
|
+
}[], task?: TaskDependency, dispatch?: string): {
|
|
8
|
+
linked: boolean;
|
|
9
|
+
error?: string;
|
|
10
|
+
};
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import * as path from "node:path";
|
|
2
|
+
import { readTasks, updateTask } from "../data/tasks.js";
|
|
3
|
+
import { taskStores } from "../data/task-store-directory.js";
|
|
4
|
+
import { getStoreProjectDirs } from "../store-registry.js";
|
|
5
|
+
import { permissionDeniedError } from "../governance/rbac.js";
|
|
6
|
+
import { parsePrLink, taskLinksSchema, uniqueLinks } from "./merge-links.js";
|
|
7
|
+
/** Record reports in the private task store. No Git/forge writes or fuzzy title matching. */
|
|
8
|
+
export function recordTaskPrs(base, reports, task, dispatch) {
|
|
9
|
+
const targets = [];
|
|
10
|
+
for (const store of taskStores(base)) {
|
|
11
|
+
if (store.available === false || store.role === "readonly" || (task && store.taskStoreId !== task.storeId))
|
|
12
|
+
continue;
|
|
13
|
+
for (const dir of getStoreProjectDirs(store)) {
|
|
14
|
+
const project = path.basename(dir);
|
|
15
|
+
if (task && task.project !== project)
|
|
16
|
+
continue;
|
|
17
|
+
const doc = readTasks(store.path, project);
|
|
18
|
+
if (!doc.ok || !doc.data.revision || path.resolve(doc.data.path) !== path.join(path.resolve(store.path), project, "tasks.md"))
|
|
19
|
+
continue;
|
|
20
|
+
for (const item of [...doc.data.items.Active, ...doc.data.items.Queue]) {
|
|
21
|
+
if (!(task ? item.stableId === task.stableId : dispatch && item.claim?.session === `task-launch:${dispatch}`))
|
|
22
|
+
continue;
|
|
23
|
+
if (!item.stableId || item.identityAmbiguous)
|
|
24
|
+
return { linked: false, error: "Ambiguous task identity." };
|
|
25
|
+
targets.push({ root: store.path, project, match: `bid:${item.stableId}`, revision: doc.data.revision, links: item.links, branches: item.links?.branches ?? [], prs: item.links?.prs ?? [] });
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
if (targets.length !== 1)
|
|
30
|
+
return { linked: false, ...(targets.length ? { error: "Ambiguous task association." } : {}) };
|
|
31
|
+
const target = targets[0];
|
|
32
|
+
if (permissionDeniedError(target.root, "update_task", target.project))
|
|
33
|
+
return { linked: false, error: "Task update denied." };
|
|
34
|
+
const prs = reports.flatMap(report => {
|
|
35
|
+
const pr = parsePrLink(report.url);
|
|
36
|
+
return pr && pr.repo.toLowerCase() === report.repo.toLowerCase() ? [pr] : [];
|
|
37
|
+
});
|
|
38
|
+
if (prs.length !== reports.length)
|
|
39
|
+
return { linked: false, error: "Report URLs must identify PRs in their reported repository." };
|
|
40
|
+
const links = taskLinksSchema.safeParse({ ...target.links, version: 1, prs: uniqueLinks([...target.prs, ...prs]), branches: uniqueLinks([...target.branches, ...reports.map(report => ({ repo: report.repo, name: report.branch }))]) });
|
|
41
|
+
if (!links.success)
|
|
42
|
+
return { linked: false, error: "Invalid task links." };
|
|
43
|
+
if (JSON.stringify(target.links) === JSON.stringify(links.data))
|
|
44
|
+
return { linked: true };
|
|
45
|
+
const result = updateTask(target.root, target.project, target.match, { links: links.data }, base, target.revision);
|
|
46
|
+
return result.ok ? { linked: true } : { linked: false, error: result.error };
|
|
47
|
+
}
|
package/dist/tools/config.js
CHANGED
|
@@ -15,6 +15,7 @@ import { ACCESS_ROLE_KEYS, ACL_LOCKOUT_HINT, permissionDeniedError, setAccessRol
|
|
|
15
15
|
import { readProjectTopics, writeProjectTopics, } from "../project-topics.js";
|
|
16
16
|
import { buildConfigView } from "../config/resolve.js";
|
|
17
17
|
import { getConfigField, CONFIG_DOMAINS } from "../config/schema.js";
|
|
18
|
+
import { DREAMING_KEYS, getDreamingConfig, parseDreamingPatch, updateDreamingConfig, } from "../config/dreaming.js";
|
|
18
19
|
// ── Helpers ─────────────────────────────────────────────────────────────────
|
|
19
20
|
function proactivitySnapshot(phrenPath) {
|
|
20
21
|
const snap = buildProactivitySnapshot(phrenPath);
|
|
@@ -184,6 +185,9 @@ async function handleGetConfig(ctx, { domain, project }) {
|
|
|
184
185
|
if (d === "all" || d === "index") {
|
|
185
186
|
result.index = getIndexPolicy(phrenPath);
|
|
186
187
|
}
|
|
188
|
+
if (d === "all" || d === "dreaming") {
|
|
189
|
+
result.dreaming = getDreamingConfig(phrenPath, project);
|
|
190
|
+
}
|
|
187
191
|
result.fields = resolvedFields(phrenPath, d, project);
|
|
188
192
|
result.schema = configSchema(d);
|
|
189
193
|
return mcpResponse({
|
|
@@ -215,6 +219,9 @@ async function handleGetConfig(ctx, { domain, project }) {
|
|
|
215
219
|
if (d === "all" || d === "index") {
|
|
216
220
|
result.index = getIndexPolicy(phrenPath);
|
|
217
221
|
}
|
|
222
|
+
if (d === "all" || d === "dreaming") {
|
|
223
|
+
result.dreaming = getDreamingConfig(phrenPath);
|
|
224
|
+
}
|
|
218
225
|
result.fields = resolvedFields(phrenPath, d);
|
|
219
226
|
result.schema = configSchema(d);
|
|
220
227
|
return mcpResponse({
|
|
@@ -587,6 +594,39 @@ async function handleSetConfig(ctx, { domain, settings, project }) {
|
|
|
587
594
|
data: { project, topics: result.topics, domain: topicDomain ?? null },
|
|
588
595
|
});
|
|
589
596
|
}
|
|
597
|
+
// ── dreaming ──────────────────────────────────────────────────
|
|
598
|
+
case "dreaming": {
|
|
599
|
+
const { clear: rawClear, ...rest } = settings;
|
|
600
|
+
const parsed = parseDreamingPatch(rest);
|
|
601
|
+
const clear = Array.isArray(rawClear) ? rawClear.map(String) : [];
|
|
602
|
+
const badClear = clear.filter((key) => !DREAMING_KEYS.includes(key));
|
|
603
|
+
if (parsed.unknown.length || badClear.length) {
|
|
604
|
+
return mcpResponse({ ok: false, error: `Unknown dreaming settings: ${[...parsed.unknown, ...badClear].join(", ")}. Valid: ${DREAMING_KEYS.join(", ")}.` });
|
|
605
|
+
}
|
|
606
|
+
if (parsed.errors.length)
|
|
607
|
+
return mcpResponse({ ok: false, error: parsed.errors.join(" ") });
|
|
608
|
+
if (clear.length && !project) {
|
|
609
|
+
return mcpResponse({ ok: false, error: "clear removes a project's override; pass project." });
|
|
610
|
+
}
|
|
611
|
+
if (!Object.keys(parsed.patch).length && !clear.length) {
|
|
612
|
+
return mcpResponse({ ok: false, error: `Provide at least one of: ${DREAMING_KEYS.join(", ")}.` });
|
|
613
|
+
}
|
|
614
|
+
let warning = null;
|
|
615
|
+
if (project) {
|
|
616
|
+
const err = validateProject(project);
|
|
617
|
+
if (err)
|
|
618
|
+
return mcpResponse({ ok: false, error: err });
|
|
619
|
+
warning = checkProjectRegistered(phrenPath, project);
|
|
620
|
+
}
|
|
621
|
+
updateDreamingConfig(phrenPath, parsed.patch, project, clear);
|
|
622
|
+
const effective = getDreamingConfig(phrenPath, project);
|
|
623
|
+
const where = project ? ` for project "${project}"` : "";
|
|
624
|
+
return mcpResponse({
|
|
625
|
+
ok: true,
|
|
626
|
+
message: warning ? `Dreaming config updated${where}. WARNING: ${warning}` : `Dreaming config updated${where}.`,
|
|
627
|
+
data: { ...(project ? { project } : {}), dreaming: effective, ...(warning ? { warning } : {}) },
|
|
628
|
+
});
|
|
629
|
+
}
|
|
590
630
|
default:
|
|
591
631
|
return mcpResponse({ ok: false, error: `Unknown config domain: ${domain}` });
|
|
592
632
|
}
|
|
@@ -596,12 +636,12 @@ export function register(server, ctx) {
|
|
|
596
636
|
server.registerTool("get_config", {
|
|
597
637
|
title: "◆ phren · get config",
|
|
598
638
|
description: "Read current configuration for one or all config domains: proactivity, taskMode, " +
|
|
599
|
-
"findingSensitivity, retention (policy), workflow, access, index, topic. " +
|
|
639
|
+
"findingSensitivity, retention (policy), workflow, access, index, topic, dreaming. " +
|
|
600
640
|
"Returns both configured and effective values. When project is provided, returns " +
|
|
601
641
|
"the merged view with project overrides applied and _source annotations.",
|
|
602
642
|
inputSchema: z.object({
|
|
603
643
|
domain: z
|
|
604
|
-
.enum(["proactivity", "taskMode", "findingSensitivity", "retention", "workflow", "access", "index", "topic", "all"])
|
|
644
|
+
.enum(["proactivity", "taskMode", "findingSensitivity", "retention", "workflow", "access", "index", "topic", "dreaming", "all"])
|
|
605
645
|
.optional()
|
|
606
646
|
.describe("Config domain to read. Defaults to 'all'."),
|
|
607
647
|
project: projectParam,
|
|
@@ -614,13 +654,15 @@ export function register(server, ctx) {
|
|
|
614
654
|
"and set_topic_config. When project is provided, writes to that project's phren.project.yaml " +
|
|
615
655
|
"instead of global .config/.",
|
|
616
656
|
inputSchema: z.object({
|
|
617
|
-
domain: z.enum(["proactivity", "taskMode", "findingSensitivity", "retention", "workflow", "access", "index", "topic"]),
|
|
657
|
+
domain: z.enum(["proactivity", "taskMode", "findingSensitivity", "retention", "workflow", "access", "index", "topic", "dreaming"]),
|
|
618
658
|
settings: z.record(z.string(), z.unknown()).describe("Domain-specific settings. proactivity: { level, scope? } | taskMode: { mode } | " +
|
|
619
659
|
"findingSensitivity: { level } | retention: { ttlDays?, retentionDays?, autoAcceptThreshold?, " +
|
|
620
660
|
"minInjectConfidence?, decay? } | workflow: { lowConfidenceThreshold?, riskySections?, taskMode?, " +
|
|
621
661
|
"findingSensitivity? } | access: { admins?, contributors?, readers? } (each an array of actor names) | " +
|
|
622
662
|
"index: { includeGlobs?, excludeGlobs?, includeHidden? } | " +
|
|
623
|
-
"topic: { topics, domain? }"
|
|
663
|
+
"topic: { topics, domain? } | " +
|
|
664
|
+
"dreaming: { enabled?, mode?, cadence?, window?, idleMinutes?, lookbackHours?, maxChanges?, injectBudgetKB?, " +
|
|
665
|
+
"phases?, model?, clear? } (clear: keys whose project override to remove, so they inherit again)"),
|
|
624
666
|
project: z.string().optional().describe("Project name. When provided, writes to that project's phren.project.yaml instead of global .config/. " +
|
|
625
667
|
"Required for the 'topic' domain."),
|
|
626
668
|
}),
|
package/dist/tools/dispatch.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { mergeTaskIdentitySchema } from "../task/merge-links.js";
|
|
1
2
|
import { prsSchema } from "../bridge/return-contract.js";
|
|
2
3
|
import { ownerInboxSchema } from "../bridge/owner-inbox.js";
|
|
3
4
|
import { z } from "zod";
|
|
@@ -30,7 +31,7 @@ export function register(server) {
|
|
|
30
31
|
server.registerTool("dispatch_report", {
|
|
31
32
|
title: "◆ phren · report PRs",
|
|
32
33
|
description: "Report PR evidence to this worker's own Hook before finishing the turn. The done return carries prs (url, repo, branch, tests summary, notes), and the Hook queues it to the configured integrator. No direct worker messaging or GitHub comment is needed. Does not claim tests passed or complete a task.",
|
|
33
|
-
inputSchema: { prs: prsSchema },
|
|
34
|
+
inputSchema: { prs: prsSchema, task: mergeTaskIdentitySchema.optional().describe("Private task to link; otherwise use the launch association. Never publish this identity to GitHub.") },
|
|
34
35
|
}, async (input) => {
|
|
35
36
|
try {
|
|
36
37
|
const origin = await terminalPaneFromEnv();
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { applyDreamProposals, pendingDreamProposals } from "../dream/apply.js";
|
|
2
|
+
import { redactSecretsForLog } from "../content/secrets.js";
|
|
3
|
+
import { z } from "zod";
|
|
4
|
+
import { mcpResponse, resolveStoreForProject } from "./types.js";
|
|
5
|
+
import { permissionDeniedError } from "../governance/rbac.js";
|
|
6
|
+
import { DREAM_LOG_DEFAULT_LIMIT, DREAM_LOG_MAX_LIMIT, dreamStatuses, readDreamJournal, runDream } from "../cli/dream.js";
|
|
7
|
+
/**
|
|
8
|
+
* Dreaming over MCP: `dream_run`, `dream_apply`, `dream_status` and `dream_log`, with the
|
|
9
|
+
* parameters of `phren dream run|apply|status|log`. They are full-profile tools, so
|
|
10
|
+
* the core profile reaches them as phren_admin actions.
|
|
11
|
+
*/
|
|
12
|
+
function target(ctx, project, mode) {
|
|
13
|
+
try {
|
|
14
|
+
return { ok: true, value: resolveStoreForProject(ctx, project, mode) };
|
|
15
|
+
}
|
|
16
|
+
catch (err) {
|
|
17
|
+
return { ok: false, error: redactSecretsForLog(err instanceof Error ? err.message : String(err)) };
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
const projectParam = z.string().describe("Project name, optionally store-qualified.");
|
|
21
|
+
export function register(server, ctx) {
|
|
22
|
+
server.registerTool("dream_apply", {
|
|
23
|
+
title: "◆ phren · dream apply",
|
|
24
|
+
description: "Apply pending structured proposals from a stored dream, refusing missing or changed target findings. Indices are zero-based; adds are approved through the review queue.",
|
|
25
|
+
inputSchema: z.object({ project: projectParam, runId: z.string(), only: z.array(z.number().int().nonnegative()).optional() }),
|
|
26
|
+
}, async ({ project: projectInput, runId, only }) => {
|
|
27
|
+
const resolved = target(ctx, projectInput, "write");
|
|
28
|
+
if (!resolved.ok)
|
|
29
|
+
return mcpResponse({ ok: false, error: resolved.error });
|
|
30
|
+
const { phrenPath, project } = resolved.value;
|
|
31
|
+
const denied = permissionDeniedError(phrenPath, "edit_finding", project);
|
|
32
|
+
if (denied)
|
|
33
|
+
return mcpResponse({ ok: false, error: denied });
|
|
34
|
+
try {
|
|
35
|
+
const record = await applyDreamProposals(phrenPath, project, runId, only);
|
|
36
|
+
await ctx.rebuildIndex().catch(() => { });
|
|
37
|
+
return mcpResponse({ ok: true, data: record });
|
|
38
|
+
}
|
|
39
|
+
catch (err) {
|
|
40
|
+
return mcpResponse({ ok: false, error: redactSecretsForLog(err instanceof Error ? err.message : String(err)) });
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
server.registerTool("dream_run", {
|
|
44
|
+
title: "◆ phren · dream run",
|
|
45
|
+
description: "Run a dream now for one project: an offline pass that reads recent transcripts, findings, truths, pages and git, " +
|
|
46
|
+
"then corrects, merges and reorganizes memory. Propose mode queues adds and stores other operations for dream_apply; apply mode makes " +
|
|
47
|
+
"the changes and logs them in dreams/journal.md. Refused while dreaming is off unless force; returns busy while another " +
|
|
48
|
+
"dream for the project runs. Uses the project's helper account; can take minutes.",
|
|
49
|
+
inputSchema: z.object({
|
|
50
|
+
project: projectParam,
|
|
51
|
+
dryRun: z.boolean().optional().describe("Return the changeset without writing anything."),
|
|
52
|
+
mode: z.enum(["propose", "apply"]).optional().describe("Override dreaming.mode for this run."),
|
|
53
|
+
force: z.boolean().optional().describe("Run even when dreaming is disabled for the project."),
|
|
54
|
+
}),
|
|
55
|
+
}, async ({ project: projectInput, dryRun, mode, force }) => {
|
|
56
|
+
const resolved = target(ctx, projectInput, dryRun ? "read" : "write");
|
|
57
|
+
if (!resolved.ok)
|
|
58
|
+
return mcpResponse({ ok: false, error: resolved.error });
|
|
59
|
+
const { phrenPath, project } = resolved.value;
|
|
60
|
+
if (!dryRun) {
|
|
61
|
+
const denied = permissionDeniedError(phrenPath, "edit_finding", project);
|
|
62
|
+
if (denied)
|
|
63
|
+
return mcpResponse({ ok: false, error: denied });
|
|
64
|
+
}
|
|
65
|
+
try {
|
|
66
|
+
// Not under the write queue: a dream takes minutes, and its writes go through the finding APIs' own locks.
|
|
67
|
+
const outcome = await runDream(phrenPath, project, { dryRun, mode, force, trigger: "manual" });
|
|
68
|
+
if (!dryRun && outcome.status === "ok")
|
|
69
|
+
await ctx.rebuildIndex().catch(() => { });
|
|
70
|
+
return mcpResponse({
|
|
71
|
+
ok: outcome.status !== "error",
|
|
72
|
+
message: `Dream for ${project}: ${outcome.status}${dryRun ? " (dry run)" : ""}.`,
|
|
73
|
+
data: outcome,
|
|
74
|
+
...(outcome.status === "error" ? { error: typeof outcome.result.error === "string" ? outcome.result.error : "The dream failed." } : {}),
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
catch (err) {
|
|
78
|
+
return mcpResponse({ ok: false, error: redactSecretsForLog(err instanceof Error ? err.message : "The dream failed.") });
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
server.registerTool("dream_status", {
|
|
82
|
+
title: "◆ phren · dream status",
|
|
83
|
+
description: "Dreaming status: enabled, mode, cadence, window, last run, next eligible time and the last run's outcome counts. " +
|
|
84
|
+
"Without project, every project in the active profile.",
|
|
85
|
+
inputSchema: z.object({ project: projectParam.optional() }),
|
|
86
|
+
}, async ({ project: projectInput }) => {
|
|
87
|
+
let phrenPath = ctx.phrenPath;
|
|
88
|
+
let project;
|
|
89
|
+
if (projectInput) {
|
|
90
|
+
const resolved = target(ctx, projectInput, "read");
|
|
91
|
+
if (!resolved.ok)
|
|
92
|
+
return mcpResponse({ ok: false, error: resolved.error });
|
|
93
|
+
({ phrenPath, project } = resolved.value);
|
|
94
|
+
}
|
|
95
|
+
const statuses = dreamStatuses(phrenPath, project, ctx.profile);
|
|
96
|
+
const on = statuses.filter((status) => status.enabled).length;
|
|
97
|
+
return mcpResponse({
|
|
98
|
+
ok: true,
|
|
99
|
+
message: project ? `${project}: dreaming ${statuses[0]?.enabled ? "on" : "off"}. ${statuses[0]?.reason ?? ""}`.trim()
|
|
100
|
+
: `Dreaming is on for ${on} of ${statuses.length} projects.`,
|
|
101
|
+
data: project ? statuses[0] : { projects: statuses },
|
|
102
|
+
});
|
|
103
|
+
});
|
|
104
|
+
server.registerTool("dream_log", {
|
|
105
|
+
title: "◆ phren · dream log",
|
|
106
|
+
description: "The latest entries of a project's dream journal (dreams/journal.md), newest first: what each dream did.",
|
|
107
|
+
inputSchema: z.object({
|
|
108
|
+
project: projectParam,
|
|
109
|
+
limit: z.number().int().min(1).max(DREAM_LOG_MAX_LIMIT).optional().describe(`Entries to return. Defaults to ${DREAM_LOG_DEFAULT_LIMIT}.`),
|
|
110
|
+
}),
|
|
111
|
+
}, async ({ project: projectInput, limit }) => {
|
|
112
|
+
const resolved = target(ctx, projectInput, "read");
|
|
113
|
+
if (!resolved.ok)
|
|
114
|
+
return mcpResponse({ ok: false, error: resolved.error });
|
|
115
|
+
const { phrenPath, project } = resolved.value;
|
|
116
|
+
const entries = readDreamJournal(phrenPath, project, limit ?? DREAM_LOG_DEFAULT_LIMIT);
|
|
117
|
+
return mcpResponse({
|
|
118
|
+
ok: true,
|
|
119
|
+
message: entries.length ? `${entries.length} dream journal entries for ${project}.` : `No dreams recorded for ${project} yet.`,
|
|
120
|
+
data: { project, entries, pendingProposals: pendingDreamProposals(phrenPath, project) },
|
|
121
|
+
});
|
|
122
|
+
});
|
|
123
|
+
}
|
package/dist/tools/tasks.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { branchLinkSchema, prLinkSchema } from "../task/merge-links.js";
|
|
1
2
|
import { taskView, taskCounts, filterTaskDoc } from "../data/task-contract.js";
|
|
2
3
|
import { mcpResponse, resolveStoreForProject } from "./types.js";
|
|
3
4
|
import { z } from "zod";
|
|
@@ -454,6 +455,8 @@ export function register(server, ctx) {
|
|
|
454
455
|
text: z.string().optional().describe("Replacement text for the task line."),
|
|
455
456
|
priority: z.enum(["high", "medium", "low"]).optional().describe("New priority tag: high, medium, or low."),
|
|
456
457
|
context: z.string().optional().describe("Text to set on the Context: line below the task."),
|
|
458
|
+
branches: z.array(branchLinkSchema).max(32).optional().describe("Replace private repository-qualified branch links ({repo, name}); [] clears."),
|
|
459
|
+
prs: z.array(prLinkSchema).max(32).optional().describe("Replace private PR links ({repo, number}); [] clears. Never publish task IDs or backlinks to GitHub."),
|
|
457
460
|
replace_context: z.boolean().optional().describe("If true, replace the existing Context: value instead of appending."),
|
|
458
461
|
responsibility: z.enum(["human", "agent"]).optional().describe("Who must act; independent of task section. Legacy tasks default to agent."),
|
|
459
462
|
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."),
|
|
@@ -589,7 +592,7 @@ export function register(server, ctx) {
|
|
|
589
592
|
});
|
|
590
593
|
}
|
|
591
594
|
// Handle github issue linking via update_task when github_issue or github_url is set (and no other field updates)
|
|
592
|
-
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) {
|
|
595
|
+
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 && updates.branches === undefined && updates.prs === undefined) {
|
|
593
596
|
if (updates.unlink_github && (updates.github_issue !== undefined || updates.github_url)) {
|
|
594
597
|
return mcpResponse({ ok: false, error: "Use either unlink_github=true or github_issue/github_url, not both." });
|
|
595
598
|
}
|