@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/data/access.js
CHANGED
|
@@ -18,7 +18,8 @@ export { readTasks, readTasksAcrossProjects, resolveTaskItem, addTask, addTasks,
|
|
|
18
18
|
export { addProjectToProfile, listMachines, listProfiles, listProjectCards, removeProjectFromProfile, setMachineProfile, } from "../profile-store.js";
|
|
19
19
|
export { loadShellState, resetShellState, saveShellState, } from "../shell/state-store.js";
|
|
20
20
|
export { getRuntimeHealth as readRuntimeHealth } from "../shared/governance.js";
|
|
21
|
-
|
|
21
|
+
import { FINDINGS_FILENAME } from "../filenames.js";
|
|
22
|
+
export { FINDINGS_FILENAME } from "../filenames.js";
|
|
22
23
|
function extractDateHeading(line) {
|
|
23
24
|
const heading = line.match(/^##\s+(.+)$/);
|
|
24
25
|
if (!heading)
|
|
@@ -131,7 +132,15 @@ export function readFindings(phrenPath, project, opts = {}) {
|
|
|
131
132
|
const file = findingsPath;
|
|
132
133
|
if (!fs.existsSync(file))
|
|
133
134
|
return phrenOk([]);
|
|
134
|
-
|
|
135
|
+
return phrenOk(parseFindingsContent(fs.readFileSync(file, "utf8"), opts));
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Parse FINDINGS.md-shaped content into findings. Shared by `readFindings`
|
|
139
|
+
* (the project's FINDINGS.md) and the memory link's scan of archived topic
|
|
140
|
+
* files under `reference/topics/`, which use the same bullet + citation shape.
|
|
141
|
+
*/
|
|
142
|
+
export function parseFindingsContent(content, opts = {}) {
|
|
143
|
+
const lines = content.split("\n");
|
|
135
144
|
const items = [];
|
|
136
145
|
let date = "unknown";
|
|
137
146
|
let index = 1;
|
|
@@ -238,7 +247,7 @@ export function readFindings(phrenPath, project, opts = {}) {
|
|
|
238
247
|
i += 1;
|
|
239
248
|
index++;
|
|
240
249
|
}
|
|
241
|
-
return
|
|
250
|
+
return items;
|
|
242
251
|
}
|
|
243
252
|
export function readFindingHistory(phrenPath, project, findingId) {
|
|
244
253
|
const result = readFindings(phrenPath, project, { includeArchived: true });
|
|
@@ -671,6 +680,7 @@ export function approveQueueItemDetailed(phrenPath, project, lineText) {
|
|
|
671
680
|
...(parsed.citation.file ? { file: parsed.citation.file } : {}),
|
|
672
681
|
...(parsed.citation.line !== undefined ? { line: parsed.citation.line } : {}),
|
|
673
682
|
...(parsed.citation.commit ? { commit: parsed.citation.commit } : {}),
|
|
683
|
+
...(parsed.citation.symbol ? { symbol: parsed.citation.symbol } : {}),
|
|
674
684
|
}
|
|
675
685
|
: undefined;
|
|
676
686
|
// The queue entry's own date is the day the observation was captured; the finding is
|
|
@@ -772,6 +782,24 @@ export function rejectQueueItem(phrenPath, project, lineText) {
|
|
|
772
782
|
const result = rejectQueueItemDetailed(phrenPath, project, lineText);
|
|
773
783
|
return result.ok ? phrenOk(result.data.message) : result;
|
|
774
784
|
}
|
|
785
|
+
/**
|
|
786
|
+
* Drop a queue line and nothing else.
|
|
787
|
+
*
|
|
788
|
+
* Unlike `rejectQueueItem`, this never touches FINDINGS.md or `reference/topics/`.
|
|
789
|
+
* It is the verb for "stop asking me about this", not "this is wrong" — which is
|
|
790
|
+
* what automated expiry needs: a governance-queued finding that already lives in
|
|
791
|
+
* FINDINGS.md must survive its queue line timing out.
|
|
792
|
+
*/
|
|
793
|
+
export function dequeueQueueItem(phrenPath, project, lineText) {
|
|
794
|
+
const located = locateQueueLine(phrenPath, project, lineText);
|
|
795
|
+
if (!located.ok)
|
|
796
|
+
return forwardErr(located);
|
|
797
|
+
const dequeued = dequeueLine(phrenPath, project, lineText);
|
|
798
|
+
if (!dequeued.ok)
|
|
799
|
+
return forwardErr(dequeued);
|
|
800
|
+
appendAuditLog(phrenPath, "review_dequeue", `project=${project}`);
|
|
801
|
+
return phrenOk(`Removed queue item from ${project} (content left untouched)`);
|
|
802
|
+
}
|
|
775
803
|
/** Edit a queue item's text in review.md and the corresponding finding in FINDINGS.md. */
|
|
776
804
|
export function editQueueItem(phrenPath, project, lineText, newText) {
|
|
777
805
|
const trimmed = newText.replace(/[\r\n]+/g, " ").trim();
|
package/dist/data/tasks.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { type PhrenResult } from "../shared.js";
|
|
2
2
|
export type TaskSection = "Active" | "Queue" | "Done";
|
|
3
|
-
export
|
|
4
|
-
export declare const TASK_FILE_ALIASES: readonly ["tasks.md"];
|
|
3
|
+
export { TASK_FILE_ALIASES, TASKS_FILENAME, isTaskFileName } from "../filenames.js";
|
|
5
4
|
export interface TaskItem {
|
|
6
5
|
/** Positional ID for display (e.g. "A1", "Q3"). Recomputed on every read — use stableId for persistent references. */
|
|
7
6
|
id: string;
|
|
@@ -31,13 +30,29 @@ export interface TaskDoc {
|
|
|
31
30
|
issues: string[];
|
|
32
31
|
path: string;
|
|
33
32
|
}
|
|
33
|
+
export declare function stripBulletPrefix(line: string): {
|
|
34
|
+
checked: boolean;
|
|
35
|
+
body: string;
|
|
36
|
+
};
|
|
37
|
+
/** Strip the metadata comment from a raw line, returning the clean text and any extracted fields. */
|
|
38
|
+
export declare function stripBid(text: string): {
|
|
39
|
+
clean: string;
|
|
40
|
+
bid?: string;
|
|
41
|
+
rank?: number;
|
|
42
|
+
lastActivity?: string;
|
|
43
|
+
createdAt?: string;
|
|
44
|
+
sessionId?: string;
|
|
45
|
+
scope?: string;
|
|
46
|
+
childFindings?: string[];
|
|
47
|
+
parentFinding?: string;
|
|
48
|
+
speculative?: boolean;
|
|
49
|
+
};
|
|
34
50
|
/**
|
|
35
51
|
* Apply gravity to tasks: items with stale lastActivity drift toward higher rank numbers.
|
|
36
52
|
* Only affects display order — does not mutate the file.
|
|
37
53
|
*/
|
|
38
54
|
export declare function applyGravity(items: TaskItem[]): TaskItem[];
|
|
39
55
|
export declare function canonicalTaskFilePath(phrenPath: string, project: string): string | null;
|
|
40
|
-
export declare function isTaskFileName(filename: string): boolean;
|
|
41
56
|
export declare function resolveTaskFilePath(phrenPath: string, project: string): string | null;
|
|
42
57
|
export declare function readTasks(phrenPath: string, project: string): PhrenResult<TaskDoc>;
|
|
43
58
|
export declare function readTasksAcrossProjects(phrenPath: string, profile?: string): TaskDoc[];
|
package/dist/data/tasks.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { moduleEnabled } from "../modules/runtime.js";
|
|
2
|
+
import { disabledHint } from "../modules/registry.js";
|
|
1
3
|
import * as fs from "fs";
|
|
2
4
|
import * as path from "path";
|
|
3
5
|
import { randomBytes, randomUUID } from "crypto";
|
|
@@ -6,11 +8,11 @@ import { validateTaskFormat } from "../shared/content.js";
|
|
|
6
8
|
import { withSafeLock, ensureProject } from "../shared/data-utils.js";
|
|
7
9
|
import { getNonPrimaryStores, getStoreProjectDirs } from "../store-registry.js";
|
|
8
10
|
import { storeAwareProjectPath } from "../store-routing.js";
|
|
11
|
+
import { TASKS_FILENAME } from "../filenames.js";
|
|
9
12
|
const ACTIVE_HEADINGS = new Set(["active", "in progress", "in-progress", "current", "wip"]);
|
|
10
13
|
const QUEUE_HEADINGS = new Set(["queue", "queued", "task", "todo", "upcoming", "next"]);
|
|
11
14
|
const DONE_HEADINGS = new Set(["done", "completed", "finished", "archived"]);
|
|
12
|
-
export
|
|
13
|
-
export const TASK_FILE_ALIASES = [TASKS_FILENAME];
|
|
15
|
+
export { TASK_FILE_ALIASES, TASKS_FILENAME, isTaskFileName } from "../filenames.js";
|
|
14
16
|
const TASK_SECTIONS = ["Active", "Queue", "Done"];
|
|
15
17
|
function normalizePriority(text) {
|
|
16
18
|
const m = text.replace(/\s*\[pinned\]/gi, "").match(/\[(high|medium|low)\]\s*$/i);
|
|
@@ -36,7 +38,7 @@ function detectPinned(text) {
|
|
|
36
38
|
function stripPinnedTag(text) {
|
|
37
39
|
return text.replace(/\s*\[pinned\]/gi, "").trim();
|
|
38
40
|
}
|
|
39
|
-
function stripBulletPrefix(line) {
|
|
41
|
+
export function stripBulletPrefix(line) {
|
|
40
42
|
const checked = /^-\s*\[[xX]\]\s+/.test(line);
|
|
41
43
|
const body = line
|
|
42
44
|
.replace(/^-\s*\[[ xX]\]\s+/, "")
|
|
@@ -112,7 +114,7 @@ function newBid() {
|
|
|
112
114
|
return randomBytes(4).toString("hex");
|
|
113
115
|
}
|
|
114
116
|
/** Strip the metadata comment from a raw line, returning the clean text and any extracted fields. */
|
|
115
|
-
function stripBid(text) {
|
|
117
|
+
export function stripBid(text) {
|
|
116
118
|
const m = text.match(METADATA_PATTERN);
|
|
117
119
|
if (!m)
|
|
118
120
|
return { clean: text };
|
|
@@ -170,9 +172,6 @@ export function canonicalTaskFilePath(phrenPath, project) {
|
|
|
170
172
|
// phantom primary-store path.
|
|
171
173
|
return storeAwareProjectPath(phrenPath, project, TASKS_FILENAME);
|
|
172
174
|
}
|
|
173
|
-
export function isTaskFileName(filename) {
|
|
174
|
-
return filename.toLowerCase() === TASKS_FILENAME;
|
|
175
|
-
}
|
|
176
175
|
export function resolveTaskFilePath(phrenPath, project) {
|
|
177
176
|
return canonicalTaskFilePath(phrenPath, project);
|
|
178
177
|
}
|
|
@@ -342,6 +341,8 @@ function taskArchivePath(phrenPath, project) {
|
|
|
342
341
|
return path.join(phrenPath, ".config", "task-archive", `${project}.md`);
|
|
343
342
|
}
|
|
344
343
|
export function readTasks(phrenPath, project) {
|
|
344
|
+
if (!moduleEnabled(phrenPath, "tasks"))
|
|
345
|
+
return phrenErr(disabledHint("tasks"), PhrenError.VALIDATION_ERROR);
|
|
345
346
|
const ensured = ensureProject(phrenPath, project);
|
|
346
347
|
if (!ensured.ok)
|
|
347
348
|
return forwardErr(ensured);
|
package/dist/entrypoint.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
+
import { activateModules, moduleSnapshot } from "./modules/runtime.js";
|
|
2
|
+
import { disabledCommand } from "./cli-registry.js";
|
|
1
3
|
import * as fs from "fs";
|
|
2
4
|
import * as path from "path";
|
|
3
5
|
import { errorMessage } from "./utils.js";
|
|
4
6
|
import { logger } from "./logger.js";
|
|
5
|
-
import { defaultPhrenPath, ensureFtsCacheRootPrivate, expandHomePath, getPhrenPath, readRootManifest, } from "./shared.js";
|
|
7
|
+
import { defaultPhrenPath, findPhrenPath, ensureFtsCacheRootPrivate, expandHomePath, getPhrenPath, readRootManifest, } from "./shared.js";
|
|
6
8
|
import { resolveRuntimeProfile } from "./runtime-profile.js";
|
|
7
9
|
import { VERSION } from "./package-metadata.js";
|
|
8
10
|
import { TOPIC_ORDER, helpTopicNames, lookupCommand, } from "./cli-registry.js";
|
|
@@ -28,7 +30,8 @@ export function resolveTopLevelInvocation(argv) {
|
|
|
28
30
|
return { kind: "mcp", phrenArg: positional };
|
|
29
31
|
}
|
|
30
32
|
if (argvCommand === "--help" || argvCommand === "-h") {
|
|
31
|
-
|
|
33
|
+
// `phren --help all` reads like `phren help all`, so it does the same.
|
|
34
|
+
return argv.length > 1 ? { kind: "manage", argv } : { kind: "help" };
|
|
32
35
|
}
|
|
33
36
|
if (argvCommand === "--version" || argvCommand === "-v" || argvCommand === "version") {
|
|
34
37
|
return { kind: "version" };
|
|
@@ -45,7 +48,7 @@ export function resolveTopLevelInvocation(argv) {
|
|
|
45
48
|
return { kind: "manage", argv };
|
|
46
49
|
}
|
|
47
50
|
export function printIntegratedHelp() {
|
|
48
|
-
console.log(formatCheatSheet());
|
|
51
|
+
console.log(formatCheatSheet(helpSnapshot()));
|
|
49
52
|
}
|
|
50
53
|
export function printIntegratedVersion() {
|
|
51
54
|
console.log(`phren v${VERSION}`);
|
|
@@ -68,24 +71,38 @@ function buildCliContext() {
|
|
|
68
71
|
profile: () => resolveRuntimeProfile(getPhrenPath()),
|
|
69
72
|
};
|
|
70
73
|
}
|
|
74
|
+
function helpSnapshot() {
|
|
75
|
+
try {
|
|
76
|
+
return moduleSnapshot(findPhrenPath() ?? defaultPhrenPath());
|
|
77
|
+
}
|
|
78
|
+
catch {
|
|
79
|
+
return undefined;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
71
82
|
async function runHelp(args) {
|
|
83
|
+
const snapshot = helpSnapshot();
|
|
72
84
|
const target = args[0]?.toLowerCase();
|
|
73
85
|
if (!target) {
|
|
74
|
-
console.log(formatCheatSheet());
|
|
86
|
+
console.log(formatCheatSheet(helpSnapshot()));
|
|
75
87
|
return finish();
|
|
76
88
|
}
|
|
77
89
|
if (target === "all") {
|
|
78
|
-
console.log(formatFullHelp());
|
|
90
|
+
console.log(formatFullHelp(snapshot));
|
|
79
91
|
return finish();
|
|
80
92
|
}
|
|
81
93
|
// Topic precedence: a name that's both a topic and a command (e.g. "projects",
|
|
82
94
|
// "skills") shows the topic view, which lists every command in that group.
|
|
83
95
|
// Matches the legacy HELP_TOPICS behavior.
|
|
84
96
|
if (TOPIC_ORDER.includes(target)) {
|
|
85
|
-
console.log(formatTopic(target));
|
|
97
|
+
console.log(formatTopic(target, snapshot));
|
|
86
98
|
return finish();
|
|
87
99
|
}
|
|
88
|
-
const
|
|
100
|
+
const unavailable = snapshot && disabledCommand([target, ...args.slice(1)].join(" "), snapshot);
|
|
101
|
+
if (unavailable) {
|
|
102
|
+
console.log(unavailable);
|
|
103
|
+
return finish();
|
|
104
|
+
}
|
|
105
|
+
const cmdHelp = formatCommand(target, snapshot);
|
|
89
106
|
if (cmdHelp !== null) {
|
|
90
107
|
console.log(cmdHelp);
|
|
91
108
|
return finish();
|
|
@@ -114,7 +131,7 @@ export async function runTopLevelCommand(argv, opts = {}) {
|
|
|
114
131
|
if (!argvCommand) {
|
|
115
132
|
if (process.stdin.isTTY && process.stdout.isTTY) {
|
|
116
133
|
if (opts.allowDefaultShell === false) {
|
|
117
|
-
console.log(formatCheatSheet());
|
|
134
|
+
console.log(formatCheatSheet(helpSnapshot()));
|
|
118
135
|
return finish();
|
|
119
136
|
}
|
|
120
137
|
const shellCmd = lookupCommand("shell");
|
|
@@ -127,14 +144,31 @@ export async function runTopLevelCommand(argv, opts = {}) {
|
|
|
127
144
|
const cmd = lookupCommand(argvCommand);
|
|
128
145
|
if (!cmd)
|
|
129
146
|
return false;
|
|
147
|
+
let snapshot;
|
|
148
|
+
try {
|
|
149
|
+
const store = findPhrenPath() ?? defaultPhrenPath();
|
|
150
|
+
snapshot = ["modules", "init", "quickstart", "verify", "uninstall", "doctor"].includes(cmd.name) || argv.includes("--help") || argv.includes("-h")
|
|
151
|
+
? moduleSnapshot(store) : activateModules(store);
|
|
152
|
+
const unavailable = disabledCommand([cmd.name, ...argv.slice(1)].join(" "), snapshot);
|
|
153
|
+
if (unavailable) {
|
|
154
|
+
console.error(unavailable);
|
|
155
|
+
return finish(1);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
catch (error) {
|
|
159
|
+
if (!["init", "modules", "doctor", "verify", "uninstall", "link"].includes(cmd.name)) {
|
|
160
|
+
console.error(errorMessage(error));
|
|
161
|
+
return finish(1);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
130
164
|
// Any command can end up building or reading the FTS snapshot cache, which
|
|
131
165
|
// is a SQLite export of the whole store landing in os.tmpdir() — /tmp (1777)
|
|
132
166
|
// on Linux and WSL. Harden the per-user cache root before the command runs.
|
|
133
167
|
ensureFtsCacheRootPrivate();
|
|
134
168
|
// Intercept before any handler runs - in particular before namespace
|
|
135
169
|
// handlers that used to print their own per-subcommand help text.
|
|
136
|
-
if (argv.includes("--help") || argv.includes("-h")) {
|
|
137
|
-
const out = formatCommand(cmd.name);
|
|
170
|
+
if (argv.includes("--help") || argv.includes("-h") || (argv.length === 1 && ["maintain", "config", "bridge"].includes(cmd.name))) {
|
|
171
|
+
const out = formatCommand(cmd.name, snapshot);
|
|
138
172
|
if (out)
|
|
139
173
|
console.log(out);
|
|
140
174
|
return finish();
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { uuid } from "./types.js";
|
|
2
|
+
export const claude = {
|
|
3
|
+
command: "claude",
|
|
4
|
+
argv: o => ["-p", "--output-format", "stream-json", "--verbose", "--model", o.model,
|
|
5
|
+
...(o.review ? ["--permission-mode", "plan"] : []), ...(o.resume ? ["--resume", o.resume] : []), ...(o.extra ?? [])],
|
|
6
|
+
session: event => uuid(event.session_id),
|
|
7
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import * as path from "node:path";
|
|
2
|
+
import { uuid } from "./types.js";
|
|
3
|
+
export const codex = {
|
|
4
|
+
command: "codex",
|
|
5
|
+
argv: o => ["exec", ...(o.resume ? ["resume"] : []), "--json",
|
|
6
|
+
...(!o.resume ? ["--sandbox", o.review ? "read-only" : "workspace-write", "-C", o.worktree] : []),
|
|
7
|
+
"-o", path.join(o.job, "final.txt"), ...(o.model ? ["-m", o.model] : []), ...(o.extra ?? []), ...(o.resume ? [o.resume] : []), "-"],
|
|
8
|
+
session: event => event.type === "thread.started" ? uuid(event.thread_id) : undefined,
|
|
9
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { driveOpencode } from "../opencode-serve.js";
|
|
2
|
+
/** `opencode run` rejects every permission ask itself, so a worker runs under
|
|
3
|
+
* `opencode serve` and the launcher drives its session over HTTP. */
|
|
4
|
+
export const opencode = {
|
|
5
|
+
command: "opencode",
|
|
6
|
+
argv: () => ["serve", "--hostname", "127.0.0.1", "--port", "0"],
|
|
7
|
+
session: event => typeof event.sessionID === "string" && /^ses_[0-9a-z]{1,64}$/i.test(event.sessionID) ? event.sessionID : undefined,
|
|
8
|
+
drive: driveOpencode,
|
|
9
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { ChildProcess } from "node:child_process";
|
|
2
|
+
import type { DriveOptions } from "../opencode-serve.js";
|
|
3
|
+
export type Provider = "codex" | "opencode" | "claude";
|
|
4
|
+
export interface LaunchOptions {
|
|
5
|
+
model: string;
|
|
6
|
+
worktree: string;
|
|
7
|
+
job: string;
|
|
8
|
+
review?: boolean;
|
|
9
|
+
resume?: string;
|
|
10
|
+
variant?: string;
|
|
11
|
+
extra?: string[];
|
|
12
|
+
}
|
|
13
|
+
export interface Adapter {
|
|
14
|
+
command: Provider;
|
|
15
|
+
argv(options: LaunchOptions): string[];
|
|
16
|
+
session(event: Record<string, unknown>): string | undefined;
|
|
17
|
+
/** A harness that serves an API instead of printing events: the launcher
|
|
18
|
+
* spawns `argv` and this drives the worker, returning its exit code. */
|
|
19
|
+
drive?(child: ChildProcess, options: DriveOptions): Promise<number>;
|
|
20
|
+
}
|
|
21
|
+
export declare function uuid(value: unknown): string | undefined;
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import * as fs from "node:fs";
|
|
2
|
+
import * as path from "node:path";
|
|
3
|
+
import * as yaml from "js-yaml";
|
|
4
|
+
import { withFileLock } from "../governance/locks.js";
|
|
5
|
+
import { archiveFinishedFanouts } from "../bridge/fanouts.js";
|
|
6
|
+
import { defaultPolicy, policySchema, pick } from "./picker.js";
|
|
7
|
+
import { readUsage, recentProviderErrors } from "./usage.js";
|
|
8
|
+
import { createJob, jobsRoot, launch, listJobs, readJob, swiftBuildCount } from "./launcher.js";
|
|
9
|
+
export async function runFanout(args, ctx) {
|
|
10
|
+
const [action, ...rest] = args, store = ctx.phrenPath();
|
|
11
|
+
if (action === "usage") {
|
|
12
|
+
console.log("Provider\tWindow\tUsed\tResets");
|
|
13
|
+
for (const account of await readUsage()) {
|
|
14
|
+
if (!account.windows.length)
|
|
15
|
+
console.log(`${account.source}\t${account.message ?? "Usage unavailable"}`);
|
|
16
|
+
for (const window of account.windows)
|
|
17
|
+
console.log(`${account.source}\t${window.name}\t${window.usedPercent === undefined ? "unknown" : window.usedPercent + " percent"}\t${window.resetsAt ?? "unknown"}`);
|
|
18
|
+
}
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
if (action === "list") {
|
|
22
|
+
for (const job of listJobs(store))
|
|
23
|
+
console.log(`${job.id}\t${job.status}\t${job.provider}/${job.model}\t${job.taskLabel}`);
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
if (action === "archive") {
|
|
27
|
+
if (rest.some(arg => arg !== "--dry-run"))
|
|
28
|
+
throw new Error("Usage: phren fanout archive [--dry-run]");
|
|
29
|
+
console.log(await archiveFinishedFanouts({ ...process.env, PHREN_PATH: store }, { dryRun: rest.includes("--dry-run") }));
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
if (!["run", "resume", "review"].includes(action))
|
|
33
|
+
throw new Error("Usage: phren fanout run|usage|resume|review|list|archive");
|
|
34
|
+
const previous = action === "run" ? undefined : readJob(store, rest.shift() ?? "");
|
|
35
|
+
const flags = {}, extra = [];
|
|
36
|
+
while (rest.length) {
|
|
37
|
+
const key = rest.shift(), value = rest.shift();
|
|
38
|
+
if (!["--tier", "--provider", "--model", "--label", "--worktree", "--variant", "--extra"].includes(key) || !value)
|
|
39
|
+
throw new Error(`Invalid fan-out option ${key}`);
|
|
40
|
+
if (key === "--extra")
|
|
41
|
+
extra.push(value);
|
|
42
|
+
else
|
|
43
|
+
flags[key.slice(2)] = value;
|
|
44
|
+
}
|
|
45
|
+
const tier = flags.tier ?? (action === "review" ? "review" : "narrow");
|
|
46
|
+
if (!["narrow", "wide", "review"].includes(tier))
|
|
47
|
+
throw new Error("Choose tier narrow, wide or review.");
|
|
48
|
+
if (previous && !previous.session)
|
|
49
|
+
throw new Error("This job has no resumable session.");
|
|
50
|
+
if (previous && flags.provider && flags.provider !== previous.provider)
|
|
51
|
+
throw new Error("Resume must use the job's original provider.");
|
|
52
|
+
if (previous && flags.worktree && path.resolve(flags.worktree) !== path.resolve(previous.worktree))
|
|
53
|
+
throw new Error("Resume must use the job's original worktree.");
|
|
54
|
+
const label = flags.label ?? previous?.taskLabel, worktree = flags.worktree ?? previous?.worktree;
|
|
55
|
+
if (!label || !worktree)
|
|
56
|
+
throw new Error("phren fanout run needs --label and --worktree.");
|
|
57
|
+
let prompt = action === "review" && process.stdin.isTTY ? "Review your changes for correctness and regressions. Report findings without editing files." : fs.readFileSync(0, "utf8");
|
|
58
|
+
if (!prompt.trim() && action === "review")
|
|
59
|
+
prompt = "Review your changes for correctness and regressions. Report findings without editing files.";
|
|
60
|
+
if (!prompt.trim())
|
|
61
|
+
throw new Error("Provide a brief on stdin.");
|
|
62
|
+
const file = path.join(store, ".config", "fanout.yaml");
|
|
63
|
+
const policy = fs.existsSync(file) ? policySchema.parse(yaml.load(fs.readFileSync(file, "utf8"), { schema: yaml.CORE_SCHEMA })) : defaultPolicy;
|
|
64
|
+
const usage = await readUsage(), errors = recentProviderErrors(), needsSwift = /\b(swift|xcodebuild|ios)\b/i.test(prompt);
|
|
65
|
+
fs.mkdirSync(jobsRoot(store), { recursive: true, mode: 0o700 });
|
|
66
|
+
const reserved = withFileLock(path.join(jobsRoot(store), "launch"), () => {
|
|
67
|
+
const running = listJobs(store).filter(job => !fs.existsSync(path.join(jobsRoot(store), job.id, "exit.txt")));
|
|
68
|
+
const chosen = pick({ policy, tier: tier, usage, errors, running, swiftBuilds: needsSwift ? swiftBuildCount() : 0, needsSwift,
|
|
69
|
+
override: { provider: (flags.provider ?? previous?.provider), model: flags.model ?? previous?.model } });
|
|
70
|
+
// An OpenCode worker is driven over HTTP; there is no command line to extend.
|
|
71
|
+
if (chosen.provider === "opencode" && extra.length)
|
|
72
|
+
throw new Error("OpenCode workers take no --extra arguments.");
|
|
73
|
+
console.log(chosen.reason);
|
|
74
|
+
const options = { ...chosen, store, label, worktree, prompt, review: tier === "review", resume: previous?.session, variant: flags.variant, extra };
|
|
75
|
+
return { options, reservation: createJob(options) };
|
|
76
|
+
});
|
|
77
|
+
return launch(reserved.options, reserved.reservation);
|
|
78
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { type FanoutManifest } from "../bridge/fanouts.js";
|
|
2
|
+
import { type LaunchOptions, type Provider } from "./adapters/types.js";
|
|
3
|
+
export declare const adapters: {
|
|
4
|
+
codex: import("./adapters/types.js").Adapter;
|
|
5
|
+
opencode: import("./adapters/types.js").Adapter;
|
|
6
|
+
claude: import("./adapters/types.js").Adapter;
|
|
7
|
+
};
|
|
8
|
+
export interface JobOptions extends Omit<LaunchOptions, "job"> {
|
|
9
|
+
store: string;
|
|
10
|
+
provider: Provider;
|
|
11
|
+
label: string;
|
|
12
|
+
reason: string;
|
|
13
|
+
prompt: string;
|
|
14
|
+
}
|
|
15
|
+
export declare function jobsRoot(store: string): string;
|
|
16
|
+
export declare function readJob(store: string, id: string): FanoutManifest;
|
|
17
|
+
export declare function listJobs(store: string): FanoutManifest[];
|
|
18
|
+
export declare function swiftBuildCount(): number;
|
|
19
|
+
export declare function writeManifest(job: string, manifest: FanoutManifest): void;
|
|
20
|
+
export declare function createJob(options: JobOptions, env?: NodeJS.ProcessEnv): {
|
|
21
|
+
job: string;
|
|
22
|
+
manifest: FanoutManifest;
|
|
23
|
+
};
|
|
24
|
+
export declare function launch(options: JobOptions, reservation?: {
|
|
25
|
+
job: string;
|
|
26
|
+
manifest: FanoutManifest;
|
|
27
|
+
}): Promise<number>;
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import { spawn, execFileSync } from "node:child_process";
|
|
2
|
+
import { randomBytes } from "node:crypto";
|
|
3
|
+
import * as fs from "node:fs";
|
|
4
|
+
import * as path from "node:path";
|
|
5
|
+
import { atomicWriteText } from "../phren-paths.js";
|
|
6
|
+
import { manifestSchema } from "../bridge/fanouts.js";
|
|
7
|
+
import { codex } from "./adapters/codex.js";
|
|
8
|
+
import { opencode } from "./adapters/opencode.js";
|
|
9
|
+
import { claude } from "./adapters/claude.js";
|
|
10
|
+
import { uuid } from "./adapters/types.js";
|
|
11
|
+
import { LoopWatchdog, stderrRefusal } from "./watchdog.js";
|
|
12
|
+
export const adapters = { codex, opencode, claude };
|
|
13
|
+
export function jobsRoot(store) { return path.join(store, ".runtime", "agent-fanouts"); }
|
|
14
|
+
export function readJob(store, id) {
|
|
15
|
+
if (!/^[a-z0-9][a-z0-9._-]{0,127}$/i.test(id))
|
|
16
|
+
throw new Error("Invalid job id.");
|
|
17
|
+
const root = fs.realpathSync(jobsRoot(store)), job = path.join(root, id);
|
|
18
|
+
if (!fs.lstatSync(job).isDirectory() || fs.realpathSync(job) !== job)
|
|
19
|
+
throw new Error("Invalid job directory.");
|
|
20
|
+
const file = path.join(job, "manifest.json"), info = fs.lstatSync(file);
|
|
21
|
+
if (!info.isFile() || info.isSymbolicLink() || info.size > 65_536)
|
|
22
|
+
throw new Error("Invalid job manifest.");
|
|
23
|
+
const result = manifestSchema.parse(JSON.parse(fs.readFileSync(file, "utf8")));
|
|
24
|
+
if (result.id !== id)
|
|
25
|
+
throw new Error("Job id does not match its manifest.");
|
|
26
|
+
return result;
|
|
27
|
+
}
|
|
28
|
+
export function listJobs(store) {
|
|
29
|
+
if (!fs.existsSync(jobsRoot(store)))
|
|
30
|
+
return [];
|
|
31
|
+
return fs.readdirSync(jobsRoot(store)).flatMap(id => { try {
|
|
32
|
+
return [readJob(store, id)];
|
|
33
|
+
}
|
|
34
|
+
catch {
|
|
35
|
+
return [];
|
|
36
|
+
} });
|
|
37
|
+
}
|
|
38
|
+
export function swiftBuildCount() {
|
|
39
|
+
const output = execFileSync("ps", ["-axo", "comm="], { encoding: "utf8", timeout: 5_000 });
|
|
40
|
+
return output.split("\n").filter(line => path.basename(line.trim()) === "xcodebuild").length;
|
|
41
|
+
}
|
|
42
|
+
export function writeManifest(job, manifest) {
|
|
43
|
+
atomicWriteText(path.join(job, "manifest.json"), JSON.stringify(manifestSchema.parse(manifest)) + "\n");
|
|
44
|
+
fs.chmodSync(path.join(job, "manifest.json"), 0o600);
|
|
45
|
+
}
|
|
46
|
+
export function createJob(options, env = process.env) {
|
|
47
|
+
if (!options.label.trim() || options.label.length > 200)
|
|
48
|
+
throw new Error("Choose a label of 1 to 200 characters.");
|
|
49
|
+
const worktree = fs.realpathSync(options.worktree);
|
|
50
|
+
if (!fs.statSync(worktree).isDirectory())
|
|
51
|
+
throw new Error("Choose a worktree directory.");
|
|
52
|
+
const id = `${options.provider}-${randomBytes(12).toString("hex")}`;
|
|
53
|
+
const root = jobsRoot(options.store), job = path.join(root, id);
|
|
54
|
+
fs.mkdirSync(job, { recursive: true, mode: 0o700 });
|
|
55
|
+
fs.chmodSync(root, 0o700);
|
|
56
|
+
const codexParent = uuid(env.CODEX_THREAD_ID || env.CODEX_SESSION_ID), claudeParent = uuid(env.CLAUDE_CODE_SESSION_ID);
|
|
57
|
+
const now = new Date().toISOString();
|
|
58
|
+
const manifest = { schemaVersion: 1, id, provider: options.provider, taskLabel: options.label,
|
|
59
|
+
cwd: worktree, worktree, model: options.model, eventLog: "events.jsonl", createdAt: now, startedAt: now, updatedAt: now,
|
|
60
|
+
status: "running", reason: options.reason, ...(options.resume ? { resumes: options.resume } : {}),
|
|
61
|
+
...(codexParent ? { parent: { provider: "codex", session: codexParent } } : claudeParent ? { parent: { provider: "claude", session: claudeParent } } : {}) };
|
|
62
|
+
for (const [file, content] of Object.entries({ "prompt.txt": options.prompt, "events.jsonl": "", "stderr.log": "" }))
|
|
63
|
+
fs.writeFileSync(path.join(job, file), content, { mode: 0o600 });
|
|
64
|
+
writeManifest(job, manifest);
|
|
65
|
+
return { job, manifest };
|
|
66
|
+
}
|
|
67
|
+
export async function launch(options, reservation = createJob(options)) {
|
|
68
|
+
const { job, manifest } = reservation, adapter = adapters[options.provider];
|
|
69
|
+
console.log(job);
|
|
70
|
+
const out = fs.openSync(path.join(job, manifest.eventLog), "a"), err = fs.openSync(path.join(job, "stderr.log"), "a");
|
|
71
|
+
// A served harness answers only with this password, so another local
|
|
72
|
+
// process cannot approve the worker's permission asks.
|
|
73
|
+
const password = randomBytes(24).toString("hex");
|
|
74
|
+
const child = spawn("nice", ["-n", "15", adapter.command, ...adapter.argv({ ...options, job })], {
|
|
75
|
+
cwd: manifest.worktree, env: { ...process.env, PHREN_FANOUT_JOB: manifest.id, PHREN_FANOUT_DIR: job,
|
|
76
|
+
...(adapter.drive ? { PHREN_FANOUT_APPROVALS: "1", OPENCODE_SERVER_USERNAME: "opencode", OPENCODE_SERVER_PASSWORD: password } : {}) },
|
|
77
|
+
stdio: ["pipe", "pipe", "pipe"], detached: process.platform !== "win32",
|
|
78
|
+
});
|
|
79
|
+
let pending = "", stderr = "", cancelled = false;
|
|
80
|
+
const watchdog = new LoopWatchdog();
|
|
81
|
+
const kill = () => { try {
|
|
82
|
+
if (process.platform !== "win32" && child.pid)
|
|
83
|
+
process.kill(-child.pid, "SIGTERM");
|
|
84
|
+
else
|
|
85
|
+
child.kill("SIGTERM");
|
|
86
|
+
}
|
|
87
|
+
catch { /* Already exited. */ } };
|
|
88
|
+
const cancel = () => { cancelled = true; kill(); };
|
|
89
|
+
for (const signal of ["SIGINT", "SIGTERM", "SIGHUP"])
|
|
90
|
+
process.on(signal, cancel);
|
|
91
|
+
const record = (session) => { if (session && !manifest.session) {
|
|
92
|
+
manifest.session = session;
|
|
93
|
+
writeManifest(job, manifest);
|
|
94
|
+
} };
|
|
95
|
+
const events = (chunk) => {
|
|
96
|
+
fs.writeSync(out, typeof chunk === "string" ? chunk : chunk.toString("utf8"));
|
|
97
|
+
pending += chunk.toString();
|
|
98
|
+
let newline;
|
|
99
|
+
while ((newline = pending.indexOf("\n")) >= 0) {
|
|
100
|
+
const line = pending.slice(0, newline);
|
|
101
|
+
pending = pending.slice(newline + 1);
|
|
102
|
+
try {
|
|
103
|
+
const event = JSON.parse(line);
|
|
104
|
+
watchdog.observe(event);
|
|
105
|
+
record(adapter.session(event));
|
|
106
|
+
}
|
|
107
|
+
catch { /* Partial or non-JSON provider output. */ }
|
|
108
|
+
}
|
|
109
|
+
if (pending.length > 1_048_576)
|
|
110
|
+
pending = "";
|
|
111
|
+
};
|
|
112
|
+
if (!adapter.drive)
|
|
113
|
+
child.stdout?.on("data", events);
|
|
114
|
+
child.stderr?.on("data", (chunk) => { fs.writeSync(err, chunk); stderr = (stderr + chunk.toString("utf8")).slice(-16_384); });
|
|
115
|
+
child.stdin?.on("error", () => { });
|
|
116
|
+
child.stdin?.end(adapter.drive ? undefined : options.prompt);
|
|
117
|
+
const closed = new Promise(resolve => { child.once("error", error => { fs.writeSync(err, `${error.message}\n`); resolve(127); }); child.once("close", code => resolve(cancelled ? 130 : code ?? 1)); });
|
|
118
|
+
const timer = setInterval(() => {
|
|
119
|
+
const reason = watchdog.reason();
|
|
120
|
+
if (!reason)
|
|
121
|
+
return;
|
|
122
|
+
fs.writeFileSync(path.join(job, "looped.txt"), reason + "\n", { mode: 0o600 });
|
|
123
|
+
atomicWriteText(path.join(job, "blocked.json"), JSON.stringify({ type: "tool_loop", pattern: "", message: reason, at: new Date().toISOString() }));
|
|
124
|
+
kill();
|
|
125
|
+
}, 30_000);
|
|
126
|
+
let exitCode;
|
|
127
|
+
if (adapter.drive) {
|
|
128
|
+
// The served harness never exits on its own: the driver's result is the
|
|
129
|
+
// worker's, and the server stops once the session is done.
|
|
130
|
+
const driven = await Promise.race([
|
|
131
|
+
adapter.drive(child, { ...options, worktree: manifest.worktree, job, jobId: manifest.id, password, emit: events, session: record })
|
|
132
|
+
.catch(error => { fs.writeSync(err, `${error instanceof Error ? error.message : String(error)}\n`); return 1; }),
|
|
133
|
+
closed.then(code => code === 0 ? 1 : code)
|
|
134
|
+
]);
|
|
135
|
+
kill();
|
|
136
|
+
await closed;
|
|
137
|
+
exitCode = cancelled ? 130 : driven;
|
|
138
|
+
}
|
|
139
|
+
else
|
|
140
|
+
exitCode = await closed;
|
|
141
|
+
clearInterval(timer);
|
|
142
|
+
for (const signal of ["SIGINT", "SIGTERM", "SIGHUP"])
|
|
143
|
+
process.off(signal, cancel);
|
|
144
|
+
fs.closeSync(out);
|
|
145
|
+
fs.closeSync(err);
|
|
146
|
+
const blockedFile = path.join(job, "blocked.json"), refusal = stderrRefusal(stderr);
|
|
147
|
+
if (refusal && !fs.existsSync(blockedFile))
|
|
148
|
+
atomicWriteText(blockedFile, JSON.stringify({ ...refusal, at: new Date().toISOString() }));
|
|
149
|
+
const blocked = fs.existsSync(blockedFile);
|
|
150
|
+
if (blocked)
|
|
151
|
+
console.error(`blocked: ${fs.readFileSync(blockedFile, "utf8").slice(0, 4000)}`);
|
|
152
|
+
fs.writeFileSync(path.join(job, "exit.txt"), `${exitCode}\n`, { mode: 0o600 });
|
|
153
|
+
writeManifest(job, { ...manifest, status: blocked ? "failed" : cancelled ? "cancelled" : exitCode === 0 ? "completed" : "failed",
|
|
154
|
+
exitCode, updatedAt: new Date().toISOString(), finishedAt: new Date().toISOString() });
|
|
155
|
+
return blocked && exitCode === 0 ? 1 : exitCode;
|
|
156
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { ChildProcess } from "node:child_process";
|
|
2
|
+
import type { LaunchOptions } from "./adapters/types.js";
|
|
3
|
+
export declare const DENIED_FEEDBACK = "The owner denied this request from the phone. Do not retry it; continue without it and say in your final report what you could not do because of it.";
|
|
4
|
+
export declare const UNANSWERED_FEEDBACK = "Nobody answered this permission request in time. Do not retry it; continue without it and say in your final report what you could not do because of it.";
|
|
5
|
+
export interface DriveOptions extends LaunchOptions {
|
|
6
|
+
store: string;
|
|
7
|
+
label: string;
|
|
8
|
+
prompt: string;
|
|
9
|
+
jobId: string;
|
|
10
|
+
password: string;
|
|
11
|
+
/** One `opencode run --format json` event line for the job's event log. */
|
|
12
|
+
emit(line: string): void;
|
|
13
|
+
/** The worker's session, as soon as it exists. */
|
|
14
|
+
session(id: string): void;
|
|
15
|
+
}
|
|
16
|
+
/** Drives one fan-out worker through `opencode serve` and its HTTP API rather
|
|
17
|
+
* than `opencode run`, which rejects every permission ask on its own. The
|
|
18
|
+
* events it writes are the ones `opencode run --format json` prints, so the
|
|
19
|
+
* Hook's transcript readers and the loop watchdog read them unchanged. A
|
|
20
|
+
* permission ask becomes the same request file the Phren plugin writes for a
|
|
21
|
+
* pane, the Hook shows it on the phone under the worker's parent, and the
|
|
22
|
+
* owner's answer resumes the same session: Allow runs the call, Deny rejects it
|
|
23
|
+
* with feedback so the worker carries on and reports the refusal. */
|
|
24
|
+
export declare function driveOpencode(child: ChildProcess, o: DriveOptions): Promise<number>;
|