@phren/cli 0.3.35 → 0.3.36

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.
Files changed (68) hide show
  1. package/dist/bridge/agent-hooks.d.ts +11 -1
  2. package/dist/bridge/agent-hooks.js +56 -19
  3. package/dist/bridge/changes.js +18 -9
  4. package/dist/bridge/dispatch-command.js +3 -1
  5. package/dist/bridge/health.js +3 -1
  6. package/dist/bridge/host-key.d.ts +16 -0
  7. package/dist/bridge/host-key.js +35 -0
  8. package/dist/bridge/launch-brief.d.ts +2 -0
  9. package/dist/bridge/launch-brief.js +5 -0
  10. package/dist/bridge/link.js +11 -4
  11. package/dist/bridge/owner-inbox-sources.d.ts +5 -0
  12. package/dist/bridge/owner-inbox-sources.js +94 -0
  13. package/dist/bridge/owner-inbox-view.js +20 -1
  14. package/dist/bridge/owner-inbox.d.ts +7 -3
  15. package/dist/bridge/owner-inbox.js +113 -69
  16. package/dist/bridge/pair.js +3 -2
  17. package/dist/bridge/server.js +3 -23
  18. package/dist/bridge/sudo.d.ts +36 -6
  19. package/dist/bridge/sudo.js +180 -37
  20. package/dist/bridge/worker-reports.d.ts +8 -1
  21. package/dist/bridge/worker-reports.js +28 -7
  22. package/dist/bridge-hook.mjs +809 -471
  23. package/dist/clanker.d.ts +54 -0
  24. package/dist/clanker.js +188 -0
  25. package/dist/cli/config.js +30 -0
  26. package/dist/cli/hooks-output.d.ts +1 -1
  27. package/dist/cli/hooks-output.js +28 -21
  28. package/dist/cli/hooks.js +1 -1
  29. package/dist/cli/namespaces-skills.js +2 -2
  30. package/dist/cli/namespaces-tasks.js +46 -7
  31. package/dist/cli/session-start.js +12 -3
  32. package/dist/cli/session-stop.js +9 -0
  33. package/dist/cli/team.js +3 -0
  34. package/dist/cli-handlers.js +7 -0
  35. package/dist/cli-registry.js +1 -0
  36. package/dist/data/task-format.d.ts +5 -1
  37. package/dist/data/task-format.js +13 -5
  38. package/dist/index.js +82 -50
  39. package/dist/init/init-configure.d.ts +2 -0
  40. package/dist/init/init-configure.js +12 -0
  41. package/dist/init/init-uninstall.js +21 -2
  42. package/dist/init/init.d.ts +2 -0
  43. package/dist/init/init.js +11 -3
  44. package/dist/init/preferences.d.ts +6 -0
  45. package/dist/init/teardown.js +18 -4
  46. package/dist/link/doctor.js +2 -2
  47. package/dist/link/link.js +9 -0
  48. package/dist/link/refresh.d.ts +10 -0
  49. package/dist/link/refresh.js +34 -0
  50. package/dist/mcp/local-index.d.ts +20 -0
  51. package/dist/mcp/local-index.js +39 -1
  52. package/dist/shared/index.d.ts +14 -0
  53. package/dist/shared/index.js +88 -74
  54. package/dist/shared/retrieval.js +1 -1
  55. package/dist/skill/files.js +40 -11
  56. package/dist/skill/registry.d.ts +6 -0
  57. package/dist/skill/registry.js +21 -5
  58. package/dist/task/lifecycle.js +3 -1
  59. package/dist/tools/dispatch.js +5 -2
  60. package/dist/tools/finding.js +20 -11
  61. package/dist/tools/graph.d.ts +2 -0
  62. package/dist/tools/graph.js +2 -0
  63. package/dist/tools/search.d.ts +2 -0
  64. package/dist/tools/search.js +88 -6
  65. package/dist/tools/tasks.js +45 -0
  66. package/dist/tools/types.d.ts +3 -1
  67. package/dist/tools/types.js +3 -2
  68. package/package.json +1 -1
