@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
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import { resolveStoreConflicts } from "./conflict-resolve.js";
|
|
2
|
+
import { gitOperationRecovery, inProgressGitOperation } from "./git-state.js";
|
|
3
|
+
import { storeCommitMessage } from "../machine-identity.js";
|
|
4
|
+
const SENSITIVE_STORE_PATHSPECS = [".env", "**/.env", "*.pem", "*.key", ".config/auth-profiles.json"];
|
|
5
|
+
async function commitLocalStoreWrites(cwd, git, message) {
|
|
6
|
+
const add = await git(cwd, ["add", "--sparse", "-A"]);
|
|
7
|
+
if (!add.ok)
|
|
8
|
+
return { committed: false, error: add.error || "git add failed" };
|
|
9
|
+
await git(cwd, ["reset", "HEAD", "--", ...SENSITIVE_STORE_PATHSPECS]);
|
|
10
|
+
const staged = await git(cwd, ["diff", "--cached", "--name-only"]);
|
|
11
|
+
if (!staged.ok)
|
|
12
|
+
return { committed: false, error: staged.error || "git diff failed" };
|
|
13
|
+
if (!staged.output)
|
|
14
|
+
return { committed: false };
|
|
15
|
+
const commit = await git(cwd, ["-c", "commit.gpgsign=false", "commit", "-m", storeCommitMessage(message)]);
|
|
16
|
+
return commit.ok ? { committed: true } : { committed: false, error: commit.error || "git commit failed" };
|
|
17
|
+
}
|
|
18
|
+
async function conflictedPaths(cwd, git) {
|
|
19
|
+
const result = await git(cwd, ["diff", "--name-only", "--diff-filter=U"]);
|
|
20
|
+
return result.ok ? result.output.split("\n").map((entry) => entry.trim()).filter(Boolean) : [];
|
|
21
|
+
}
|
|
22
|
+
async function abortMerge(cwd, git) {
|
|
23
|
+
if (inProgressGitOperation(cwd) !== "merge")
|
|
24
|
+
return true;
|
|
25
|
+
const aborted = await git(cwd, ["merge", "--abort"]);
|
|
26
|
+
if (aborted.ok)
|
|
27
|
+
return true;
|
|
28
|
+
const reset = await git(cwd, ["reset", "--merge", "ORIG_HEAD"]);
|
|
29
|
+
return reset.ok && inProgressGitOperation(cwd) !== "merge";
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Fetch and integrate a store's configured upstream without rebasing local
|
|
33
|
+
* commits. Conflicts in tasks.md (per task id against the merge base), the
|
|
34
|
+
* generated summary and topic blocks, findings and the task archive resolve
|
|
35
|
+
* automatically (see conflict-resolve.ts). Any other conflict aborts the
|
|
36
|
+
* merge and names its files.
|
|
37
|
+
*/
|
|
38
|
+
export async function mergeStoreUpstream(cwd, options) {
|
|
39
|
+
const { git } = options;
|
|
40
|
+
const operation = inProgressGitOperation(cwd);
|
|
41
|
+
if (operation) {
|
|
42
|
+
const recovery = gitOperationRecovery(operation);
|
|
43
|
+
return {
|
|
44
|
+
status: "busy",
|
|
45
|
+
detail: `The store already has a Git operation in progress (${operation}). Run '${recovery}' in the store before syncing again.`,
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
const branch = await git(cwd, ["symbolic-ref", "--quiet", "HEAD"]);
|
|
49
|
+
if (!branch.ok)
|
|
50
|
+
return { status: "error", detail: "No branch is checked out." };
|
|
51
|
+
let committedLocalWrites = false;
|
|
52
|
+
if (options.commitLocalWrites !== false) {
|
|
53
|
+
const saved = await commitLocalStoreWrites(cwd, git, options.commitMessage ?? "auto-save phren (store sync)");
|
|
54
|
+
if (saved.error)
|
|
55
|
+
return { status: "error", detail: `Cannot commit local store writes: ${saved.error}` };
|
|
56
|
+
committedLocalWrites = saved.committed;
|
|
57
|
+
}
|
|
58
|
+
const refs = await git(cwd, ["for-each-ref", "--format=%(upstream:remotename)%09%(upstream:remoteref)%09%(upstream)", branch.output]);
|
|
59
|
+
const [remote, remoteRef, trackingRef] = refs.output.split("\t");
|
|
60
|
+
if (!refs.ok || !remote || !remoteRef || !trackingRef) {
|
|
61
|
+
return {
|
|
62
|
+
status: "unchanged",
|
|
63
|
+
detail: committedLocalWrites ? "Committed local store writes; no tracking remote is configured." : "No tracking remote is configured.",
|
|
64
|
+
committedLocalWrites,
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
const tracked = await git(cwd, ["rev-parse", "--verify", trackingRef]);
|
|
68
|
+
if (!options.advertisedHead || !tracked.ok || tracked.output !== options.advertisedHead) {
|
|
69
|
+
const fetched = await git(cwd, ["fetch", "--quiet", "--no-tags", "--no-recurse-submodules", "--", remote, `${remoteRef}:${trackingRef}`]);
|
|
70
|
+
if (!fetched.ok)
|
|
71
|
+
return { status: "error", detail: `Fetch failed: ${fetched.error || "unknown Git error"}`, committedLocalWrites };
|
|
72
|
+
}
|
|
73
|
+
const target = await git(cwd, ["rev-parse", "--verify", trackingRef]);
|
|
74
|
+
if (!target.ok || !target.output)
|
|
75
|
+
return { status: "error", detail: "Cannot read the fetched tracking branch.", committedLocalWrites };
|
|
76
|
+
if ((await git(cwd, ["merge-base", "--is-ancestor", target.output, "HEAD"])).ok) {
|
|
77
|
+
return {
|
|
78
|
+
status: "unchanged",
|
|
79
|
+
detail: committedLocalWrites ? "Committed local store writes; the store already contains the remote changes." : "The store already contains the remote changes.",
|
|
80
|
+
committedLocalWrites,
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
const canFastForward = (await git(cwd, ["merge-base", "--is-ancestor", "HEAD", target.output])).ok;
|
|
84
|
+
const merged = await git(cwd, canFastForward
|
|
85
|
+
? ["merge", "--ff-only", target.output]
|
|
86
|
+
: ["merge", "--no-edit", target.output]);
|
|
87
|
+
if (merged.ok) {
|
|
88
|
+
return {
|
|
89
|
+
status: "updated",
|
|
90
|
+
detail: canFastForward ? "Store fast-forwarded to the remote." : "Store merged with the remote.",
|
|
91
|
+
committedLocalWrites,
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
const initialConflicts = await conflictedPaths(cwd, git);
|
|
95
|
+
if (initialConflicts.length === 0 && inProgressGitOperation(cwd) !== "merge") {
|
|
96
|
+
return {
|
|
97
|
+
status: "error",
|
|
98
|
+
detail: `Merge failed before it started: ${merged.error || "unknown Git error"}`,
|
|
99
|
+
committedLocalWrites,
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
if (initialConflicts.length > 0 && resolveStoreConflicts(cwd).unresolved.length === 0) {
|
|
103
|
+
const commit = await git(cwd, ["-c", "commit.gpgsign=false", "commit", "--no-edit"]);
|
|
104
|
+
if (commit.ok) {
|
|
105
|
+
return {
|
|
106
|
+
status: "updated",
|
|
107
|
+
detail: `Store merged with the remote; resolved conflicts in ${initialConflicts.join(", ")}.`,
|
|
108
|
+
conflicts: initialConflicts,
|
|
109
|
+
committedLocalWrites,
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
const unresolvedConflicts = await conflictedPaths(cwd, git);
|
|
114
|
+
const conflicts = unresolvedConflicts.length > 0 ? unresolvedConflicts : initialConflicts;
|
|
115
|
+
const cleaned = await abortMerge(cwd, git);
|
|
116
|
+
if (!cleaned) {
|
|
117
|
+
return {
|
|
118
|
+
status: "error",
|
|
119
|
+
detail: `Merge cleanup failed${conflicts.length ? ` after conflicts in: ${conflicts.join(", ")}` : ""}. Run 'git merge --abort' in the store.`,
|
|
120
|
+
conflicts,
|
|
121
|
+
committedLocalWrites,
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
if (conflicts.length > 0) {
|
|
125
|
+
return {
|
|
126
|
+
status: "conflict",
|
|
127
|
+
detail: `Merge aborted; manual resolution is required for: ${conflicts.join(", ")}`,
|
|
128
|
+
conflicts,
|
|
129
|
+
committedLocalWrites,
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
return {
|
|
133
|
+
status: "error",
|
|
134
|
+
detail: `Merge failed and was aborted: ${merged.error || "unknown Git error"}`,
|
|
135
|
+
committedLocalWrites,
|
|
136
|
+
};
|
|
137
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Three-way merge of a tasks.md file by task id, for store sync conflicts.
|
|
3
|
+
*
|
|
4
|
+
* Each task is keyed by its `bid:` comment (or its normalized text when it has
|
|
5
|
+
* none) and compared across the merge base, the local side and the incoming
|
|
6
|
+
* side. The side that changed a task wins; when both changed it, a completed
|
|
7
|
+
* side wins, then an edit beats a removal, then the incoming side wins. The
|
|
8
|
+
* result keeps the incoming file's layout and section order.
|
|
9
|
+
*/
|
|
10
|
+
interface TaskEntry {
|
|
11
|
+
key: string;
|
|
12
|
+
section: string;
|
|
13
|
+
lines: string[];
|
|
14
|
+
}
|
|
15
|
+
/** The winning version of one task, or undefined when it is removed. */
|
|
16
|
+
export declare function pickTask<T extends TaskEntry>(base: T | undefined, ours: T | undefined, theirs: T | undefined): T | undefined;
|
|
17
|
+
/**
|
|
18
|
+
* Merges three versions of a tasks.md. `base` is empty when the file was
|
|
19
|
+
* added on both sides.
|
|
20
|
+
*/
|
|
21
|
+
export declare function mergeTasksByBid(base: string, ours: string, theirs: string): string;
|
|
22
|
+
export {};
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Three-way merge of a tasks.md file by task id, for store sync conflicts.
|
|
3
|
+
*
|
|
4
|
+
* Each task is keyed by its `bid:` comment (or its normalized text when it has
|
|
5
|
+
* none) and compared across the merge base, the local side and the incoming
|
|
6
|
+
* side. The side that changed a task wins; when both changed it, a completed
|
|
7
|
+
* side wins, then an edit beats a removal, then the incoming side wins. The
|
|
8
|
+
* result keeps the incoming file's layout and section order.
|
|
9
|
+
*/
|
|
10
|
+
const BID_PATTERN = /<!--\s*bid:([a-z0-9]{8})\b[^>]*-->/;
|
|
11
|
+
const COMPLETED_PATTERN = /^- \[[xX]\]/;
|
|
12
|
+
function taskKey(bullet) {
|
|
13
|
+
const bid = BID_PATTERN.exec(bullet);
|
|
14
|
+
if (bid)
|
|
15
|
+
return `bid:${bid[1]}`;
|
|
16
|
+
return `text:${bullet.replace(/^- \[[ xX]\]\s*/, "").replace(/<!--[\s\S]*?-->/g, "").trim().toLowerCase()}`;
|
|
17
|
+
}
|
|
18
|
+
/** Splits a tasks file into a preamble and `## ` sections of task records and other lines. */
|
|
19
|
+
function parse(content) {
|
|
20
|
+
const sections = [{ heading: null, name: "", rows: [] }];
|
|
21
|
+
let current = sections[0];
|
|
22
|
+
let task = null;
|
|
23
|
+
for (const line of content.replace(/\r\n/g, "\n").split("\n")) {
|
|
24
|
+
if (line.startsWith("## ")) {
|
|
25
|
+
task = null;
|
|
26
|
+
current = { heading: line, name: line.slice(3).trim(), rows: [] };
|
|
27
|
+
sections.push(current);
|
|
28
|
+
}
|
|
29
|
+
else if (line.startsWith("- ") && current.heading !== null) {
|
|
30
|
+
task = { key: taskKey(line), section: current.name, lines: [line] };
|
|
31
|
+
current.rows.push({ kind: "task", entry: task });
|
|
32
|
+
}
|
|
33
|
+
else if (task && line.startsWith(" ") && line.trim()) {
|
|
34
|
+
task.lines.push(line);
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
task = null;
|
|
38
|
+
current.rows.push({ kind: "line", text: line });
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return sections;
|
|
42
|
+
}
|
|
43
|
+
function index(sections) {
|
|
44
|
+
const map = new Map();
|
|
45
|
+
for (const section of sections) {
|
|
46
|
+
for (const row of section.rows) {
|
|
47
|
+
if (row.kind === "task" && !map.has(row.entry.key))
|
|
48
|
+
map.set(row.entry.key, row.entry);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return map;
|
|
52
|
+
}
|
|
53
|
+
const value = (entry) => entry ? `${entry.section}\n${entry.lines.join("\n")}` : undefined;
|
|
54
|
+
const completed = (entry) => !!entry && COMPLETED_PATTERN.test(entry.lines[0]);
|
|
55
|
+
/** The winning version of one task, or undefined when it is removed. */
|
|
56
|
+
export function pickTask(base, ours, theirs) {
|
|
57
|
+
const [b, o, t] = [value(base), value(ours), value(theirs)];
|
|
58
|
+
if (o === t)
|
|
59
|
+
return theirs;
|
|
60
|
+
if (o === b)
|
|
61
|
+
return theirs;
|
|
62
|
+
if (t === b)
|
|
63
|
+
return ours;
|
|
64
|
+
if (completed(ours) !== completed(theirs))
|
|
65
|
+
return completed(ours) ? ours : theirs;
|
|
66
|
+
if (!theirs)
|
|
67
|
+
return ours;
|
|
68
|
+
return theirs;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Merges three versions of a tasks.md. `base` is empty when the file was
|
|
72
|
+
* added on both sides.
|
|
73
|
+
*/
|
|
74
|
+
export function mergeTasksByBid(base, ours, theirs) {
|
|
75
|
+
const oursSections = parse(ours);
|
|
76
|
+
const theirsSections = parse(theirs);
|
|
77
|
+
const b = index(parse(base));
|
|
78
|
+
const o = index(oursSections);
|
|
79
|
+
const t = index(theirsSections);
|
|
80
|
+
const chosen = new Map();
|
|
81
|
+
for (const key of new Set([...b.keys(), ...o.keys(), ...t.keys()])) {
|
|
82
|
+
const winner = pickTask(b.get(key), o.get(key), t.get(key));
|
|
83
|
+
if (winner)
|
|
84
|
+
chosen.set(key, winner);
|
|
85
|
+
}
|
|
86
|
+
// Local order, per section, so a task only the local side placed there lands after its local predecessor.
|
|
87
|
+
const localOrder = new Map();
|
|
88
|
+
for (const section of oursSections) {
|
|
89
|
+
localOrder.set(section.name, section.rows.flatMap((row) => row.kind === "task" ? [row.entry.key] : []));
|
|
90
|
+
}
|
|
91
|
+
const emitted = new Set();
|
|
92
|
+
const out = [];
|
|
93
|
+
const renderSection = (section) => {
|
|
94
|
+
if (section.heading !== null)
|
|
95
|
+
out.push(section.heading);
|
|
96
|
+
const rows = section.rows.filter((row) => {
|
|
97
|
+
if (row.kind !== "task")
|
|
98
|
+
return true;
|
|
99
|
+
const winner = chosen.get(row.entry.key);
|
|
100
|
+
return !!winner && winner.section === section.name && !emitted.has(row.entry.key);
|
|
101
|
+
}).map((row) => row.kind === "task" ? { kind: "task", entry: chosen.get(row.entry.key) } : row);
|
|
102
|
+
for (const row of rows)
|
|
103
|
+
if (row.kind === "task")
|
|
104
|
+
emitted.add(row.entry.key);
|
|
105
|
+
if (section.heading !== null) {
|
|
106
|
+
const missing = [...chosen.values()].filter((entry) => entry.section === section.name && !emitted.has(entry.key));
|
|
107
|
+
const order = localOrder.get(section.name) ?? [];
|
|
108
|
+
for (const entry of missing) {
|
|
109
|
+
const at = order.indexOf(entry.key);
|
|
110
|
+
const before = order.slice(0, Math.max(at, 0)).reverse().find((key) => rows.some((row) => row.kind === "task" && row.entry.key === key));
|
|
111
|
+
let position;
|
|
112
|
+
if (before) {
|
|
113
|
+
position = rows.findIndex((row) => row.kind === "task" && row.entry.key === before) + 1;
|
|
114
|
+
}
|
|
115
|
+
else {
|
|
116
|
+
const first = rows.findIndex((row) => row.kind === "task");
|
|
117
|
+
if (at >= 0 && first >= 0) {
|
|
118
|
+
position = first;
|
|
119
|
+
}
|
|
120
|
+
else {
|
|
121
|
+
let last = -1;
|
|
122
|
+
rows.forEach((row, i) => { if (row.kind === "task")
|
|
123
|
+
last = i; });
|
|
124
|
+
position = last >= 0 ? last + 1 : (rows.length > 0 && rows[0].kind === "line" && rows[0].text === "" ? 1 : 0);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
rows.splice(position, 0, { kind: "task", entry });
|
|
128
|
+
emitted.add(entry.key);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
for (const row of rows) {
|
|
132
|
+
if (row.kind === "task")
|
|
133
|
+
out.push(...row.entry.lines);
|
|
134
|
+
else
|
|
135
|
+
out.push(row.text);
|
|
136
|
+
}
|
|
137
|
+
};
|
|
138
|
+
for (const section of theirsSections)
|
|
139
|
+
renderSection(section);
|
|
140
|
+
// Sections only the local side has, in local order.
|
|
141
|
+
const theirNames = new Set(theirsSections.map((section) => section.name));
|
|
142
|
+
for (const section of oursSections) {
|
|
143
|
+
if (section.heading === null || theirNames.has(section.name))
|
|
144
|
+
continue;
|
|
145
|
+
const entries = [...chosen.values()].filter((entry) => entry.section === section.name && !emitted.has(entry.key));
|
|
146
|
+
if (entries.length === 0)
|
|
147
|
+
continue;
|
|
148
|
+
if (out.length > 0 && out[out.length - 1] !== "")
|
|
149
|
+
out.push("");
|
|
150
|
+
out.push(section.heading, "");
|
|
151
|
+
for (const entry of entries) {
|
|
152
|
+
out.push(...entry.lines);
|
|
153
|
+
emitted.add(entry.key);
|
|
154
|
+
}
|
|
155
|
+
out.push("");
|
|
156
|
+
}
|
|
157
|
+
return out.join("\n");
|
|
158
|
+
}
|
package/dist/task/github.js
CHANGED
|
@@ -22,7 +22,7 @@ export function extractGithubRepoFromText(content) {
|
|
|
22
22
|
return match?.[1];
|
|
23
23
|
}
|
|
24
24
|
export function resolveProjectGithubRepo(phrenPath, project) {
|
|
25
|
-
for (const file of ["
|
|
25
|
+
for (const file of ["AGENTS.md", "summary.md"]) {
|
|
26
26
|
const fullPath = path.join(phrenPath, project, file);
|
|
27
27
|
if (!fs.existsSync(fullPath))
|
|
28
28
|
continue;
|
package/dist/task/lifecycle.d.ts
CHANGED
|
@@ -4,6 +4,11 @@ interface TaskPromptLifecycleResult {
|
|
|
4
4
|
mode: TaskMode;
|
|
5
5
|
noticeLines: string[];
|
|
6
6
|
}
|
|
7
|
+
/** What the person typed: the prompt without pasted blocks. */
|
|
8
|
+
export declare function typedPromptText(prompt: string): string;
|
|
9
|
+
/** A frame from another agent or the harness, or a message relayed from one,
|
|
10
|
+
* rather than something the person asked. */
|
|
11
|
+
export declare function isAgentFramePrompt(prompt: string): boolean;
|
|
7
12
|
export declare function handleTaskPromptLifecycle(args: {
|
|
8
13
|
phrenPath: string;
|
|
9
14
|
prompt: string;
|
package/dist/task/lifecycle.js
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import * as fs from "fs";
|
|
2
|
-
import { addTask,
|
|
2
|
+
import { addTask, readTasks, resolveTaskItem, updateTask, } from "../data/access.js";
|
|
3
3
|
import { parseGithubIssueUrl, resolveProjectGithubRepo } from "./github.js";
|
|
4
|
-
import { getProactivityLevelForTask, shouldAutoCaptureTaskForLevel, hasExecutionIntent, hasDiscoveryIntent, hasSuppressTaskIntent, hasCodeChangeContext } from "../proactivity.js";
|
|
4
|
+
import { getProactivityLevelForTask, shouldAutoCaptureTaskForLevel, hasExecutionIntent, hasDiscoveryIntent, hasExplicitTaskSignal, hasSuppressTaskIntent, hasCodeChangeContext } from "../proactivity.js";
|
|
5
5
|
import { getWorkflowPolicy } from "../shared/governance.js";
|
|
6
6
|
import { debugLog, sessionMarker } from "../shared.js";
|
|
7
7
|
import { errorMessage } from "../utils.js";
|
|
8
|
-
import { incrementSessionTasksCompleted } from "../tools/session.js";
|
|
9
8
|
const ACTION_PREFIX_RE = /^(?:please\s+|can you\s+|could you\s+|would you\s+|i want you to\s+|i want to\s+|let(?:'|’)s\s+|lets\s+|help me\s+)/i;
|
|
10
9
|
const EXPLICIT_TASK_PREFIX_RE = /^(?:add(?:\s+(?:this|that|it))?\s+(?:to\s+(?:the\s+)?)?(?:task|todo(?:\s+list)?|task(?:\s+list)?)|add\s+(?:a\s+)?task|put(?:\s+(?:this|that|it))?\s+(?:in|on)\s+(?:the\s+)?(?:task|todo(?:\s+list)?|task(?:\s+list)?))\s*(?::|-|,)?\s*/i;
|
|
11
10
|
const NON_ACTIONABLE_RE = /\b(brainstorm|idea|ideas|maybe|what if|should we|could we|would it make sense|question|explain|why is|how does)\b/i;
|
|
@@ -40,6 +39,39 @@ const PASTED_CONTENT_RE = new RegExp([
|
|
|
40
39
|
// because the observed echoes wrap filler around an incidental verb — "Its literally just the
|
|
41
40
|
// start of the day LMAO" clears the substance floor on "start" but is not a task.
|
|
42
41
|
const CONVERSATIONAL_FILLER_RE = /\b(?:lmao|lmfao|rofl|lol+|haha+|idk|idc|tbh|ngl|smh|wtf|meh|yolo)\b/i;
|
|
42
|
+
// Claude Code wraps bracketed-paste input as <pasted_content id="…">…</pasted_content id="…">:
|
|
43
|
+
// any multi-line paste, every message typed in from the phone, and every message another
|
|
44
|
+
// agent relays into the pane. The text inside cannot be told apart from someone else's
|
|
45
|
+
// words (a relayed conductor message rewrote a task's Context three times), so it never
|
|
46
|
+
// files or touches a task; only what was typed outside the wrapper counts.
|
|
47
|
+
const PASTED_CONTENT_WRAPPER_RE = /<pasted_content\b[^>]*>[\s\S]*?<\/pasted_content\b[^>]*>/g;
|
|
48
|
+
// A message relayed from another agent: "From the conductor, a correction: …",
|
|
49
|
+
// "From tidy-phren: …". One name (optionally after "the"), then a comma or colon.
|
|
50
|
+
const RELAYED_MESSAGE_RE = /^\s*from\s+(?:the\s+)?(?!(?:now|here|there|then|scratch|today|tomorrow)\b)[\w.-]+\s*[,:]/i;
|
|
51
|
+
// Frames another agent or the harness put in the prompt: a cross-session message, a
|
|
52
|
+
// sub-agent hand-back, a delivery/idle notice, a task or system notification, a system
|
|
53
|
+
// reminder. Not the person's request. Matched anywhere, since a harness may put the
|
|
54
|
+
// person's own words inside or after one of these, and a frame is never worth a task.
|
|
55
|
+
const AGENT_FRAME_RE = /<\/?(?:agent-message|cross-session-message|task-notification|system-reminder|system-notification|phren-notice|command-name|command-message)\b|\[(?:SYSTEM NOTIFICATION|Cross-session (?:delivery|idle) notice)\b/i;
|
|
56
|
+
// A reply to the agent — "Yep /herdr the phren agent is there" — starts with an
|
|
57
|
+
// acknowledgement and asks for nothing; a question ends with one.
|
|
58
|
+
const REPLY_OPENER_RE = /^(?:yep|yeah|yes|yup|ya|nah|no|nope|ok|okay|right|correct|exactly|indeed|true|sure|fine|agreed|(?:just\s+)?curious|(?:i(?:'|’)?m\s+)?wondering|i wonder)\b/i;
|
|
59
|
+
const QUESTION_RE = /\?\s*$/;
|
|
60
|
+
/** What the person typed: the prompt without pasted blocks. */
|
|
61
|
+
export function typedPromptText(prompt) {
|
|
62
|
+
return prompt.includes("<pasted_content") ? prompt.replace(PASTED_CONTENT_WRAPPER_RE, " ").trim() : prompt;
|
|
63
|
+
}
|
|
64
|
+
/** A frame from another agent or the harness, or a message relayed from one,
|
|
65
|
+
* rather than something the person asked. */
|
|
66
|
+
export function isAgentFramePrompt(prompt) {
|
|
67
|
+
return AGENT_FRAME_RE.test(prompt) || RELAYED_MESSAGE_RE.test(prompt);
|
|
68
|
+
}
|
|
69
|
+
/** A reply or a question: conversation with the agent, not a request for work. */
|
|
70
|
+
function isConversationalTurn(prompt) {
|
|
71
|
+
if (QUESTION_RE.test(prompt))
|
|
72
|
+
return true;
|
|
73
|
+
return REPLY_OPENER_RE.test(prompt) && !hasExplicitTaskSignal(prompt) && !hasExecutionIntent(prompt);
|
|
74
|
+
}
|
|
43
75
|
const ACTIONABLE_RE = /\b(add|build|change|complete|continue|create|delete|fix|implement|improve|investigate|make|move|refactor|remove|rename|repair|ship|start|update|wire)\b/i;
|
|
44
76
|
const CONTINUE_RE = /\b(continue|keep going|finish|resume|pick up|work on that|that task)\b/i;
|
|
45
77
|
const GITHUB_URL_RE = /https:\/\/github\.com\/[A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+\/issues\/\d+(?:[?#][^\s]*)?/g;
|
|
@@ -149,6 +181,10 @@ function isActionablePrompt(prompt, intent) {
|
|
|
149
181
|
return false;
|
|
150
182
|
if (CONVERSATIONAL_FILLER_RE.test(normalized))
|
|
151
183
|
return false;
|
|
184
|
+
if (isAgentFramePrompt(normalized))
|
|
185
|
+
return false;
|
|
186
|
+
if (isConversationalTurn(normalized))
|
|
187
|
+
return false;
|
|
152
188
|
// Substance floor — independent of intent / proactivity. Short utterances without
|
|
153
189
|
// any actionable signal are conversational fragments, not tasks.
|
|
154
190
|
if (!hasMinimumTaskSubstance(normalized))
|
|
@@ -272,24 +308,31 @@ export function handleTaskPromptLifecycle(args) {
|
|
|
272
308
|
if (mode === "off" || mode === "manual" || !args.project || !args.sessionId) {
|
|
273
309
|
return { mode, noticeLines: [] };
|
|
274
310
|
}
|
|
311
|
+
// A sub-agent hand-back, a system notification or a harness reminder arrives as a
|
|
312
|
+
// prompt but nobody typed it: it never creates, moves or reuses a task.
|
|
313
|
+
if (isAgentFramePrompt(args.prompt)) {
|
|
314
|
+
debugLog(`task lifecycle skipped ${args.project}: machine-originated prompt`);
|
|
315
|
+
return { mode, noticeLines: [] };
|
|
316
|
+
}
|
|
317
|
+
const prompt = typedPromptText(args.prompt);
|
|
275
318
|
// Suppression takes absolute priority — user explicitly said not to create a task.
|
|
276
|
-
if (hasSuppressTaskIntent(
|
|
319
|
+
if (hasSuppressTaskIntent(prompt)) {
|
|
277
320
|
debugLog(`task lifecycle suppressed ${args.project}: suppress-task intent detected`);
|
|
278
321
|
return { mode, noticeLines: [] };
|
|
279
322
|
}
|
|
280
|
-
if (!isActionablePrompt(
|
|
323
|
+
if (!isActionablePrompt(prompt, args.intent)) {
|
|
281
324
|
return { mode, noticeLines: [] };
|
|
282
325
|
}
|
|
283
326
|
const taskLevel = args.taskLevel ?? getProactivityLevelForTask(args.phrenPath);
|
|
284
|
-
if (mode === "auto" && !shouldAutoCaptureTaskForLevel(taskLevel,
|
|
327
|
+
if (mode === "auto" && !shouldAutoCaptureTaskForLevel(taskLevel, prompt)) {
|
|
285
328
|
debugLog(`task lifecycle skipped ${args.project}: task proactivity=${taskLevel}`);
|
|
286
329
|
return { mode, noticeLines: [] };
|
|
287
330
|
}
|
|
288
331
|
const parsed = readTasks(args.phrenPath, args.project);
|
|
289
332
|
if (!parsed.ok)
|
|
290
333
|
return { mode, noticeLines: [] };
|
|
291
|
-
const summary = normalizeTaskSummary(
|
|
292
|
-
const issueMeta = extractGithubMetadata(args.phrenPath, args.project,
|
|
334
|
+
const summary = normalizeTaskSummary(prompt);
|
|
335
|
+
const issueMeta = extractGithubMetadata(args.phrenPath, args.project, prompt);
|
|
293
336
|
const trackedState = readTaskSessionState(args.phrenPath, args.sessionId);
|
|
294
337
|
const trackedItem = trackedState && trackedState.project === args.project
|
|
295
338
|
? resolveTrackedSessionTask(args.phrenPath, trackedState)
|
|
@@ -297,7 +340,7 @@ export function handleTaskPromptLifecycle(args) {
|
|
|
297
340
|
const activeItems = parsed.data.items.Active;
|
|
298
341
|
const reusable = trackedItem && trackedItem.section === "Active"
|
|
299
342
|
? trackedItem
|
|
300
|
-
: matchExistingActiveTask(
|
|
343
|
+
: matchExistingActiveTask(prompt, activeItems);
|
|
301
344
|
if (mode === "suggest") {
|
|
302
345
|
const line = reusable?.line || summary;
|
|
303
346
|
return {
|
|
@@ -308,7 +351,7 @@ export function handleTaskPromptLifecycle(args) {
|
|
|
308
351
|
// Intent-aware auto mode: if the user is in discovery mode (brainstorming,
|
|
309
352
|
// exploring ideas) and NOT in execution mode (approving, committing to work,
|
|
310
353
|
// or performing code changes), create a speculative task and surface a suggestion.
|
|
311
|
-
if (mode === "auto" && !hasExecutionIntent(
|
|
354
|
+
if (mode === "auto" && !hasExecutionIntent(prompt) && !hasCodeChangeContext(prompt) && hasDiscoveryIntent(prompt)) {
|
|
312
355
|
const line = reusable?.line || summary;
|
|
313
356
|
debugLog(`task lifecycle auto→speculative ${args.project}: discovery intent detected`);
|
|
314
357
|
if (!reusable) {
|
|
@@ -334,12 +377,15 @@ export function handleTaskPromptLifecycle(args) {
|
|
|
334
377
|
return { mode, noticeLines: [] };
|
|
335
378
|
}
|
|
336
379
|
}
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
380
|
+
// Something the person asked to track ("add this to task") goes to Active, as does
|
|
381
|
+
// a match on a task that is already there. What the hook picked up on its own is a
|
|
382
|
+
// guess about the work: it waits in Queue until someone takes it up.
|
|
383
|
+
// An existing task keeps its own Context and GitHub link: a later prompt that
|
|
384
|
+
// matches it is not a better description of the work.
|
|
385
|
+
const section = reusable || hasExplicitTaskSignal(prompt) ? "active" : "queue";
|
|
386
|
+
const update = updateTask(args.phrenPath, args.project, targetMatch || summary, reusable
|
|
387
|
+
? { section }
|
|
388
|
+
: { section, context: summary, replace_context: true, ...issueMeta });
|
|
343
389
|
if (!update.ok) {
|
|
344
390
|
debugLog(`task lifecycle update ${args.project}: ${update.error}`);
|
|
345
391
|
return { mode, noticeLines: [] };
|
|
@@ -354,7 +400,7 @@ export function handleTaskPromptLifecycle(args) {
|
|
|
354
400
|
mode,
|
|
355
401
|
noticeLines: [
|
|
356
402
|
"<phren-notice>",
|
|
357
|
-
|
|
403
|
+
`${section === "active" ? "Active" : "Queued"} task (${args.project}): ${resolved.data.line}`,
|
|
358
404
|
"<phren-notice>",
|
|
359
405
|
],
|
|
360
406
|
};
|
|
@@ -367,12 +413,10 @@ export function finalizeTaskSession(args) {
|
|
|
367
413
|
return;
|
|
368
414
|
const match = state.stableId ? `bid:${state.stableId}` : state.item;
|
|
369
415
|
if (args.status === "saved-local" || args.status === "saved-pushed" || args.status === "no-upstream") {
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
}
|
|
375
|
-
incrementSessionTasksCompleted(args.phrenPath, 1, state.sessionId, state.project);
|
|
416
|
+
// A saved turn is not finished work. The Stop hook runs after every turn, so
|
|
417
|
+
// completing here marked real work Done as soon as the next prompt came in.
|
|
418
|
+
// The task stays where it is; completion is explicit. Detaching it keeps the
|
|
419
|
+
// next prompt from rewriting its context unless that prompt matches it.
|
|
376
420
|
clearTaskSessionState(args.phrenPath, args.sessionId);
|
|
377
421
|
return;
|
|
378
422
|
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/** Removes CSI sequences (colors, cursor moves, modes), OSC sequences (window
|
|
2
|
+
* titles, hyperlinks) and carriage returns. Line breaks and every printable
|
|
3
|
+
* character are kept, box drawing and spinners included: callers that parse a
|
|
4
|
+
* harness screen drop those themselves, because there they carry meaning. */
|
|
5
|
+
export declare function stripTerminal(text: string): string;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// Plain text from terminal output: pane reads, harness screens, CLI stdout.
|
|
2
|
+
// CSI (ESC [ parameters, intermediates, final byte), OSC (ESC ] up to BEL or
|
|
3
|
+
// ESC \) and carriage returns, in one pass.
|
|
4
|
+
const TERMINAL_CONTROL = /\x1b\[[0-?]*[ -/]*[@-~]|\x1b\][^\x07\x1b]*(?:\x07|\x1b\\)|\r/g;
|
|
5
|
+
/** Removes CSI sequences (colors, cursor moves, modes), OSC sequences (window
|
|
6
|
+
* titles, hyperlinks) and carriage returns. Line breaks and every printable
|
|
7
|
+
* character are kept, box drawing and spinners included: callers that parse a
|
|
8
|
+
* harness screen drop those themselves, because there they carry meaning. */
|
|
9
|
+
export function stripTerminal(text) {
|
|
10
|
+
return text.replace(TERMINAL_CONTROL, "");
|
|
11
|
+
}
|
|
@@ -35,6 +35,13 @@ function sandboxHomeDir() {
|
|
|
35
35
|
sandboxHome = fs.mkdtempSync(path.join(os.tmpdir(), "phren-test-home-"));
|
|
36
36
|
process.env.HOME = sandboxHome;
|
|
37
37
|
process.env.USERPROFILE = sandboxHome;
|
|
38
|
+
// findPhrenPath walks up from the cwd before it tries $HOME/.phren. The
|
|
39
|
+
// checkout usually sits under the developer's real home, so that walk found
|
|
40
|
+
// their real ~/.phren and the logger appended every test's errors to its
|
|
41
|
+
// .runtime/debug.log. Naming the sandbox's own store skips the walk and
|
|
42
|
+
// resolves exactly as on a clean CI machine: the sandbox store if a test
|
|
43
|
+
// makes one, otherwise no store. A test that needs the walk clears this.
|
|
44
|
+
process.env.PHREN_PATH = path.join(sandboxHome, ".phren");
|
|
38
45
|
}
|
|
39
46
|
export async function teardown() {
|
|
40
47
|
if (sandboxHome)
|
package/dist/tool-registry.d.ts
CHANGED
package/dist/tool-registry.js
CHANGED
|
@@ -108,8 +108,10 @@ export function getToolsByCategory() {
|
|
|
108
108
|
}))
|
|
109
109
|
.filter((entry) => entry.tools.length > 0);
|
|
110
110
|
}
|
|
111
|
-
export function renderToolCatalogMarkdown() {
|
|
111
|
+
export function renderToolCatalogMarkdown(allowed) {
|
|
112
112
|
return getToolsByCategory()
|
|
113
|
+
.map(entry => ({ ...entry, tools: entry.tools.filter(tool => !allowed || allowed.has(tool.name)) }))
|
|
114
|
+
.filter(entry => entry.tools.length > 0)
|
|
113
115
|
.map(({ category, tools }) => {
|
|
114
116
|
const lines = tools.map((tool) => `- \`${tool.name}\`: ${tool.description}`);
|
|
115
117
|
return `**${category}:**\n${lines.join("\n")}`;
|