@phren/cli 0.3.35 → 0.3.37
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/account-choice.d.ts +82 -0
- package/dist/bridge/account-choice.js +173 -0
- package/dist/bridge/account-failover.d.ts +57 -0
- package/dist/bridge/account-failover.js +181 -0
- package/dist/bridge/account-usage.d.ts +2 -0
- package/dist/bridge/account-usage.js +17 -2
- package/dist/bridge/agent-hooks.d.ts +11 -1
- package/dist/bridge/agent-hooks.js +56 -19
- package/dist/bridge/changes.js +18 -9
- package/dist/bridge/dispatch-command.js +3 -1
- package/dist/bridge/dispatch-returns.d.ts +12 -0
- package/dist/bridge/dispatch-returns.js +37 -6
- package/dist/bridge/dispatch.d.ts +31 -3
- package/dist/bridge/dispatch.js +68 -10
- package/dist/bridge/hand-off.d.ts +23 -1
- package/dist/bridge/hand-off.js +36 -3
- package/dist/bridge/health.js +3 -1
- package/dist/bridge/host-key.d.ts +16 -0
- package/dist/bridge/host-key.js +35 -0
- package/dist/bridge/launch-brief.d.ts +5 -0
- package/dist/bridge/launch-brief.js +21 -0
- package/dist/bridge/link.js +11 -4
- package/dist/bridge/owner-inbox-sources.d.ts +5 -0
- package/dist/bridge/owner-inbox-sources.js +94 -0
- package/dist/bridge/owner-inbox-view.js +20 -1
- package/dist/bridge/owner-inbox.d.ts +7 -3
- package/dist/bridge/owner-inbox.js +113 -69
- package/dist/bridge/pair.js +3 -2
- package/dist/bridge/peers.js +4 -2
- package/dist/bridge/schedule-launch.js +5 -1
- package/dist/bridge/schedule-watch.d.ts +3 -0
- package/dist/bridge/schedule-watch.js +27 -1
- package/dist/bridge/server-launch.js +6 -2
- package/dist/bridge/server-routes.js +5 -1
- package/dist/bridge/server.js +9 -23
- package/dist/bridge/sudo.d.ts +36 -6
- package/dist/bridge/sudo.js +180 -37
- package/dist/bridge/usage.d.ts +4 -2
- package/dist/bridge/usage.js +4 -2
- package/dist/bridge/worker-reports.d.ts +8 -1
- package/dist/bridge/worker-reports.js +28 -7
- package/dist/bridge-hook.mjs +7120 -6298
- package/dist/clanker.d.ts +54 -0
- package/dist/clanker.js +188 -0
- package/dist/cli/config.js +56 -0
- package/dist/cli/hooks-output.d.ts +1 -1
- package/dist/cli/hooks-output.js +28 -21
- package/dist/cli/hooks.js +1 -1
- package/dist/cli/namespaces-skills.js +2 -2
- package/dist/cli/namespaces-tasks.js +46 -7
- package/dist/cli/session-start.js +12 -3
- package/dist/cli/session-stop.js +9 -0
- package/dist/cli/team.js +3 -0
- package/dist/cli-handlers.js +7 -0
- package/dist/cli-registry.js +1 -0
- package/dist/data/task-format.d.ts +5 -1
- package/dist/data/task-format.js +13 -5
- package/dist/index.js +82 -50
- package/dist/init/init-configure.d.ts +2 -0
- package/dist/init/init-configure.js +12 -0
- package/dist/init/init-uninstall.js +21 -2
- package/dist/init/init.d.ts +2 -0
- package/dist/init/init.js +11 -3
- package/dist/init/preferences.d.ts +12 -0
- package/dist/init/teardown.js +18 -4
- package/dist/link/doctor.js +2 -2
- package/dist/link/link.js +9 -0
- package/dist/link/refresh.d.ts +10 -0
- package/dist/link/refresh.js +34 -0
- package/dist/mcp/local-index.d.ts +20 -0
- package/dist/mcp/local-index.js +39 -1
- package/dist/modules/registry.js +1 -1
- package/dist/shared/index.d.ts +14 -0
- package/dist/shared/index.js +88 -74
- package/dist/shared/retrieval.js +1 -1
- package/dist/skill/files.js +40 -11
- package/dist/skill/registry.d.ts +6 -0
- package/dist/skill/registry.js +21 -5
- package/dist/task/lifecycle.js +3 -1
- package/dist/tools/dispatch.js +7 -4
- package/dist/tools/finding.js +20 -11
- package/dist/tools/graph.d.ts +2 -0
- package/dist/tools/graph.js +2 -0
- package/dist/tools/search.d.ts +2 -0
- package/dist/tools/search.js +88 -6
- package/dist/tools/tasks.js +45 -0
- package/dist/tools/types.d.ts +3 -1
- package/dist/tools/types.js +3 -2
- package/package.json +1 -1
package/dist/modules/registry.js
CHANGED
|
@@ -131,7 +131,7 @@ export const BUILTIN_MODULES = [
|
|
|
131
131
|
{
|
|
132
132
|
schemaVersion: 1, name: "conductor", version: VERSION, defaultEnabled: false, requires: ["memory", "hook"],
|
|
133
133
|
tools: full(["dispatch", "dispatch_returns", "dispatch_approve", "hand_off", "live_sessions", "account_usage", "authority", "dispatch_report", "owner_inbox"]), cliCommands: ["dispatch", "dispatch status", "dispatch returns", "dispatch sessions", "dispatch usage", "dispatch report", "hand-off", "conductor", "conductor grants", "conductor status", "conductor make", "conductor stop", "conductor sets", "conductor integrator", "owner-inbox", "authority", "bridge enroll-computer"], agentHooks: [],
|
|
134
|
-
hookRoutes: [...routes("GET", ["/v1/dispatch", "/v1/dispatch/capacity", "/v1/dispatch/arrival", "/v1/conductor", "/v1/conductor/grants", "/v1/computers", "/v1/sets", "/v1/authority", "/v1/owner-inbox", "/v1/conductor/integrator"]),
|
|
134
|
+
hookRoutes: [...routes("GET", ["/v1/dispatch", "/v1/dispatch/capacity", "/v1/dispatch/arrival", "/v1/dispatch/brief", "/v1/conductor", "/v1/conductor/grants", "/v1/computers", "/v1/sets", "/v1/authority", "/v1/owner-inbox", "/v1/conductor/integrator"]),
|
|
135
135
|
...routes("POST", ["/v1/dispatch", "/v1/dispatch/workers", "/v1/dispatch/returns", "/v1/dispatch/approve", "/v1/dispatch/report", "/v1/dispatch/close", "/v1/owner-inbox", "/v1/conductor/integrator", "/v1/hand-off", "/v1/hand-off/status", "/v1/conductor/grants", "/v1/conductor/make", "/v1/conductor/stop", "/v1/sets/name", "/v1/authority", "/v1/authority/confirm"]), ...routes("DELETE", ["/v1/conductor/grants", "/v1/authority"])],
|
|
136
136
|
capabilities: ["dispatch", "conductorSets", "ownerInbox", "workerReports", "queuedHandOff"], storeFiles: ["global/skills/conductor/**"],
|
|
137
137
|
localFiles: ["<bridge>/hooks.yaml", "<bridge>/conductor.yaml", "<bridge>/conductor-role.json", "<bridge>/conductor/brief.md", "<bridge>/authority.yaml", "<bridge>/authority-confirmations.json", "<bridge>/dispatches/*.json", "<bridge>/hand-offs/*.json", "<bridge>/worker-reports/*.json", "<bridge>/closed-workers/*.json", "<bridge>/owner-inbox.json", "<bridge>/integrator.json"], phoneScreens: [], skills: ["conductor"],
|
package/dist/shared/index.d.ts
CHANGED
|
@@ -29,6 +29,20 @@ export declare function updateFileInIndex(db: SqlJsDatabase, filePath: string, p
|
|
|
29
29
|
* known paths: no glob, content reads, Git operations, or database rebuild.
|
|
30
30
|
*/
|
|
31
31
|
export declare function captureIndexInputs(phrenPath: string, profile?: string): Promise<() => boolean>;
|
|
32
|
+
/** Thrown by a `requireFresh` build while another process holds the rebuild lock. */
|
|
33
|
+
export declare class IndexBusyError extends Error {
|
|
34
|
+
readonly code = "PHREN_INDEX_BUSY";
|
|
35
|
+
constructor(message?: string);
|
|
36
|
+
}
|
|
37
|
+
export declare function isIndexBusyError(error: unknown): boolean;
|
|
38
|
+
/**
|
|
39
|
+
* Whether another process is rebuilding right now. A lock younger than the
|
|
40
|
+
* stale threshold still counts as free when the pid written into it is gone:
|
|
41
|
+
* a rebuild killed mid-way (a hook timed out, a detached reindex OOM-killed)
|
|
42
|
+
* never unlinks its lock, and without the pid check every fresh-required
|
|
43
|
+
* refresh in every MCP server failed for up to 30 s after it.
|
|
44
|
+
*/
|
|
45
|
+
export declare function isRebuildLockHeld(phrenPath: string): boolean;
|
|
32
46
|
export declare function buildIndex(phrenPath: string, profile?: string, options?: {
|
|
33
47
|
force?: boolean;
|
|
34
48
|
requireFresh?: boolean;
|
package/dist/shared/index.js
CHANGED
|
@@ -6,69 +6,33 @@ import * as os from "os";
|
|
|
6
6
|
import * as crypto from "crypto";
|
|
7
7
|
import { globSync } from "glob";
|
|
8
8
|
import { debugLog, appendIndexEvent, getProjectDirs, collectNativeMemoryFiles, nativeMemoryEnabled, runtimeFile, homeDir, readRootManifest, } from "../shared.js";
|
|
9
|
-
/**
|
|
10
|
-
* Cached store project dirs to avoid repeated dynamic imports in sync code paths.
|
|
11
|
-
* Populated by `refreshStoreProjectDirs()`, consumed by `getAllStoreProjectDirs()`.
|
|
12
|
-
*/
|
|
13
|
-
let _cachedStoreProjectDirs = null;
|
|
14
|
-
let _cachedStorePhrenPath = null;
|
|
15
9
|
/**
|
|
16
10
|
* Gather project directories from the primary store AND all non-primary stores.
|
|
17
|
-
* This enables the FTS5 index to include team store
|
|
18
|
-
*
|
|
11
|
+
* This enables the FTS5 index and project detection to include team store
|
|
12
|
+
* projects alongside personal ones. The profile filters the primary store only:
|
|
13
|
+
* profiles list the primary's projects, and a team store narrows its own with
|
|
14
|
+
* its subscription list, matching `listAllProjects` and `resolveProject`.
|
|
19
15
|
*/
|
|
20
16
|
function getAllStoreProjectDirs(phrenPath, profile) {
|
|
21
17
|
const dirs = [...getProjectDirs(phrenPath, profile)];
|
|
22
|
-
if (_cachedStoreProjectDirs && _cachedStorePhrenPath === phrenPath) {
|
|
23
|
-
dirs.push(..._cachedStoreProjectDirs);
|
|
24
|
-
}
|
|
25
|
-
return dirs;
|
|
26
|
-
}
|
|
27
|
-
/**
|
|
28
|
-
* Refresh the store project dirs cache. Called from async contexts (buildIndex, etc.)
|
|
29
|
-
* before sync code paths that need getAllStoreProjectDirs.
|
|
30
|
-
*/
|
|
31
|
-
async function refreshStoreProjectDirs(phrenPath, profile) {
|
|
32
18
|
try {
|
|
33
|
-
const
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
for (const store of otherStores) {
|
|
37
|
-
if (!fs.existsSync(store.path))
|
|
38
|
-
continue;
|
|
39
|
-
dirs.push(...getStoreProjectDirs(store));
|
|
40
|
-
}
|
|
41
|
-
// Filter by active profile's project list, matching getProjectDirs behavior
|
|
42
|
-
if (profile) {
|
|
43
|
-
const profilePath = path.join(phrenPath, "profiles", `${profile}.yaml`);
|
|
44
|
-
if (fs.existsSync(profilePath)) {
|
|
45
|
-
try {
|
|
46
|
-
const yaml = await import("js-yaml");
|
|
47
|
-
const data = yaml.load(fs.readFileSync(profilePath, "utf-8"), { schema: yaml.CORE_SCHEMA });
|
|
48
|
-
const projects = data?.projects;
|
|
49
|
-
if (Array.isArray(projects)) {
|
|
50
|
-
const allowed = new Set(projects.map(String));
|
|
51
|
-
dirs = dirs.filter(dir => allowed.has(path.basename(dir)));
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
catch {
|
|
55
|
-
// Profile parse error — include all dirs as fallback
|
|
56
|
-
}
|
|
57
|
-
}
|
|
19
|
+
for (const store of getNonPrimaryStores(phrenPath)) {
|
|
20
|
+
if (fs.existsSync(store.path))
|
|
21
|
+
dirs.push(...getStoreProjectDirs(store));
|
|
58
22
|
}
|
|
59
|
-
_cachedStoreProjectDirs = dirs;
|
|
60
|
-
_cachedStorePhrenPath = phrenPath;
|
|
61
23
|
}
|
|
62
|
-
catch {
|
|
63
|
-
|
|
64
|
-
_cachedStorePhrenPath = phrenPath;
|
|
24
|
+
catch (err) {
|
|
25
|
+
debugLog(`getAllStoreProjectDirs: ${errorMessage(err)}`);
|
|
65
26
|
}
|
|
27
|
+
return dirs;
|
|
66
28
|
}
|
|
67
29
|
import { getIndexPolicy, withFileLock } from "./governance.js";
|
|
30
|
+
import { tryFileLock } from "../governance/locks.js";
|
|
68
31
|
import { stripTaskDoneSection } from "./content.js";
|
|
69
32
|
import { isInactiveFindingLine } from "../finding/lifecycle.js";
|
|
70
33
|
import { invalidateDfCache } from "./search-fallback.js";
|
|
71
34
|
import { errorMessage } from "../utils.js";
|
|
35
|
+
import { getNonPrimaryStores, getStoreProjectDirs } from "../store-registry.js";
|
|
72
36
|
import { logger } from "../logger.js";
|
|
73
37
|
import { formatActorAttribution, parseSourceComment } from "../content/citation.js";
|
|
74
38
|
import { beginUserFragmentBuildCache, endUserFragmentBuildCache, extractAndLinkFragments, ensureGlobalEntitiesTable, } from "./fragment-graph.js";
|
|
@@ -963,7 +927,6 @@ export async function captureIndexInputs(phrenPath, profile) {
|
|
|
963
927
|
throw error;
|
|
964
928
|
}
|
|
965
929
|
};
|
|
966
|
-
await refreshStoreProjectDirs(phrenPath, profile);
|
|
967
930
|
const { resolveAllStores } = await import("../store-registry.js");
|
|
968
931
|
const projectDirs = getAllStoreProjectDirs(phrenPath, profile);
|
|
969
932
|
const globalDir = path.join(phrenPath, "global");
|
|
@@ -1255,7 +1218,6 @@ function mergeManualLinks(db, phrenPath) {
|
|
|
1255
1218
|
}
|
|
1256
1219
|
async function buildIndexImpl(phrenPath, profile) {
|
|
1257
1220
|
const t0 = Date.now();
|
|
1258
|
-
await refreshStoreProjectDirs(phrenPath, profile);
|
|
1259
1221
|
const projectDirs = getAllStoreProjectDirs(phrenPath, profile);
|
|
1260
1222
|
beginUserFragmentBuildCache(phrenPath, projectDirs.map(dir => path.basename(dir)));
|
|
1261
1223
|
beginTopicBuildCache();
|
|
@@ -1669,18 +1631,57 @@ function createEmptyIndexDb(SQL) {
|
|
|
1669
1631
|
ensureGlobalEntitiesTable(db);
|
|
1670
1632
|
return db;
|
|
1671
1633
|
}
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
|
|
1634
|
+
/** Thrown by a `requireFresh` build while another process holds the rebuild lock. */
|
|
1635
|
+
export class IndexBusyError extends Error {
|
|
1636
|
+
code = "PHREN_INDEX_BUSY";
|
|
1637
|
+
constructor(message = "Index rebuild is busy; retry shortly.") { super(message); this.name = "IndexBusyError"; }
|
|
1638
|
+
}
|
|
1639
|
+
export function isIndexBusyError(error) {
|
|
1640
|
+
return error instanceof IndexBusyError
|
|
1641
|
+
|| error?.code === "PHREN_INDEX_BUSY";
|
|
1642
|
+
}
|
|
1643
|
+
/**
|
|
1644
|
+
* Whether another process is rebuilding right now. A lock younger than the
|
|
1645
|
+
* stale threshold still counts as free when the pid written into it is gone:
|
|
1646
|
+
* a rebuild killed mid-way (a hook timed out, a detached reindex OOM-killed)
|
|
1647
|
+
* never unlinks its lock, and without the pid check every fresh-required
|
|
1648
|
+
* refresh in every MCP server failed for up to 30 s after it.
|
|
1649
|
+
*/
|
|
1650
|
+
export function isRebuildLockHeld(phrenPath) {
|
|
1651
|
+
const lockPath = runtimeFile(phrenPath, "index-rebuild") + ".lock";
|
|
1652
|
+
let contents;
|
|
1653
|
+
let mtimeMs;
|
|
1675
1654
|
try {
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
return Date.now() - stat.mtimeMs <= staleThreshold;
|
|
1655
|
+
mtimeMs = fs.statSync(lockPath).mtimeMs;
|
|
1656
|
+
contents = fs.readFileSync(lockPath, "utf8");
|
|
1679
1657
|
}
|
|
1680
|
-
catch
|
|
1681
|
-
|
|
1658
|
+
catch {
|
|
1659
|
+
return false; // absent is the normal case
|
|
1660
|
+
}
|
|
1661
|
+
const staleThreshold = Number.parseInt((process.env.PHREN_FILE_LOCK_STALE_MS) || "30000", 10) || 30000;
|
|
1662
|
+
if (Date.now() - mtimeMs > staleThreshold)
|
|
1682
1663
|
return false;
|
|
1664
|
+
const pid = Number.parseInt(contents.split("\n")[0], 10);
|
|
1665
|
+
// Empty or unparseable: the owner may be between create and write. Trust age.
|
|
1666
|
+
if (!(pid > 0))
|
|
1667
|
+
return true;
|
|
1668
|
+
try {
|
|
1669
|
+
process.kill(pid, 0);
|
|
1670
|
+
return true;
|
|
1671
|
+
}
|
|
1672
|
+
catch (err) {
|
|
1673
|
+
if (err.code !== "ESRCH")
|
|
1674
|
+
return true; // EPERM: alive, not ours
|
|
1683
1675
|
}
|
|
1676
|
+
try {
|
|
1677
|
+
if (fs.readFileSync(lockPath, "utf8") === contents)
|
|
1678
|
+
fs.unlinkSync(lockPath);
|
|
1679
|
+
debugLog(`Removed rebuild lock left by dead pid ${pid}`);
|
|
1680
|
+
}
|
|
1681
|
+
catch {
|
|
1682
|
+
// Someone else already replaced or removed it.
|
|
1683
|
+
}
|
|
1684
|
+
return false;
|
|
1684
1685
|
}
|
|
1685
1686
|
async function loadIndexSnapshotOrEmpty(phrenPath, profile, knownHash) {
|
|
1686
1687
|
const SQL = await bootstrapSqlJs();
|
|
@@ -1907,7 +1908,6 @@ export async function loadIndexForHook(phrenPath, profile) {
|
|
|
1907
1908
|
// Resolve team stores the same way buildIndex does. Without this the hook's
|
|
1908
1909
|
// file set (and therefore its hash) can never match the one buildIndex sealed,
|
|
1909
1910
|
// so every prompt would miss the cache and spawn a redundant reindex.
|
|
1910
|
-
await refreshStoreProjectDirs(phrenPath, profile);
|
|
1911
1911
|
const projectDirs = getAllStoreProjectDirs(phrenPath, profile);
|
|
1912
1912
|
// Skip the glob when the sentinel proves nothing changed (see the sentinel
|
|
1913
1913
|
// block above): ~20x cheaper than re-globbing, and yields the same hash.
|
|
@@ -1978,28 +1978,42 @@ async function _buildIndexGuarded(phrenPath, profile, requireFresh = false) {
|
|
|
1978
1978
|
const lockTarget = runtimeFile(phrenPath, "index-rebuild");
|
|
1979
1979
|
if (isRebuildLockHeld(phrenPath)) {
|
|
1980
1980
|
if (requireFresh)
|
|
1981
|
-
throw new
|
|
1981
|
+
throw new IndexBusyError();
|
|
1982
1982
|
return loadIndexSnapshotOrEmpty(phrenPath, profile);
|
|
1983
1983
|
}
|
|
1984
|
-
|
|
1985
|
-
|
|
1986
|
-
|
|
1987
|
-
|
|
1988
|
-
timer = setTimeout(() => reject(new Error("buildIndex timed out after 30s")), 30000);
|
|
1989
|
-
});
|
|
1990
|
-
try {
|
|
1991
|
-
return await Promise.race([buildIndexImpl(phrenPath, profile), timeout]);
|
|
1992
|
-
}
|
|
1993
|
-
finally {
|
|
1994
|
-
clearTimeout(timer);
|
|
1995
|
-
}
|
|
1984
|
+
const timedBuild = async () => {
|
|
1985
|
+
let timer;
|
|
1986
|
+
const timeout = new Promise((_, reject) => {
|
|
1987
|
+
timer = setTimeout(() => reject(new Error("buildIndex timed out after 30s")), 30000);
|
|
1996
1988
|
});
|
|
1989
|
+
try {
|
|
1990
|
+
return await Promise.race([buildIndexImpl(phrenPath, profile), timeout]);
|
|
1991
|
+
}
|
|
1992
|
+
finally {
|
|
1993
|
+
clearTimeout(timer);
|
|
1994
|
+
}
|
|
1995
|
+
};
|
|
1996
|
+
if (requireFresh) {
|
|
1997
|
+
// A caller that must not settle for a snapshot (the MCP server) waits
|
|
1998
|
+
// asynchronously in its own bounded retry instead of withFileLock's
|
|
1999
|
+
// synchronous spin, which would freeze the server's event loop for up to
|
|
2000
|
+
// 5 s while another process finishes its rebuild.
|
|
2001
|
+
const release = tryFileLock(lockTarget);
|
|
2002
|
+
if (!release)
|
|
2003
|
+
throw new IndexBusyError();
|
|
2004
|
+
try {
|
|
2005
|
+
return await timedBuild();
|
|
2006
|
+
}
|
|
2007
|
+
finally {
|
|
2008
|
+
release();
|
|
2009
|
+
}
|
|
2010
|
+
}
|
|
2011
|
+
try {
|
|
2012
|
+
return await withFileLock(lockTarget, timedBuild);
|
|
1997
2013
|
}
|
|
1998
2014
|
catch (err) {
|
|
1999
2015
|
const message = errorMessage(err);
|
|
2000
2016
|
if (message.includes("could not acquire lock")) {
|
|
2001
|
-
if (requireFresh)
|
|
2002
|
-
throw err;
|
|
2003
2017
|
debugLog(`FTS rebuild skipped because another process holds the rebuild lock: ${message}`);
|
|
2004
2018
|
return loadIndexSnapshotOrEmpty(phrenPath, profile);
|
|
2005
2019
|
}
|
package/dist/shared/retrieval.js
CHANGED
|
@@ -625,7 +625,7 @@ export async function searchKnowledgeRows(db, options) {
|
|
|
625
625
|
*/
|
|
626
626
|
export async function searchFederatedStores(localPhrenPath, options) {
|
|
627
627
|
// Registered non-primary stores are already included in the main FTS index
|
|
628
|
-
// by buildIndex (via
|
|
628
|
+
// by buildIndex (via getAllStoreProjectDirs). Only search unregistered
|
|
629
629
|
// federation paths from PHREN_FEDERATION_PATHS to avoid double indexing.
|
|
630
630
|
let registeredStorePaths;
|
|
631
631
|
try {
|
package/dist/skill/files.js
CHANGED
|
@@ -2,11 +2,12 @@ import * as fs from "fs";
|
|
|
2
2
|
import * as path from "path";
|
|
3
3
|
import { homePath } from "../shared.js";
|
|
4
4
|
import { findProjectDir } from "../project-locator.js";
|
|
5
|
-
import { buildSkillManifest } from "./registry.js";
|
|
5
|
+
import { buildSkillManifest, skillMirrorPath } from "./registry.js";
|
|
6
6
|
import { setSkillEnabled } from "./state.js";
|
|
7
7
|
import { errorMessage } from "../utils.js";
|
|
8
8
|
import { isManagedSymlink } from "../link/skills.js";
|
|
9
9
|
import { logger } from "../logger.js";
|
|
10
|
+
import { getNonPrimaryStores } from "../store-registry.js";
|
|
10
11
|
function normalizeSkillRemovalTarget(skillPath) {
|
|
11
12
|
if (!skillPath)
|
|
12
13
|
return skillPath;
|
|
@@ -15,7 +16,14 @@ function normalizeSkillRemovalTarget(skillPath) {
|
|
|
15
16
|
}
|
|
16
17
|
return skillPath;
|
|
17
18
|
}
|
|
18
|
-
|
|
19
|
+
/** Every store root whose skills phren links, so a link into a team store counts as phren's own. */
|
|
20
|
+
function managedSkillRoots(phrenPath) {
|
|
21
|
+
return [phrenPath, ...getNonPrimaryStores(phrenPath).map((store) => store.path)];
|
|
22
|
+
}
|
|
23
|
+
function isManagedSkillLink(dest, managedRoots) {
|
|
24
|
+
return managedRoots.some((root) => isManagedSymlink(dest, root));
|
|
25
|
+
}
|
|
26
|
+
function symlinkManagedSkill(src, dest, managedRoots) {
|
|
19
27
|
try {
|
|
20
28
|
const stat = fs.lstatSync(dest);
|
|
21
29
|
if (stat.isSymbolicLink()) {
|
|
@@ -23,7 +31,7 @@ function symlinkManagedSkill(src, dest, managedRoot) {
|
|
|
23
31
|
const resolvedTarget = path.resolve(path.dirname(dest), currentTarget);
|
|
24
32
|
if (resolvedTarget === path.resolve(src))
|
|
25
33
|
return;
|
|
26
|
-
if (!
|
|
34
|
+
if (!isManagedSkillLink(dest, managedRoots))
|
|
27
35
|
return;
|
|
28
36
|
fs.unlinkSync(dest);
|
|
29
37
|
}
|
|
@@ -38,9 +46,26 @@ function symlinkManagedSkill(src, dest, managedRoot) {
|
|
|
38
46
|
fs.mkdirSync(path.dirname(dest), { recursive: true });
|
|
39
47
|
fs.symlinkSync(src, dest);
|
|
40
48
|
}
|
|
41
|
-
|
|
49
|
+
/** A folder phren made for a flat skill: it holds only a managed SKILL.md link. */
|
|
50
|
+
function isManagedSkillFolder(dest, managedRoots) {
|
|
42
51
|
try {
|
|
43
|
-
if (!
|
|
52
|
+
if (!fs.lstatSync(dest).isDirectory())
|
|
53
|
+
return false;
|
|
54
|
+
const entries = fs.readdirSync(dest);
|
|
55
|
+
return entries.length === 1 && entries[0] === "SKILL.md" && isManagedSkillLink(path.join(dest, "SKILL.md"), managedRoots);
|
|
56
|
+
}
|
|
57
|
+
catch {
|
|
58
|
+
return false;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
function removeManagedSkillLink(dest, managedRoots) {
|
|
62
|
+
try {
|
|
63
|
+
if (isManagedSkillFolder(dest, managedRoots)) {
|
|
64
|
+
fs.unlinkSync(path.join(dest, "SKILL.md"));
|
|
65
|
+
fs.rmdirSync(dest);
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
if (!isManagedSkillLink(dest, managedRoots))
|
|
44
69
|
return;
|
|
45
70
|
fs.unlinkSync(dest);
|
|
46
71
|
}
|
|
@@ -64,21 +89,25 @@ function writeSkillArtifacts(destDir, manifest) {
|
|
|
64
89
|
export function syncScopeSkillsToDir(phrenPath, scope, destDir) {
|
|
65
90
|
const manifest = buildSkillManifest(phrenPath, "", scope, destDir);
|
|
66
91
|
const expectedNames = new Set();
|
|
92
|
+
const managedRoots = managedSkillRoots(phrenPath);
|
|
67
93
|
fs.mkdirSync(destDir, { recursive: true });
|
|
68
94
|
for (const skill of manifest.skills) {
|
|
69
|
-
const
|
|
70
|
-
const destPath = path.join(destDir, destName);
|
|
95
|
+
const entryPath = path.join(destDir, skill.name);
|
|
71
96
|
if (!skill.visibleToAgents) {
|
|
72
|
-
removeManagedSkillLink(
|
|
97
|
+
removeManagedSkillLink(entryPath, managedRoots);
|
|
73
98
|
continue;
|
|
74
99
|
}
|
|
75
|
-
expectedNames.add(
|
|
76
|
-
|
|
100
|
+
expectedNames.add(skill.name);
|
|
101
|
+
// A skill that switched between flat and folder leaves the other shape behind.
|
|
102
|
+
if (skill.format === "folder" ? isManagedSkillFolder(entryPath, managedRoots) : isManagedSkillLink(entryPath, managedRoots)) {
|
|
103
|
+
removeManagedSkillLink(entryPath, managedRoots);
|
|
104
|
+
}
|
|
105
|
+
symlinkManagedSkill(skill.root, skillMirrorPath(destDir, skill), managedRoots);
|
|
77
106
|
}
|
|
78
107
|
for (const entry of fs.readdirSync(destDir)) {
|
|
79
108
|
if (expectedNames.has(entry))
|
|
80
109
|
continue;
|
|
81
|
-
removeManagedSkillLink(path.join(destDir, entry),
|
|
110
|
+
removeManagedSkillLink(path.join(destDir, entry), managedRoots);
|
|
82
111
|
}
|
|
83
112
|
writeSkillArtifacts(destDir, manifest);
|
|
84
113
|
return manifest;
|
package/dist/skill/registry.d.ts
CHANGED
|
@@ -36,6 +36,12 @@ interface SkillManifestProblem {
|
|
|
36
36
|
command?: string;
|
|
37
37
|
skillIds?: string[];
|
|
38
38
|
}
|
|
39
|
+
/**
|
|
40
|
+
* Where a skill appears in an agent's skills folder. Claude Code only loads
|
|
41
|
+
* `<name>/SKILL.md`, so a flat `name.md` skill gets a folder of its own holding
|
|
42
|
+
* a SKILL.md link to the file; a folder skill is linked whole.
|
|
43
|
+
*/
|
|
44
|
+
export declare function skillMirrorPath(destDir: string, skill: Pick<SkillEntry, "name" | "format">): string;
|
|
39
45
|
export interface SkillManifest {
|
|
40
46
|
scope: string;
|
|
41
47
|
project?: string;
|
package/dist/skill/registry.js
CHANGED
|
@@ -5,6 +5,16 @@ import { getProjectDirs } from "../shared.js";
|
|
|
5
5
|
import { parseSkillFrontmatter } from "../link/skills.js";
|
|
6
6
|
import { readSkillEnabledState } from "./state.js";
|
|
7
7
|
import { safeProjectPath } from "../utils.js";
|
|
8
|
+
import { storeAwareProjectPath } from "../store-routing.js";
|
|
9
|
+
import { getNonPrimaryStores, getStoreProjectDirs } from "../store-registry.js";
|
|
10
|
+
/**
|
|
11
|
+
* Where a skill appears in an agent's skills folder. Claude Code only loads
|
|
12
|
+
* `<name>/SKILL.md`, so a flat `name.md` skill gets a folder of its own holding
|
|
13
|
+
* a SKILL.md link to the file; a folder skill is linked whole.
|
|
14
|
+
*/
|
|
15
|
+
export function skillMirrorPath(destDir, skill) {
|
|
16
|
+
return skill.format === "folder" ? path.join(destDir, skill.name) : path.join(destDir, skill.name, "SKILL.md");
|
|
17
|
+
}
|
|
8
18
|
function normalizeCommand(raw, fallbackName) {
|
|
9
19
|
const value = typeof raw === "string" && raw.trim() ? raw.trim() : `/${fallbackName}`;
|
|
10
20
|
return value.startsWith("/") ? value : `/${value}`;
|
|
@@ -85,7 +95,8 @@ function getGlobalSkills(phrenPath, isEnabled) {
|
|
|
85
95
|
}
|
|
86
96
|
function getProjectLocalSkills(phrenPath, project, isEnabled) {
|
|
87
97
|
const seen = new Set();
|
|
88
|
-
|
|
98
|
+
// A project that lives in a team store keeps its skills there.
|
|
99
|
+
const projectDir = storeAwareProjectPath(phrenPath, project) ?? path.join(phrenPath, project);
|
|
89
100
|
return collectSkills(isEnabled, path.join(projectDir, "skills"), project, "project", "canonical", seen);
|
|
90
101
|
}
|
|
91
102
|
function skillPriority(skill) {
|
|
@@ -124,7 +135,6 @@ function buildResolvedSkills(raw, mirrorDir) {
|
|
|
124
135
|
path: candidate.path,
|
|
125
136
|
sourceKind: candidate.sourceKind,
|
|
126
137
|
}));
|
|
127
|
-
const destName = chosen.format === "folder" ? chosen.name : path.basename(chosen.path);
|
|
128
138
|
skills.push({
|
|
129
139
|
path: chosen.path,
|
|
130
140
|
format: chosen.format,
|
|
@@ -140,7 +150,7 @@ function buildResolvedSkills(raw, mirrorDir) {
|
|
|
140
150
|
visibleToAgents: chosen.enabled,
|
|
141
151
|
commandRegistered: true,
|
|
142
152
|
overrides,
|
|
143
|
-
mirrorTargets: mirrorDir ? [
|
|
153
|
+
mirrorTargets: mirrorDir ? [skillMirrorPath(mirrorDir, chosen)] : [],
|
|
144
154
|
});
|
|
145
155
|
grouped.delete(key);
|
|
146
156
|
}
|
|
@@ -219,8 +229,14 @@ export function getAllSkills(phrenPath, profile) {
|
|
|
219
229
|
const skillState = readSkillEnabledState(phrenPath);
|
|
220
230
|
const isEnabled = (scope, name) => skillState(scope, name) && skillEnabled(phrenPath, name, profile || undefined);
|
|
221
231
|
const all = getGlobalSkills(phrenPath, isEnabled);
|
|
222
|
-
|
|
223
|
-
|
|
232
|
+
const projects = new Set(getProjectDirs(phrenPath, profile).map((dir) => path.basename(dir)));
|
|
233
|
+
for (const store of getNonPrimaryStores(phrenPath)) {
|
|
234
|
+
if (!fs.existsSync(store.path))
|
|
235
|
+
continue;
|
|
236
|
+
for (const dir of getStoreProjectDirs(store))
|
|
237
|
+
projects.add(path.basename(dir));
|
|
238
|
+
}
|
|
239
|
+
for (const source of projects) {
|
|
224
240
|
if (source === "global")
|
|
225
241
|
continue;
|
|
226
242
|
all.push(...getProjectLocalSkills(phrenPath, source, isEnabled));
|
package/dist/task/lifecycle.js
CHANGED
|
@@ -5,6 +5,7 @@ import { getProactivityLevelForTask, shouldAutoCaptureTaskForLevel, hasExecution
|
|
|
5
5
|
import { getWorkflowPolicy } from "../shared/governance.js";
|
|
6
6
|
import { debugLog, sessionMarker } from "../shared.js";
|
|
7
7
|
import { errorMessage } from "../utils.js";
|
|
8
|
+
import { clankerEnabled, rowTitle } from "../clanker.js";
|
|
8
9
|
const ACTION_PREFIX_RE = /^(?:please\s+|can you\s+|could you\s+|would you\s+|i want you to\s+|i want to\s+|let(?:'|’)s\s+|lets\s+|help me\s+)/i;
|
|
9
10
|
const EXPLICIT_TASK_PREFIX_RE = /^(?:add(?:\s+(?:this|that|it))?\s+(?:to\s+(?:the\s+)?)?(?:task|todo(?:\s+list)?|task(?:\s+list)?)|add\s+(?:a\s+)?task|put(?:\s+(?:this|that|it))?\s+(?:in|on)\s+(?:the\s+)?(?:task|todo(?:\s+list)?|task(?:\s+list)?))\s*(?::|-|,)?\s*/i;
|
|
10
11
|
const NON_ACTIONABLE_RE = /\b(brainstorm|idea|ideas|maybe|what if|should we|could we|would it make sense|question|explain|why is|how does)\b/i;
|
|
@@ -421,7 +422,8 @@ export function handleTaskPromptLifecycle(args) {
|
|
|
421
422
|
mode,
|
|
422
423
|
noticeLines: [
|
|
423
424
|
"<phren-notice>",
|
|
424
|
-
|
|
425
|
+
// Clanker mode names the task by id and title; get_tasks or get_memory_detail has the rest.
|
|
426
|
+
`${section === "active" ? "Active" : "Queued"} task (${args.project}): ${clankerEnabled(args.phrenPath) && resolved.data.stableId ? `bid:${resolved.data.stableId} ${rowTitle(resolved.data.line)}` : resolved.data.line}`,
|
|
425
427
|
"<phren-notice>",
|
|
426
428
|
],
|
|
427
429
|
};
|
package/dist/tools/dispatch.js
CHANGED
|
@@ -6,6 +6,7 @@ import { dispatchSchema } from "../bridge/dispatch.js";
|
|
|
6
6
|
import { handOff, handOffSchema, listLiveSessions } from "../bridge/hand-off.js";
|
|
7
7
|
import { readAccountUsage, usageSummary } from "../bridge/account-usage.js";
|
|
8
8
|
import { terminalPaneFromEnv } from "../bridge/terminal.js";
|
|
9
|
+
import { dispatchIdFromEnv } from "../bridge/launch-brief.js";
|
|
9
10
|
import { approvalDecisions } from "../bridge/protocol.js";
|
|
10
11
|
import { mcpResponse } from "./types.js";
|
|
11
12
|
export function register(server) {
|
|
@@ -33,7 +34,9 @@ export function register(server) {
|
|
|
33
34
|
const origin = await terminalPaneFromEnv();
|
|
34
35
|
if (!origin)
|
|
35
36
|
throw new Error("Run dispatch_report inside the worker's terminal pane.");
|
|
36
|
-
|
|
37
|
+
// The launch's dispatch id lets the Hook accept a report whose turn it did not record (worker-reports.ts).
|
|
38
|
+
const dispatch = dispatchIdFromEnv();
|
|
39
|
+
const result = await hookRequest("/v1/dispatch/report", { ...input, origin, ...(dispatch ? { dispatch } : {}) });
|
|
37
40
|
return mcpResponse({ ok: result.ok === true, data: result, message: "PR evidence recorded for this turn's done return." });
|
|
38
41
|
}
|
|
39
42
|
catch (error) {
|
|
@@ -42,7 +45,7 @@ export function register(server) {
|
|
|
42
45
|
});
|
|
43
46
|
server.registerTool("owner_inbox", {
|
|
44
47
|
title: "◆ phren · owner inbox",
|
|
45
|
-
description: "One owner inbox on this conductor's Hook: list open needs-you returns, blocked prompts and manual items; add a title and optional project; resolve an id with an optional resolution. Reading returns does not resolve inbox items. Resolving an inbox item does not answer or approve a worker prompt. Use operation add, list or resolve (also through phren_admin action owner_inbox). includeResolved lists history. Keep an id on retried adds.",
|
|
48
|
+
description: "One owner inbox on this conductor's Hook: list open needs-you returns, blocked prompts and manual items; add a title and optional project; resolve an id with an optional resolution. Automatic items are deduplicated by pane, session and question, and resolve when their source stops waiting or disappears; only verified live automatic items are listed. Manual items remain until resolved. Reading returns does not resolve inbox items. Resolving an inbox item does not answer or approve a worker prompt. Use operation add, list or resolve (also through phren_admin action owner_inbox). includeResolved lists history. Keep an id on retried adds.",
|
|
46
49
|
inputSchema: ownerInboxSchema.omit({ action: true }).extend({ operation: ownerInboxSchema.shape.action }),
|
|
47
50
|
}, async (input) => {
|
|
48
51
|
try {
|
|
@@ -56,7 +59,7 @@ export function register(server) {
|
|
|
56
59
|
});
|
|
57
60
|
server.registerTool("dispatch_returns", {
|
|
58
61
|
title: "◆ phren · dispatch returns",
|
|
59
|
-
description: "List unread returns from dispatched workers and mark them read: the worker finished (done, with its final reply), finished by asking the owner something (needs-you, with the question), failed (the harness ended the turn on an error such as a usage limit, with the error), is blocked on terminal input, or its pane is gone. A blocked row with an `approval` field (actionId, tool, request) is a permission request the worker is waiting on, forwarded from its computer: answer it with dispatch_approve. A worker that ended its turn with background tasks pending is waited on for up to two hours; a row has `waited` (the most tasks it waited on) or, if some were still running after that, `background`. A stalled row flags an unchanged working screen and transcript. A done row can include structured prs and integratorDelivery. Reading a done return closes its finished pane unless closeOnFinish:false was specified, after rechecking new and queued work. Each row has the dispatch id, computer, project, label and the worker's target for hand_off.",
|
|
62
|
+
description: "List unread returns from dispatched workers and mark them read: the worker finished (done, with its final reply), finished by asking the owner something (needs-you, with the question), failed (the harness ended the turn on an error such as a usage limit, with the error), is blocked on terminal input, or its pane is gone. A blocked row with an `approval` field (actionId, tool, request) is a permission request the worker is waiting on, forwarded from its computer: answer it with dispatch_approve. A worker that ended its turn with background tasks pending is waited on for up to two hours; a row has `waited` (the most tasks it waited on) or, if some were still running after that, `background`. A stalled row flags an unchanged working screen and transcript. A done row can include structured prs and integratorDelivery. Reading a done return closes its finished pane unless closeOnFinish:false was specified, after rechecking new and queued work. Each row has the dispatch id, computer, project, label and the worker's target for hand_off. When the owner has turned on `phren config account-failover on` (off by default), a Claude worker that stopped at its usage limit is continued on another signed-in account with room (same computer first, never the same login before its window resets): its row comes back with continued (the new dispatch id, computer and account, or why none could) and the error says \"Continued on account X\".",
|
|
60
63
|
inputSchema: {},
|
|
61
64
|
}, async () => {
|
|
62
65
|
try {
|
|
@@ -88,7 +91,7 @@ export function register(server) {
|
|
|
88
91
|
});
|
|
89
92
|
server.registerTool("live_sessions", {
|
|
90
93
|
title: "◆ phren · live sessions",
|
|
91
|
-
description: "List the live agent sessions on this computer and every enrolled computer: computer, project, harness, status (working, with backgroundTasks, while background work runs after the main turn ended), idleFor (seconds since the tab last changed), role
|
|
94
|
+
description: "List the live agent sessions on this computer and every enrolled computer: computer, project, harness, status (working, with backgroundTasks, while background work runs after the main turn ended), idleFor (seconds since the tab last changed), role, the target hand_off takes, and for Claude sessions quota (the account's 5-hour and weekly percent left and reset time). claudeAccounts lists every signed-in Claude account per computer with the same room. Computers that could not be reached are listed separately, and computers registered in the store but not linked in hooks.yaml come back in notLinked: their sessions are unknown, not absent.",
|
|
92
95
|
inputSchema: {},
|
|
93
96
|
}, async () => {
|
|
94
97
|
try {
|
package/dist/tools/finding.js
CHANGED
|
@@ -576,20 +576,29 @@ export async function syncTeamStores(phrenPath) {
|
|
|
576
576
|
}
|
|
577
577
|
};
|
|
578
578
|
try {
|
|
579
|
-
if (
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
579
|
+
if (runStoreGit(["status", "--porcelain"])) {
|
|
580
|
+
// Stage each team-safe pathspec individually — a single no-match
|
|
581
|
+
// (e.g. no */truths.md in this store) used to abort the whole add.
|
|
582
|
+
for (const spec of TEAM_STORE_PATHSPECS) {
|
|
583
|
+
try {
|
|
584
|
+
runStoreGit(["add", "--sparse", "--", spec]);
|
|
585
|
+
}
|
|
586
|
+
catch { /* best-effort */ }
|
|
586
587
|
}
|
|
587
|
-
|
|
588
|
+
if (runStoreGit(["diff", "--cached", "--name-only"])) {
|
|
589
|
+
const actor = process.env.PHREN_ACTOR || process.env.USER || "unknown";
|
|
590
|
+
runStoreGit(["commit", "-m", storeCommitMessage(`phren: ${actor} team sync`)]);
|
|
591
|
+
}
|
|
592
|
+
}
|
|
593
|
+
// A clean tree can still hold commits the remote lacks: the session-start
|
|
594
|
+
// pull commits local writes before merging, and nothing else pushed them.
|
|
595
|
+
let ahead = 1;
|
|
596
|
+
try {
|
|
597
|
+
ahead = Number(runStoreGit(["rev-list", "--count", "@{u}..HEAD"]));
|
|
588
598
|
}
|
|
589
|
-
|
|
599
|
+
catch { /* no upstream: let push decide */ }
|
|
600
|
+
if (ahead === 0)
|
|
590
601
|
continue;
|
|
591
|
-
const actor = process.env.PHREN_ACTOR || process.env.USER || "unknown";
|
|
592
|
-
runStoreGit(["commit", "-m", storeCommitMessage(`phren: ${actor} team sync`)]);
|
|
593
602
|
try {
|
|
594
603
|
runStoreGit(["push"], { timeout: 15000 });
|
|
595
604
|
teamResults.push({ store: store.name, pushed: true });
|
package/dist/tools/graph.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
1
|
import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
2
2
|
import { type McpContext } from "./types.js";
|
|
3
|
+
/** These tools answer from the FTS index; the MCP server refreshes it before each call. */
|
|
4
|
+
export declare const readsIndex = true;
|
|
3
5
|
export declare function register(server: McpServer, ctx: McpContext): void;
|
package/dist/tools/graph.js
CHANGED
|
@@ -9,6 +9,8 @@ import { withFileLock } from "../shared/governance.js";
|
|
|
9
9
|
import { logger } from "../logger.js";
|
|
10
10
|
// Compatibility decision (2026-09): fragments keep the established entity /
|
|
11
11
|
// entity_type wire keys and manual-links.json fields. See docs/api-reference.md.
|
|
12
|
+
/** These tools answer from the FTS index; the MCP server refreshes it before each call. */
|
|
13
|
+
export const readsIndex = true;
|
|
12
14
|
export function register(server, ctx) {
|
|
13
15
|
// ── search_fragments ──────────────────────────────────────────────────
|
|
14
16
|
server.registerTool("search_fragments", {
|
package/dist/tools/search.d.ts
CHANGED
|
@@ -5,4 +5,6 @@ import { type McpContext } from "./types.js";
|
|
|
5
5
|
* Strips PII-like tokens (emails, UUIDs, numbers) and keeps only query terms.
|
|
6
6
|
*/
|
|
7
7
|
export declare function logSearchMiss(phrenPath: string, query: string, project?: string): void;
|
|
8
|
+
/** These tools answer from the FTS index; the MCP server refreshes it before each call. */
|
|
9
|
+
export declare const readsIndex = true;
|
|
8
10
|
export declare function register(server: McpServer, ctx: McpContext): void;
|