@@ -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 projects alongside personal ones.
18
- * Uses a sync cache populated by the async buildIndex path.
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 { getNonPrimaryStores, getStoreProjectDirs } = await import("../store-registry.js");
34
- const otherStores = getNonPrimaryStores(phrenPath);
35
- let dirs = [];
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
- _cachedStoreProjectDirs = [];
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
- function isRebuildLockHeld(phrenPath) {
1673
- const lockTarget = runtimeFile(phrenPath, "index-rebuild");
1674
- const lockPath = lockTarget + ".lock";
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
- const stat = fs.statSync(lockPath);
1677
- const staleThreshold = Number.parseInt((process.env.PHREN_FILE_LOCK_STALE_MS) || "30000", 10) || 30000;
1678
- return Date.now() - stat.mtimeMs <= staleThreshold;
1655
+ mtimeMs = fs.statSync(lockPath).mtimeMs;
1656
+ contents = fs.readFileSync(lockPath, "utf8");
1679
1657
  }
1680
- catch (err) {
1681
- logger.debug("isRebuildLockHeld stat", errorMessage(err));
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 Error("Index rebuild is busy; retry shortly.");
1981
+ throw new IndexBusyError();
1982
1982
  return loadIndexSnapshotOrEmpty(phrenPath, profile);
1983
1983
  }
1984
- try {
1985
- return await withFileLock(lockTarget, async () => {
1986
- let timer;
1987
- const timeout = new Promise((_, reject) => {
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
  }
@@ -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 refreshStoreProjectDirs). Only search unregistered
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 {
@@ -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
- function symlinkManagedSkill(src, dest, managedRoot) {
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 (!isManagedSymlink(dest, managedRoot))
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
- function removeManagedSkillLink(dest, managedRoot) {
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 (!isManagedSymlink(dest, managedRoot))
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 destName = skill.format === "folder" ? skill.name : path.basename(skill.path);
70
- const destPath = path.join(destDir, destName);
95
+ const entryPath = path.join(destDir, skill.name);
71
96
  if (!skill.visibleToAgents) {
72
- removeManagedSkillLink(destPath, phrenPath);
97
+ removeManagedSkillLink(entryPath, managedRoots);
73
98
  continue;
74
99
  }
75
- expectedNames.add(destName);
76
- symlinkManagedSkill(skill.root, destPath, phrenPath);
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), phrenPath);
110
+ removeManagedSkillLink(path.join(destDir, entry), managedRoots);
82
111
  }
83
112
  writeSkillArtifacts(destDir, manifest);
84
113
  return manifest;
@@ -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;
@@ -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
- const projectDir = path.join(phrenPath, project);
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 ? [path.join(mirrorDir, destName)] : [],
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
- for (const dir of getProjectDirs(phrenPath, profile)) {
223
- const source = path.basename(dir);
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));
@@ -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
- `${section === "active" ? "Active" : "Queued"} task (${args.project}): ${resolved.data.line}`,
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
  };
@@ -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
- const result = await hookRequest("/v1/dispatch/report", { ...input, origin });
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 {
@@ -576,20 +576,29 @@ export async function syncTeamStores(phrenPath) {
576
576
  }
577
577
  };
578
578
  try {
579
- if (!runStoreGit(["status", "--porcelain"]))
580
- continue;
581
- // Stage each team-safe pathspec individually — a single no-match
582
- // (e.g. no */truths.md in this store) used to abort the whole add.
583
- for (const spec of TEAM_STORE_PATHSPECS) {
584
- try {
585
- runStoreGit(["add", "--sparse", "--", spec]);
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
- catch { /* best-effort */ }
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
- if (!runStoreGit(["diff", "--cached", "--name-only"]))
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 });
@@ -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;
@@ -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", {
@@ -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;