@phren/cli 0.2.15 → 0.3.0
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/README.md +2 -2
- package/dist/agent-instructions.d.ts +12 -0
- package/dist/agent-instructions.js +52 -0
- package/dist/bridge/agent-hook-stores.d.ts +32 -0
- package/dist/bridge/agent-hook-stores.js +67 -0
- package/dist/bridge/agent-hooks.d.ts +195 -2
- package/dist/bridge/agent-hooks.js +1049 -38
- package/dist/bridge/canary.d.ts +27 -0
- package/dist/bridge/canary.js +189 -0
- package/dist/bridge/changes.d.ts +57 -0
- package/dist/bridge/changes.js +403 -0
- package/dist/bridge/client.d.ts +3 -0
- package/dist/bridge/client.js +36 -0
- package/dist/bridge/code-note.d.ts +23 -0
- package/dist/bridge/code-note.js +51 -0
- package/dist/bridge/code-routes.d.ts +151 -0
- package/dist/bridge/code-routes.js +442 -0
- package/dist/bridge/codex-threads.d.ts +27 -0
- package/dist/bridge/codex-threads.js +442 -0
- package/dist/bridge/command.d.ts +7 -0
- package/dist/bridge/command.js +50 -5
- package/dist/bridge/computer-names.d.ts +4 -0
- package/dist/bridge/computer-names.js +16 -0
- package/dist/bridge/computers.d.ts +9 -0
- package/dist/bridge/computers.js +111 -0
- package/dist/bridge/context.d.ts +14 -0
- package/dist/bridge/context.js +149 -0
- package/dist/bridge/dispatch-command.d.ts +3 -0
- package/dist/bridge/dispatch-command.js +93 -0
- package/dist/bridge/dispatch-hosts.d.ts +23 -0
- package/dist/bridge/dispatch-hosts.js +25 -0
- package/dist/bridge/dispatch-returns.d.ts +125 -0
- package/dist/bridge/dispatch-returns.js +283 -0
- package/dist/bridge/dispatch-tree.d.ts +54 -0
- package/dist/bridge/dispatch-tree.js +198 -0
- package/dist/bridge/dispatch.d.ts +210 -0
- package/dist/bridge/dispatch.js +286 -0
- package/dist/bridge/enroll.d.ts +31 -0
- package/dist/bridge/enroll.js +236 -0
- package/dist/bridge/fanout-messages.d.ts +74 -0
- package/dist/bridge/fanout-messages.js +230 -0
- package/dist/bridge/fanouts.d.ts +160 -0
- package/dist/bridge/fanouts.js +702 -0
- package/dist/bridge/file-range.d.ts +16 -0
- package/dist/bridge/file-range.js +90 -0
- package/dist/bridge/files.d.ts +20 -0
- package/dist/bridge/files.js +54 -0
- package/dist/bridge/git-publish.d.ts +23 -0
- package/dist/bridge/git-publish.js +145 -0
- package/dist/bridge/git-worktrees.d.ts +21 -0
- package/dist/bridge/git-worktrees.js +150 -0
- package/dist/bridge/git.d.ts +54 -0
- package/dist/bridge/git.js +552 -0
- package/dist/bridge/grants.d.ts +31 -0
- package/dist/bridge/grants.js +181 -0
- package/dist/bridge/hand-off.d.ts +79 -0
- package/dist/bridge/hand-off.js +151 -0
- package/dist/bridge/health.d.ts +128 -0
- package/dist/bridge/health.js +260 -0
- package/dist/bridge/herdr.d.ts +79 -6
- package/dist/bridge/herdr.js +292 -27
- package/dist/bridge/hook-main.js +2 -0
- package/dist/bridge/install.d.ts +28 -1
- package/dist/bridge/install.js +225 -38
- package/dist/bridge/launch-worktree.d.ts +21 -0
- package/dist/bridge/launch-worktree.js +70 -0
- package/dist/bridge/limits.d.ts +20 -0
- package/dist/bridge/limits.js +65 -0
- package/dist/bridge/locate.d.ts +16 -0
- package/dist/bridge/locate.js +75 -0
- package/dist/bridge/metrics.d.ts +29 -0
- package/dist/bridge/metrics.js +71 -0
- package/dist/bridge/model-switch.d.ts +35 -0
- package/dist/bridge/model-switch.js +250 -0
- package/dist/bridge/models.d.ts +46 -0
- package/dist/bridge/models.js +257 -0
- package/dist/bridge/opencode-approvals.d.ts +6 -0
- package/dist/bridge/opencode-approvals.js +60 -0
- package/dist/bridge/pane-text.d.ts +15 -0
- package/dist/bridge/pane-text.js +23 -0
- package/dist/bridge/peers.d.ts +27 -0
- package/dist/bridge/peers.js +130 -0
- package/dist/bridge/projects.d.ts +12 -1
- package/dist/bridge/projects.js +268 -20
- package/dist/bridge/protocol.d.ts +35 -2
- package/dist/bridge/protocol.js +61 -7
- package/dist/bridge/push.d.ts +83 -0
- package/dist/bridge/push.js +199 -0
- package/dist/bridge/questions.d.ts +38 -0
- package/dist/bridge/questions.js +205 -0
- package/dist/bridge/schedule-format.d.ts +103 -0
- package/dist/bridge/schedule-format.js +266 -0
- package/dist/bridge/schedule-launch.d.ts +11 -0
- package/dist/bridge/schedule-launch.js +169 -0
- package/dist/bridge/schedule-watch.d.ts +54 -0
- package/dist/bridge/schedule-watch.js +255 -0
- package/dist/bridge/schedules.d.ts +48 -0
- package/dist/bridge/schedules.js +205 -0
- package/dist/bridge/server-launch.d.ts +14 -0
- package/dist/bridge/server-launch.js +218 -0
- package/dist/bridge/server-overview.d.ts +45 -0
- package/dist/bridge/server-overview.js +102 -0
- package/dist/bridge/server-pane-routes.d.ts +36 -0
- package/dist/bridge/server-pane-routes.js +479 -0
- package/dist/bridge/server-routes.d.ts +108 -0
- package/dist/bridge/server-routes.js +556 -0
- package/dist/bridge/server-stream.d.ts +46 -0
- package/dist/bridge/server-stream.js +253 -0
- package/dist/bridge/server.d.ts +3 -15
- package/dist/bridge/server.js +162 -264
- package/dist/bridge/session-servers.d.ts +24 -0
- package/dist/bridge/session-servers.js +136 -0
- package/dist/bridge/side-questions.d.ts +74 -0
- package/dist/bridge/side-questions.js +252 -0
- package/dist/bridge/simulators.d.ts +28 -0
- package/dist/bridge/simulators.js +198 -0
- package/dist/bridge/speech-transcribe.d.ts +24 -0
- package/dist/bridge/speech-transcribe.js +124 -0
- package/dist/bridge/speech.d.ts +35 -0
- package/dist/bridge/speech.js +98 -0
- package/dist/bridge/steps.d.ts +13 -0
- package/dist/bridge/steps.js +222 -0
- package/dist/bridge/tab-activity.d.ts +18 -0
- package/dist/bridge/tab-activity.js +99 -0
- package/dist/bridge/terminal-choice.d.ts +64 -0
- package/dist/bridge/terminal-choice.js +281 -0
- package/dist/bridge/transcript-claude.d.ts +22 -0
- package/dist/bridge/transcript-claude.js +353 -0
- package/dist/bridge/transcript-codex.d.ts +30 -0
- package/dist/bridge/transcript-codex.js +282 -0
- package/dist/bridge/transcript-copilot.d.ts +4 -0
- package/dist/bridge/transcript-copilot.js +14 -0
- package/dist/bridge/transcript-opencode.d.ts +5 -0
- package/dist/bridge/transcript-opencode.js +26 -0
- package/dist/bridge/transcript-preview.d.ts +96 -0
- package/dist/bridge/transcript-preview.js +491 -0
- package/dist/bridge/transcripts.d.ts +81 -4
- package/dist/bridge/transcripts.js +332 -67
- package/dist/bridge/transport.d.ts +3 -0
- package/dist/bridge/transport.js +96 -15
- package/dist/bridge/uploads.d.ts +15 -0
- package/dist/bridge/uploads.js +44 -2
- package/dist/bridge/usage.d.ts +124 -0
- package/dist/bridge/usage.js +859 -0
- package/dist/bridge-hook.mjs +46545 -21051
- package/dist/cli/actions.js +14 -1
- package/dist/cli/config-policy.js +25 -0
- package/dist/cli/config-proactivity.d.ts +3 -1
- package/dist/cli/config-proactivity.js +35 -3
- package/dist/cli/config.js +4 -1
- package/dist/cli/extract.d.ts +0 -8
- package/dist/cli/extract.js +4 -7
- package/dist/cli/govern.js +5 -2
- package/dist/cli/hooks-globs.js +1 -1
- package/dist/cli/hooks.d.ts +1 -1
- package/dist/cli/hooks.js +9 -7
- package/dist/cli/namespaces-projects.js +12 -6
- package/dist/cli/namespaces-store.js +37 -6
- package/dist/cli/namespaces-tasks.js +1 -1
- package/dist/cli/schedules.d.ts +1 -0
- package/dist/cli/schedules.js +164 -0
- package/dist/cli/session-background.js +1 -1
- package/dist/cli/session-git.d.ts +8 -5
- package/dist/cli/session-git.js +45 -120
- package/dist/cli/session-start.js +3 -1
- package/dist/cli/session-stop.js +19 -8
- package/dist/cli/team.js +13 -10
- package/dist/cli-handlers.d.ts +1 -1
- package/dist/cli-handlers.js +8 -4
- package/dist/cli-help.d.ts +5 -4
- package/dist/cli-help.js +15 -15
- package/dist/cli-registry.d.ts +4 -1
- package/dist/cli-registry.js +119 -6
- package/dist/content/archive.js +2 -2
- package/dist/content/citation.d.ts +11 -0
- package/dist/content/citation.js +18 -0
- package/dist/content/learning.js +2 -0
- package/dist/content/summarize.d.ts +14 -15
- package/dist/content/summarize.js +60 -5
- package/dist/content/validate.d.ts +17 -4
- package/dist/content/validate.js +200 -122
- package/dist/core/project-registry.d.ts +26 -0
- package/dist/core/project-registry.js +573 -0
- package/dist/core/project.js +2 -3
- package/dist/data/access.d.ts +16 -1
- package/dist/data/access.js +31 -3
- package/dist/data/tasks.d.ts +18 -3
- package/dist/data/tasks.js +8 -7
- package/dist/entrypoint.js +44 -10
- package/dist/fanout/adapters/claude.d.ts +2 -0
- package/dist/fanout/adapters/claude.js +7 -0
- package/dist/fanout/adapters/codex.d.ts +2 -0
- package/dist/fanout/adapters/codex.js +9 -0
- package/dist/fanout/adapters/opencode.d.ts +4 -0
- package/dist/fanout/adapters/opencode.js +9 -0
- package/dist/fanout/adapters/types.d.ts +21 -0
- package/dist/fanout/adapters/types.js +3 -0
- package/dist/fanout/command.d.ts +2 -0
- package/dist/fanout/command.js +78 -0
- package/dist/fanout/launcher.d.ts +27 -0
- package/dist/fanout/launcher.js +156 -0
- package/dist/fanout/opencode-serve.d.ts +24 -0
- package/dist/fanout/opencode-serve.js +191 -0
- package/dist/fanout/picker.d.ts +91 -0
- package/dist/fanout/picker.js +51 -0
- package/dist/fanout/usage.d.ts +5 -0
- package/dist/fanout/usage.js +51 -0
- package/dist/fanout/watchdog.d.ts +10 -0
- package/dist/fanout/watchdog.js +27 -0
- package/dist/filenames.d.ts +9 -0
- package/dist/filenames.js +11 -0
- package/dist/finding/context.js +4 -22
- package/dist/generated/memory-ui-graph.browser.js +525 -419
- package/dist/governance/policy-constants.d.ts +11 -0
- package/dist/governance/policy-constants.js +9 -0
- package/dist/governance/policy.d.ts +5 -8
- package/dist/governance/policy.js +11 -8
- package/dist/graph-core/camera.d.ts +24 -0
- package/dist/graph-core/camera.js +18 -0
- package/dist/graph-core/index.d.ts +2 -0
- package/dist/graph-core/index.js +2 -0
- package/dist/graph-core/labels.d.ts +77 -0
- package/dist/graph-core/labels.js +124 -0
- package/dist/graph-core/model.d.ts +13 -0
- package/dist/graph-core/model.js +33 -0
- package/dist/graph-core/types.d.ts +2 -0
- package/dist/home-paths.d.ts +7 -0
- package/dist/home-paths.js +21 -0
- package/dist/hooks.d.ts +3 -15
- package/dist/hooks.js +14 -1
- package/dist/index.js +24 -2
- package/dist/init/guard-globals.d.ts +1 -1
- package/dist/init/guard-globals.js +4 -4
- package/dist/init/init-configure.js +3 -3
- package/dist/init/init-uninstall.js +15 -5
- package/dist/init/init-walkthrough.js +1 -1
- package/dist/init/init.js +26 -6
- package/dist/init/management-preset.d.ts +1 -1
- package/dist/init/management-preset.js +2 -2
- package/dist/init/preferences.js +1 -1
- package/dist/init/self-wiring.js +1 -1
- package/dist/init/setup.d.ts +3 -26
- package/dist/init/setup.js +68 -593
- package/dist/init/shared.js +2 -0
- package/dist/init/store-gitignore.d.ts +1 -6
- package/dist/init/store-gitignore.js +2 -8
- package/dist/init/teardown.d.ts +1 -1
- package/dist/init/teardown.js +2 -2
- package/dist/link/context-imports.d.ts +15 -0
- package/dist/link/context-imports.js +101 -0
- package/dist/link/context.js +1 -1
- package/dist/link/doctor.d.ts +22 -1
- package/dist/link/doctor.js +128 -58
- package/dist/link/link.js +29 -61
- package/dist/link/refresh.js +2 -2
- package/dist/link/skills.js +26 -5
- package/dist/machine-identity.d.ts +3 -0
- package/dist/machine-identity.js +6 -0
- package/dist/mcp/profile.d.ts +2 -19
- package/dist/mcp/profile.js +64 -22
- package/dist/memory-ui-graph.runtime.js +525 -419
- package/dist/modules/code-package.d.ts +16 -0
- package/dist/modules/code-package.js +160 -0
- package/dist/modules/command.d.ts +2 -0
- package/dist/modules/command.js +67 -0
- package/dist/modules/config.d.ts +4 -0
- package/dist/modules/config.js +70 -0
- package/dist/modules/manifest.d.ts +41 -0
- package/dist/modules/manifest.js +1 -0
- package/dist/modules/provision.d.ts +3 -0
- package/dist/modules/provision.js +84 -0
- package/dist/modules/registry.d.ts +16 -0
- package/dist/modules/registry.js +250 -0
- package/dist/modules/runtime.d.ts +15 -0
- package/dist/modules/runtime.js +59 -0
- package/dist/package-metadata.js +10 -2
- package/dist/phren-dotenv.js +4 -2
- package/dist/phren-paths.d.ts +3 -2
- package/dist/phren-paths.js +4 -5
- package/dist/profile-store.js +43 -8
- package/dist/project-config.d.ts +19 -1
- package/dist/project-config.js +29 -3
- package/dist/project-topics.d.ts +1 -0
- package/dist/project-topics.js +13 -10
- package/dist/provider-adapters.js +1 -4
- package/dist/query-correlation.js +6 -6
- package/dist/session/artifacts.js +5 -5
- package/dist/session/checkpoints.js +5 -0
- package/dist/session/utils.d.ts +2 -2
- package/dist/session/utils.js +6 -6
- package/dist/shared/content.d.ts +1 -1
- package/dist/shared/content.js +1 -1
- package/dist/shared/data-utils.js +1 -1
- package/dist/shared/fragment-graph.d.ts +1 -1
- package/dist/shared/fragment-graph.js +5 -5
- package/dist/shared/index.js +48 -7
- package/dist/shared/retrieval.d.ts +18 -3
- package/dist/shared/retrieval.js +101 -12
- package/dist/shared/search-fallback.js +4 -6
- package/dist/shared/sqljs.d.ts +2 -0
- package/dist/shared/sqljs.js +4 -2
- package/dist/shared.d.ts +0 -1
- package/dist/shared.js +0 -1
- package/dist/shell/input.d.ts +1 -5
- package/dist/shell/input.js +16 -10
- package/dist/shell/palette.d.ts +2 -2
- package/dist/shell/palette.js +3 -7
- package/dist/shell/render.d.ts +3 -1
- package/dist/shell/render.js +4 -4
- package/dist/shell/shell.js +4 -1
- package/dist/shell/types.d.ts +1 -0
- package/dist/shell/types.js +4 -0
- package/dist/shell/view.d.ts +0 -4
- package/dist/shell/view.js +19 -27
- package/dist/skill/registry.js +25 -17
- package/dist/skill/state.d.ts +3 -0
- package/dist/skill/state.js +13 -7
- package/dist/status.js +38 -17
- package/dist/store-registry.d.ts +44 -18
- package/dist/store-registry.js +169 -60
- package/dist/store-weight.d.ts +1 -6
- package/dist/store-weight.js +4 -2
- package/dist/sync/auth-doctor.d.ts +8 -0
- package/dist/sync/auth-doctor.js +27 -0
- package/dist/sync/auth.d.ts +27 -0
- package/dist/sync/auth.js +114 -0
- package/dist/sync/conflict-resolve.d.ts +9 -0
- package/dist/sync/conflict-resolve.js +146 -0
- package/dist/sync/git-state.d.ts +4 -0
- package/dist/sync/git-state.js +49 -0
- package/dist/sync/outcome.d.ts +34 -0
- package/dist/sync/outcome.js +57 -0
- package/dist/sync/pull.d.ts +15 -7
- package/dist/sync/pull.js +84 -35
- package/dist/sync/store-merge.d.ts +29 -0
- package/dist/sync/store-merge.js +137 -0
- package/dist/sync/task-merge.d.ts +22 -0
- package/dist/sync/task-merge.js +158 -0
- package/dist/task/github.js +1 -1
- package/dist/task/lifecycle.d.ts +5 -0
- package/dist/task/lifecycle.js +67 -23
- package/dist/terminal-text.d.ts +5 -0
- package/dist/terminal-text.js +11 -0
- package/dist/test-global-setup.js +7 -0
- package/dist/tool-registry.d.ts +1 -1
- package/dist/tool-registry.js +3 -1
- package/dist/tools/code.d.ts +3 -0
- package/dist/tools/code.js +186 -0
- package/dist/tools/config.js +8 -0
- package/dist/tools/data.js +14 -7
- package/dist/tools/dispatch.d.ts +2 -0
- package/dist/tools/dispatch.js +66 -0
- package/dist/tools/finding.d.ts +11 -0
- package/dist/tools/finding.js +180 -123
- package/dist/tools/ops.js +5 -2
- package/dist/tools/search.js +21 -8
- package/dist/tools/session.js +21 -22
- package/dist/tools/tasks.js +8 -2
- package/dist/tools/types.d.ts +2 -2
- package/dist/tools/types.js +2 -2
- package/dist/ui/assets.js +1 -1
- package/dist/ui/data.js +14 -15
- package/dist/ui/deep-void.d.ts +1 -1
- package/dist/ui/deep-void.js +0 -1
- package/dist/ui/graph-chrome.d.ts +1 -1
- package/dist/ui/graph-chrome.js +51 -0
- package/dist/ui/page.js +5 -5
- package/dist/ui/scripts.js +67 -30
- package/dist/ui/server.js +52 -7
- package/dist/update.js +22 -11
- package/dist/utils-fts.js +1 -0
- package/dist/utils-helpers.d.ts +7 -0
- package/dist/utils-helpers.js +17 -0
- package/dist/utils.d.ts +1 -1
- package/dist/utils.js +1 -1
- package/package.json +49 -7
- package/plugins/opencode/phren-transcript.js +340 -0
- package/starter/README.md +4 -4
- package/starter/global/{CLAUDE.md → AGENTS.md} +2 -2
- package/starter/global/skills/conductor/SKILL.md +106 -0
- package/starter/global/skills/fanout/SKILL.md +20 -0
- package/starter/global/skills/phren-discover/SKILL.md +6 -6
- package/starter/global/skills/phren-init/SKILL.md +4 -4
- package/starter/global/skills/phren-sync/SKILL.md +3 -3
- package/starter/templates/frontend/reference/README.md +1 -1
- package/starter/templates/library/reference/README.md +1 -1
- package/starter/templates/monorepo/reference/README.md +1 -1
- package/starter/templates/python-project/reference/README.md +1 -1
- /package/starter/templates/frontend/{CLAUDE.md → AGENTS.md} +0 -0
- /package/starter/templates/library/{CLAUDE.md → AGENTS.md} +0 -0
- /package/starter/templates/monorepo/{CLAUDE.md → AGENTS.md} +0 -0
- /package/starter/templates/python-project/{CLAUDE.md → AGENTS.md} +0 -0
package/dist/link/link.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { nonInteractiveGitEnv } from "../utils-helpers.js";
|
|
2
|
+
import { reconcileModuleHooks } from "../bridge/install.js";
|
|
1
3
|
import * as fs from "fs";
|
|
2
4
|
import * as path from "path";
|
|
3
5
|
import * as readline from "readline";
|
|
@@ -18,7 +20,6 @@ import { listMachines as listMachinesShared, listProfiles as listProfilesShared,
|
|
|
18
20
|
import { writeSkillMd, isManagedSymlink } from "./skills.js";
|
|
19
21
|
import { resolveManagementCapabilities } from "../init/management-preset.js";
|
|
20
22
|
import { syncScopeSkillsToDir } from "../skill/files.js";
|
|
21
|
-
import { renderSkillInstructionsSection } from "../skill/registry.js";
|
|
22
23
|
import { findProjectDir } from "../project-locator.js";
|
|
23
24
|
import { getProjectOwnershipMode, readProjectConfig, } from "../project-config.js";
|
|
24
25
|
import { writeContextDefault, writeContextDebugging, writeContextPlanning, writeContextClean, readBackNativeMemory, rebuildMemory, } from "./context.js";
|
|
@@ -81,7 +82,7 @@ function maybeOfferStarterTemplateUpdate(phrenPath) {
|
|
|
81
82
|
const prefs = JSON.parse(fs.readFileSync(prefsPath, "utf8"));
|
|
82
83
|
if (isVersionNewer(current, prefs.installedVersion)) {
|
|
83
84
|
log(` Starter template update available: v${prefs.installedVersion} -> v${current}`);
|
|
84
|
-
log(` Run \`phren init --apply-starter-update\` to refresh global/
|
|
85
|
+
log(` Run \`phren init --apply-starter-update\` to refresh global/AGENTS.md and global skills.`);
|
|
85
86
|
}
|
|
86
87
|
}
|
|
87
88
|
catch (err) {
|
|
@@ -118,7 +119,7 @@ async function registerMachine(phrenPath) {
|
|
|
118
119
|
// ── Sparse checkout ─────────────────────────────────────────────────────────
|
|
119
120
|
function setupSparseCheckout(phrenPath, projects) {
|
|
120
121
|
try {
|
|
121
|
-
execFileSync("git", ["rev-parse", "--git-dir"], { cwd: phrenPath, stdio: "ignore", timeout: EXEC_TIMEOUT_QUICK_MS });
|
|
122
|
+
execFileSync("git", ["rev-parse", "--git-dir"], { env: nonInteractiveGitEnv(), cwd: phrenPath, stdio: "ignore", timeout: EXEC_TIMEOUT_QUICK_MS });
|
|
122
123
|
}
|
|
123
124
|
catch (err) {
|
|
124
125
|
logger.debug("link", `setupSparseCheckout notAGitRepo: ${errorMessage(err)}`);
|
|
@@ -141,8 +142,8 @@ function setupSparseCheckout(phrenPath, projects) {
|
|
|
141
142
|
];
|
|
142
143
|
const paths = [...alwaysInclude, ...projects];
|
|
143
144
|
try {
|
|
144
|
-
execFileSync("git", ["sparse-checkout", "set", ...paths], { cwd: phrenPath, stdio: "ignore", timeout: EXEC_TIMEOUT_MS });
|
|
145
|
-
execFileSync("git", ["pull", "--ff-only"], { cwd: phrenPath, stdio: "ignore", timeout: EXEC_TIMEOUT_MS });
|
|
145
|
+
execFileSync("git", ["sparse-checkout", "set", ...paths], { env: nonInteractiveGitEnv(), cwd: phrenPath, stdio: "ignore", timeout: EXEC_TIMEOUT_MS });
|
|
146
|
+
execFileSync("git", ["pull", "--ff-only"], { env: nonInteractiveGitEnv(), cwd: phrenPath, stdio: "ignore", timeout: EXEC_TIMEOUT_MS });
|
|
146
147
|
}
|
|
147
148
|
catch (err) {
|
|
148
149
|
debugLog(`setupSparseCheckout: git sparse-checkout or pull failed: ${errorMessage(err)}`);
|
|
@@ -157,10 +158,11 @@ function addGitExcludes(projectDir, entries) {
|
|
|
157
158
|
return;
|
|
158
159
|
try {
|
|
159
160
|
// Filter out files already tracked by git — exclude only affects untracked files,
|
|
160
|
-
// and adding tracked files could confuse users who version-control their own
|
|
161
|
+
// and adding tracked files could confuse users who version-control their own AGENTS.md
|
|
161
162
|
let tracked;
|
|
162
163
|
try {
|
|
163
164
|
const out = execFileSync("git", ["ls-files", "--", ...entries], {
|
|
165
|
+
env: nonInteractiveGitEnv(),
|
|
164
166
|
cwd: projectDir,
|
|
165
167
|
timeout: EXEC_TIMEOUT_QUICK_MS,
|
|
166
168
|
encoding: "utf8",
|
|
@@ -205,7 +207,10 @@ function symlinkFile(src, dest, managedRoot) {
|
|
|
205
207
|
}
|
|
206
208
|
else {
|
|
207
209
|
try {
|
|
208
|
-
|
|
210
|
+
const existing = stat.isFile() ? fs.readFileSync(dest, "utf8") : "";
|
|
211
|
+
const isOldGeneratedAgents = path.basename(dest) === "AGENTS.md"
|
|
212
|
+
&& existing.includes("<!-- phren:generated-agents -->");
|
|
213
|
+
if (stat.isFile() && (existing === fs.readFileSync(src, "utf8") || isOldGeneratedAgents)) {
|
|
209
214
|
fs.unlinkSync(dest);
|
|
210
215
|
}
|
|
211
216
|
else {
|
|
@@ -237,41 +242,6 @@ function addTokenAnnotation(filePath) {
|
|
|
237
242
|
const rounded = Math.round((tokens + 50) / 100) * 100;
|
|
238
243
|
atomicWriteText(filePath, `<!-- tokens: ~${rounded} -->\n${content}`);
|
|
239
244
|
}
|
|
240
|
-
const GENERATED_AGENTS_MARKER = "<!-- phren:generated-agents -->";
|
|
241
|
-
function writeManagedAgentsFile(src, dest, content, managedRoot) {
|
|
242
|
-
try {
|
|
243
|
-
const stat = fs.lstatSync(dest);
|
|
244
|
-
if (stat.isDirectory()) {
|
|
245
|
-
log(` preserve existing directory: ${dest}`);
|
|
246
|
-
return false;
|
|
247
|
-
}
|
|
248
|
-
if (stat.isSymbolicLink()) {
|
|
249
|
-
const currentTarget = fs.readlinkSync(dest);
|
|
250
|
-
const resolvedTarget = path.resolve(path.dirname(dest), currentTarget);
|
|
251
|
-
if (resolvedTarget === path.resolve(src) || isManagedSymlink(dest, managedRoot)) {
|
|
252
|
-
fs.unlinkSync(dest);
|
|
253
|
-
}
|
|
254
|
-
else {
|
|
255
|
-
log(` preserve existing file: ${dest}`);
|
|
256
|
-
return false;
|
|
257
|
-
}
|
|
258
|
-
}
|
|
259
|
-
else {
|
|
260
|
-
const existing = fs.readFileSync(dest, "utf8");
|
|
261
|
-
if (!existing.includes(GENERATED_AGENTS_MARKER)) {
|
|
262
|
-
log(` preserve existing file: ${dest}`);
|
|
263
|
-
return false;
|
|
264
|
-
}
|
|
265
|
-
fs.unlinkSync(dest);
|
|
266
|
-
}
|
|
267
|
-
}
|
|
268
|
-
catch (err) {
|
|
269
|
-
if (err.code !== "ENOENT")
|
|
270
|
-
throw err;
|
|
271
|
-
}
|
|
272
|
-
atomicWriteText(dest, `${content.trimEnd()}\n`);
|
|
273
|
-
return true;
|
|
274
|
-
}
|
|
275
245
|
// ── Linking operations ──────────────────────────────────────────────────────
|
|
276
246
|
function linkGlobal(phrenPath, tools, caps) {
|
|
277
247
|
if (caps.installSkillLinks) {
|
|
@@ -290,7 +260,7 @@ function linkGlobal(phrenPath, tools, caps) {
|
|
|
290
260
|
}
|
|
291
261
|
}
|
|
292
262
|
if (caps.linkGlobalClaudeMd) {
|
|
293
|
-
const globalClaude = path.join(phrenPath, "global", "
|
|
263
|
+
const globalClaude = path.join(phrenPath, "global", "AGENTS.md");
|
|
294
264
|
if (fs.existsSync(globalClaude)) {
|
|
295
265
|
symlinkFile(globalClaude, homePath(".claude", "CLAUDE.md"), phrenPath);
|
|
296
266
|
if (tools.has("copilot")) {
|
|
@@ -350,12 +320,21 @@ function linkProject(phrenPath, project, tools, caps) {
|
|
|
350
320
|
return;
|
|
351
321
|
log(` ${project} -> ${target}`);
|
|
352
322
|
const excludeEntries = [];
|
|
353
|
-
for (const f of ["
|
|
323
|
+
for (const f of ["AGENTS.md", "REFERENCE.md", FINDINGS_FILENAME]) {
|
|
354
324
|
const src = path.join(phrenPath, project, f);
|
|
355
325
|
if (fs.existsSync(src)) {
|
|
356
326
|
if (symlinkFile(src, path.join(target, f), phrenPath))
|
|
357
327
|
excludeEntries.push(f);
|
|
358
|
-
if (f === "
|
|
328
|
+
if (f === "AGENTS.md") {
|
|
329
|
+
if (tools.has("claude")) {
|
|
330
|
+
try {
|
|
331
|
+
if (symlinkFile(src, path.join(target, "CLAUDE.md"), phrenPath))
|
|
332
|
+
excludeEntries.push("CLAUDE.md");
|
|
333
|
+
}
|
|
334
|
+
catch (err) {
|
|
335
|
+
logger.debug("link", `linkProject claudeInstructions: ${errorMessage(err)}`);
|
|
336
|
+
}
|
|
337
|
+
}
|
|
359
338
|
if (tools.has("copilot")) {
|
|
360
339
|
try {
|
|
361
340
|
const copilotDir = path.join(target, ".github");
|
|
@@ -379,8 +358,8 @@ function linkProject(phrenPath, project, tools, caps) {
|
|
|
379
358
|
}
|
|
380
359
|
}
|
|
381
360
|
}
|
|
382
|
-
// Token annotation on
|
|
383
|
-
const claudeFile = path.join(phrenPath, project, "
|
|
361
|
+
// Token annotation on AGENTS.md
|
|
362
|
+
const claudeFile = path.join(phrenPath, project, "AGENTS.md");
|
|
384
363
|
if (fs.existsSync(claudeFile)) {
|
|
385
364
|
try {
|
|
386
365
|
addTokenAnnotation(claudeFile);
|
|
@@ -391,20 +370,8 @@ function linkProject(phrenPath, project, tools, caps) {
|
|
|
391
370
|
}
|
|
392
371
|
// Project-level skills
|
|
393
372
|
const targetSkills = path.join(target, ".claude", "skills");
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
: undefined;
|
|
397
|
-
if (tools.has("codex") && fs.existsSync(claudeFile)) {
|
|
398
|
-
try {
|
|
399
|
-
const manifest = skillManifest || syncScopeSkillsToDir(phrenPath, project, targetSkills);
|
|
400
|
-
const agentsContent = `${fs.readFileSync(claudeFile, "utf8").trimEnd()}\n\n${GENERATED_AGENTS_MARKER}\n${renderSkillInstructionsSection(manifest)}\n`;
|
|
401
|
-
if (writeManagedAgentsFile(claudeFile, path.join(target, "AGENTS.md"), agentsContent, phrenPath))
|
|
402
|
-
excludeEntries.push("AGENTS.md");
|
|
403
|
-
}
|
|
404
|
-
catch (err) {
|
|
405
|
-
logger.debug("link", `linkProject agentsMd: ${errorMessage(err)}`);
|
|
406
|
-
}
|
|
407
|
-
}
|
|
373
|
+
if (config.skills !== false)
|
|
374
|
+
syncScopeSkillsToDir(phrenPath, project, targetSkills);
|
|
408
375
|
// Auto-exclude phren-managed files from git status
|
|
409
376
|
if (excludeEntries.length > 0)
|
|
410
377
|
addGitExcludes(target, excludeEntries);
|
|
@@ -548,6 +515,7 @@ export async function runLink(phrenPath, opts = {}) {
|
|
|
548
515
|
else {
|
|
549
516
|
log(` Hooks registration skipped (hooks-mode is off)`);
|
|
550
517
|
}
|
|
518
|
+
await reconcileModuleHooks(phrenPath, profile);
|
|
551
519
|
// Write phren.SKILL.md
|
|
552
520
|
try {
|
|
553
521
|
writeSkillMd(phrenPath);
|
package/dist/link/refresh.js
CHANGED
|
@@ -34,8 +34,8 @@ export function refreshLinkedContext(phrenPath, profile) {
|
|
|
34
34
|
? syncScopeSkillsToDir(phrenPath, project, skillsDir)
|
|
35
35
|
: buildSkillManifest(phrenPath, profile, project);
|
|
36
36
|
const agentsPath = path.join(target, "AGENTS.md");
|
|
37
|
-
const claudePath = path.join(source, "
|
|
38
|
-
// The generated file is a snapshot, unlike the live
|
|
37
|
+
const claudePath = path.join(source, "AGENTS.md");
|
|
38
|
+
// The generated file is a snapshot, unlike the live AGENTS.md symlink.
|
|
39
39
|
// Preserve native/user-owned instructions and installations without a Codex mirror.
|
|
40
40
|
if (!fs.existsSync(agentsPath) || !fs.existsSync(claudePath) || fs.lstatSync(agentsPath).isSymbolicLink())
|
|
41
41
|
continue;
|
package/dist/link/skills.js
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import { atomicWriteText } from "../phren-paths.js";
|
|
3
|
+
import { moduleSnapshot } from "../modules/runtime.js";
|
|
4
|
+
import { getRegisteredTools } from "../tool-registry.js";
|
|
1
5
|
import * as fs from "fs";
|
|
2
6
|
import * as path from "path";
|
|
3
7
|
import * as yaml from "js-yaml";
|
|
@@ -7,7 +11,7 @@ import { errorMessage } from "../utils.js";
|
|
|
7
11
|
import { buildSharedLifecycleCommands } from "../hooks.js";
|
|
8
12
|
import { VERSION } from "../package-metadata.js";
|
|
9
13
|
import { getToolCount, renderToolCatalogMarkdown } from "../tool-registry.js";
|
|
10
|
-
import {
|
|
14
|
+
import { readSkillEnabledState } from "../skill/state.js";
|
|
11
15
|
import { logger } from "../logger.js";
|
|
12
16
|
const REQUIRED_SKILL_FIELDS = ["name", "description"];
|
|
13
17
|
export function parseSkillFrontmatter(rawContent) {
|
|
@@ -202,11 +206,12 @@ export function linkSkillsDir(srcDir, destDir, managedRoot, symlinkFile, opts) {
|
|
|
202
206
|
fs.mkdirSync(destDir, { recursive: true });
|
|
203
207
|
const expectedNames = new Set();
|
|
204
208
|
const collisions = [];
|
|
209
|
+
const isEnabled = opts?.phrenPath && opts.scope ? readSkillEnabledState(opts.phrenPath) : undefined;
|
|
205
210
|
for (const entry of fs.readdirSync(srcDir)) {
|
|
206
211
|
const srcPath = path.join(srcDir, entry);
|
|
207
212
|
const stat = fs.statSync(srcPath);
|
|
208
213
|
const skillName = stat.isDirectory() ? entry : entry.replace(/\.md$/, "");
|
|
209
|
-
if (
|
|
214
|
+
if (isEnabled && opts?.scope && !isEnabled(opts.scope, skillName)) {
|
|
210
215
|
continue;
|
|
211
216
|
}
|
|
212
217
|
if (stat.isFile() && entry.endsWith(".md")) {
|
|
@@ -254,8 +259,10 @@ export function writeSkillMd(phrenPath) {
|
|
|
254
259
|
const promptCmd = lifecycle.userPromptSubmit.replace(/"/g, '\\"');
|
|
255
260
|
const stopCmd = lifecycle.stop.replace(/"/g, '\\"');
|
|
256
261
|
const version = VERSION;
|
|
257
|
-
const
|
|
258
|
-
const
|
|
262
|
+
const allowed = new Set(moduleSnapshot(phrenPath).modules.flatMap(module => module.tools.map(tool => tool.name)));
|
|
263
|
+
const excluded = getRegisteredTools().filter(tool => !allowed.has(tool.name));
|
|
264
|
+
const toolCount = getToolCount() - excluded.length;
|
|
265
|
+
const toolCatalog = excluded.length ? renderToolCatalogMarkdown(allowed) : renderToolCatalogMarkdown();
|
|
259
266
|
const content = `---
|
|
260
267
|
name: phren
|
|
261
268
|
description: Long-term memory for your AI agents with automatic context injection and finding capture
|
|
@@ -295,5 +302,19 @@ ${toolCatalog}
|
|
|
295
302
|
|
|
296
303
|
`;
|
|
297
304
|
const dest = path.join(phrenPath, "phren.SKILL.md");
|
|
298
|
-
|
|
305
|
+
const ledger = path.join(phrenPath, ".runtime", "module-skill.sha256");
|
|
306
|
+
const digest = (text) => createHash("sha256").update(text).digest("hex");
|
|
307
|
+
const stat = fs.lstatSync(dest, { throwIfNoEntry: false });
|
|
308
|
+
if (stat) {
|
|
309
|
+
if (!stat.isFile() || stat.isSymbolicLink())
|
|
310
|
+
return;
|
|
311
|
+
const existing = fs.readFileSync(dest, "utf8");
|
|
312
|
+
const previous = fs.existsSync(ledger) ? fs.readFileSync(ledger, "utf8").trim() : "";
|
|
313
|
+
const legacy = content.replace(`## MCP tools (${toolCount})\n\n${toolCatalog}`, `## MCP tools (${getToolCount()})\n\n${renderToolCatalogMarkdown()}`);
|
|
314
|
+
if (existing !== content && existing !== legacy && digest(existing) !== previous)
|
|
315
|
+
return;
|
|
316
|
+
}
|
|
317
|
+
atomicWriteText(dest, content);
|
|
318
|
+
fs.mkdirSync(path.dirname(ledger), { recursive: true });
|
|
319
|
+
atomicWriteText(ledger, digest(content) + "\n");
|
|
299
320
|
}
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
export declare function machineFilePath(): string;
|
|
2
2
|
export declare function defaultMachineName(): string;
|
|
3
3
|
export declare function getMachineName(): string;
|
|
4
|
+
/** A store commit's subject with this machine's name, so `git log` on a synced
|
|
5
|
+
* store shows which computer wrote each change. */
|
|
6
|
+
export declare function storeCommitMessage(message: string): string;
|
|
4
7
|
export declare function persistMachineName(machine: string): void;
|
|
5
8
|
export declare function getCurrentActor(): string;
|
package/dist/machine-identity.js
CHANGED
|
@@ -25,6 +25,12 @@ export function getMachineName() {
|
|
|
25
25
|
}
|
|
26
26
|
return (cachedMachineName = defaultMachineName());
|
|
27
27
|
}
|
|
28
|
+
/** A store commit's subject with this machine's name, so `git log` on a synced
|
|
29
|
+
* store shows which computer wrote each change. */
|
|
30
|
+
export function storeCommitMessage(message) {
|
|
31
|
+
const machine = getMachineName().replace(/[\r\n\]]/g, " ").trim();
|
|
32
|
+
return machine ? `${message} [${machine}]` : message;
|
|
33
|
+
}
|
|
28
34
|
export function persistMachineName(machine) {
|
|
29
35
|
const normalized = machine.trim();
|
|
30
36
|
if (!normalized)
|
package/dist/mcp/profile.d.ts
CHANGED
|
@@ -1,18 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
* MCP tool profiles.
|
|
3
|
-
*
|
|
4
|
-
* The server used to hand every client 59 tools, about 11k tokens of schema
|
|
5
|
-
* before a word was said, and 59 similar verbs to choose the wrong one from.
|
|
6
|
-
* The `core` profile (the default) exposes the handful an agent reaches for
|
|
7
|
-
* during normal work plus one `phren_admin` tool that reaches everything
|
|
8
|
-
* else by name. `full` is the old surface for anyone who scripted against
|
|
9
|
-
* it, and it also gains the composites.
|
|
10
|
-
*
|
|
11
|
-
* Nothing here knows how a tool works. Modules register tools exactly as
|
|
12
|
-
* before; the server's registerTool wrapper records each one in a catalog and
|
|
13
|
-
* only exposes the core ones, and the composites built here dispatch into
|
|
14
|
-
* that catalog, validating against the target tool's own schema first.
|
|
15
|
-
*/
|
|
1
|
+
import type { ModuleManifest } from "../modules/manifest.js";
|
|
16
2
|
export type McpProfile = "core" | "full";
|
|
17
3
|
export declare const MCP_PROFILES: readonly McpProfile[];
|
|
18
4
|
/** What an agent gets in the core profile. Order is the order clients list them. */
|
|
@@ -56,6 +42,7 @@ export interface ToolGate {
|
|
|
56
42
|
*/
|
|
57
43
|
export declare function createToolGate(opts: {
|
|
58
44
|
profile: McpProfile;
|
|
45
|
+
modules?: readonly ModuleManifest[];
|
|
59
46
|
register: (name: string, config: ToolConfig, handler: ToolHandler) => unknown;
|
|
60
47
|
/** Wraps every handler (guards, telemetry) before it is stored or exposed. */
|
|
61
48
|
wrap?: (name: string, handler: ToolHandler) => ToolHandler;
|
|
@@ -74,7 +61,3 @@ export interface BuiltTool {
|
|
|
74
61
|
* (a module not loaded, say) is left out rather than advertised.
|
|
75
62
|
*/
|
|
76
63
|
export declare function buildCompositeTools(catalog: Catalog): BuiltTool[];
|
|
77
|
-
/** Rough size of what a client downloads for a set of tools, for tests and doctor. */
|
|
78
|
-
export declare function schemaWeight(entries: Iterable<{
|
|
79
|
-
config: ToolConfig;
|
|
80
|
-
}>): number;
|
package/dist/mcp/profile.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { toolOwner, disabledHint } from "../modules/registry.js";
|
|
1
2
|
/**
|
|
2
3
|
* MCP tool profiles.
|
|
3
4
|
*
|
|
@@ -125,7 +126,9 @@ export function decorateAddFinding(entry, catalog) {
|
|
|
125
126
|
* Code, and registers the composites when `finish` is called.
|
|
126
127
|
*/
|
|
127
128
|
export function createToolGate(opts) {
|
|
128
|
-
const
|
|
129
|
+
const allowed = opts.modules && new Set(opts.modules.flatMap(module => module.tools.map(tool => tool.name)));
|
|
130
|
+
const core = opts.modules ? CORE_TOOLS.filter(name => opts.modules.some(module => module.tools.some(tool => tool.name === name && tool.profiles.includes("core")))) : CORE_TOOLS;
|
|
131
|
+
const alwaysLoad = new Set([...core, ...(opts.alwaysLoad ?? [])]);
|
|
129
132
|
const catalog = new Map();
|
|
130
133
|
const exposed = new Set();
|
|
131
134
|
const expose = (name, config, handler) => {
|
|
@@ -138,6 +141,8 @@ export function createToolGate(opts) {
|
|
|
138
141
|
exposed.add(name);
|
|
139
142
|
};
|
|
140
143
|
const registerTool = (name, config, handler) => {
|
|
144
|
+
if (allowed && !allowed.has(name))
|
|
145
|
+
return;
|
|
141
146
|
if (catalog.has(name))
|
|
142
147
|
throw new Error(`Duplicate MCP tool registration: "${name}"`);
|
|
143
148
|
const wrapped = opts.wrap ? opts.wrap(name, handler) : handler;
|
|
@@ -145,13 +150,13 @@ export function createToolGate(opts) {
|
|
|
145
150
|
if (name === "add_finding")
|
|
146
151
|
entry = decorateAddFinding(entry, catalog);
|
|
147
152
|
catalog.set(name, entry);
|
|
148
|
-
if (opts.profile === "core" && !
|
|
153
|
+
if (opts.profile === "core" && !core.includes(name))
|
|
149
154
|
return;
|
|
150
155
|
expose(name, entry.config, entry.handler);
|
|
151
156
|
};
|
|
152
157
|
const finish = () => {
|
|
153
158
|
for (const tool of buildCompositeTools(catalog)) {
|
|
154
|
-
if (catalog.has(tool.name))
|
|
159
|
+
if (catalog.has(tool.name) || (allowed && !allowed.has(tool.name)))
|
|
155
160
|
continue;
|
|
156
161
|
catalog.set(tool.name, { name: tool.name, config: tool.config, handler: tool.handler });
|
|
157
162
|
expose(tool.name, tool.config, tool.handler);
|
|
@@ -192,14 +197,64 @@ function actionLine(action, entry) {
|
|
|
192
197
|
function errorResponse(error, extra = {}) {
|
|
193
198
|
return { content: [{ type: "text", text: JSON.stringify({ ok: false, error, ...extra }, null, 2) }] };
|
|
194
199
|
}
|
|
200
|
+
/**
|
|
201
|
+
* A composite's schema is `passthrough`, so the host serializes whatever it
|
|
202
|
+
* does not recognize; Claude Code hands nested objects (`updates`, `settings`)
|
|
203
|
+
* over as JSON strings, sometimes wrapped twice. A JSON-looking string whose
|
|
204
|
+
* decode validates replaces the raw string; so does a decode that does not
|
|
205
|
+
* validate when the raw string never would, so the miss reports its real inner
|
|
206
|
+
* path instead of "expected object, received string". A string the field
|
|
207
|
+
* accepts as-is (JSON that is genuinely text) and a string that is not JSON
|
|
208
|
+
* are left to the schema's own error. The same untyped schema turns a number
|
|
209
|
+
* or a boolean into its text ("5", "true"); that text is decoded only when the
|
|
210
|
+
* field rejects it and accepts the decoded value.
|
|
211
|
+
*/
|
|
212
|
+
function decodeJsonArguments(schema, args) {
|
|
213
|
+
const out = { ...args };
|
|
214
|
+
for (const [key, value] of Object.entries(args)) {
|
|
215
|
+
if (typeof value !== "string")
|
|
216
|
+
continue;
|
|
217
|
+
const field = schema.shape[key];
|
|
218
|
+
if (!field)
|
|
219
|
+
continue;
|
|
220
|
+
const text = value.trim();
|
|
221
|
+
if (/^(?:true|false|-?\d+(?:\.\d+)?)$/.test(text)) {
|
|
222
|
+
const primitive = text === "true" ? true : text === "false" ? false : Number(text);
|
|
223
|
+
if (!field.safeParse(value).success && field.safeParse(primitive).success)
|
|
224
|
+
out[key] = primitive;
|
|
225
|
+
continue;
|
|
226
|
+
}
|
|
227
|
+
if (!/^\s*[[{"]/.test(value))
|
|
228
|
+
continue;
|
|
229
|
+
let decoded = value;
|
|
230
|
+
for (let hop = 0; hop < 3; hop++) {
|
|
231
|
+
if (typeof decoded !== "string" || !/^\s*[[{"]/.test(decoded))
|
|
232
|
+
break;
|
|
233
|
+
try {
|
|
234
|
+
decoded = JSON.parse(decoded);
|
|
235
|
+
}
|
|
236
|
+
catch {
|
|
237
|
+
decoded = undefined;
|
|
238
|
+
break;
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
if (decoded === undefined || decoded === null || typeof decoded !== "object")
|
|
242
|
+
continue;
|
|
243
|
+
if (field.safeParse(decoded).success || !field.safeParse(value).success)
|
|
244
|
+
out[key] = decoded;
|
|
245
|
+
}
|
|
246
|
+
return out;
|
|
247
|
+
}
|
|
195
248
|
/** Run a catalog tool by name after validating the arguments against its own schema. */
|
|
196
249
|
export async function dispatch(catalog, target, args) {
|
|
197
250
|
const entry = catalog.get(target);
|
|
198
|
-
if (!entry)
|
|
199
|
-
|
|
251
|
+
if (!entry) {
|
|
252
|
+
const owner = toolOwner(target);
|
|
253
|
+
return errorResponse(`Unknown tool "${target}"${owner ? `: ${disabledHint(owner.name)}` : ""}`, { errorCode: "UNAVAILABLE" });
|
|
254
|
+
}
|
|
200
255
|
const schema = schemaOf(entry);
|
|
201
256
|
if (schema) {
|
|
202
|
-
const parsed = schema.safeParse(args);
|
|
257
|
+
const parsed = schema.safeParse(decodeJsonArguments(schema, args));
|
|
203
258
|
if (!parsed.success) {
|
|
204
259
|
return errorResponse(`Invalid arguments for ${target}`, {
|
|
205
260
|
issues: parsed.error.issues.map((i) => ({ path: i.path.join("."), message: i.message })),
|
|
@@ -228,11 +283,11 @@ export function buildCompositeTools(catalog) {
|
|
|
228
283
|
config: {
|
|
229
284
|
title: composite.title,
|
|
230
285
|
description: `${composite.summary}\nActions:\n${lines.map((l) => `- ${l}`).join("\n")}`,
|
|
231
|
-
inputSchema: z.object({ action: z.
|
|
286
|
+
inputSchema: z.object({ action: z.string().describe(`Which change to make: ${actionNames.join(", ")}.`) }).passthrough(),
|
|
232
287
|
},
|
|
233
288
|
handler: (args) => {
|
|
234
289
|
const { action, ...rest } = args;
|
|
235
|
-
return dispatch(catalog, map[action], rest);
|
|
290
|
+
return dispatch(catalog, map[action] ?? composite.actions[action] ?? action, rest);
|
|
236
291
|
},
|
|
237
292
|
});
|
|
238
293
|
}
|
|
@@ -250,7 +305,7 @@ export function buildCompositeTools(catalog) {
|
|
|
250
305
|
description: "Everything else phren can do — skills, hooks, config, notes, review queue, export/import, doctor, the fragment graph — behind one tool. " +
|
|
251
306
|
"Pass `action` plus that action's parameters; `list_actions` returns every action with its full parameter list.\nActions:\n" +
|
|
252
307
|
lines.map((l) => `- ${l}`).join("\n"),
|
|
253
|
-
inputSchema: z.object({ action: z.
|
|
308
|
+
inputSchema: z.object({ action: z.string().describe(`Which admin action to run: ${actionNames.join(", ")}.`) }).passthrough(),
|
|
254
309
|
},
|
|
255
310
|
handler: (args) => {
|
|
256
311
|
const { action, ...rest } = args;
|
|
@@ -267,16 +322,3 @@ export function buildCompositeTools(catalog) {
|
|
|
267
322
|
}
|
|
268
323
|
return out;
|
|
269
324
|
}
|
|
270
|
-
/** Rough size of what a client downloads for a set of tools, for tests and doctor. */
|
|
271
|
-
export function schemaWeight(entries) {
|
|
272
|
-
let chars = 0;
|
|
273
|
-
for (const { config } of entries) {
|
|
274
|
-
chars += (config.title ?? "").length + (config.description ?? "").length;
|
|
275
|
-
const raw = config.inputSchema;
|
|
276
|
-
const schema = raw instanceof z.ZodObject ? raw : raw && typeof raw === "object" ? z.object(raw) : null;
|
|
277
|
-
if (schema)
|
|
278
|
-
for (const [k, t] of Object.entries(schema.shape))
|
|
279
|
-
chars += k.length + (t.description ?? "").length + 24;
|
|
280
|
-
}
|
|
281
|
-
return chars;
|
|
282
|
-
}
|