@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/content/validate.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { nonInteractiveGitEnv } from "../utils-helpers.js";
|
|
1
2
|
import * as fs from "fs";
|
|
2
3
|
import * as path from "path";
|
|
3
4
|
import * as crypto from "crypto";
|
|
@@ -5,10 +6,10 @@ import { execFileSync } from "child_process";
|
|
|
5
6
|
import { debugLog, EXEC_TIMEOUT_MS, getProjectDirs } from "../shared.js";
|
|
6
7
|
import { errorMessage } from "../utils.js";
|
|
7
8
|
import { countActiveFindings } from "./archive.js";
|
|
8
|
-
import { isTaskFileName } from "../
|
|
9
|
+
import { isTaskFileName } from "../filenames.js";
|
|
9
10
|
import { METADATA_REGEX } from "./metadata.js";
|
|
10
11
|
import { getNonPrimaryStores, getStoreProjectDirs } from "../store-registry.js";
|
|
11
|
-
import { FINDINGS_FILENAME } from "../
|
|
12
|
+
import { FINDINGS_FILENAME } from "../filenames.js";
|
|
12
13
|
/** Maximum allowed length for a single finding entry (token budget protection). */
|
|
13
14
|
export const MAX_FINDING_LENGTH = 2000;
|
|
14
15
|
function safeParseDate(s) {
|
|
@@ -181,160 +182,225 @@ export function extractConflictVersions(content) {
|
|
|
181
182
|
}
|
|
182
183
|
return { ours: oursLines.join("\n"), theirs: theirsLines.join("\n") };
|
|
183
184
|
}
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
185
|
+
/** Does this line open a region that is not a live date section? */
|
|
186
|
+
function opensTrailingRegion(line) {
|
|
187
|
+
const trimmed = line.trim();
|
|
188
|
+
if (trimmed.startsWith("<details"))
|
|
189
|
+
return true;
|
|
190
|
+
if (trimmed.startsWith("<!-- phren:archive:start"))
|
|
191
|
+
return true;
|
|
192
|
+
if (line.startsWith("## ") && !/^\d{4}-\d{2}-\d{2}$/.test(line.slice(3).trim()))
|
|
193
|
+
return true;
|
|
194
|
+
return false;
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Parse FINDINGS.md into title / preamble / date sections / trailing.
|
|
198
|
+
*
|
|
199
|
+
* Two rules matter for not losing content:
|
|
200
|
+
*
|
|
201
|
+
* 1. A finding block is its bullet plus **every** following line up to the next
|
|
202
|
+
* bullet, heading, or blank line — not only `<!--` comments. Hand-written
|
|
203
|
+
* indented detail lines (" - rationale: …") used to end the block, which
|
|
204
|
+
* dropped them *and* the citation comment that followed them.
|
|
205
|
+
* 2. Once an archive wrapper (`<details>`, `<!-- phren:archive:start -->`) or a
|
|
206
|
+
* non-date `## ` section starts, everything after it is trailing content that
|
|
207
|
+
* is carried through verbatim. Parsing archived bullets as live date entries
|
|
208
|
+
* is how a merge promoted archived findings back into the active section.
|
|
209
|
+
*/
|
|
210
|
+
function parseFindings(content) {
|
|
211
|
+
const lines = content.split("\n");
|
|
212
|
+
const title = lines[0] ?? "# Findings";
|
|
213
|
+
const preamble = [];
|
|
214
|
+
const dates = new Map();
|
|
215
|
+
const trailing = [];
|
|
190
216
|
let currentDate = "";
|
|
191
217
|
let currentBlock = [];
|
|
192
|
-
|
|
193
|
-
|
|
218
|
+
let phase = "preamble";
|
|
219
|
+
const flush = () => {
|
|
220
|
+
if (currentBlock.length > 0 && currentDate) {
|
|
221
|
+
dates.get(currentDate).push(currentBlock.join("\n").replace(/\s+$/, ""));
|
|
222
|
+
}
|
|
223
|
+
currentBlock = [];
|
|
224
|
+
};
|
|
225
|
+
for (let i = 1; i < lines.length; i++) {
|
|
194
226
|
const line = lines[i];
|
|
195
|
-
if (
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
entries.get(currentDate).push(currentBlock.join("\n"));
|
|
199
|
-
currentBlock = [];
|
|
200
|
-
}
|
|
201
|
-
const heading = line.slice(3).trim();
|
|
202
|
-
if (/^\d{4}-\d{2}-\d{2}$/.test(heading)) {
|
|
203
|
-
currentDate = heading;
|
|
204
|
-
if (!entries.has(currentDate))
|
|
205
|
-
entries.set(currentDate, []);
|
|
206
|
-
}
|
|
227
|
+
if (phase === "trailing") {
|
|
228
|
+
trailing.push(line);
|
|
229
|
+
continue;
|
|
207
230
|
}
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
231
|
+
if (opensTrailingRegion(line)) {
|
|
232
|
+
flush();
|
|
233
|
+
phase = "trailing";
|
|
234
|
+
trailing.push(line);
|
|
235
|
+
continue;
|
|
236
|
+
}
|
|
237
|
+
if (line.startsWith("## ") && /^\d{4}-\d{2}-\d{2}$/.test(line.slice(3).trim())) {
|
|
238
|
+
flush();
|
|
239
|
+
phase = "dates";
|
|
240
|
+
currentDate = line.slice(3).trim();
|
|
241
|
+
if (!dates.has(currentDate))
|
|
242
|
+
dates.set(currentDate, []);
|
|
243
|
+
continue;
|
|
244
|
+
}
|
|
245
|
+
if (phase === "preamble") {
|
|
246
|
+
preamble.push(line);
|
|
247
|
+
continue;
|
|
248
|
+
}
|
|
249
|
+
if (line.startsWith("- ")) {
|
|
250
|
+
flush();
|
|
213
251
|
currentBlock = [line];
|
|
252
|
+
continue;
|
|
214
253
|
}
|
|
215
|
-
|
|
216
|
-
//
|
|
254
|
+
if (line.trim() !== "") {
|
|
255
|
+
// Either a continuation of the current finding (an indented sub-bullet, a
|
|
256
|
+
// metadata comment, a wrapped sentence) or, with no bullet open, a stray
|
|
257
|
+
// run of content — a fenced block, a stray paragraph. Both are kept as
|
|
258
|
+
// part of a block so the writer can put them back; dropping "lines the
|
|
259
|
+
// parser did not recognise" is what made this merge lossy.
|
|
217
260
|
currentBlock.push(line);
|
|
261
|
+
continue;
|
|
218
262
|
}
|
|
219
|
-
|
|
220
|
-
// Non-comment, non-bullet line: flush any pending block
|
|
221
|
-
if (currentBlock.length > 0 && currentDate) {
|
|
222
|
-
entries.get(currentDate).push(currentBlock.join("\n"));
|
|
223
|
-
currentBlock = [];
|
|
224
|
-
}
|
|
225
|
-
}
|
|
263
|
+
flush();
|
|
226
264
|
}
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
265
|
+
flush();
|
|
266
|
+
while (preamble.length > 0 && preamble[preamble.length - 1].trim() === "")
|
|
267
|
+
preamble.pop();
|
|
268
|
+
while (trailing.length > 0 && trailing[trailing.length - 1].trim() === "")
|
|
269
|
+
trailing.pop();
|
|
270
|
+
return { title, preamble, dates, trailing };
|
|
232
271
|
}
|
|
233
272
|
// Extract the bullet text from a finding block (first line) for dedup purposes
|
|
234
273
|
function findingBulletText(block) {
|
|
235
274
|
// Strip stable finding ID so two entries with different fids but same text are considered duplicates during merge.
|
|
236
275
|
return block.split("\n")[0].replace(METADATA_REGEX.findingId, "").replace(/\s+/g, " ").trim();
|
|
237
276
|
}
|
|
238
|
-
/**
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
break;
|
|
250
|
-
preamble.push(line);
|
|
277
|
+
/** Union two line lists, keeping order and dropping lines already present. */
|
|
278
|
+
function unionLines(ourLines, theirLines) {
|
|
279
|
+
const present = new Set(ourLines.map((line) => line.trim()).filter(Boolean));
|
|
280
|
+
const out = [...ourLines];
|
|
281
|
+
for (const line of theirLines) {
|
|
282
|
+
const key = line.trim();
|
|
283
|
+
if (key && present.has(key))
|
|
284
|
+
continue;
|
|
285
|
+
if (key)
|
|
286
|
+
present.add(key);
|
|
287
|
+
out.push(line);
|
|
251
288
|
}
|
|
252
|
-
|
|
253
|
-
|
|
289
|
+
while (out.length > 0 && out[out.length - 1].trim() === "")
|
|
290
|
+
out.pop();
|
|
291
|
+
return out;
|
|
254
292
|
}
|
|
255
293
|
/**
|
|
256
|
-
*
|
|
257
|
-
*
|
|
294
|
+
* Union trailing regions (archive `<details>` blocks, non-date sections).
|
|
295
|
+
*
|
|
296
|
+
* Segment-wise rather than line-wise: filtering individual lines could strip a
|
|
297
|
+
* bullet out of theirs' `<details>` block and leave a stray `</details>`. When
|
|
298
|
+
* one side's content lines are a subset of the other's, the subset is dropped —
|
|
299
|
+
* that covers the common "theirs is ours plus one archived finding" case. When
|
|
300
|
+
* they genuinely differ, both are emitted: a duplicated archive block is
|
|
301
|
+
* recoverable, a deleted one is not.
|
|
258
302
|
*/
|
|
259
|
-
function
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
303
|
+
function unionTrailing(ourTrailing, theirTrailing) {
|
|
304
|
+
if (ourTrailing.length === 0)
|
|
305
|
+
return [...theirTrailing];
|
|
306
|
+
if (theirTrailing.length === 0)
|
|
307
|
+
return [...ourTrailing];
|
|
308
|
+
const ourKeys = new Set(ourTrailing.map((line) => line.trim()).filter(Boolean));
|
|
309
|
+
const theirContent = theirTrailing.map((line) => line.trim()).filter(Boolean);
|
|
310
|
+
if (theirContent.every((line) => ourKeys.has(line)))
|
|
311
|
+
return [...ourTrailing];
|
|
312
|
+
const theirKeys = new Set(theirContent);
|
|
313
|
+
const ourContent = ourTrailing.map((line) => line.trim()).filter(Boolean);
|
|
314
|
+
if (ourContent.every((line) => theirKeys.has(line)))
|
|
315
|
+
return [...theirTrailing];
|
|
316
|
+
return [...ourTrailing, "", ...theirTrailing];
|
|
317
|
+
}
|
|
318
|
+
/** Content lines a merge must round-trip: no blanks, no title, no date headings. */
|
|
319
|
+
function significantLines(content) {
|
|
320
|
+
return content
|
|
321
|
+
.split("\n")
|
|
322
|
+
.slice(1)
|
|
323
|
+
.map((line) => line.trim())
|
|
324
|
+
.filter((line) => line !== "")
|
|
325
|
+
.filter((line) => !(line.startsWith("## ") && /^\d{4}-\d{2}-\d{2}$/.test(line.slice(3).trim())));
|
|
326
|
+
}
|
|
327
|
+
/** Raised when a merge would drop content; the caller must leave the conflict alone. */
|
|
328
|
+
export class FindingsMergeLossError extends Error {
|
|
281
329
|
}
|
|
282
330
|
/**
|
|
283
331
|
* Merge two FINDINGS.md versions: union entries per date, newest date first.
|
|
284
|
-
*
|
|
285
|
-
*
|
|
286
|
-
*
|
|
332
|
+
*
|
|
333
|
+
* Deduplicates by bullet text, keeping the continuation lines of whichever copy
|
|
334
|
+
* wins (ours takes priority). Preamble and trailing regions are unioned from
|
|
335
|
+
* **both** sides — taking them from `ours` alone silently deleted theirs'
|
|
336
|
+
* archive blocks and non-date sections.
|
|
337
|
+
*
|
|
338
|
+
* Runs unattended (push_changes, session-stop conflict recovery) and its result
|
|
339
|
+
* is committed and pushed, so it verifies itself: every content line of either
|
|
340
|
+
* input must appear in the output, and a merge that cannot manage that throws
|
|
341
|
+
* `FindingsMergeLossError` rather than committing the loss. Callers leave the
|
|
342
|
+
* conflict for the user.
|
|
287
343
|
*/
|
|
288
344
|
export function mergeFindings(ours, theirs) {
|
|
289
|
-
const
|
|
290
|
-
const
|
|
291
|
-
const
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
345
|
+
const { text, dedupedContinuations } = buildMergedFindings(ours, theirs);
|
|
346
|
+
const present = new Set(text.split("\n").map((line) => line.trim()));
|
|
347
|
+
const lost = [...significantLines(ours), ...significantLines(theirs)]
|
|
348
|
+
.filter((line) => !present.has(line))
|
|
349
|
+
// A block that lost a dedup race takes its own continuation lines with it —
|
|
350
|
+
// that is the intended rule (the finding is present, ours' provenance wins),
|
|
351
|
+
// not the content loss this guard exists to catch.
|
|
352
|
+
.filter((line) => !dedupedContinuations.has(line));
|
|
353
|
+
if (lost.length > 0) {
|
|
354
|
+
throw new FindingsMergeLossError(`Refusing to auto-merge ${FINDINGS_FILENAME}: ${lost.length} line(s) would be dropped, ` +
|
|
355
|
+
`starting with "${lost[0].slice(0, 80)}". Resolve this conflict by hand.`);
|
|
300
356
|
}
|
|
301
|
-
|
|
357
|
+
return text;
|
|
358
|
+
}
|
|
359
|
+
function buildMergedFindings(ours, theirs) {
|
|
360
|
+
const ourSide = parseFindings(ours);
|
|
361
|
+
const theirSide = parseFindings(theirs);
|
|
362
|
+
const allDates = [...new Set([...ourSide.dates.keys(), ...theirSide.dates.keys()])].sort().reverse();
|
|
363
|
+
const lines = [ourSide.title || theirSide.title || "# Findings"];
|
|
364
|
+
const dedupedContinuations = new Set();
|
|
365
|
+
const preamble = unionLines(ourSide.preamble, theirSide.preamble);
|
|
366
|
+
if (preamble.length > 0)
|
|
367
|
+
lines.push(...preamble, "");
|
|
368
|
+
else
|
|
302
369
|
lines.push("");
|
|
303
|
-
}
|
|
304
370
|
for (const date of allDates) {
|
|
305
|
-
const ourItems = ourEntries.get(date) ?? [];
|
|
306
|
-
const theirItems = theirEntries.get(date) ?? [];
|
|
307
|
-
// Dedup by bullet text, ours wins on conflict
|
|
308
371
|
const seen = new Set();
|
|
309
372
|
const merged = [];
|
|
310
|
-
for (const block of
|
|
311
|
-
const key = findingBulletText(block);
|
|
312
|
-
if (!seen.has(key)) {
|
|
313
|
-
seen.add(key);
|
|
314
|
-
merged.push(block);
|
|
315
|
-
}
|
|
316
|
-
}
|
|
317
|
-
for (const block of theirItems) {
|
|
373
|
+
for (const block of [...(ourSide.dates.get(date) ?? []), ...(theirSide.dates.get(date) ?? [])]) {
|
|
318
374
|
const key = findingBulletText(block);
|
|
319
|
-
if (
|
|
320
|
-
|
|
321
|
-
|
|
375
|
+
if (seen.has(key)) {
|
|
376
|
+
for (const line of block.split("\n").slice(1)) {
|
|
377
|
+
const trimmed = line.trim();
|
|
378
|
+
if (trimmed)
|
|
379
|
+
dedupedContinuations.add(trimmed);
|
|
380
|
+
}
|
|
381
|
+
continue;
|
|
322
382
|
}
|
|
383
|
+
seen.add(key);
|
|
384
|
+
merged.push(block);
|
|
323
385
|
}
|
|
324
386
|
if (merged.length > 0) {
|
|
325
387
|
lines.push(`## ${date}`, "");
|
|
326
|
-
for (const block of merged)
|
|
388
|
+
for (const block of merged)
|
|
327
389
|
lines.push(block, "");
|
|
328
|
-
}
|
|
329
390
|
}
|
|
330
391
|
}
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
return lines.join("\n");
|
|
392
|
+
const trailing = unionTrailing(ourSide.trailing, theirSide.trailing);
|
|
393
|
+
if (trailing.length > 0)
|
|
394
|
+
lines.push(...trailing, "");
|
|
395
|
+
return { text: lines.join("\n"), dedupedContinuations };
|
|
335
396
|
}
|
|
336
|
-
/**
|
|
337
|
-
|
|
397
|
+
/**
|
|
398
|
+
* Pattern for the stable bid comment embedded in task lines. The comment carries
|
|
399
|
+
* more than the bid in real files (`<!-- bid:HASH rank:N created:... -->`), so the
|
|
400
|
+
* pattern must accept any trailing fields up to the closing `-->` — matching only
|
|
401
|
+
* `<!-- bid:HASH -->` silently disabled stable-ID dedup in the union merge.
|
|
402
|
+
*/
|
|
403
|
+
const MERGE_BID_PATTERN = /<!--\s*bid:([a-z0-9]{8})\b[^>]*-->/;
|
|
338
404
|
/** Render a TaskRecord back to its original lines. */
|
|
339
405
|
function renderTaskRecord(record) {
|
|
340
406
|
return [record.bullet, ...record.continuations];
|
|
@@ -372,7 +438,10 @@ function parseTaskSections(content) {
|
|
|
372
438
|
continuations: [],
|
|
373
439
|
};
|
|
374
440
|
}
|
|
375
|
-
else if (currentRecord && line.
|
|
441
|
+
else if (currentRecord && line.startsWith(" ") && line.trim()) {
|
|
442
|
+
// Any indented, non-empty line belongs to the preceding task: Context:,
|
|
443
|
+
// GitHub:, sub-bullets. Keeping only Context: dropped GitHub links (and any
|
|
444
|
+
// future continuation field) from the merged file.
|
|
376
445
|
currentRecord.continuations.push(line);
|
|
377
446
|
}
|
|
378
447
|
else {
|
|
@@ -426,14 +495,23 @@ export function mergeTask(ours, theirs) {
|
|
|
426
495
|
}
|
|
427
496
|
return lines.join("\n");
|
|
428
497
|
}
|
|
498
|
+
/** The store paths whose record-oriented markdown can safely use union merge. */
|
|
499
|
+
export function isAutoMergeableStorePath(relFile) {
|
|
500
|
+
const normalized = relFile.replace(/\\/g, "/");
|
|
501
|
+
const filename = path.posix.basename(normalized).toLowerCase();
|
|
502
|
+
return filename === "findings.md"
|
|
503
|
+
|| isTaskFileName(filename)
|
|
504
|
+
|| /^\.config\/task-archive\/[^/]+\.md$/i.test(normalized);
|
|
505
|
+
}
|
|
429
506
|
/**
|
|
430
|
-
* Attempt to auto-resolve git conflicts in
|
|
507
|
+
* Attempt to auto-resolve git conflicts in union-safe store markdown files.
|
|
431
508
|
* Returns true if all conflicts were resolved, false if any remain.
|
|
432
509
|
*/
|
|
433
510
|
export function autoMergeConflicts(phrenPath) {
|
|
434
511
|
let conflictedFiles;
|
|
435
512
|
try {
|
|
436
513
|
const out = execFileSync("git", ["diff", "--name-only", "--diff-filter=U"], {
|
|
514
|
+
env: nonInteractiveGitEnv(),
|
|
437
515
|
cwd: phrenPath,
|
|
438
516
|
encoding: "utf8",
|
|
439
517
|
stdio: ["ignore", "pipe", "ignore"],
|
|
@@ -451,7 +529,7 @@ export function autoMergeConflicts(phrenPath) {
|
|
|
451
529
|
for (const relFile of conflictedFiles) {
|
|
452
530
|
const fullPath = path.join(phrenPath, relFile);
|
|
453
531
|
const filename = path.basename(relFile).toLowerCase();
|
|
454
|
-
const canAutoMerge =
|
|
532
|
+
const canAutoMerge = isAutoMergeableStorePath(relFile);
|
|
455
533
|
if (!canAutoMerge) {
|
|
456
534
|
debugLog(`Cannot auto-merge: ${relFile} (not a known mergeable file)`);
|
|
457
535
|
allResolved = false;
|
|
@@ -468,7 +546,7 @@ export function autoMergeConflicts(phrenPath) {
|
|
|
468
546
|
const tmpMergePath = fullPath + `.tmp-${crypto.randomUUID()}`;
|
|
469
547
|
fs.writeFileSync(tmpMergePath, merged);
|
|
470
548
|
fs.renameSync(tmpMergePath, fullPath);
|
|
471
|
-
execFileSync("git", ["add", "--", relFile], { cwd: phrenPath, stdio: ["ignore", "ignore", "ignore"], timeout: EXEC_TIMEOUT_MS });
|
|
549
|
+
execFileSync("git", ["add", "--", relFile], { env: nonInteractiveGitEnv(), cwd: phrenPath, stdio: ["ignore", "ignore", "ignore"], timeout: EXEC_TIMEOUT_MS });
|
|
472
550
|
debugLog(`Auto-merged: ${relFile}`);
|
|
473
551
|
}
|
|
474
552
|
catch (err) {
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { type ProjectOwnershipMode } from "../project-config.js";
|
|
2
|
+
import { type BuiltinTopic } from "../project-topics.js";
|
|
3
|
+
/** Project domain used to pick starter topics and the AGENTS.md template. */
|
|
4
|
+
export type InitProjectDomain = "software" | "music" | "game" | "research" | "writing" | "creative" | "other";
|
|
5
|
+
interface BootstrapProjectOptions {
|
|
6
|
+
profile?: string;
|
|
7
|
+
profilePhrenPath?: string;
|
|
8
|
+
ownership?: ProjectOwnershipMode;
|
|
9
|
+
}
|
|
10
|
+
interface BootstrapProjectResult {
|
|
11
|
+
project: string;
|
|
12
|
+
ownership: ProjectOwnershipMode;
|
|
13
|
+
claudePath: string | null;
|
|
14
|
+
}
|
|
15
|
+
export interface InferredInitScaffold {
|
|
16
|
+
domain: InitProjectDomain;
|
|
17
|
+
topics: BuiltinTopic[];
|
|
18
|
+
referenceHints: string[];
|
|
19
|
+
commandHints: string[];
|
|
20
|
+
confidence: number;
|
|
21
|
+
reason: string;
|
|
22
|
+
}
|
|
23
|
+
export declare function inferInitScaffoldFromRepo(repoRoot: string, fallbackDomain?: InitProjectDomain): InferredInitScaffold | null;
|
|
24
|
+
export declare function ensureProjectScaffold(projectDir: string, projectName: string, domain?: InitProjectDomain, inference?: InferredInitScaffold | null): void;
|
|
25
|
+
export declare function bootstrapFromExisting(phrenPath: string, projectPath: string, opts?: string | BootstrapProjectOptions): BootstrapProjectResult;
|
|
26
|
+
export {};
|