@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/cli/actions.js
CHANGED
|
@@ -138,7 +138,20 @@ export async function handleDoctor(args) {
|
|
|
138
138
|
}
|
|
139
139
|
process.exit(0);
|
|
140
140
|
}
|
|
141
|
-
const
|
|
141
|
+
const confirmStoreRemoval = async (message) => {
|
|
142
|
+
// Unlike init's general confirmation helper, absent stdin is never consent.
|
|
143
|
+
if (!process.stdin.isTTY || !process.stdout.isTTY || process.env.CI === "true")
|
|
144
|
+
return false;
|
|
145
|
+
const { createInterface } = await import("node:readline/promises");
|
|
146
|
+
const prompt = createInterface({ input: process.stdin, output: process.stdout });
|
|
147
|
+
try {
|
|
148
|
+
return /^(y|yes)$/i.test((await prompt.question(`${message} [y/N] `)).trim());
|
|
149
|
+
}
|
|
150
|
+
finally {
|
|
151
|
+
prompt.close();
|
|
152
|
+
}
|
|
153
|
+
};
|
|
154
|
+
const result = await runDoctor(getPhrenPath(), fix, checkData, confirmStoreRemoval);
|
|
142
155
|
if (agentsOnly) {
|
|
143
156
|
const agentChecks = result.checks.filter((check) => check.name.includes("cursor") || check.name.includes("copilot") || check.name.includes("codex") || check.name.includes("windsurf"));
|
|
144
157
|
console.log(`phren doctor --agents: ${agentChecks.every((check) => check.ok) ? "all configured" : "some not configured"}`);
|
|
@@ -3,6 +3,27 @@ import { getIndexPolicy, updateIndexPolicy, getRetentionPolicy, updateRetentionP
|
|
|
3
3
|
import { updateProjectConfigOverrides } from "../project-config.js";
|
|
4
4
|
import { isValidProjectName } from "../utils.js";
|
|
5
5
|
import { parseProjectArg, warnIfUnregistered } from "./config-shared.js";
|
|
6
|
+
/**
|
|
7
|
+
* Exit 1 unless every `set` token is a `--key=value` pair. The parsers below skip
|
|
8
|
+
* anything else, so `set ttlDays 90` or `set --ttlDays 90` used to write an
|
|
9
|
+
* unchanged config and print it as if the change had applied.
|
|
10
|
+
*/
|
|
11
|
+
function requireFlagPairs(setArgs, usage) {
|
|
12
|
+
const isPair = (arg) => {
|
|
13
|
+
if (!arg.startsWith("--"))
|
|
14
|
+
return false;
|
|
15
|
+
const [k, v] = arg.slice(2).split("=");
|
|
16
|
+
return Boolean(k) && v !== undefined;
|
|
17
|
+
};
|
|
18
|
+
const bad = setArgs.filter((arg) => !isPair(arg));
|
|
19
|
+
if (setArgs.length > 0 && bad.length === 0)
|
|
20
|
+
return;
|
|
21
|
+
console.error("No settings changed: every value must be given as --key=value.");
|
|
22
|
+
if (bad.length > 0)
|
|
23
|
+
console.error(` Not understood: ${bad.join(" ")}`);
|
|
24
|
+
console.error(` Usage: ${usage}`);
|
|
25
|
+
process.exit(1);
|
|
26
|
+
}
|
|
6
27
|
// ── Finding sensitivity config ────────────────────────────────────────────────
|
|
7
28
|
export const FINDING_SENSITIVITY_CONFIG = {
|
|
8
29
|
minimal: {
|
|
@@ -185,6 +206,7 @@ export async function handleRetentionPolicy(args) {
|
|
|
185
206
|
console.error(`Invalid project name: "${projectArg}"`);
|
|
186
207
|
process.exit(1);
|
|
187
208
|
}
|
|
209
|
+
requireFlagPairs(filteredArgs.slice(1), "phren config policy set --project <name> --ttlDays=90 --retentionDays=365");
|
|
188
210
|
warnIfUnregistered(phrenPath, projectArg);
|
|
189
211
|
updateProjectConfigOverrides(phrenPath, projectArg, (current) => {
|
|
190
212
|
const existingRetention = current.retentionPolicy ?? {};
|
|
@@ -211,6 +233,7 @@ export async function handleRetentionPolicy(args) {
|
|
|
211
233
|
console.log(JSON.stringify({ _project: projectArg, ...resolved.retentionPolicy }, null, 2));
|
|
212
234
|
return;
|
|
213
235
|
}
|
|
236
|
+
requireFlagPairs(filteredArgs.slice(1), "phren config policy set --ttlDays=90 --retentionDays=365");
|
|
214
237
|
const patch = {};
|
|
215
238
|
for (const arg of filteredArgs.slice(1)) {
|
|
216
239
|
if (!arg.startsWith("--"))
|
|
@@ -264,6 +287,7 @@ export async function handleWorkflowPolicy(args) {
|
|
|
264
287
|
console.error(`Invalid project name: "${projectArg}"`);
|
|
265
288
|
process.exit(1);
|
|
266
289
|
}
|
|
290
|
+
requireFlagPairs(filteredArgs.slice(1), "phren config workflow set --project <name> --lowConfidenceThreshold=0.7");
|
|
267
291
|
warnIfUnregistered(phrenPath, projectArg);
|
|
268
292
|
updateProjectConfigOverrides(phrenPath, projectArg, (current) => {
|
|
269
293
|
const nextConfig = { ...current };
|
|
@@ -298,6 +322,7 @@ export async function handleWorkflowPolicy(args) {
|
|
|
298
322
|
console.log(JSON.stringify({ _project: projectArg, ...resolved.workflowPolicy }, null, 2));
|
|
299
323
|
return;
|
|
300
324
|
}
|
|
325
|
+
requireFlagPairs(filteredArgs.slice(1), "phren config workflow set --lowConfidenceThreshold=0.7 --riskySections=Stale,Conflicts");
|
|
301
326
|
const patch = {};
|
|
302
327
|
for (const arg of filteredArgs.slice(1)) {
|
|
303
328
|
if (!arg.startsWith("--"))
|
|
@@ -11,5 +11,7 @@ export declare function buildProactivitySnapshot(phrenPath: string): {
|
|
|
11
11
|
proactivityTask: "high" | "low" | "medium";
|
|
12
12
|
};
|
|
13
13
|
};
|
|
14
|
-
|
|
14
|
+
type ProactivitySubcommand = "proactivity" | "proactivity.findings" | "proactivity.tasks";
|
|
15
|
+
export declare function handleConfigProactivity(requested: ProactivitySubcommand, args: string[]): void;
|
|
15
16
|
export declare function handleConfigProjectOwnership(args: string[]): void;
|
|
17
|
+
export {};
|
|
@@ -31,11 +31,43 @@ function normalizeProactivityLevel(raw) {
|
|
|
31
31
|
: undefined;
|
|
32
32
|
}
|
|
33
33
|
function printProactivityUsage(subcommand) {
|
|
34
|
-
console.error(
|
|
34
|
+
console.error(subcommand === "proactivity"
|
|
35
|
+
? "Usage: phren config proactivity [high|medium|low] [--scope base|findings|tasks] [--project <name>]"
|
|
36
|
+
: `Usage: phren config ${subcommand} [high|medium|low] [--project <name>]`);
|
|
35
37
|
}
|
|
36
|
-
|
|
38
|
+
const SCOPE_SUBCOMMANDS = {
|
|
39
|
+
base: "proactivity", findings: "proactivity.findings", tasks: "proactivity.tasks", task: "proactivity.tasks",
|
|
40
|
+
};
|
|
41
|
+
/** `--scope tasks` on the base command is the same as `proactivity.tasks`. */
|
|
42
|
+
function parseScopeArg(args) {
|
|
43
|
+
const rest = [];
|
|
44
|
+
let scope, invalid;
|
|
45
|
+
for (let i = 0; i < args.length; i++) {
|
|
46
|
+
const arg = args[i];
|
|
47
|
+
const inline = arg.startsWith("--scope=") ? arg.slice("--scope=".length) : undefined;
|
|
48
|
+
if (arg === "--scope" || inline !== undefined) {
|
|
49
|
+
const raw = inline ?? args[++i] ?? "";
|
|
50
|
+
const match = SCOPE_SUBCOMMANDS[raw.trim().toLowerCase()];
|
|
51
|
+
if (match)
|
|
52
|
+
scope = match;
|
|
53
|
+
else
|
|
54
|
+
invalid = raw;
|
|
55
|
+
continue;
|
|
56
|
+
}
|
|
57
|
+
rest.push(arg);
|
|
58
|
+
}
|
|
59
|
+
return { scope, rest, invalid };
|
|
60
|
+
}
|
|
61
|
+
export function handleConfigProactivity(requested, args) {
|
|
37
62
|
const phrenPath = getPhrenPath();
|
|
38
|
-
const
|
|
63
|
+
const scoped = parseScopeArg(args);
|
|
64
|
+
if (scoped.invalid !== undefined || (scoped.scope && requested !== "proactivity")) {
|
|
65
|
+
printProactivityUsage(requested);
|
|
66
|
+
process.exitCode = 1;
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
const subcommand = scoped.scope ?? requested;
|
|
70
|
+
const { project: projectArg, rest: filteredArgs } = parseProjectArg(scoped.rest);
|
|
39
71
|
const value = filteredArgs[0];
|
|
40
72
|
if (value === undefined) {
|
|
41
73
|
if (projectArg) {
|
package/dist/cli/config.js
CHANGED
|
@@ -148,11 +148,14 @@ Subcommands:
|
|
|
148
148
|
phren config policy [get|set ...] Memory retention, TTL, confidence, decay
|
|
149
149
|
phren config workflow [get|set ...] Risky-memory thresholds, task automation mode
|
|
150
150
|
phren config index [get|set ...] Indexer include/exclude globs
|
|
151
|
-
phren config proactivity [level]
|
|
151
|
+
phren config proactivity [level] [--scope base|findings|tasks]
|
|
152
|
+
Auto-capture level (high|medium|low); --scope sets
|
|
153
|
+
the findings-only or task-only override instead
|
|
152
154
|
phren config proactivity.findings [level]
|
|
153
155
|
Findings-specific auto-capture level override
|
|
154
156
|
phren config proactivity.tasks [level]
|
|
155
157
|
Task-specific auto-capture level override
|
|
158
|
+
(all take --project <name> for one project)
|
|
156
159
|
phren config task-mode [get|set <mode>]
|
|
157
160
|
Task automation mode (off|manual|suggest|auto)
|
|
158
161
|
phren config finding-sensitivity [get|set <level>]
|
package/dist/cli/extract.d.ts
CHANGED
|
@@ -18,14 +18,6 @@ export declare function scoreFindingCandidate(subject: string, body: string): {
|
|
|
18
18
|
score: number;
|
|
19
19
|
text: string;
|
|
20
20
|
} | null;
|
|
21
|
-
/**
|
|
22
|
-
* Dedup key for the human-readable part of a candidate.
|
|
23
|
-
*
|
|
24
|
-
* Hash dedup alone is necessary but not sufficient: rebased history re-scrapes an identical
|
|
25
|
-
* commit message under a new hash (observed pairs 0a918619/c55f38fa and 6b9a2ab9/9479d2ad),
|
|
26
|
-
* so the same finding still arrives twice.
|
|
27
|
-
*/
|
|
28
|
-
export declare function extractSubjectKey(text: string): string;
|
|
29
21
|
/**
|
|
30
22
|
* Render the provenance a queued candidate needs to stay promotable.
|
|
31
23
|
*
|
package/dist/cli/extract.js
CHANGED
|
@@ -2,7 +2,7 @@ import { debugLog, appendAuditLog, atomicWriteText, EXEC_TIMEOUT_MS, getPhrenPat
|
|
|
2
2
|
import { appendReviewQueue, getRetentionPolicy, recordFeedback, flushEntryScores, entryScoreKey, } from "../shared/governance.js";
|
|
3
3
|
import { detectProject } from "../shared/index.js";
|
|
4
4
|
import { commandExists } from "../hooks.js";
|
|
5
|
-
import { runGit
|
|
5
|
+
import { runGit, isFeatureEnabled, clampInt, errorMessage, isValidProjectName, resolveExecCommand } from "../utils.js";
|
|
6
6
|
import { storeAwareProjectPath } from "../store-routing.js";
|
|
7
7
|
import { appendFindingJournal, compactFindingJournals } from "../finding/journal.js";
|
|
8
8
|
import { findingQualityReason } from "../content/quality.js";
|
|
@@ -15,9 +15,6 @@ import * as crypto from "crypto";
|
|
|
15
15
|
import { execFileSync } from "child_process";
|
|
16
16
|
import { resolveRuntimeProfile } from "../runtime-profile.js";
|
|
17
17
|
import { buildCitationComment, buildSourceComment, } from "../content/citation.js";
|
|
18
|
-
function runGit(cwd, args) {
|
|
19
|
-
return runGitShared(cwd, args, EXEC_TIMEOUT_MS, debugLog);
|
|
20
|
-
}
|
|
21
18
|
function shouldRetryGh(err) {
|
|
22
19
|
const message = err instanceof Error
|
|
23
20
|
? err.message
|
|
@@ -35,7 +32,7 @@ function inferProject(arg) {
|
|
|
35
32
|
// ── Git log parsing ──────────────────────────────────────────────────────────
|
|
36
33
|
export function parseGitLogRecords(cwd, days) {
|
|
37
34
|
const fmt = "%H%x1f%s%x1f%b%x1e";
|
|
38
|
-
const raw = runGit(cwd, ["log", `--since=${days} days ago`, "--first-parent", `--pretty=format:${fmt}`]) || "";
|
|
35
|
+
const raw = runGit(cwd, ["log", `--since=${days} days ago`, "--first-parent", `--pretty=format:${fmt}`], EXEC_TIMEOUT_MS, debugLog) || "";
|
|
39
36
|
const records = [];
|
|
40
37
|
for (const rec of raw.split("\x1e")) {
|
|
41
38
|
const trimmed = rec.trim();
|
|
@@ -234,7 +231,7 @@ function shortHash(hash) {
|
|
|
234
231
|
* commit message under a new hash (observed pairs 0a918619/c55f38fa and 6b9a2ab9/9479d2ad),
|
|
235
232
|
* so the same finding still arrives twice.
|
|
236
233
|
*/
|
|
237
|
-
|
|
234
|
+
function extractSubjectKey(text) {
|
|
238
235
|
return text
|
|
239
236
|
.replace(/<!--[\s\S]*?-->/g, " ")
|
|
240
237
|
.replace(new RegExp(SOURCE_COMMIT_MARKER.source, "gi"), " ")
|
|
@@ -410,7 +407,7 @@ export async function handleExtractMemories(projectArg, cwdArg, silent = false,
|
|
|
410
407
|
process.exit(1);
|
|
411
408
|
return;
|
|
412
409
|
}
|
|
413
|
-
const repoRoot = runGit(cwdArg || process.cwd(), ["rev-parse", "--show-toplevel"]);
|
|
410
|
+
const repoRoot = runGit(cwdArg || process.cwd(), ["rev-parse", "--show-toplevel"], EXEC_TIMEOUT_MS, debugLog);
|
|
414
411
|
if (!repoRoot) {
|
|
415
412
|
if (!silent)
|
|
416
413
|
console.error("extract-memories must run from inside a git repository.");
|
package/dist/cli/govern.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { nonInteractiveGitEnv } from "../utils-helpers.js";
|
|
1
2
|
import { appendAuditLog, qualityMarkers, getProjectDirs, getPhrenPath, } from "../shared.js";
|
|
2
3
|
import { appendReviewQueue, getRetentionPolicy, consolidateProjectFindings, updateRuntimeHealth, pruneDeadMemories, } from "../shared/governance.js";
|
|
3
4
|
import { filterTrustedFindingsDetailed, } from "../shared/content.js";
|
|
@@ -166,7 +167,7 @@ async function handleGcMaintain(args = []) {
|
|
|
166
167
|
}
|
|
167
168
|
else {
|
|
168
169
|
try {
|
|
169
|
-
execFileSync("git", ["gc", "--aggressive", "--quiet"], { cwd: phrenPath, stdio: "pipe" });
|
|
170
|
+
execFileSync("git", ["gc", "--aggressive", "--quiet"], { env: nonInteractiveGitEnv(), cwd: phrenPath, stdio: "pipe" });
|
|
170
171
|
report.gitGcRan = true;
|
|
171
172
|
console.log("git gc --aggressive: done");
|
|
172
173
|
}
|
|
@@ -179,6 +180,7 @@ async function handleGcMaintain(args = []) {
|
|
|
179
180
|
let oldCommits = [];
|
|
180
181
|
try {
|
|
181
182
|
const raw = execFileSync("git", ["log", `--before=${sevenDaysAgo}`, "--format=%H %ci %s"], {
|
|
183
|
+
env: nonInteractiveGitEnv(),
|
|
182
184
|
cwd: phrenPath,
|
|
183
185
|
encoding: "utf8",
|
|
184
186
|
}).trim();
|
|
@@ -222,6 +224,7 @@ async function handleGcMaintain(args = []) {
|
|
|
222
224
|
const newest = hashes[0];
|
|
223
225
|
// Use git rev-parse to get the parent of the oldest commit
|
|
224
226
|
const parentOfOldest = execFileSync("git", ["rev-parse", `${oldest}^`], {
|
|
227
|
+
env: nonInteractiveGitEnv(),
|
|
225
228
|
cwd: phrenPath,
|
|
226
229
|
encoding: "utf8",
|
|
227
230
|
}).trim();
|
|
@@ -236,7 +239,7 @@ async function handleGcMaintain(args = []) {
|
|
|
236
239
|
execFileSync("git", ["rebase", "-i", parentOfOldest], {
|
|
237
240
|
cwd: phrenPath,
|
|
238
241
|
stdio: "pipe",
|
|
239
|
-
env: { ...process.env, GIT_SEQUENCE_EDITOR: `cat ${scriptPath} >` },
|
|
242
|
+
env: nonInteractiveGitEnv({ ...process.env, GIT_SEQUENCE_EDITOR: `cat ${scriptPath} >` }),
|
|
240
243
|
});
|
|
241
244
|
fs.unlinkSync(scriptPath);
|
|
242
245
|
report.commitsSquashed += hashes.length - 1;
|
package/dist/cli/hooks-globs.js
CHANGED
|
@@ -11,7 +11,7 @@ export function clearProjectGlobCache() {
|
|
|
11
11
|
function parseProjectGlobs(phrenPathLocal, project) {
|
|
12
12
|
if (projectGlobCache.has(project))
|
|
13
13
|
return projectGlobCache.get(project);
|
|
14
|
-
const claudeMdPath = path.join(phrenPathLocal, project, "
|
|
14
|
+
const claudeMdPath = path.join(phrenPathLocal, project, "AGENTS.md");
|
|
15
15
|
let globs = null;
|
|
16
16
|
try {
|
|
17
17
|
if (fs.existsSync(claudeMdPath)) {
|
package/dist/cli/hooks.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { parseCitations, validateCitation, annotateStale, clearCitationValidCache, type ParsedCitation, } from "./hooks-citations.js";
|
|
2
2
|
export { getProjectGlobBoost, clearProjectGlobCache, } from "./hooks-globs.js";
|
|
3
|
-
export { detectTaskIntent, filterTaskByPriority, searchDocuments, applyTrustFilter, rankResults, applyRelevanceFloor, DEFAULT_MIN_QUERY_RELEVANCE, selectSnippets, type SelectedSnippet, } from "../shared/retrieval.js";
|
|
3
|
+
export { detectTaskIntent, filterTaskByPriority, searchDocuments, applyTrustFilter, rankResults, applyRelevanceFloor, promptRarity, DEFAULT_MIN_QUERY_RELEVANCE, selectSnippets, type SelectedSnippet, } from "../shared/retrieval.js";
|
|
4
4
|
export { buildHookOutput, } from "./hooks-output.js";
|
|
5
5
|
export { handleHookSessionStart, handleHookStop, handleBackgroundSync, handleHookContext, handleHookTool, trackSessionMetrics, filterConversationInsightsForProactivity, extractToolFindings, filterToolFindingsForProactivity, resolveSubprocessArgs, } from "./hooks-session.js";
|
|
6
6
|
export interface HookPromptInput {
|
package/dist/cli/hooks.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { moduleEnabled } from "../modules/runtime.js";
|
|
1
2
|
// cli-hooks.ts — Thin orchestrator. Delegates to focused modules:
|
|
2
3
|
// shared-retrieval.ts — shared search, scoring, ranking, snippet selection
|
|
3
4
|
// cli-hooks-citations.ts — citation parsing and validation
|
|
@@ -25,13 +26,13 @@ export { parseCitations, validateCitation, annotateStale, clearCitationValidCach
|
|
|
25
26
|
// Globs
|
|
26
27
|
export { getProjectGlobBoost, clearProjectGlobCache, } from "./hooks-globs.js";
|
|
27
28
|
// Retrieval
|
|
28
|
-
export { detectTaskIntent, filterTaskByPriority, searchDocuments, applyTrustFilter, rankResults, applyRelevanceFloor, DEFAULT_MIN_QUERY_RELEVANCE, selectSnippets, } from "../shared/retrieval.js";
|
|
29
|
+
export { detectTaskIntent, filterTaskByPriority, searchDocuments, applyTrustFilter, rankResults, applyRelevanceFloor, promptRarity, DEFAULT_MIN_QUERY_RELEVANCE, selectSnippets, } from "../shared/retrieval.js";
|
|
29
30
|
// Output
|
|
30
31
|
export { buildHookOutput, } from "./hooks-output.js";
|
|
31
32
|
// Session
|
|
32
33
|
export { handleHookSessionStart, handleHookStop, handleBackgroundSync, handleHookContext, handleHookTool, trackSessionMetrics, filterConversationInsightsForProactivity, extractToolFindings, filterToolFindingsForProactivity, resolveSubprocessArgs, } from "./hooks-session.js";
|
|
33
34
|
// ── Imports for the orchestrator ─────────────────────────────────────────────
|
|
34
|
-
import { searchDocumentsAsync, applyTrustFilter, rankResults, applyRelevanceFloor, DEFAULT_MIN_QUERY_RELEVANCE, selectSnippets, detectTaskIntent, wantsTasks } from "../shared/retrieval.js";
|
|
35
|
+
import { searchDocumentsAsync, applyTrustFilter, rankResults, applyRelevanceFloor, promptRarity, DEFAULT_MIN_QUERY_RELEVANCE, selectSnippets, detectTaskIntent, wantsTasks } from "../shared/retrieval.js";
|
|
35
36
|
import { buildHookOutput } from "./hooks-output.js";
|
|
36
37
|
import { getGitContext, trackSessionMetrics, } from "./hooks-session.js";
|
|
37
38
|
import { approximateTokens, SNIPPET_OVERHEAD_TOKENS } from "../shared/retrieval.js";
|
|
@@ -134,7 +135,7 @@ export async function handleHookPrompt() {
|
|
|
134
135
|
}
|
|
135
136
|
// Resolve git context AFTER the enabled check — it spawns 3 git processes and is
|
|
136
137
|
// wasted work when the project has hooks disabled.
|
|
137
|
-
const gitCtx = getGitContext(cwd);
|
|
138
|
+
const gitCtx = moduleEnabled(getPhrenPath(), "git") ? getGitContext(cwd) : null;
|
|
138
139
|
const resolvedConfig = mergeConfig(getPhrenPath(), detectedProject ?? undefined);
|
|
139
140
|
const safeQuery = buildRobustFtsQuery(keywords, detectedProject, getPhrenPath());
|
|
140
141
|
if (!safeQuery)
|
|
@@ -162,7 +163,7 @@ export async function handleHookPrompt() {
|
|
|
162
163
|
const findingsProactivity = resolvedConfig.proactivity.findings
|
|
163
164
|
?? resolvedConfig.proactivity.base
|
|
164
165
|
?? getProactivityLevelForFindings(getPhrenPath());
|
|
165
|
-
if (isFeatureEnabled("PHREN_FEATURE_AUTO_EXTRACT", true) && findingsProactivity !== "low" && sessionId && detectedProject && cwd) {
|
|
166
|
+
if (moduleEnabled(getPhrenPath(), "git") && isFeatureEnabled("PHREN_FEATURE_AUTO_EXTRACT", true) && findingsProactivity !== "low" && sessionId && detectedProject && cwd) {
|
|
166
167
|
const marker = sessionMarker(getPhrenPath(), `extracted-${sessionId}-${detectedProject}`);
|
|
167
168
|
if (!fs.existsSync(marker)) {
|
|
168
169
|
try {
|
|
@@ -184,7 +185,8 @@ export async function handleHookPrompt() {
|
|
|
184
185
|
// than pad to a quota with noise (env PHREN_MIN_QUERY_RELEVANCE=0 disables).
|
|
185
186
|
const relevanceFloor = clampFloat(process.env.PHREN_MIN_QUERY_RELEVANCE, DEFAULT_MIN_QUERY_RELEVANCE, 0, 1);
|
|
186
187
|
const preFloorCount = rows.length;
|
|
187
|
-
|
|
188
|
+
debugLog(`relevance-floor candidates: ${rows.slice(0, 12).map((row) => `${row.project}/${row.filename}`).join(", ")}`);
|
|
189
|
+
rows = applyRelevanceFloor(rows, keywords, gitCtx, detectedProject, relevanceFloor, promptRarity(db, keywords));
|
|
188
190
|
if (rows.length !== preFloorCount) {
|
|
189
191
|
debugLog(`relevance-floor: ${preFloorCount} -> ${rows.length} rows (floor=${relevanceFloor})`);
|
|
190
192
|
}
|
|
@@ -285,14 +287,14 @@ export async function handleHookPrompt() {
|
|
|
285
287
|
const taskLevel = resolvedConfig.proactivity.tasks
|
|
286
288
|
?? resolvedConfig.proactivity.base
|
|
287
289
|
?? getProactivityLevelForTask(getPhrenPath());
|
|
288
|
-
const taskLifecycle = handleTaskPromptLifecycle({
|
|
290
|
+
const taskLifecycle = moduleEnabled(getPhrenPath(), "tasks") ? handleTaskPromptLifecycle({
|
|
289
291
|
phrenPath: getPhrenPath(),
|
|
290
292
|
prompt,
|
|
291
293
|
project: detectedProject,
|
|
292
294
|
sessionId,
|
|
293
295
|
intent,
|
|
294
296
|
taskLevel,
|
|
295
|
-
});
|
|
297
|
+
}) : { noticeLines: [] };
|
|
296
298
|
if (taskLifecycle.noticeLines.length > 0) {
|
|
297
299
|
parts.push("");
|
|
298
300
|
parts.push(...taskLifecycle.noticeLines);
|
|
@@ -119,9 +119,14 @@ export async function handleProjectsNamespace(args, profile) {
|
|
|
119
119
|
if (taskRawPath && fs.existsSync(taskRawPath))
|
|
120
120
|
exported.taskRaw = fs.readFileSync(taskRawPath, "utf8");
|
|
121
121
|
}
|
|
122
|
-
const
|
|
123
|
-
|
|
124
|
-
|
|
122
|
+
const agentsPath = path.join(projectDir, "AGENTS.md");
|
|
123
|
+
const legacyPath = path.join(projectDir, "CLAUDE.md");
|
|
124
|
+
const instructionsPath = fs.existsSync(agentsPath) ? agentsPath : legacyPath;
|
|
125
|
+
if (fs.existsSync(instructionsPath)) {
|
|
126
|
+
const instructions = fs.readFileSync(instructionsPath, "utf8");
|
|
127
|
+
exported.agentsMd = instructions;
|
|
128
|
+
exported.claudeMd = instructions; // Deprecated export alias for older clients.
|
|
129
|
+
}
|
|
125
130
|
process.stdout.write(JSON.stringify(exported, null, 2) + "\n");
|
|
126
131
|
return;
|
|
127
132
|
}
|
|
@@ -182,9 +187,10 @@ export async function handleProjectsNamespace(args, profile) {
|
|
|
182
187
|
fs.writeFileSync(path.join(stagedProjectDir, "summary.md"), decoded.summary);
|
|
183
188
|
imported.push("summary.md");
|
|
184
189
|
}
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
190
|
+
const instructions = typeof decoded.agentsMd === "string" ? decoded.agentsMd : decoded.claudeMd;
|
|
191
|
+
if (typeof instructions === "string") {
|
|
192
|
+
fs.writeFileSync(path.join(stagedProjectDir, "AGENTS.md"), instructions);
|
|
193
|
+
imported.push("AGENTS.md");
|
|
188
194
|
}
|
|
189
195
|
if (typeof decoded.findingsRaw === "string") {
|
|
190
196
|
fs.writeFileSync(path.join(stagedProjectDir, FINDINGS_FILENAME), decoded.findingsRaw);
|
|
@@ -1,9 +1,11 @@
|
|
|
1
|
+
import { nonInteractiveGitEnv } from "../utils-helpers.js";
|
|
1
2
|
import * as fs from "fs";
|
|
2
3
|
import * as path from "path";
|
|
3
4
|
import { execFileSync } from "child_process";
|
|
4
5
|
import { getPhrenPath } from "../shared.js";
|
|
5
6
|
import { isValidProjectName, errorMessage, getOptionValue } from "../utils.js";
|
|
6
7
|
import { resolveAllStores, addStoreToRegistry, removeStoreFromRegistry, generateStoreId, getStoreProjectDirs, readTeamBootstrap, } from "../store-registry.js";
|
|
8
|
+
import { mergeStoreUpstream } from "../sync/store-merge.js";
|
|
7
9
|
function printStoreUsage() {
|
|
8
10
|
console.log("Usage:");
|
|
9
11
|
console.log(" phren store list List registered stores");
|
|
@@ -116,6 +118,7 @@ export async function handleStoreNamespace(args) {
|
|
|
116
118
|
try {
|
|
117
119
|
fs.mkdirSync(storesDir, { recursive: true });
|
|
118
120
|
execFileSync("git", ["clone", "--", remote, storePath], {
|
|
121
|
+
env: nonInteractiveGitEnv(),
|
|
119
122
|
stdio: "inherit",
|
|
120
123
|
timeout: 60_000,
|
|
121
124
|
});
|
|
@@ -211,6 +214,21 @@ export async function handleStoreNamespace(args) {
|
|
|
211
214
|
if (subcommand === "sync") {
|
|
212
215
|
const stores = resolveAllStores(phrenPath);
|
|
213
216
|
let hasErrors = false;
|
|
217
|
+
const git = async (cwd, gitArgs) => {
|
|
218
|
+
try {
|
|
219
|
+
const output = execFileSync("git", gitArgs, {
|
|
220
|
+
cwd,
|
|
221
|
+
encoding: "utf8",
|
|
222
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
223
|
+
timeout: 30_000,
|
|
224
|
+
env: nonInteractiveGitEnv(),
|
|
225
|
+
}).trim();
|
|
226
|
+
return { ok: true, output };
|
|
227
|
+
}
|
|
228
|
+
catch (err) {
|
|
229
|
+
return { ok: false, output: "", error: errorMessage(err) };
|
|
230
|
+
}
|
|
231
|
+
};
|
|
214
232
|
for (const store of stores) {
|
|
215
233
|
if (!fs.existsSync(store.path)) {
|
|
216
234
|
console.log(` ${store.name}: SKIP (path missing)`);
|
|
@@ -221,22 +239,35 @@ export async function handleStoreNamespace(args) {
|
|
|
221
239
|
console.log(` ${store.name}: SKIP (not a git repo)`);
|
|
222
240
|
continue;
|
|
223
241
|
}
|
|
242
|
+
const result = await mergeStoreUpstream(store.path, { git });
|
|
243
|
+
if (result.status === "busy") {
|
|
244
|
+
console.log(` ${store.name}: SKIP (${result.detail})`);
|
|
245
|
+
hasErrors = true;
|
|
246
|
+
continue;
|
|
247
|
+
}
|
|
248
|
+
if (result.status === "conflict") {
|
|
249
|
+
console.log(` ${store.name}: NEEDS MANUAL RESOLUTION (${result.detail})`);
|
|
250
|
+
hasErrors = true;
|
|
251
|
+
continue;
|
|
252
|
+
}
|
|
253
|
+
if (result.status === "error") {
|
|
254
|
+
console.log(` ${store.name}: FAILED (${result.detail})`);
|
|
255
|
+
hasErrors = true;
|
|
256
|
+
continue;
|
|
257
|
+
}
|
|
224
258
|
try {
|
|
225
|
-
execFileSync("git", ["pull", "--rebase", "--quiet"], {
|
|
226
|
-
cwd: store.path,
|
|
227
|
-
stdio: "pipe",
|
|
228
|
-
timeout: 30_000,
|
|
229
|
-
});
|
|
230
259
|
// Re-apply sparse-checkout after pull on primary store to avoid materializing all files
|
|
231
260
|
if (store.role === "primary") {
|
|
232
261
|
try {
|
|
233
262
|
const sparseList = execFileSync("git", ["sparse-checkout", "list"], {
|
|
263
|
+
env: nonInteractiveGitEnv(),
|
|
234
264
|
cwd: store.path,
|
|
235
265
|
stdio: "pipe",
|
|
236
266
|
timeout: 10_000,
|
|
237
267
|
}).toString().trim();
|
|
238
268
|
if (sparseList) {
|
|
239
269
|
execFileSync("git", ["sparse-checkout", "reapply"], {
|
|
270
|
+
env: nonInteractiveGitEnv(),
|
|
240
271
|
cwd: store.path,
|
|
241
272
|
stdio: "pipe",
|
|
242
273
|
timeout: 10_000,
|
|
@@ -247,7 +278,7 @@ export async function handleStoreNamespace(args) {
|
|
|
247
278
|
// sparse-checkout not configured — nothing to reapply
|
|
248
279
|
}
|
|
249
280
|
}
|
|
250
|
-
console.log(` ${store.name}: ok`);
|
|
281
|
+
console.log(` ${store.name}: ok (${result.detail})`);
|
|
251
282
|
}
|
|
252
283
|
catch (err) {
|
|
253
284
|
console.log(` ${store.name}: FAILED (${errorMessage(err).split("\n")[0]})`);
|
|
@@ -332,7 +332,7 @@ export async function handleTaskNamespace(args) {
|
|
|
332
332
|
}
|
|
333
333
|
const targetRepo = repoArg || resolveProjectGithubRepo(phrenPath, project);
|
|
334
334
|
if (!targetRepo) {
|
|
335
|
-
console.error("Could not infer a GitHub repo. Provide --repo <owner/name> or add a GitHub URL to
|
|
335
|
+
console.error("Could not infer a GitHub repo. Provide --repo <owner/name> or add a GitHub URL to AGENTS.md/summary.md.");
|
|
336
336
|
process.exit(1);
|
|
337
337
|
}
|
|
338
338
|
const created = createGithubIssueForTask({
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function handleScheduleCommand(args: string[], store: string): Promise<number>;
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import * as fs from "node:fs";
|
|
2
|
+
import { request } from "node:http";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { SCHEDULE_EVERY, SCHEDULE_HARNESSES, WEEKDAYS, canonicalComputer, newScheduleId, parseSchedule, readScheduleDocument, writeScheduleDocument, } from "../bridge/schedules.js";
|
|
5
|
+
import { object, socketPath } from "../bridge/protocol.js";
|
|
6
|
+
import { listMachines } from "../profile-store.js";
|
|
7
|
+
import { getProjectDirs } from "../shared.js";
|
|
8
|
+
function option(args, name) {
|
|
9
|
+
const index = args.indexOf(name);
|
|
10
|
+
if (index < 0)
|
|
11
|
+
return undefined;
|
|
12
|
+
const value = args[index + 1];
|
|
13
|
+
if (!value || value.startsWith("--"))
|
|
14
|
+
throw new Error(`${name} needs a value.`);
|
|
15
|
+
return value;
|
|
16
|
+
}
|
|
17
|
+
function projectDirectory(store, name) {
|
|
18
|
+
const directory = getProjectDirs(store).find(candidate => path.basename(candidate).toLowerCase() === name.toLowerCase());
|
|
19
|
+
if (!directory)
|
|
20
|
+
throw new Error(`Unknown project "${name}".`);
|
|
21
|
+
return directory;
|
|
22
|
+
}
|
|
23
|
+
function scheduleDescription(schedule) {
|
|
24
|
+
if (schedule.every === "interval")
|
|
25
|
+
return `every ${schedule.interval}`;
|
|
26
|
+
if (schedule.every === "daily")
|
|
27
|
+
return `daily at ${schedule.at}`;
|
|
28
|
+
if (schedule.every === "weekly")
|
|
29
|
+
return `${schedule.days.join(",")} at ${schedule.at}`;
|
|
30
|
+
if (schedule.every === "once")
|
|
31
|
+
return `once ${schedule.once}`;
|
|
32
|
+
return `cron ${schedule.cron}`;
|
|
33
|
+
}
|
|
34
|
+
async function list(store, projectName) {
|
|
35
|
+
const directories = projectName ? [projectDirectory(store, projectName)] : getProjectDirs(store);
|
|
36
|
+
let count = 0;
|
|
37
|
+
for (const directory of directories) {
|
|
38
|
+
const project = path.basename(directory), schedules = (await readScheduleDocument(directory)).schedules;
|
|
39
|
+
for (const schedule of schedules) {
|
|
40
|
+
count++;
|
|
41
|
+
console.log(`${project} ${schedule.id} ${schedule.enabled ? "enabled " : "paused "} ${schedule.name}`);
|
|
42
|
+
console.log(` ${schedule.computer} · ${schedule.harness}${schedule.model ? `/${schedule.model}` : ""} · ${scheduleDescription(schedule)}`);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
if (!count)
|
|
46
|
+
console.log("No schedules.");
|
|
47
|
+
}
|
|
48
|
+
async function add(store, args) {
|
|
49
|
+
const projectName = args[1];
|
|
50
|
+
if (!projectName || projectName.startsWith("--"))
|
|
51
|
+
throw new Error("Usage: phren schedule add <project> --name ... --prompt <text>");
|
|
52
|
+
const directory = projectDirectory(store, projectName), file = await readScheduleDocument(directory);
|
|
53
|
+
const name = option(args, "--name"), harness = option(args, "--harness");
|
|
54
|
+
const requestedComputer = option(args, "--computer"), every = option(args, "--every");
|
|
55
|
+
if (!name || !harness || !requestedComputer || !every)
|
|
56
|
+
throw new Error("--name, --harness, --computer, and --every are required.");
|
|
57
|
+
if (!SCHEDULE_HARNESSES.includes(harness))
|
|
58
|
+
throw new Error(`--harness must be one of: ${SCHEDULE_HARNESSES.join(", ")}.`);
|
|
59
|
+
if (!SCHEDULE_EVERY.includes(every))
|
|
60
|
+
throw new Error(`--every must be one of: ${SCHEDULE_EVERY.join(", ")}.`);
|
|
61
|
+
const machines = listMachines(store);
|
|
62
|
+
if (!machines.ok)
|
|
63
|
+
throw new Error(machines.error);
|
|
64
|
+
const computer = Object.keys(machines.data).find(machine => canonicalComputer(machine) === canonicalComputer(requestedComputer));
|
|
65
|
+
if (!computer)
|
|
66
|
+
throw new Error(`Computer "${requestedComputer}" is not a machines.yaml key.`);
|
|
67
|
+
const inlinePrompt = option(args, "--prompt"), promptFile = option(args, "--prompt-file");
|
|
68
|
+
if (Boolean(inlinePrompt) === Boolean(promptFile))
|
|
69
|
+
throw new Error("Choose exactly one of --prompt or --prompt-file.");
|
|
70
|
+
const prompt = promptFile ? fs.readFileSync(path.resolve(promptFile), "utf8") : inlinePrompt;
|
|
71
|
+
const now = new Date().toISOString();
|
|
72
|
+
const schedule = {
|
|
73
|
+
id: newScheduleId(file.schedules.map(item => item.id)), name, enabled: true, computer, harness,
|
|
74
|
+
...(option(args, "--model") ? { model: option(args, "--model") } : {}), every, prompt, createdAt: now, updatedAt: now,
|
|
75
|
+
...(option(args, "--at") ? { at: option(args, "--at") } : {}),
|
|
76
|
+
...(option(args, "--days") ? { days: option(args, "--days").split(",").map(day => day.trim().toLowerCase()) } : {}),
|
|
77
|
+
...(option(args, "--interval") ? { interval: option(args, "--interval") } : {}),
|
|
78
|
+
...(option(args, "--once") ? { once: option(args, "--once") } : {}),
|
|
79
|
+
...(option(args, "--cron") ? { cron: option(args, "--cron") } : {}),
|
|
80
|
+
};
|
|
81
|
+
if (schedule.days?.some(day => !WEEKDAYS.includes(day)))
|
|
82
|
+
throw new Error(`--days accepts: ${WEEKDAYS.join(", ")}.`);
|
|
83
|
+
const validated = parseSchedule(schedule);
|
|
84
|
+
await writeScheduleDocument(directory, [...file.schedules, validated], file.document);
|
|
85
|
+
console.log(`Added schedule ${validated.id} to ${path.basename(directory)}.`);
|
|
86
|
+
}
|
|
87
|
+
async function mutate(store, action, projectName, id) {
|
|
88
|
+
if (!projectName || !id)
|
|
89
|
+
throw new Error(`Usage: phren schedule ${action} <project> <id>`);
|
|
90
|
+
const directory = projectDirectory(store, projectName), file = await readScheduleDocument(directory);
|
|
91
|
+
const existing = file.schedules.find(schedule => schedule.id === id);
|
|
92
|
+
if (!existing)
|
|
93
|
+
throw new Error(`Schedule "${id}" was not found in ${path.basename(directory)}.`);
|
|
94
|
+
const schedules = action === "remove" ? file.schedules.filter(schedule => schedule.id !== id)
|
|
95
|
+
: file.schedules.map(schedule => schedule.id === id ? { ...schedule, enabled: action === "enable", updatedAt: new Date().toISOString() } : schedule);
|
|
96
|
+
await writeScheduleDocument(directory, schedules, file.document);
|
|
97
|
+
console.log(`${action === "remove" ? "Removed" : action === "enable" ? "Enabled" : "Disabled"} schedule ${id}.`);
|
|
98
|
+
}
|
|
99
|
+
async function hookPost(route, data) {
|
|
100
|
+
return new Promise((resolve, reject) => {
|
|
101
|
+
const payload = JSON.stringify(data);
|
|
102
|
+
const req = request({ socketPath: socketPath(), path: route, method: "POST", timeout: 60_000,
|
|
103
|
+
headers: { "Content-Type": "application/json", "Content-Length": Buffer.byteLength(payload) } }, response => {
|
|
104
|
+
let text = "";
|
|
105
|
+
response.on("data", chunk => { text += chunk.toString(); if (text.length > 8 * 1024 * 1024)
|
|
106
|
+
req.destroy(new Error("Phren Hook response is too large.")); });
|
|
107
|
+
response.on("end", () => {
|
|
108
|
+
let result;
|
|
109
|
+
try {
|
|
110
|
+
result = object(JSON.parse(text));
|
|
111
|
+
}
|
|
112
|
+
catch {
|
|
113
|
+
reject(new Error("Phren Hook returned an invalid response."));
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
if ((response.statusCode ?? 500) >= 400)
|
|
117
|
+
reject(new Error(typeof result.error === "string" ? result.error : "Phren Hook rejected the request."));
|
|
118
|
+
else
|
|
119
|
+
resolve(result);
|
|
120
|
+
});
|
|
121
|
+
});
|
|
122
|
+
req.on("timeout", () => req.destroy(new Error("Phren Hook did not answer.")));
|
|
123
|
+
req.on("error", error => reject(error.code === "ENOENT" || error.code === "ECONNREFUSED"
|
|
124
|
+
? new Error("Phren Hook is not running. Start it with `phren bridge install`.") : error));
|
|
125
|
+
req.end(payload);
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
async function runNow(project, id) {
|
|
129
|
+
if (!project || !id)
|
|
130
|
+
throw new Error("Usage: phren schedule run <project> <id>");
|
|
131
|
+
const result = await hookPost("/v1/schedules/run", { project, id });
|
|
132
|
+
const run = object(result.run);
|
|
133
|
+
console.log(`Launched schedule ${id} (${String(run.id ?? "run recorded")}).`);
|
|
134
|
+
}
|
|
135
|
+
async function history(args) {
|
|
136
|
+
const project = args[1] && !args[1].startsWith("--") ? args[1] : undefined;
|
|
137
|
+
const rawLimit = option(args, "--limit"), limit = rawLimit === undefined ? undefined : Number(rawLimit);
|
|
138
|
+
if (limit !== undefined && (!Number.isInteger(limit) || limit < 1 || limit > 500))
|
|
139
|
+
throw new Error("--limit must be between 1 and 500.");
|
|
140
|
+
const result = await hookPost("/v1/schedules/history", { ...(project ? { project } : {}), ...(option(args, "--id") ? { id: option(args, "--id") } : {}), ...(limit ? { limit } : {}) });
|
|
141
|
+
const runs = Array.isArray(result.runs) ? result.runs.map(object) : [];
|
|
142
|
+
if (!runs.length) {
|
|
143
|
+
console.log("No schedule runs.");
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
for (const run of runs)
|
|
147
|
+
console.log(`${String(run.startedAt)} ${String(run.status).padEnd(9)} ${String(run.project)}/${String(run.scheduleId)}${run.reason ? ` ${String(run.reason)}` : ""}`);
|
|
148
|
+
}
|
|
149
|
+
export async function handleScheduleCommand(args, store) {
|
|
150
|
+
const action = args[0];
|
|
151
|
+
if (!action || action === "list")
|
|
152
|
+
await list(store, args[1]);
|
|
153
|
+
else if (action === "add")
|
|
154
|
+
await add(store, args);
|
|
155
|
+
else if (action === "remove" || action === "enable" || action === "disable")
|
|
156
|
+
await mutate(store, action, args[1], args[2]);
|
|
157
|
+
else if (action === "run")
|
|
158
|
+
await runNow(args[1], args[2]);
|
|
159
|
+
else if (action === "history")
|
|
160
|
+
await history(args);
|
|
161
|
+
else
|
|
162
|
+
throw new Error("Usage: phren schedule <list|add|remove|enable|disable|run|history>");
|
|
163
|
+
return 0;
|
|
164
|
+
}
|