@adhdev/daemon-core 0.9.82-rc.31 → 0.9.82-rc.310
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/dist/boot/daemon-lifecycle.d.ts +8 -0
- package/dist/boot/process-hardening.d.ts +50 -0
- package/dist/build-info.d.ts +37 -0
- package/dist/chat/source-machine.d.ts +166 -0
- package/dist/chat/source-resolver.d.ts +104 -0
- package/dist/chat/subscription-updates.d.ts +1 -0
- package/dist/cli-adapter-types.d.ts +23 -2
- package/dist/cli-adapters/cli-script-runner.d.ts +117 -0
- package/dist/cli-adapters/cli-state-engine.d.ts +198 -0
- package/dist/cli-adapters/provider-cli-adapter.d.ts +106 -63
- package/dist/cli-adapters/provider-cli-parse.d.ts +4 -0
- package/dist/cli-adapters/provider-cli-shared.d.ts +38 -0
- package/dist/cli-adapters/raw-terminal-io.d.ts +37 -0
- package/dist/cli-adapters/resolve-executable.d.ts +14 -0
- package/dist/cli-adapters/terminal-backends/ghostty-vt-backend.d.ts +6 -3
- package/dist/cli-adapters/terminal-backends/types.d.ts +10 -2
- package/dist/cli-adapters/terminal-screen.d.ts +4 -11
- package/dist/commands/cli-manager.d.ts +2 -1
- package/dist/commands/handler.d.ts +110 -0
- package/dist/commands/mesh-coordinator.d.ts +85 -1
- package/dist/commands/router.d.ts +210 -1
- package/dist/config/chat-history.d.ts +9 -0
- package/dist/config/config.d.ts +5 -0
- package/dist/config/mesh-config.d.ts +72 -1
- package/dist/git/git-commands.d.ts +9 -1
- package/dist/git/git-diff.d.ts +6 -0
- package/dist/git/git-executor.d.ts +11 -0
- package/dist/git/git-status.d.ts +9 -0
- package/dist/git/git-types.d.ts +2 -50
- package/dist/index.d.ts +51 -12
- package/dist/index.js +38320 -16024
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +38009 -15817
- package/dist/index.mjs.map +1 -1
- package/dist/installer.d.ts +1 -4
- package/dist/ipc/local-ipc-server.d.ts +91 -0
- package/dist/launch.d.ts +1 -1
- package/dist/logging/async-batch-writer.d.ts +10 -0
- package/dist/mesh/contracts.d.ts +164 -0
- package/dist/mesh/coordinator-prompt.d.ts +36 -0
- package/dist/mesh/coordinator-registry.d.ts +59 -0
- package/dist/mesh/mesh-active-work.d.ts +108 -0
- package/dist/mesh/mesh-delivery-policy.d.ts +131 -0
- package/dist/mesh/mesh-events-coordinator.d.ts +138 -0
- package/dist/mesh/mesh-events-pending.d.ts +45 -0
- package/dist/mesh/mesh-events-stale.d.ts +40 -0
- package/dist/mesh/mesh-events-utils.d.ts +47 -0
- package/dist/mesh/mesh-events.d.ts +6 -49
- package/dist/mesh/mesh-fast-forward.d.ts +81 -0
- package/dist/mesh/mesh-host-ownership.d.ts +9 -0
- package/dist/mesh/mesh-init.d.ts +86 -0
- package/dist/mesh/mesh-ledger-reconciliation.d.ts +23 -3
- package/dist/mesh/mesh-ledger.d.ts +77 -1
- package/dist/mesh/mesh-missions.d.ts +116 -0
- package/dist/mesh/mesh-reconcile-loop.d.ts +7 -0
- package/dist/mesh/mesh-refine-batch.d.ts +68 -0
- package/dist/mesh/mesh-refine-status.d.ts +62 -0
- package/dist/mesh/mesh-review-inbox.d.ts +90 -0
- package/dist/mesh/mesh-routing.d.ts +70 -0
- package/dist/mesh/mesh-runtime-store.d.ts +377 -0
- package/dist/mesh/mesh-task-stats.d.ts +49 -0
- package/dist/mesh/mesh-unresolved-forward-outbox.d.ts +30 -0
- package/dist/mesh/mesh-work-queue.d.ts +181 -5
- package/dist/mesh/preview-freshness.d.ts +18 -0
- package/dist/mesh/refine-config.d.ts +215 -0
- package/dist/mesh/worktree-bootstrap-config.d.ts +135 -0
- package/dist/providers/acp-provider-instance.d.ts +2 -0
- package/dist/providers/approval-utils.d.ts +13 -0
- package/dist/providers/cli-provider-instance.d.ts +61 -3
- package/dist/providers/contracts.d.ts +130 -6
- package/dist/providers/external-sources.d.ts +71 -0
- package/dist/providers/native-history/antigravity-cli-transcript.d.ts +100 -0
- package/dist/providers/native-history/claude-cli-transcript.d.ts +70 -0
- package/dist/providers/native-history/codex-cli-transcript.d.ts +73 -0
- package/dist/providers/native-history/dispatcher.d.ts +27 -0
- package/dist/providers/native-history/hermes-cli-transcript.d.ts +30 -0
- package/dist/providers/native-history/index.d.ts +13 -0
- package/dist/providers/provider-instance-manager.d.ts +13 -0
- package/dist/providers/provider-instance.d.ts +13 -1
- package/dist/providers/provider-loader.d.ts +26 -4
- package/dist/providers/provider-trust.d.ts +31 -0
- package/dist/providers/read-chat-contract.d.ts +29 -0
- package/dist/providers/sdk/v1/builders/acp/detect-status.d.ts +68 -0
- package/dist/providers/sdk/v1/builders/cli/detect-status.d.ts +85 -0
- package/dist/providers/sdk/v1/builders/cli/parse-approval-squash.d.ts +59 -0
- package/dist/providers/sdk/v1/builders/cli/parse-approval.d.ts +65 -0
- package/dist/providers/sdk/v1/builders/cli/parse-session.d.ts +91 -0
- package/dist/providers/sdk/v1/builders/cli/visible-region.d.ts +42 -0
- package/dist/providers/sdk/v1/fixture-tooling/format.d.ts +126 -0
- package/dist/providers/sdk/v1/fixture-tooling/index.d.ts +8 -0
- package/dist/providers/sdk/v1/fixture-tooling/replay.d.ts +38 -0
- package/dist/providers/sdk/v1/index.d.ts +30 -0
- package/dist/providers/sdk/v1/sandbox/README-design.d.ts +193 -0
- package/dist/providers/sdk/v1/sandbox/require-whitelist.d.ts +74 -0
- package/dist/providers/sdk/v1/sandbox/script-runner.d.ts +98 -0
- package/dist/providers/sdk/v1/types/cli/index.d.ts +277 -0
- package/dist/providers/sdk/v1/types/common/index.d.ts +203 -0
- package/dist/providers/sdk/v1/validators/index.d.ts +5 -0
- package/dist/providers/sdk/v1/validators/manifest.d.ts +40 -0
- package/dist/providers/sdk/v1/validators/taint.d.ts +52 -0
- package/dist/providers/spec/adapter.d.ts +59 -0
- package/dist/providers/spec/cli-adapter.d.ts +186 -0
- package/dist/providers/spec/evaluator.d.ts +23 -0
- package/dist/providers/spec/fsm-driver.d.ts +278 -0
- package/dist/providers/spec/fsm-evaluator.d.ts +72 -0
- package/dist/providers/spec/fsm-loader.d.ts +14 -0
- package/dist/providers/spec/fsm-types.d.ts +128 -0
- package/dist/providers/spec/native-history-executor.d.ts +41 -0
- package/dist/providers/spec/pre-launch-trust.d.ts +16 -0
- package/dist/providers/spec/route.d.ts +4 -0
- package/dist/providers/spec/types.d.ts +144 -0
- package/dist/providers/transcript-v2.d.ts +176 -0
- package/dist/providers/types/interactive-prompt.d.ts +84 -0
- package/dist/repo-mesh-types.d.ts +203 -13
- package/dist/sessions/registry.d.ts +6 -0
- package/dist/shared-types-extra.d.ts +2 -4
- package/dist/shared-types.d.ts +42 -1
- package/dist/status/normalize.d.ts +1 -1
- package/dist/status/normalize.js +1 -0
- package/dist/status/normalize.js.map +1 -1
- package/dist/status/normalize.mjs +1 -0
- package/dist/status/normalize.mjs.map +1 -1
- package/dist/status/reporter.d.ts +2 -0
- package/dist/status/snapshot.d.ts +1 -0
- package/dist/types.d.ts +5 -0
- package/package.json +7 -3
- package/src/agent-stream/poller.ts +2 -3
- package/src/boot/daemon-lifecycle.ts +55 -12
- package/src/boot/process-hardening.ts +89 -0
- package/src/build-info.ts +73 -0
- package/src/chat/source-machine.ts +534 -0
- package/src/chat/source-resolver.ts +0 -0
- package/src/chat/subscription-updates.ts +20 -1
- package/src/cli-adapter-types.d.ts +1 -0
- package/src/cli-adapter-types.ts +22 -2
- package/src/cli-adapters/cli-script-runner.ts +421 -0
- package/src/cli-adapters/cli-state-engine.ts +1215 -0
- package/src/cli-adapters/provider-cli-adapter.d.ts +1 -1
- package/src/cli-adapters/provider-cli-adapter.ts +674 -1139
- package/src/cli-adapters/provider-cli-parse.d.ts +1 -0
- package/src/cli-adapters/provider-cli-parse.ts +13 -0
- package/src/cli-adapters/provider-cli-runtime.ts +3 -1
- package/src/cli-adapters/provider-cli-shared.d.ts +2 -0
- package/src/cli-adapters/provider-cli-shared.ts +68 -11
- package/src/cli-adapters/pty-transport.ts +2 -1
- package/src/cli-adapters/raw-terminal-io.ts +252 -0
- package/src/cli-adapters/resolve-executable.ts +45 -0
- package/src/cli-adapters/session-host-transport.ts +2 -1
- package/src/cli-adapters/terminal-backends/ghostty-vt-backend.ts +53 -29
- package/src/cli-adapters/terminal-backends/types.ts +10 -3
- package/src/cli-adapters/terminal-screen.ts +16 -81
- package/src/commands/chat-commands.ts +1813 -60
- package/src/commands/cli-manager.ts +286 -14
- package/src/commands/handler.ts +809 -2
- package/src/commands/mesh-coordinator.ts +332 -122
- package/src/commands/router.ts +5911 -595
- package/src/commands/upgrade-helper.ts +29 -0
- package/src/config/chat-history.ts +474 -24
- package/src/config/config.ts +12 -0
- package/src/config/mesh-config.ts +303 -3
- package/src/config/recent-activity.ts +8 -2
- package/src/daemon/dev-auto-implement.ts +3 -2
- package/src/daemon/dev-cli-debug.ts +10 -1
- package/src/detection/ide-detector.ts +26 -16
- package/src/git/git-commands.ts +42 -12
- package/src/git/git-diff.ts +53 -0
- package/src/git/git-executor.ts +12 -0
- package/src/git/git-status.ts +302 -18
- package/src/git/git-types.ts +14 -62
- package/src/git/git-worktree.ts +8 -1
- package/src/index.ts +131 -11
- package/src/installer.d.ts +1 -1
- package/src/installer.ts +8 -6
- package/src/ipc/local-ipc-server.ts +278 -0
- package/src/launch.d.ts +1 -1
- package/src/launch.ts +37 -28
- package/src/logging/async-batch-writer.ts +55 -0
- package/src/logging/logger.ts +2 -1
- package/src/mesh/contracts.ts +329 -0
- package/src/mesh/coordinator-prompt.ts +234 -31
- package/src/mesh/coordinator-registry.ts +121 -0
- package/src/mesh/mesh-active-work.ts +469 -0
- package/src/mesh/mesh-delivery-policy.ts +315 -0
- package/src/mesh/mesh-events-coordinator.ts +1786 -0
- package/src/mesh/mesh-events-pending.ts +508 -0
- package/src/mesh/mesh-events-stale.ts +290 -0
- package/src/mesh/mesh-events-utils.ts +254 -0
- package/src/mesh/mesh-events.ts +30 -1035
- package/src/mesh/mesh-fast-forward.ts +839 -0
- package/src/mesh/mesh-host-ownership.ts +73 -0
- package/src/mesh/mesh-init.ts +260 -0
- package/src/mesh/mesh-ledger-reconciliation.ts +12 -5
- package/src/mesh/mesh-ledger.ts +589 -102
- package/src/mesh/mesh-missions.ts +248 -0
- package/src/mesh/mesh-reconcile-loop.ts +466 -0
- package/src/mesh/mesh-refine-batch.ts +197 -0
- package/src/mesh/mesh-refine-status.ts +231 -0
- package/src/mesh/mesh-review-inbox.ts +307 -0
- package/src/mesh/mesh-routing.ts +291 -0
- package/src/mesh/mesh-runtime-store.ts +1513 -0
- package/src/mesh/mesh-task-stats.ts +154 -0
- package/src/mesh/mesh-unresolved-forward-outbox.ts +185 -0
- package/src/mesh/mesh-work-queue.ts +604 -145
- package/src/mesh/preview-freshness.ts +118 -0
- package/src/mesh/refine-config.ts +403 -0
- package/src/mesh/worktree-bootstrap-config.ts +326 -0
- package/src/providers/acp-provider-instance.ts +15 -1
- package/src/providers/approval-utils.d.ts +4 -0
- package/src/providers/approval-utils.ts +47 -5
- package/src/providers/chat-message-normalization.ts +4 -11
- package/src/providers/cli-provider-instance.ts +953 -87
- package/src/providers/contracts.d.ts +55 -0
- package/src/providers/contracts.ts +141 -6
- package/src/providers/extension-provider-instance.ts +5 -1
- package/src/providers/external-sources.ts +218 -0
- package/src/providers/ide-provider-instance.ts +25 -6
- package/src/providers/native-history/antigravity-cli-transcript.ts +643 -0
- package/src/providers/native-history/claude-cli-transcript.ts +396 -0
- package/src/providers/native-history/codex-cli-transcript.ts +479 -0
- package/src/providers/native-history/dispatcher.ts +340 -0
- package/src/providers/native-history/hermes-cli-transcript.ts +230 -0
- package/src/providers/native-history/index.ts +30 -0
- package/src/providers/provider-instance-manager.ts +30 -0
- package/src/providers/provider-instance.ts +10 -1
- package/src/providers/provider-loader.ts +584 -50
- package/src/providers/provider-schema.ts +87 -14
- package/src/providers/provider-trust.ts +114 -0
- package/src/providers/read-chat-contract.ts +76 -16
- package/src/providers/sdk/README.md +49 -0
- package/src/providers/sdk/v1/builders/acp/detect-status.ts +144 -0
- package/src/providers/sdk/v1/builders/cli/detect-status.ts +262 -0
- package/src/providers/sdk/v1/builders/cli/parse-approval-squash.ts +158 -0
- package/src/providers/sdk/v1/builders/cli/parse-approval.ts +250 -0
- package/src/providers/sdk/v1/builders/cli/parse-session.ts +276 -0
- package/src/providers/sdk/v1/builders/cli/visible-region.ts +143 -0
- package/src/providers/sdk/v1/fixture-tooling/format.ts +130 -0
- package/src/providers/sdk/v1/fixture-tooling/index.ts +22 -0
- package/src/providers/sdk/v1/fixture-tooling/replay.ts +352 -0
- package/src/providers/sdk/v1/index.ts +152 -0
- package/src/providers/sdk/v1/sandbox/README-design.ts +195 -0
- package/src/providers/sdk/v1/sandbox/require-whitelist.ts +472 -0
- package/src/providers/sdk/v1/sandbox/script-runner.ts +150 -0
- package/src/providers/sdk/v1/schemas/cli/provider.schema.json +504 -0
- package/src/providers/sdk/v1/schemas/primitives/acp-session-protocol-v1.json +131 -0
- package/src/providers/sdk/v1/schemas/primitives/native-history-codex-rollout-v1.json +66 -0
- package/src/providers/sdk/v1/schemas/primitives/tui-approval-squash-v1.json +91 -0
- package/src/providers/sdk/v1/schemas/primitives/tui-assistant-block-v1.json +91 -0
- package/src/providers/sdk/v1/schemas/primitives/tui-cue-ordering-v1.json +47 -0
- package/src/providers/sdk/v1/schemas/primitives/tui-dispatch-order-v1.json +32 -0
- package/src/providers/sdk/v1/schemas/primitives/tui-footer-chrome-v1.json +42 -0
- package/src/providers/sdk/v1/schemas/primitives/tui-index-finder-v1.json +27 -0
- package/src/providers/sdk/v1/schemas/primitives/tui-modal-v1.json +125 -0
- package/src/providers/sdk/v1/schemas/primitives/tui-prompt-marker-v1.json +45 -0
- package/src/providers/sdk/v1/schemas/primitives/tui-session-id-extraction-v1.json +46 -0
- package/src/providers/sdk/v1/schemas/primitives/tui-settled-prompt-v1.json +71 -0
- package/src/providers/sdk/v1/schemas/primitives/tui-spinner-v1.json +83 -0
- package/src/providers/sdk/v1/schemas/primitives/tui-transcript-pty-v1.json +83 -0
- package/src/providers/sdk/v1/schemas/primitives/tui-visible-region-v1.json +57 -0
- package/src/providers/sdk/v1/schemas/primitives/tui-welcome-screen-v1.json +35 -0
- package/src/providers/sdk/v1/types/cli/index.ts +365 -0
- package/src/providers/sdk/v1/types/common/index.ts +229 -0
- package/src/providers/sdk/v1/validators/index.ts +19 -0
- package/src/providers/sdk/v1/validators/manifest.ts +110 -0
- package/src/providers/sdk/v1/validators/taint.ts +309 -0
- package/src/providers/spec/adapter.ts +155 -0
- package/src/providers/spec/cli-adapter.ts +838 -0
- package/src/providers/spec/evaluator.ts +345 -0
- package/src/providers/spec/fsm-driver.ts +875 -0
- package/src/providers/spec/fsm-evaluator.ts +255 -0
- package/src/providers/spec/fsm-loader.ts +112 -0
- package/src/providers/spec/fsm-types.ts +222 -0
- package/src/providers/spec/native-history-executor.ts +943 -0
- package/src/providers/spec/pre-launch-trust.ts +104 -0
- package/src/providers/spec/route.ts +51 -0
- package/src/providers/spec/types.ts +189 -0
- package/src/providers/transcript-v2.ts +567 -0
- package/src/providers/types/interactive-prompt.ts +536 -0
- package/src/providers/version-archive.ts +38 -20
- package/src/repo-mesh-types.ts +257 -13
- package/src/sessions/registry.ts +6 -0
- package/src/shared-types-extra.ts +2 -4
- package/src/shared-types.ts +45 -1
- package/src/status/builders.ts +26 -6
- package/src/status/normalize.ts +2 -0
- package/src/status/reporter.ts +15 -0
- package/src/status/snapshot.ts +84 -25
- package/src/system/host-memory.ts +29 -12
- package/src/types.ts +5 -0
- package/dist/cli-adapters/terminal-backends/xterm-backend.d.ts +0 -17
- package/dist/mesh/mesh-sync.d.ts +0 -53
- package/src/cli-adapters/terminal-backends/ghostty-vt-backend.d.ts +0 -16
- package/src/cli-adapters/terminal-backends/xterm-backend.ts +0 -97
- package/src/mesh/mesh-sync.ts +0 -111
package/src/git/git-diff.ts
CHANGED
|
@@ -10,6 +10,20 @@ export interface GitDiffOptions {
|
|
|
10
10
|
timeoutMs?: number;
|
|
11
11
|
maxFiles?: number;
|
|
12
12
|
maxBytes?: number;
|
|
13
|
+
/**
|
|
14
|
+
* When set, diff `<baseRef>...HEAD` (merge-base range — "what this branch
|
|
15
|
+
* adds on top of base") instead of the working tree. Staged/untracked
|
|
16
|
+
* sections do not apply in this mode.
|
|
17
|
+
*/
|
|
18
|
+
baseRef?: string;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function validateBaseRef(ref: string): string {
|
|
22
|
+
const trimmed = ref.trim();
|
|
23
|
+
if (!trimmed || trimmed.startsWith('-') || trimmed.includes('..') || !/^[A-Za-z0-9][A-Za-z0-9._/@-]*$/.test(trimmed)) {
|
|
24
|
+
throw new GitCommandError('invalid_args', `Invalid base ref: ${ref}`);
|
|
25
|
+
}
|
|
26
|
+
return trimmed;
|
|
13
27
|
}
|
|
14
28
|
|
|
15
29
|
export interface GitFileDiffResult {
|
|
@@ -44,6 +58,30 @@ export async function getGitDiffSummary(
|
|
|
44
58
|
try {
|
|
45
59
|
const repo = await resolveGitRepository(workspace, options);
|
|
46
60
|
const repoRoot = repo.repoRoot!;
|
|
61
|
+
|
|
62
|
+
if (options.baseRef) {
|
|
63
|
+
const range = `${validateBaseRef(options.baseRef)}...HEAD`;
|
|
64
|
+
const [nameStatus, numstat] = await Promise.all([
|
|
65
|
+
runGit(repo, ['diff', '--no-ext-diff', '--name-status', range, '--'], { ...options, cwd: repoRoot }),
|
|
66
|
+
runGit(repo, ['diff', '--no-ext-diff', '--numstat', range, '--'], { ...options, cwd: repoRoot }),
|
|
67
|
+
]);
|
|
68
|
+
const outputBytes = byteLength(nameStatus.stdout + numstat.stdout);
|
|
69
|
+
const changes = combineDiffEntries(nameStatus.stdout, numstat.stdout, false);
|
|
70
|
+
const maxFiles = normalizePositiveInteger(options.maxFiles, DEFAULT_MAX_FILES);
|
|
71
|
+
const maxBytes = normalizePositiveInteger(options.maxBytes, DEFAULT_MAX_BYTES);
|
|
72
|
+
const files = changes.slice(0, maxFiles);
|
|
73
|
+
return {
|
|
74
|
+
workspace: repo.workspace,
|
|
75
|
+
repoRoot,
|
|
76
|
+
isGitRepo: true,
|
|
77
|
+
files,
|
|
78
|
+
totalInsertions: files.reduce((sum, file) => sum + file.insertions, 0),
|
|
79
|
+
totalDeletions: files.reduce((sum, file) => sum + file.deletions, 0),
|
|
80
|
+
truncated: changes.length > files.length || outputBytes > maxBytes,
|
|
81
|
+
lastCheckedAt,
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
|
|
47
85
|
const [unstagedNameStatus, unstagedNumstat, stagedNameStatus, stagedNumstat, untracked] = await Promise.all([
|
|
48
86
|
runGit(repo, ['diff', '--no-ext-diff', '--name-status'], { ...options, cwd: repoRoot }),
|
|
49
87
|
runGit(repo, ['diff', '--no-ext-diff', '--numstat'], { ...options, cwd: repoRoot }),
|
|
@@ -106,6 +144,21 @@ export async function getGitFileDiff(
|
|
|
106
144
|
const selected = await resolveRepoFilePath(repoRoot, filePath);
|
|
107
145
|
const maxBytes = normalizePositiveInteger(options.maxBytes, DEFAULT_MAX_BYTES);
|
|
108
146
|
|
|
147
|
+
if (options.baseRef) {
|
|
148
|
+
const range = `${validateBaseRef(options.baseRef)}...HEAD`;
|
|
149
|
+
const result = await runGit(repo, ['diff', '--no-ext-diff', range, '--', selected.relativePath], { ...options, cwd: repoRoot });
|
|
150
|
+
const bounded = truncateText(result.stdout, maxBytes);
|
|
151
|
+
return {
|
|
152
|
+
workspace: repo.workspace,
|
|
153
|
+
repoRoot,
|
|
154
|
+
isGitRepo: true,
|
|
155
|
+
path: selected.relativePath,
|
|
156
|
+
diff: bounded.text,
|
|
157
|
+
truncated: bounded.truncated,
|
|
158
|
+
lastCheckedAt,
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
|
|
109
162
|
const [unstaged, staged] = await Promise.all([
|
|
110
163
|
runGit(repo, ['diff', '--no-ext-diff', '--', selected.relativePath], { ...options, cwd: repoRoot }),
|
|
111
164
|
runGit(repo, ['diff', '--cached', '--no-ext-diff', '--', selected.relativePath], { ...options, cwd: repoRoot }),
|
package/src/git/git-executor.ts
CHANGED
|
@@ -10,6 +10,18 @@ const execFileAsync = promisify(execFile);
|
|
|
10
10
|
const DEFAULT_TIMEOUT_MS = 5_000;
|
|
11
11
|
const DEFAULT_MAX_BUFFER = 1024 * 1024;
|
|
12
12
|
|
|
13
|
+
/**
|
|
14
|
+
* Timeout for status-collection git commands (status/log/submodule/stash/fetch).
|
|
15
|
+
* The default 5s is fine for porcelain status, but on Windows the `git` subprocess
|
|
16
|
+
* spawn itself is pathologically slow (measured: `submodule status` ~3.5s, cold
|
|
17
|
+
* `log -1` ~4.2s) and overlaps with refreshUpstream fetches — a single command
|
|
18
|
+
* routinely exceeds 5s, which previously collapsed the whole status to all-null and
|
|
19
|
+
* dropped the node from the mesh graph. Give the collection path a much larger
|
|
20
|
+
* budget so a slow-but-healthy repo never reads as "not a git repo". Windows gets a
|
|
21
|
+
* larger budget than POSIX because the spawn cost is OS-specific, not repo-specific.
|
|
22
|
+
*/
|
|
23
|
+
export const GIT_STATUS_TIMEOUT_MS = process.platform === 'win32' ? 30_000 : 20_000;
|
|
24
|
+
|
|
13
25
|
export interface GitExecutorOptions {
|
|
14
26
|
timeoutMs?: number;
|
|
15
27
|
maxBuffer?: number;
|
package/src/git/git-status.ts
CHANGED
|
@@ -1,8 +1,31 @@
|
|
|
1
|
-
import type { GitRepoStatus, GitSubmoduleStatus, GitUpstreamFreshness } from './git-types.js';
|
|
2
|
-
import { GitCommandError, resolveGitRepository, runGit } from './git-executor.js';
|
|
1
|
+
import type { DaemonBuildBehind, GitRepoStatus, GitSubmoduleStatus, GitUpstreamFreshness } from './git-types.js';
|
|
2
|
+
import { GIT_STATUS_TIMEOUT_MS, GitCommandError, resolveGitRepository, runGit } from './git-executor.js';
|
|
3
|
+
import { getDaemonBuildInfo, type DaemonBuildInfo } from '../build-info.js';
|
|
3
4
|
|
|
4
5
|
type ResolvedGitRepo = { workspace: string; repoRoot: string | null; isGitRepo: boolean };
|
|
5
6
|
|
|
7
|
+
/**
|
|
8
|
+
* Last successfully-collected status per workspace, used to survive a transient git
|
|
9
|
+
* failure (timeout, slow Windows spawn under load, a momentary lock) WITHOUT dropping
|
|
10
|
+
* the node out of the mesh graph. A genuine "not a git repository" answer is NOT a
|
|
11
|
+
* transient failure — it never populates this cache and always reports isGitRepo:false.
|
|
12
|
+
*/
|
|
13
|
+
const lastKnownGoodStatus = new Map<string, GitRepoStatus>();
|
|
14
|
+
|
|
15
|
+
/** Test seam: clear the last-known-good status cache between cases. */
|
|
16
|
+
export function __resetGitStatusCacheForTests(): void {
|
|
17
|
+
lastKnownGoodStatus.clear();
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* git failure reasons that are transient/environmental rather than a real statement
|
|
22
|
+
* that the workspace is not a repo. On these we prefer the last-known-good status so a
|
|
23
|
+
* single slow git call cannot make a healthy node vanish from the graph.
|
|
24
|
+
*/
|
|
25
|
+
function isTransientGitFailure(error: GitCommandError): boolean {
|
|
26
|
+
return error.reason === 'timeout' || error.reason === 'git_command_failed';
|
|
27
|
+
}
|
|
28
|
+
|
|
6
29
|
export interface GitStatusOptions {
|
|
7
30
|
timeoutMs?: number;
|
|
8
31
|
/** When true, include submodule status in the result. Defaults to true. */
|
|
@@ -14,6 +37,12 @@ export interface GitStatusOptions {
|
|
|
14
37
|
* Callers should opt into this only for convergence-critical surfaces.
|
|
15
38
|
*/
|
|
16
39
|
refreshUpstream?: boolean;
|
|
40
|
+
/**
|
|
41
|
+
* Test/override seam for the daemon build stamp used by the stale-build
|
|
42
|
+
* detector. Production callers omit this so the real baked-in build commit
|
|
43
|
+
* (getDaemonBuildInfo) is used.
|
|
44
|
+
*/
|
|
45
|
+
daemonBuildInfo?: DaemonBuildInfo;
|
|
17
46
|
}
|
|
18
47
|
|
|
19
48
|
interface GitUpstreamProbe {
|
|
@@ -28,9 +57,50 @@ export async function getGitRepoStatus(
|
|
|
28
57
|
): Promise<GitRepoStatus> {
|
|
29
58
|
const lastCheckedAt = Date.now();
|
|
30
59
|
const includeSubmodules = options.includeSubmodules !== false;
|
|
60
|
+
// Status collection fans out into several git subprocesses (status, head, stash,
|
|
61
|
+
// submodule, optionally fetch). On Windows the per-spawn cost alone can exceed the
|
|
62
|
+
// 5s default, so unless the caller pinned a timeout, give the whole collection path
|
|
63
|
+
// the larger status budget. A caller that explicitly sets timeoutMs (e.g. a test
|
|
64
|
+
// injecting 1ms to exercise the transient-failure path) is respected.
|
|
65
|
+
const effectiveOptions: GitStatusOptions =
|
|
66
|
+
options.timeoutMs === undefined ? { ...options, timeoutMs: GIT_STATUS_TIMEOUT_MS } : options;
|
|
31
67
|
|
|
32
68
|
try {
|
|
33
|
-
const repo = await resolveGitRepository(workspace,
|
|
69
|
+
const repo = await resolveGitRepository(workspace, effectiveOptions);
|
|
70
|
+
const status = await collectGitRepoStatus(repo, includeSubmodules, lastCheckedAt, effectiveOptions);
|
|
71
|
+
lastKnownGoodStatus.set(workspace, status);
|
|
72
|
+
return status;
|
|
73
|
+
} catch (error) {
|
|
74
|
+
const gitError = error instanceof GitCommandError
|
|
75
|
+
? error
|
|
76
|
+
: new GitCommandError('git_command_failed', 'Failed to read Git status', { cause: error });
|
|
77
|
+
|
|
78
|
+
// A transient/environmental failure (timeout, slow-spawn-under-load) must NOT make
|
|
79
|
+
// a healthy node lose its repo identity and drop out of the mesh graph. Prefer the
|
|
80
|
+
// last status we successfully collected for this workspace, re-stamped as stale.
|
|
81
|
+
if (isTransientGitFailure(gitError)) {
|
|
82
|
+
const cached = lastKnownGoodStatus.get(workspace);
|
|
83
|
+
if (cached) {
|
|
84
|
+
return {
|
|
85
|
+
...cached,
|
|
86
|
+
lastCheckedAt,
|
|
87
|
+
upstreamStatus: 'unavailable',
|
|
88
|
+
error: gitError.stderr || gitError.message,
|
|
89
|
+
reason: gitError.reason,
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
return emptyStatus(workspace, lastCheckedAt, gitError);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
async function collectGitRepoStatus(
|
|
99
|
+
repo: ResolvedGitRepo,
|
|
100
|
+
includeSubmodules: boolean,
|
|
101
|
+
lastCheckedAt: number,
|
|
102
|
+
options: GitStatusOptions,
|
|
103
|
+
): Promise<GitRepoStatus> {
|
|
34
104
|
let parsed = await readPorcelainStatus(repo, options);
|
|
35
105
|
let upstreamProbe: GitUpstreamProbe = getInitialUpstreamProbe(parsed);
|
|
36
106
|
|
|
@@ -48,6 +118,13 @@ export async function getGitRepoStatus(
|
|
|
48
118
|
if (includeSubmodules) {
|
|
49
119
|
submodules = await getSubmoduleStatuses(repo, options);
|
|
50
120
|
}
|
|
121
|
+
const submoduleDirty = (submodules || []).some(submodule => submodule.dirty || submodule.outOfSync || !!submodule.error);
|
|
122
|
+
const dirty = parsed.staged + parsed.modified + parsed.untracked + parsed.deleted + parsed.renamed > 0
|
|
123
|
+
|| parsed.conflictFiles.length > 0
|
|
124
|
+
|| stashCount > 0
|
|
125
|
+
|| submoduleDirty;
|
|
126
|
+
|
|
127
|
+
const daemonBuildBehind = await detectDaemonBuildBehind(repo, submodules, options);
|
|
51
128
|
|
|
52
129
|
return {
|
|
53
130
|
workspace: repo.workspace,
|
|
@@ -67,24 +144,203 @@ export async function getGitRepoStatus(
|
|
|
67
144
|
untracked: parsed.untracked,
|
|
68
145
|
deleted: parsed.deleted,
|
|
69
146
|
renamed: parsed.renamed,
|
|
147
|
+
dirty,
|
|
70
148
|
hasConflicts: parsed.conflictFiles.length > 0,
|
|
71
149
|
conflictFiles: parsed.conflictFiles,
|
|
72
150
|
stashCount,
|
|
73
151
|
lastCheckedAt,
|
|
74
152
|
submodules,
|
|
153
|
+
...(daemonBuildBehind ? { daemonBuildBehind } : {}),
|
|
75
154
|
};
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* Detect whether the running daemon's build commit is a STRICT ancestor of this
|
|
159
|
+
* workspace's HEAD (root) or any of its submodules' HEAD. This surfaces the
|
|
160
|
+
* "merged a fix to main but the live daemon still ships the old bundle" gap:
|
|
161
|
+
* once the fix is committed, the workspace HEAD advances past the daemon's
|
|
162
|
+
* baked-in build commit, but the daemon keeps the old behavior until it is
|
|
163
|
+
* rebuilt/redeployed and restarted.
|
|
164
|
+
*
|
|
165
|
+
* Conservative by construction — returns undefined unless ancestry is provable:
|
|
166
|
+
* - build commit unknown → undefined
|
|
167
|
+
* - build commit not an object in this repo/submodule (different repo) → skip
|
|
168
|
+
* - build commit === HEAD (daemon is current) → undefined
|
|
169
|
+
* - build commit NOT an ancestor of HEAD (daemon ahead / diverged) → undefined
|
|
170
|
+
* Any git error is swallowed (no warning) so a flaky probe never over-warns.
|
|
171
|
+
*/
|
|
172
|
+
/**
|
|
173
|
+
* Package names that, when changed, mean the daemon runtime is stale and must be
|
|
174
|
+
* rebuilt/redeployed + restarted. Everything NOT in this set (web-core,
|
|
175
|
+
* web-standalone, web-devconsole, terminal-render-web) is web-only — a daemon
|
|
176
|
+
* restart is not required for those, only a web redeploy. mcp-server runs in the
|
|
177
|
+
* same process surface as the daemon tooling, so it is classified as
|
|
178
|
+
* daemon-affecting (conservative). Unknown package → daemon-affecting.
|
|
179
|
+
*/
|
|
180
|
+
const DAEMON_RUNTIME_PACKAGES = new Set([
|
|
181
|
+
'daemon-core',
|
|
182
|
+
'daemon-standalone',
|
|
183
|
+
'session-host-core',
|
|
184
|
+
'session-host-daemon',
|
|
185
|
+
'terminal-mux-core',
|
|
186
|
+
'terminal-mux-control',
|
|
187
|
+
'terminal-mux-cli',
|
|
188
|
+
'ghostty-vt-node',
|
|
189
|
+
'mcp-server',
|
|
190
|
+
]);
|
|
191
|
+
|
|
192
|
+
const WEB_ONLY_PACKAGES = new Set([
|
|
193
|
+
'web-core',
|
|
194
|
+
'web-standalone',
|
|
195
|
+
'web-devconsole',
|
|
196
|
+
'terminal-render-web',
|
|
197
|
+
]);
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* Root-level (non-package) files that demonstrably cannot change what the daemon
|
|
201
|
+
* runtime executes: convergence/verify markers, documentation, and license/notice
|
|
202
|
+
* text. A root commit that moves the oss gitlink while the oss commit only touched
|
|
203
|
+
* one of these is NOT a reason to rebuild/restart the daemon — flagging it produces
|
|
204
|
+
* the staleDaemonBuild false-positive this guard exists to suppress.
|
|
205
|
+
*
|
|
206
|
+
* Deliberately conservative: anything NOT matched here (root config like
|
|
207
|
+
* package.json / tsconfig / build scripts, `.txt` fixtures, lockfiles, unknown
|
|
208
|
+
* dotfiles) stays daemon-affecting, because a false-negative — staying silent when
|
|
209
|
+
* the daemon really IS stale — is worse than an over-warn. Markers are the common
|
|
210
|
+
* real-world case (e.g. `.verify-patch-equiv-rc292`), so they are matched broadly;
|
|
211
|
+
* docs are matched by the `docs/` prefix or a markdown/text-doc extension at a
|
|
212
|
+
* filename we recognize as documentation (README/CHANGELOG/LICENSE/NOTICE).
|
|
213
|
+
*/
|
|
214
|
+
function isNonRuntimeRootFile(file: string): boolean {
|
|
215
|
+
const base = file.slice(file.lastIndexOf('/') + 1);
|
|
216
|
+
// Verify/convergence markers: dotfiles whose name signals a transient marker.
|
|
217
|
+
if (/^\.(?:verify|marker|converge|ff-verify|patch-equiv|live-verify)\b/i.test(base)) return true;
|
|
218
|
+
// Documentation living under a docs/ tree (any depth, root or nested).
|
|
219
|
+
if (/(?:^|\/)docs\//i.test(file)) return true;
|
|
220
|
+
// Recognized top-level documentation / license files.
|
|
221
|
+
if (/^(?:README|CHANGELOG|LICENSE|NOTICE|AUTHORS|CONTRIBUTING|CODEOWNERS)(?:\.[A-Za-z0-9]+)?$/i.test(base)) {
|
|
222
|
+
return true;
|
|
223
|
+
}
|
|
224
|
+
return false;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
/**
|
|
228
|
+
* Determine whether the changes between buildCommit..HEAD touch any daemon-runtime
|
|
229
|
+
* package. Returns isDaemonAffecting:true conservatively when the changed-file set
|
|
230
|
+
* can't be obtained or any changed path is outside the known web-only package set
|
|
231
|
+
* AND is not a recognized non-runtime root file (marker/doc/license).
|
|
232
|
+
*/
|
|
233
|
+
async function classifyDaemonBuildChange(
|
|
234
|
+
repoPath: string,
|
|
235
|
+
buildCommit: string,
|
|
236
|
+
options: GitStatusOptions,
|
|
237
|
+
): Promise<{ isDaemonAffecting: boolean; affectedPackages: string[] }> {
|
|
238
|
+
try {
|
|
239
|
+
const diff = await runGit(repoPath, ['diff', '--name-only', `${buildCommit}..HEAD`], options);
|
|
240
|
+
const files = diff.stdout
|
|
241
|
+
.split('\n')
|
|
242
|
+
.map((line) => line.trim())
|
|
243
|
+
.filter(Boolean);
|
|
244
|
+
if (files.length === 0) {
|
|
245
|
+
// No file diff (e.g. only merge metadata) — nothing actionable, but stay
|
|
246
|
+
// conservative and treat as daemon-affecting so we don't suppress a real warning.
|
|
247
|
+
return { isDaemonAffecting: true, affectedPackages: [] };
|
|
79
248
|
}
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
249
|
+
const pkgs = new Set<string>();
|
|
250
|
+
// A non-package path that is NOT a recognized benign root file (marker/doc).
|
|
251
|
+
// Only these force daemon-affecting; benign markers/docs are ignored so a
|
|
252
|
+
// gitlink-moving root commit over a marker-only oss commit no longer over-warns.
|
|
253
|
+
let sawRuntimeAmbiguousNonPackage = false;
|
|
254
|
+
for (const file of files) {
|
|
255
|
+
const match = file.match(/(?:^|\/)packages\/([^/]+)\//);
|
|
256
|
+
if (!match) {
|
|
257
|
+
if (!isNonRuntimeRootFile(file)) sawRuntimeAmbiguousNonPackage = true;
|
|
258
|
+
continue;
|
|
259
|
+
}
|
|
260
|
+
pkgs.add(match[1]);
|
|
261
|
+
}
|
|
262
|
+
const affectedPackages = [...pkgs].sort();
|
|
263
|
+
// Daemon-affecting if: any runtime-ambiguous non-package file changed, any
|
|
264
|
+
// unknown package changed, or any explicit daemon-runtime package changed.
|
|
265
|
+
// The daemon is unaffected only when every changed file is either a known
|
|
266
|
+
// web-only package or a recognized benign root file (and at least one such
|
|
267
|
+
// file changed) — i.e. nothing runtime-ambiguous remains.
|
|
268
|
+
const allBenign =
|
|
269
|
+
!sawRuntimeAmbiguousNonPackage &&
|
|
270
|
+
affectedPackages.every((p) => WEB_ONLY_PACKAGES.has(p) && !DAEMON_RUNTIME_PACKAGES.has(p));
|
|
271
|
+
return { isDaemonAffecting: !allBenign, affectedPackages };
|
|
272
|
+
} catch {
|
|
273
|
+
// diff probe failed → can't prove web-only; stay conservative.
|
|
274
|
+
return { isDaemonAffecting: true, affectedPackages: [] };
|
|
85
275
|
}
|
|
86
276
|
}
|
|
87
277
|
|
|
278
|
+
async function detectDaemonBuildBehind(
|
|
279
|
+
repo: ResolvedGitRepo,
|
|
280
|
+
submodules: GitSubmoduleStatus[] | undefined,
|
|
281
|
+
options: GitStatusOptions,
|
|
282
|
+
): Promise<DaemonBuildBehind | undefined> {
|
|
283
|
+
const build = options.daemonBuildInfo ?? getDaemonBuildInfo();
|
|
284
|
+
if (!build.commit || build.commit === 'unknown') return undefined;
|
|
285
|
+
|
|
286
|
+
// Check the root repo first, then each submodule. The daemon build commit is
|
|
287
|
+
// baked from the daemon-core (oss submodule) HEAD, so on an adhdev
|
|
288
|
+
// superproject worktree the match is expected on the `oss` submodule, not the
|
|
289
|
+
// root — checking both keeps the helper repo-agnostic.
|
|
290
|
+
const scopes: Array<{ scope: string; repoPath: string }> = [
|
|
291
|
+
{ scope: 'root', repoPath: repo.repoRoot || repo.workspace },
|
|
292
|
+
];
|
|
293
|
+
for (const sub of submodules || []) {
|
|
294
|
+
if (sub.repoPath && !sub.error) scopes.push({ scope: sub.path, repoPath: sub.repoPath });
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
for (const { scope, repoPath } of scopes) {
|
|
298
|
+
try {
|
|
299
|
+
// Build commit must be a real object in THIS repo, else it's a different repo.
|
|
300
|
+
await runGit(repoPath, ['cat-file', '-e', `${build.commit}^{commit}`], options);
|
|
301
|
+
const headResult = await runGit(repoPath, ['rev-parse', 'HEAD'], options);
|
|
302
|
+
const head = headResult.stdout.trim();
|
|
303
|
+
if (!head || head === build.commit) continue;
|
|
304
|
+
// Strict ancestor: build commit is reachable from HEAD but is not HEAD.
|
|
305
|
+
await runGit(repoPath, ['merge-base', '--is-ancestor', build.commit, 'HEAD'], options);
|
|
306
|
+
// No throw → build commit IS an ancestor of HEAD → daemon is behind.
|
|
307
|
+
// Inspect WHICH packages changed in buildCommit..HEAD. A daemon rebuild/restart
|
|
308
|
+
// is only actually required when a daemon-runtime package changed; if only web /
|
|
309
|
+
// render packages changed, the daemon is unaffected and just the web deploy is
|
|
310
|
+
// pending. Conservative: any probe failure → treat as daemon-affecting.
|
|
311
|
+
const { isDaemonAffecting, affectedPackages } = await classifyDaemonBuildChange(
|
|
312
|
+
repoPath,
|
|
313
|
+
build.commit,
|
|
314
|
+
options,
|
|
315
|
+
);
|
|
316
|
+
const scopeLabel = scope === 'root' ? 'workspace' : scope;
|
|
317
|
+
const benignDetail = affectedPackages.length > 0
|
|
318
|
+
? `only web packages changed (${affectedPackages.join(', ')})`
|
|
319
|
+
: 'only non-runtime files changed (markers/docs)';
|
|
320
|
+
const warning = isDaemonAffecting
|
|
321
|
+
? `Live daemon was built from ${build.commitShort} which is behind ${scopeLabel} HEAD ${head.slice(0, 7)}. ` +
|
|
322
|
+
`Merged code is NOT live until the daemon is rebuilt/redeployed and restarted — a local dist rebuild alone does not update a cloud daemon.`
|
|
323
|
+
: `Live daemon was built from ${build.commitShort} which is behind ${scopeLabel} HEAD ${head.slice(0, 7)}, ` +
|
|
324
|
+
`but ${benignDetail}. ` +
|
|
325
|
+
`Daemon restart NOT required — redeploy the web app to reflect the change.`;
|
|
326
|
+
return {
|
|
327
|
+
buildCommit: build.commit,
|
|
328
|
+
buildCommitShort: build.commitShort,
|
|
329
|
+
head,
|
|
330
|
+
scope,
|
|
331
|
+
isDaemonAffecting,
|
|
332
|
+
...(affectedPackages && affectedPackages.length > 0 ? { affectedPackages } : {}),
|
|
333
|
+
warning,
|
|
334
|
+
};
|
|
335
|
+
} catch {
|
|
336
|
+
// cat-file / merge-base non-zero exit (commit absent or not an ancestor)
|
|
337
|
+
// or any git error → not a provable staleness for this scope; try next.
|
|
338
|
+
continue;
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
return undefined;
|
|
342
|
+
}
|
|
343
|
+
|
|
88
344
|
interface ParsedPorcelainStatus {
|
|
89
345
|
branch: string | null;
|
|
90
346
|
upstream: string | null;
|
|
@@ -285,6 +541,7 @@ function emptyStatus(workspace: string, lastCheckedAt: number, error: GitCommand
|
|
|
285
541
|
untracked: 0,
|
|
286
542
|
deleted: 0,
|
|
287
543
|
renamed: 0,
|
|
544
|
+
dirty: false,
|
|
288
545
|
hasConflicts: false,
|
|
289
546
|
conflictFiles: [],
|
|
290
547
|
stashCount: 0,
|
|
@@ -303,13 +560,40 @@ async function getSubmoduleStatuses(
|
|
|
303
560
|
if (!repo.repoRoot) return [];
|
|
304
561
|
|
|
305
562
|
try {
|
|
306
|
-
|
|
307
|
-
|
|
563
|
+
// No `--recursive`: this superproject's submodules (oss, adhdev-providers) are
|
|
564
|
+
// leaf repos with no nested submodules, so `--recursive` doubles the (already
|
|
565
|
+
// slow on Windows) submodule-status spawn time for zero additional rows. If a
|
|
566
|
+
// nested submodule is ever introduced, restore --recursive WITH its own longer
|
|
567
|
+
// per-command timeout rather than reverting this wholesale.
|
|
568
|
+
const result = await runGit(repo, ['submodule', 'status'], options);
|
|
569
|
+
const submodules = parseSubmoduleStatusOutput(result.stdout, repo.repoRoot, options.submoduleIgnorePaths);
|
|
570
|
+
await Promise.all(submodules.map(submodule => enrichSubmoduleWorktreeStatus(repo, submodule, options)));
|
|
571
|
+
return submodules;
|
|
308
572
|
} catch {
|
|
309
573
|
return [];
|
|
310
574
|
}
|
|
311
575
|
}
|
|
312
576
|
|
|
577
|
+
async function enrichSubmoduleWorktreeStatus(
|
|
578
|
+
repo: ResolvedGitRepo,
|
|
579
|
+
submodule: GitSubmoduleStatus,
|
|
580
|
+
options: GitStatusOptions,
|
|
581
|
+
): Promise<void> {
|
|
582
|
+
try {
|
|
583
|
+
const result = await runGit(repo, ['status', '--porcelain=v2', '--branch'], {
|
|
584
|
+
...options,
|
|
585
|
+
cwd: submodule.repoPath,
|
|
586
|
+
});
|
|
587
|
+
const parsed = parsePorcelainV2Status(result.stdout);
|
|
588
|
+
const dirty = parsed.staged + parsed.modified + parsed.untracked + parsed.deleted + parsed.renamed > 0
|
|
589
|
+
|| parsed.conflictFiles.length > 0;
|
|
590
|
+
submodule.dirty = submodule.dirty || dirty;
|
|
591
|
+
} catch (error) {
|
|
592
|
+
submodule.dirty = true;
|
|
593
|
+
submodule.error = formatGitError(error);
|
|
594
|
+
}
|
|
595
|
+
}
|
|
596
|
+
|
|
313
597
|
function parseSubmoduleStatusOutput(
|
|
314
598
|
output: string,
|
|
315
599
|
repoRoot: string,
|
|
@@ -321,9 +605,9 @@ function parseSubmoduleStatusOutput(
|
|
|
321
605
|
for (const line of output.split('\n')) {
|
|
322
606
|
if (!line.trim()) continue;
|
|
323
607
|
|
|
324
|
-
// Format: [+- ]<commit> <path> (<branch>)
|
|
325
|
-
// - = out of sync,
|
|
326
|
-
const match = line.match(/^([
|
|
608
|
+
// Format: [+-U ]<commit> <path> (<branch>)
|
|
609
|
+
// - = not initialized, + = gitlink out of sync, U = conflict, ' ' = aligned.
|
|
610
|
+
const match = line.match(/^([\-+U\s])([0-9a-f]{40})\s+(\S+)(?:\s+\(([^)]+)\))?/);
|
|
327
611
|
if (!match) continue;
|
|
328
612
|
|
|
329
613
|
const prefix = match[1];
|
|
@@ -336,8 +620,8 @@ function parseSubmoduleStatusOutput(
|
|
|
336
620
|
path,
|
|
337
621
|
commit,
|
|
338
622
|
repoPath: repoRoot + '/' + path,
|
|
339
|
-
dirty: prefix === '
|
|
340
|
-
outOfSync: prefix === '-',
|
|
623
|
+
dirty: prefix === 'U',
|
|
624
|
+
outOfSync: prefix === '-' || prefix === '+',
|
|
341
625
|
lastCheckedAt: Date.now(),
|
|
342
626
|
});
|
|
343
627
|
}
|
package/src/git/git-types.ts
CHANGED
|
@@ -6,69 +6,21 @@
|
|
|
6
6
|
* infer these values from agent transcripts in frontend code.
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
9
|
+
// Pure shape types now live in @adhdev/mesh-shared so the cloud (web-core) and
|
|
10
|
+
// standalone (daemon-core) transports share ONE definition instead of hand-syncing
|
|
11
|
+
// two. Re-exported here so existing `from './git-types'` / package imports keep
|
|
12
|
+
// working unchanged. Daemon-specific types (GitSnapshot, GitCommandName, …) stay
|
|
13
|
+
// local below and consume these re-exports.
|
|
14
|
+
export type {
|
|
15
|
+
GitFailureReason,
|
|
16
|
+
GitRepoIdentity,
|
|
17
|
+
GitSubmoduleStatus,
|
|
18
|
+
GitUpstreamFreshness,
|
|
19
|
+
GitRepoStatus,
|
|
20
|
+
DaemonBuildBehind,
|
|
21
|
+
} from '@adhdev/mesh-shared';
|
|
19
22
|
|
|
20
|
-
|
|
21
|
-
workspace: string;
|
|
22
|
-
repoRoot: string | null;
|
|
23
|
-
isGitRepo: boolean;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export interface GitSubmoduleStatus {
|
|
27
|
-
/** Submodule path relative to repo root */
|
|
28
|
-
path: string;
|
|
29
|
-
/** Current commit SHA the submodule is at */
|
|
30
|
-
commit: string;
|
|
31
|
-
/** Path to the submodule repo (absolute) */
|
|
32
|
-
repoPath: string;
|
|
33
|
-
/** Whether the submodule has uncommitted changes */
|
|
34
|
-
dirty: boolean;
|
|
35
|
-
/** Whether the submodule commit differs from what the parent repo expects */
|
|
36
|
-
outOfSync: boolean;
|
|
37
|
-
/** Last checked timestamp */
|
|
38
|
-
lastCheckedAt: number;
|
|
39
|
-
/** Error message if submodule status could not be read */
|
|
40
|
-
error?: string;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
export type GitUpstreamFreshness = 'fresh' | 'unchecked' | 'stale' | 'no_upstream' | 'unavailable';
|
|
44
|
-
|
|
45
|
-
export interface GitRepoStatus extends GitRepoIdentity {
|
|
46
|
-
branch: string | null;
|
|
47
|
-
headCommit: string | null;
|
|
48
|
-
headMessage: string | null;
|
|
49
|
-
upstream: string | null;
|
|
50
|
-
/** Whether ahead/behind was verified against a freshly fetched upstream ref. */
|
|
51
|
-
upstreamStatus: GitUpstreamFreshness;
|
|
52
|
-
/** Timestamp for the fetch that refreshed upstream refs when upstreamStatus === 'fresh'. */
|
|
53
|
-
upstreamFetchedAt?: number;
|
|
54
|
-
/** Error from the last refresh attempt when upstreamStatus === 'stale'. */
|
|
55
|
-
upstreamFetchError?: string;
|
|
56
|
-
ahead: number;
|
|
57
|
-
behind: number;
|
|
58
|
-
staged: number;
|
|
59
|
-
modified: number;
|
|
60
|
-
untracked: number;
|
|
61
|
-
deleted: number;
|
|
62
|
-
renamed: number;
|
|
63
|
-
hasConflicts: boolean;
|
|
64
|
-
conflictFiles: string[];
|
|
65
|
-
stashCount: number;
|
|
66
|
-
lastCheckedAt: number;
|
|
67
|
-
/** Submodule statuses when auto-discover is enabled */
|
|
68
|
-
submodules?: GitSubmoduleStatus[];
|
|
69
|
-
error?: string;
|
|
70
|
-
reason?: GitFailureReason;
|
|
71
|
-
}
|
|
23
|
+
import type { GitRepoIdentity, GitRepoStatus, GitFailureReason, GitUpstreamFreshness } from '@adhdev/mesh-shared';
|
|
72
24
|
|
|
73
25
|
export type GitFileChangeStatus =
|
|
74
26
|
| 'added'
|
package/src/git/git-worktree.ts
CHANGED
|
@@ -116,8 +116,11 @@ export async function createWorktree(opts: WorktreeCreateOptions): Promise<Workt
|
|
|
116
116
|
});
|
|
117
117
|
} catch (error: any) {
|
|
118
118
|
const stderr = typeof error.stderr === 'string' ? error.stderr : '';
|
|
119
|
-
// Clean error messages for common failures
|
|
120
119
|
if (/already exists/i.test(stderr)) {
|
|
120
|
+
// Distinguish directory-collision (TOCTOU race) from branch-already-exists
|
|
121
|
+
if (existsSync(targetDir)) {
|
|
122
|
+
throw new Error(`Worktree target directory was created concurrently: ${targetDir}`);
|
|
123
|
+
}
|
|
121
124
|
throw new Error(`Branch '${branch}' already exists or is checked out in another worktree`);
|
|
122
125
|
}
|
|
123
126
|
throw new Error(`git worktree add failed: ${stderr.trim() || error.message}`);
|
|
@@ -170,6 +173,10 @@ export async function removeWorktree(repoRoot: string, worktreePath: string, opt
|
|
|
170
173
|
const stdout = typeof error.stdout === 'string' ? error.stdout : '';
|
|
171
174
|
const detail = `${stderr}\n${stdout}\n${error.message || ''}`;
|
|
172
175
|
if (opts.allowSubmoduleForceFallback && SUBMODULE_WORKTREE_REMOVE_RE.test(detail)) {
|
|
176
|
+
process.stderr.write(
|
|
177
|
+
`[adhdev-mesh] WARNING: git worktree remove --force fallback for submodule worktree '${worktreePath}'. `
|
|
178
|
+
+ `Any uncommitted changes inside submodules will be lost.\n`,
|
|
179
|
+
);
|
|
173
180
|
try {
|
|
174
181
|
await execFileAsync('git', ['worktree', 'remove', '--force', worktreePath], {
|
|
175
182
|
cwd: repoRoot,
|