@agimon-ai/doompi-git 0.0.1-alpha.4 → 0.0.1-alpha.6
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 -0
- package/dist/api-contracts.cjs +1 -0
- package/dist/api-contracts.d.cts +2 -0
- package/dist/api-contracts.d.mts +2 -0
- package/dist/api-contracts.mjs +1 -0
- package/dist/constants/git.cjs +2 -0
- package/dist/constants/git.cjs.map +1 -0
- package/dist/constants/git.mjs +2 -0
- package/dist/constants/git.mjs.map +1 -0
- package/dist/controllers/gitCommand.cjs +2 -0
- package/dist/controllers/gitCommand.cjs.map +1 -0
- package/dist/controllers/gitCommand.mjs +2 -0
- package/dist/controllers/gitCommand.mjs.map +1 -0
- package/dist/controllers/gitSession.cjs +2 -0
- package/dist/controllers/gitSession.cjs.map +1 -0
- package/dist/controllers/gitSession.mjs +2 -0
- package/dist/controllers/gitSession.mjs.map +1 -0
- package/dist/controllers/hubApi.cjs +2 -0
- package/dist/controllers/hubApi.cjs.map +1 -0
- package/dist/controllers/hubApi.mjs +2 -0
- package/dist/controllers/hubApi.mjs.map +1 -0
- package/dist/controllers/worktreesChannel.cjs +2 -0
- package/dist/controllers/worktreesChannel.cjs.map +1 -0
- package/dist/controllers/worktreesChannel.mjs +2 -0
- package/dist/controllers/worktreesChannel.mjs.map +1 -0
- package/dist/extensions/pi.cjs +2 -1
- package/dist/extensions/pi.cjs.map +1 -0
- package/dist/extensions/pi.d.cts +6 -2
- package/dist/extensions/pi.d.cts.map +1 -0
- package/dist/extensions/pi.d.mts +6 -2
- package/dist/extensions/pi.d.mts.map +1 -0
- package/dist/extensions/pi.mjs +2 -1
- package/dist/extensions/pi.mjs.map +1 -0
- package/dist/extensions/server.cjs +2 -0
- package/dist/extensions/server.cjs.map +1 -0
- package/dist/extensions/server.d.cts +5 -0
- package/dist/extensions/server.d.cts.map +1 -0
- package/dist/extensions/server.d.mts +5 -0
- package/dist/extensions/server.d.mts.map +1 -0
- package/dist/extensions/server.mjs +2 -0
- package/dist/extensions/server.mjs.map +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +3 -4
- package/dist/index.d.mts +3 -4
- package/dist/index.mjs +1 -1
- package/dist/schemas/apiContracts.cjs +2 -0
- package/dist/schemas/apiContracts.cjs.map +1 -0
- package/dist/schemas/apiContracts.d.cts +53 -0
- package/dist/schemas/apiContracts.d.cts.map +1 -0
- package/dist/schemas/apiContracts.d.mts +53 -0
- package/dist/schemas/apiContracts.d.mts.map +1 -0
- package/dist/schemas/apiContracts.mjs +2 -0
- package/dist/schemas/apiContracts.mjs.map +1 -0
- package/dist/{adapters/filesystem/atomicJson.cjs → services/atomicJson/index.cjs} +1 -1
- package/dist/services/atomicJson/index.cjs.map +1 -0
- package/dist/{adapters/filesystem/atomicJson.mjs → services/atomicJson/index.mjs} +1 -1
- package/dist/services/atomicJson/index.mjs.map +1 -0
- package/dist/services/compositionMirror/index.cjs +2 -0
- package/dist/services/compositionMirror/index.cjs.map +1 -0
- package/dist/services/compositionMirror/index.mjs +2 -0
- package/dist/services/compositionMirror/index.mjs.map +1 -0
- package/dist/services/errors/index.cjs +2 -0
- package/dist/services/errors/index.cjs.map +1 -0
- package/dist/services/errors/index.mjs +2 -0
- package/dist/services/errors/index.mjs.map +1 -0
- package/dist/services/{extensionService.cjs → extensionService/index.cjs} +1 -1
- package/dist/services/extensionService/index.cjs.map +1 -0
- package/dist/services/extensionService/index.d.cts +8 -0
- package/dist/services/extensionService/index.d.cts.map +1 -0
- package/dist/services/extensionService/index.d.mts +8 -0
- package/dist/services/extensionService/index.d.mts.map +1 -0
- package/dist/services/{extensionService.mjs → extensionService/index.mjs} +1 -1
- package/dist/services/extensionService/index.mjs.map +1 -0
- package/dist/{adapters/worktree/gitCli.cjs → services/gitCli/index.cjs} +2 -2
- package/dist/services/gitCli/index.cjs.map +1 -0
- package/dist/{adapters/worktree/gitCli.mjs → services/gitCli/index.mjs} +2 -2
- package/dist/services/gitCli/index.mjs.map +1 -0
- package/dist/services/gitDependencies/index.cjs +2 -0
- package/dist/services/gitDependencies/index.cjs.map +1 -0
- package/dist/services/gitDependencies/index.d.cts +6 -0
- package/dist/services/gitDependencies/index.d.cts.map +1 -0
- package/dist/services/gitDependencies/index.d.mts +6 -0
- package/dist/services/gitDependencies/index.d.mts.map +1 -0
- package/dist/services/gitDependencies/index.mjs +2 -0
- package/dist/services/gitDependencies/index.mjs.map +1 -0
- package/dist/services/paths/index.cjs +2 -0
- package/dist/services/paths/index.cjs.map +1 -0
- package/dist/services/paths/index.mjs +2 -0
- package/dist/services/paths/index.mjs.map +1 -0
- package/dist/{adapters/worktree/repositoryIdentity.cjs → services/repositoryIdentity/index.cjs} +1 -1
- package/dist/services/repositoryIdentity/index.cjs.map +1 -0
- package/dist/{adapters/worktree/repositoryIdentity.mjs → services/repositoryIdentity/index.mjs} +1 -1
- package/dist/services/repositoryIdentity/index.mjs.map +1 -0
- package/dist/services/runWorktree/index.cjs +15 -0
- package/dist/services/runWorktree/index.cjs.map +1 -0
- package/dist/services/runWorktree/index.mjs +15 -0
- package/dist/services/runWorktree/index.mjs.map +1 -0
- package/dist/services/worktreeEvents/index.cjs +2 -0
- package/dist/services/worktreeEvents/index.cjs.map +1 -0
- package/dist/services/worktreeEvents/index.d.cts +15 -0
- package/dist/services/worktreeEvents/index.d.cts.map +1 -0
- package/dist/services/worktreeEvents/index.d.mts +15 -0
- package/dist/services/worktreeEvents/index.d.mts.map +1 -0
- package/dist/services/worktreeEvents/index.mjs +2 -0
- package/dist/services/worktreeEvents/index.mjs.map +1 -0
- package/dist/services/{worktreeNaming.cjs → worktreeNaming/index.cjs} +2 -2
- package/dist/services/{worktreeNaming.cjs.map → worktreeNaming/index.cjs.map} +1 -1
- package/dist/services/{worktreeNaming.d.mts → worktreeNaming/index.d.cts} +10 -3
- package/dist/services/worktreeNaming/index.d.cts.map +1 -0
- package/dist/services/{worktreeNaming.d.cts → worktreeNaming/index.d.mts} +10 -3
- package/dist/services/worktreeNaming/index.d.mts.map +1 -0
- package/dist/services/{worktreeNaming.mjs → worktreeNaming/index.mjs} +2 -2
- package/dist/services/{worktreeNaming.mjs.map → worktreeNaming/index.mjs.map} +1 -1
- package/dist/services/worktreeOperations/index.cjs +2 -0
- package/dist/services/worktreeOperations/index.cjs.map +1 -0
- package/dist/{adapters/worktree/worktreeOperations.d.cts → services/worktreeOperations/index.d.cts} +14 -8
- package/dist/services/worktreeOperations/index.d.cts.map +1 -0
- package/dist/{adapters/worktree/worktreeOperations.d.mts → services/worktreeOperations/index.d.mts} +14 -8
- package/dist/services/worktreeOperations/index.d.mts.map +1 -0
- package/dist/services/worktreeOperations/index.mjs +2 -0
- package/dist/services/worktreeOperations/index.mjs.map +1 -0
- package/dist/services/worktreeRegistry/index.cjs +2 -0
- package/dist/services/worktreeRegistry/index.cjs.map +1 -0
- package/dist/services/worktreeRegistry/index.mjs +2 -0
- package/dist/services/worktreeRegistry/index.mjs.map +1 -0
- package/dist/tools/runWorktree.cjs +2 -0
- package/dist/tools/runWorktree.cjs.map +1 -0
- package/dist/tools/runWorktree.mjs +2 -0
- package/dist/tools/runWorktree.mjs.map +1 -0
- package/dist/types/extension.d.cts +1 -1
- package/dist/types/extension.d.mts +1 -1
- package/package.json +27 -21
- package/src/extensions/web.ts +33 -0
- package/src/prompts/doompi-use-git/SKILL.md +5 -2
- package/src/types/worktreeRegistry.ts +9 -0
- package/src/web/components/RunWorktreeToolMessage.tsx +21 -13
- package/src/web/components/WorktreesActivitySection.tsx +29 -13
- package/src/web/components/WorktreesPanel.tsx +98 -48
- package/src/web/components/toolRenderers.ts +3 -2
- package/src/web/stores/worktreesActivityStore.ts +3 -2
- package/src/web/tsconfig.json +1 -1
- package/dist/adapters/channel/worktreeChannel.cjs +0 -2
- package/dist/adapters/channel/worktreeChannel.cjs.map +0 -1
- package/dist/adapters/channel/worktreeChannel.d.cts +0 -40
- package/dist/adapters/channel/worktreeChannel.d.cts.map +0 -1
- package/dist/adapters/channel/worktreeChannel.d.mts +0 -40
- package/dist/adapters/channel/worktreeChannel.d.mts.map +0 -1
- package/dist/adapters/channel/worktreeChannel.mjs +0 -2
- package/dist/adapters/channel/worktreeChannel.mjs.map +0 -1
- package/dist/adapters/filesystem/atomicJson.cjs.map +0 -1
- package/dist/adapters/filesystem/atomicJson.mjs.map +0 -1
- package/dist/adapters/filesystem/paths.cjs +0 -2
- package/dist/adapters/filesystem/paths.cjs.map +0 -1
- package/dist/adapters/filesystem/paths.mjs +0 -2
- package/dist/adapters/filesystem/paths.mjs.map +0 -1
- package/dist/adapters/hub/hubClient.cjs +0 -2
- package/dist/adapters/hub/hubClient.cjs.map +0 -1
- package/dist/adapters/hub/hubClient.d.cts +0 -1
- package/dist/adapters/hub/hubClient.d.mts +0 -1
- package/dist/adapters/hub/hubClient.mjs +0 -2
- package/dist/adapters/hub/hubClient.mjs.map +0 -1
- package/dist/adapters/pi/extension.cjs +0 -2
- package/dist/adapters/pi/extension.cjs.map +0 -1
- package/dist/adapters/pi/extension.d.cts +0 -9
- package/dist/adapters/pi/extension.d.cts.map +0 -1
- package/dist/adapters/pi/extension.d.mts +0 -9
- package/dist/adapters/pi/extension.d.mts.map +0 -1
- package/dist/adapters/pi/extension.mjs +0 -2
- package/dist/adapters/pi/extension.mjs.map +0 -1
- package/dist/adapters/pi/extensions/runWorktreeTool.cjs +0 -15
- package/dist/adapters/pi/extensions/runWorktreeTool.cjs.map +0 -1
- package/dist/adapters/pi/extensions/runWorktreeTool.mjs +0 -15
- package/dist/adapters/pi/extensions/runWorktreeTool.mjs.map +0 -1
- package/dist/adapters/web/worktreesChannel.cjs +0 -2
- package/dist/adapters/web/worktreesChannel.cjs.map +0 -1
- package/dist/adapters/web/worktreesChannel.d.cts +0 -21
- package/dist/adapters/web/worktreesChannel.d.cts.map +0 -1
- package/dist/adapters/web/worktreesChannel.d.mts +0 -21
- package/dist/adapters/web/worktreesChannel.d.mts.map +0 -1
- package/dist/adapters/web/worktreesChannel.mjs +0 -2
- package/dist/adapters/web/worktreesChannel.mjs.map +0 -1
- package/dist/adapters/worktree/dependencyInstall.cjs +0 -2
- package/dist/adapters/worktree/dependencyInstall.cjs.map +0 -1
- package/dist/adapters/worktree/dependencyInstall.mjs +0 -2
- package/dist/adapters/worktree/dependencyInstall.mjs.map +0 -1
- package/dist/adapters/worktree/gitCli.cjs.map +0 -1
- package/dist/adapters/worktree/gitCli.mjs.map +0 -1
- package/dist/adapters/worktree/repositoryIdentity.cjs.map +0 -1
- package/dist/adapters/worktree/repositoryIdentity.mjs.map +0 -1
- package/dist/adapters/worktree/worktreeOperations.cjs +0 -2
- package/dist/adapters/worktree/worktreeOperations.cjs.map +0 -1
- package/dist/adapters/worktree/worktreeOperations.d.cts.map +0 -1
- package/dist/adapters/worktree/worktreeOperations.d.mts.map +0 -1
- package/dist/adapters/worktree/worktreeOperations.mjs +0 -2
- package/dist/adapters/worktree/worktreeOperations.mjs.map +0 -1
- package/dist/adapters/worktree/worktreeRegistry.cjs +0 -2
- package/dist/adapters/worktree/worktreeRegistry.cjs.map +0 -1
- package/dist/adapters/worktree/worktreeRegistry.mjs +0 -2
- package/dist/adapters/worktree/worktreeRegistry.mjs.map +0 -1
- package/dist/commands/doomGitCommand.cjs +0 -2
- package/dist/commands/doomGitCommand.cjs.map +0 -1
- package/dist/commands/doomGitCommand.mjs +0 -2
- package/dist/commands/doomGitCommand.mjs.map +0 -1
- package/dist/container/index.cjs +0 -2
- package/dist/container/index.cjs.map +0 -1
- package/dist/container/index.d.cts +0 -6
- package/dist/container/index.d.cts.map +0 -1
- package/dist/container/index.d.mts +0 -6
- package/dist/container/index.d.mts.map +0 -1
- package/dist/container/index.mjs +0 -2
- package/dist/container/index.mjs.map +0 -1
- package/dist/hubApi.cjs +0 -2
- package/dist/hubApi.cjs.map +0 -1
- package/dist/hubApi.d.cts +0 -6
- package/dist/hubApi.d.cts.map +0 -1
- package/dist/hubApi.d.mts +0 -6
- package/dist/hubApi.d.mts.map +0 -1
- package/dist/hubApi.mjs +0 -2
- package/dist/hubApi.mjs.map +0 -1
- package/dist/services/extensionService.cjs.map +0 -1
- package/dist/services/extensionService.d.cts +0 -8
- package/dist/services/extensionService.d.cts.map +0 -1
- package/dist/services/extensionService.d.mts +0 -8
- package/dist/services/extensionService.d.mts.map +0 -1
- package/dist/services/extensionService.mjs.map +0 -1
- package/dist/services/support/errors.cjs +0 -2
- package/dist/services/support/errors.cjs.map +0 -1
- package/dist/services/support/errors.mjs +0 -2
- package/dist/services/support/errors.mjs.map +0 -1
- package/dist/services/worktreeNaming.d.cts.map +0 -1
- package/dist/services/worktreeNaming.d.mts.map +0 -1
- package/dist/webHub.cjs +0 -1
- package/dist/webHub.d.cts +0 -2
- package/dist/webHub.d.mts +0 -2
- package/dist/webHub.mjs +0 -1
- package/src/exports/webClient.ts +0 -1
- package/src/web/index.ts +0 -30
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import type { ToolMessageRenderProps } from '@agimon-ai/doompi-web
|
|
1
|
+
import type { ToolMessageRenderProps } from '@agimon-ai/doompi-core/web';
|
|
2
|
+
import { MessageItem, MessageItemBody, MessageItemHeader, toolTone } from '@agimon-ai/doompi-web-components';
|
|
2
3
|
|
|
3
4
|
const ACTION_LABEL: Readonly<Record<string, string>> = {
|
|
4
5
|
spawn_worktree: 'Create worktree',
|
|
@@ -14,24 +15,31 @@ const ACTION_LABEL: Readonly<Record<string, string>> = {
|
|
|
14
15
|
/**
|
|
15
16
|
* The timeline item for `run_worktree`.
|
|
16
17
|
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
* the
|
|
18
|
+
* DESIGN PATTERNS:
|
|
19
|
+
* - Built on MessageItem, like every other tool renderer in the cockpit. That
|
|
20
|
+
* is what gives it the shared collapse toggle and the RUNNING/OK/ERROR badge
|
|
21
|
+
* rather than a hand-rolled ellipsis that never resolves.
|
|
22
|
+
* - The action and its subject go in the heading because that is what a reader
|
|
23
|
+
* scanning a transcript needs: "close_worktree a1b2c3d4" answers the question
|
|
24
|
+
* the raw JSON arguments make them decode.
|
|
25
|
+
* - A create takes as long as the cockpit needs to start a session, and the
|
|
26
|
+
* tool streams each phase into `output`, so the body is where the wait is
|
|
27
|
+
* visible.
|
|
20
28
|
*/
|
|
21
29
|
export function RunWorktreeToolMessage({ args, output, running, isError }: ToolMessageRenderProps) {
|
|
22
30
|
const action = typeof args.action === 'string' ? args.action : '';
|
|
23
31
|
const subject = typeof args.branch === 'string' ? args.branch : typeof args.id === 'string' ? args.id : '';
|
|
24
32
|
|
|
25
33
|
return (
|
|
26
|
-
<
|
|
27
|
-
<
|
|
28
|
-
{
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
+
<MessageItem tone={toolTone({ running, isError })} expandable={output !== ''}>
|
|
35
|
+
<MessageItemHeader title={ACTION_LABEL[action] ?? 'Worktree'}>
|
|
36
|
+
{subject === '' ? null : <span className="min-w-0 truncate text-doom-dim">{subject}</span>}
|
|
37
|
+
</MessageItemHeader>
|
|
38
|
+
{output === '' ? null : (
|
|
39
|
+
<MessageItemBody>
|
|
40
|
+
<pre className={`whitespace-pre-wrap text-xs ${isError ? 'text-doom-red' : 'text-doom-dim'}`}>{output}</pre>
|
|
41
|
+
</MessageItemBody>
|
|
34
42
|
)}
|
|
35
|
-
</
|
|
43
|
+
</MessageItem>
|
|
36
44
|
);
|
|
37
45
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { WebPluginSlotProps } from '@agimon-ai/doompi-core/web';
|
|
1
2
|
/**
|
|
2
3
|
* The '# git' group's body in the activity dock.
|
|
3
4
|
*
|
|
@@ -12,12 +13,12 @@
|
|
|
12
13
|
* - Doing work here. This section reports and launches; the panel and the tool
|
|
13
14
|
* own everything else.
|
|
14
15
|
*/
|
|
15
|
-
import { Button } from '@agimon-ai/doompi-web-components';
|
|
16
|
-
import type { WebPluginSlotProps } from '@agimon-ai/doompi-web-contracts';
|
|
16
|
+
import { Button, Dot, Spinner, StatusBadge } from '@agimon-ai/doompi-web-components';
|
|
17
17
|
import { useStore } from '@tanstack/react-store';
|
|
18
|
-
|
|
19
|
-
import {
|
|
20
|
-
import {
|
|
18
|
+
|
|
19
|
+
import type { WorktreeView } from '../../types/webWorktrees';
|
|
20
|
+
import { worktreeActivity } from '../stores/worktreesActivityStore';
|
|
21
|
+
import { worktreesTab } from './WorktreesPanel';
|
|
21
22
|
|
|
22
23
|
export function WorktreesActivitySection({ sessionId, openTransientTab }: WebPluginSlotProps) {
|
|
23
24
|
const session = useStore(worktreeActivity.store, (state) => worktreeActivity.select(state, sessionId));
|
|
@@ -45,19 +46,34 @@ export function WorktreesActivitySection({ sessionId, openTransientTab }: WebPlu
|
|
|
45
46
|
|
|
46
47
|
return (
|
|
47
48
|
<div data-testid="activity-git-worktrees" className="flex flex-col gap-0.5">
|
|
48
|
-
{session.pending === undefined ? null :
|
|
49
|
+
{session.pending === undefined ? null : (
|
|
50
|
+
<span className="flex min-w-0 items-center gap-1.5 px-1">
|
|
51
|
+
<Spinner className="h-3 w-3 shrink-0 text-doom-faint" label={session.pending} />
|
|
52
|
+
<span className="min-w-0 truncate text-xs text-doom-dim">{session.pending}</span>
|
|
53
|
+
</span>
|
|
54
|
+
)}
|
|
49
55
|
{session.worktrees.map((worktree: WorktreeView) => (
|
|
50
|
-
<
|
|
56
|
+
<Button
|
|
51
57
|
key={worktree.id}
|
|
52
|
-
|
|
58
|
+
variant="ghost"
|
|
59
|
+
size="card"
|
|
53
60
|
data-testid={`activity-git-worktree-${worktree.id}`}
|
|
54
|
-
className="
|
|
61
|
+
className="min-w-0 gap-1.5 px-1"
|
|
55
62
|
onClick={() => openTransientTab(worktreesTab())}
|
|
56
63
|
>
|
|
57
|
-
<
|
|
58
|
-
|
|
59
|
-
{worktree.
|
|
60
|
-
|
|
64
|
+
<Dot tone={worktree.orphaned ? 'red' : worktree.sessionId === null ? 'muted' : 'blue'} />
|
|
65
|
+
<span className="min-w-0 flex-1 truncate text-left text-xs font-bold text-doom-hi">{worktree.branch}</span>
|
|
66
|
+
{worktree.orphaned ? (
|
|
67
|
+
<StatusBadge tone="error" size="xs">
|
|
68
|
+
orphaned
|
|
69
|
+
</StatusBadge>
|
|
70
|
+
) : null}
|
|
71
|
+
{worktree.unowned ? (
|
|
72
|
+
<StatusBadge tone="info" size="xs">
|
|
73
|
+
unowned
|
|
74
|
+
</StatusBadge>
|
|
75
|
+
) : null}
|
|
76
|
+
</Button>
|
|
61
77
|
))}
|
|
62
78
|
</div>
|
|
63
79
|
);
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { TransientTab, WebPluginSlotProps } from '@agimon-ai/doompi-core/web';
|
|
1
2
|
/**
|
|
2
3
|
* The '# git' group's tab: this session's worktrees, and the form that makes one.
|
|
3
4
|
*
|
|
@@ -5,24 +6,30 @@
|
|
|
5
6
|
* - Lives in the activity dock, opened by the group's name. A worktree is work
|
|
6
7
|
* in progress belonging to the session that started it, so it sits beside
|
|
7
8
|
* agents, runners and workflows rather than in a settings screen.
|
|
9
|
+
* - Header, form, then cards, the same rhythm the runners and workflows panels
|
|
10
|
+
* use. A worktree row is a card because it carries three facts and two
|
|
11
|
+
* actions, which a single line cannot hold without becoming a puzzle.
|
|
8
12
|
* - Local form state is never reset by a data refresh. The hub republishes this
|
|
9
13
|
* list on a timer, and a half-typed branch name must survive that.
|
|
10
14
|
* - Acts through the plugin's own hub channel, so a worktree made here and one
|
|
11
15
|
* made by the tool take exactly the same path.
|
|
12
|
-
* - Creating
|
|
13
|
-
* channel and
|
|
14
|
-
* minutes reads as broken.
|
|
16
|
+
* - Creating waits on the cockpit starting a session, so the hub reports each
|
|
17
|
+
* phase on that channel and the header shows it turning. A button that looks
|
|
18
|
+
* idle for two minutes reads as broken.
|
|
15
19
|
*
|
|
16
20
|
* AVOID:
|
|
17
21
|
* - Deriving form state from props or store data. That is what wiped the
|
|
18
22
|
* fields on every poll.
|
|
23
|
+
* - Colour classes outside the token set. `doom-error`, `doom-line` and
|
|
24
|
+
* `doom-bright` are not tokens: they compile to nothing and the row silently
|
|
25
|
+
* loses its border.
|
|
19
26
|
*/
|
|
20
|
-
import { Button, Input } from '@agimon-ai/doompi-web-components';
|
|
21
|
-
import type { TransientTab, WebPluginSlotProps } from '@agimon-ai/doompi-web-contracts';
|
|
27
|
+
import { Button, Dot, EmptyState, Input, Spinner, StatusBadge } from '@agimon-ai/doompi-web-components';
|
|
22
28
|
import { useStore } from '@tanstack/react-store';
|
|
23
29
|
import { useState } from 'react';
|
|
24
|
-
|
|
25
|
-
import {
|
|
30
|
+
|
|
31
|
+
import type { WorktreeView } from '../../types/webWorktrees';
|
|
32
|
+
import { requestWorktreeClose, requestWorktreeCreate, worktreeActivity } from '../stores/worktreesActivityStore';
|
|
26
33
|
|
|
27
34
|
const WORKTREES_TAB_ID = 'git-worktrees';
|
|
28
35
|
|
|
@@ -46,12 +53,28 @@ export function WorktreesPanel({ sessionId }: WebPluginSlotProps) {
|
|
|
46
53
|
};
|
|
47
54
|
|
|
48
55
|
return (
|
|
49
|
-
<div className="flex
|
|
50
|
-
<div className="flex
|
|
56
|
+
<div data-testid="git-worktrees-panel" className="flex min-h-0 flex-1 flex-col overflow-auto">
|
|
57
|
+
<div className="flex min-h-11 shrink-0 items-center gap-2.5 border-b border-doom-border-soft px-3 sm:px-[26px]">
|
|
58
|
+
<span className="text-sm font-bold text-doom-hi">worktrees</span>
|
|
59
|
+
<span data-testid="git-worktrees-count" className="text-xs text-doom-faint">
|
|
60
|
+
{session.worktrees.length === 0 ? 'none yet' : `${String(session.worktrees.length)} open`}
|
|
61
|
+
</span>
|
|
62
|
+
<span className="min-w-0 flex-1" />
|
|
63
|
+
{session.pending === undefined ? null : (
|
|
64
|
+
<span data-testid="git-worktree-pending" className="flex min-w-0 items-center gap-1.5">
|
|
65
|
+
<Spinner className="h-3 w-3 shrink-0 text-doom-faint" label={session.pending} />
|
|
66
|
+
<span className="min-w-0 truncate text-xs text-doom-dim">{session.pending}</span>
|
|
67
|
+
</span>
|
|
68
|
+
)}
|
|
69
|
+
</div>
|
|
70
|
+
|
|
71
|
+
<div className="flex shrink-0 flex-col gap-1.5 border-b border-doom-border-soft px-3 py-2.5 sm:px-[26px]">
|
|
51
72
|
<div className="flex items-center gap-2">
|
|
52
73
|
<Input
|
|
53
74
|
data-testid="git-worktree-branch"
|
|
54
75
|
aria-label="Branch"
|
|
76
|
+
size="sm"
|
|
77
|
+
className="min-w-0 flex-1"
|
|
55
78
|
placeholder="wt/fix-auth"
|
|
56
79
|
value={branch}
|
|
57
80
|
onChange={(event) => setBranch(event.target.value)}
|
|
@@ -62,64 +85,91 @@ export function WorktreesPanel({ sessionId }: WebPluginSlotProps) {
|
|
|
62
85
|
<Input
|
|
63
86
|
data-testid="git-worktree-base"
|
|
64
87
|
aria-label="Base ref"
|
|
88
|
+
size="sm"
|
|
65
89
|
placeholder="base (current)"
|
|
66
90
|
value={baseRef}
|
|
67
91
|
onChange={(event) => setBaseRef(event.target.value)}
|
|
68
|
-
className="w-
|
|
92
|
+
className="w-32 shrink-0"
|
|
69
93
|
/>
|
|
70
|
-
<Button data-testid="git-worktree-create" size="
|
|
94
|
+
<Button data-testid="git-worktree-create" size="sm" disabled={!canCreate} onClick={create}>
|
|
71
95
|
Create
|
|
72
96
|
</Button>
|
|
73
97
|
</div>
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
</p>
|
|
78
|
-
{session.pending === undefined ? null : (
|
|
79
|
-
<p data-testid="git-worktree-pending" className="text-xs text-doom-dim">
|
|
80
|
-
{session.pending}
|
|
98
|
+
{session.error === undefined ? (
|
|
99
|
+
<p className="text-2xs text-doom-faint">
|
|
100
|
+
Creates the worktree outside the repository and starts a session nested under this one.
|
|
81
101
|
</p>
|
|
82
|
-
)
|
|
83
|
-
|
|
84
|
-
<p data-testid="git-worktree-error" className="text-xs text-doom-error">
|
|
102
|
+
) : (
|
|
103
|
+
<p data-testid="git-worktree-error" className="text-2xs text-doom-red">
|
|
85
104
|
{session.error}
|
|
86
105
|
</p>
|
|
87
106
|
)}
|
|
88
107
|
</div>
|
|
89
108
|
|
|
90
109
|
{session.worktrees.length === 0 ? (
|
|
91
|
-
<
|
|
110
|
+
<EmptyState
|
|
111
|
+
data-testid="git-worktrees-empty"
|
|
112
|
+
className="px-4 py-8"
|
|
113
|
+
title="no worktrees yet"
|
|
114
|
+
description="a worktree is its own checkout on its own branch, with its own session nested under this one."
|
|
115
|
+
/>
|
|
92
116
|
) : (
|
|
93
|
-
<ul className="flex flex-col gap-
|
|
117
|
+
<ul data-testid="git-worktrees-list" className="flex flex-col gap-2.5 px-3 py-3 sm:px-[26px]">
|
|
94
118
|
{session.worktrees.map((worktree: WorktreeView) => (
|
|
95
|
-
<
|
|
96
|
-
key={worktree.id}
|
|
97
|
-
data-testid={`git-worktree-${worktree.id}`}
|
|
98
|
-
className="flex items-center justify-between gap-2 border border-doom-line px-2 py-1"
|
|
99
|
-
>
|
|
100
|
-
<div className="flex min-w-0 flex-col">
|
|
101
|
-
<span className="truncate text-sm text-doom-bright">{worktree.branch}</span>
|
|
102
|
-
<span className="truncate text-xs text-doom-faint">{worktree.path}</span>
|
|
103
|
-
</div>
|
|
104
|
-
<div className="flex items-center gap-2">
|
|
105
|
-
{worktree.orphaned ? <span className="text-xs text-doom-faint">orphaned</span> : null}
|
|
106
|
-
{worktree.unowned ? <span className="text-xs text-doom-faint">unowned</span> : null}
|
|
107
|
-
{sessionId === null ? null : (
|
|
108
|
-
<Button
|
|
109
|
-
variant="link"
|
|
110
|
-
size="xs"
|
|
111
|
-
disabled={busy}
|
|
112
|
-
data-testid={`git-worktree-close-${worktree.id}`}
|
|
113
|
-
onClick={() => requestWorktreeClose(sessionId, worktree.id)}
|
|
114
|
-
>
|
|
115
|
-
close
|
|
116
|
-
</Button>
|
|
117
|
-
)}
|
|
118
|
-
</div>
|
|
119
|
-
</li>
|
|
119
|
+
<WorktreeCard key={worktree.id} worktree={worktree} sessionId={sessionId} busy={busy} />
|
|
120
120
|
))}
|
|
121
121
|
</ul>
|
|
122
122
|
)}
|
|
123
123
|
</div>
|
|
124
124
|
);
|
|
125
125
|
}
|
|
126
|
+
|
|
127
|
+
/** One worktree: what it is, where it is, and the one thing you can do to it. */
|
|
128
|
+
function WorktreeCard({
|
|
129
|
+
worktree,
|
|
130
|
+
sessionId,
|
|
131
|
+
busy,
|
|
132
|
+
}: {
|
|
133
|
+
worktree: WorktreeView;
|
|
134
|
+
busy: boolean;
|
|
135
|
+
} & Pick<WebPluginSlotProps, 'sessionId'>) {
|
|
136
|
+
return (
|
|
137
|
+
<li
|
|
138
|
+
data-testid={`git-worktree-${worktree.id}`}
|
|
139
|
+
className="flex min-w-0 flex-col gap-1.5 rounded-md border border-doom-border-soft bg-doom-panel p-2.5"
|
|
140
|
+
>
|
|
141
|
+
<div className="flex min-w-0 items-center gap-1.5">
|
|
142
|
+
<Dot tone={worktree.orphaned ? 'red' : worktree.sessionId === null ? 'muted' : 'blue'} />
|
|
143
|
+
<span className="min-w-0 flex-1 truncate text-sm font-bold text-doom-hi">{worktree.branch}</span>
|
|
144
|
+
{worktree.orphaned ? (
|
|
145
|
+
<StatusBadge tone="error" size="xs">
|
|
146
|
+
orphaned
|
|
147
|
+
</StatusBadge>
|
|
148
|
+
) : null}
|
|
149
|
+
{worktree.unowned ? (
|
|
150
|
+
<StatusBadge tone="info" size="xs">
|
|
151
|
+
unowned
|
|
152
|
+
</StatusBadge>
|
|
153
|
+
) : null}
|
|
154
|
+
</div>
|
|
155
|
+
|
|
156
|
+
<span className="min-w-0 truncate text-2xs text-doom-faint">{worktree.path}</span>
|
|
157
|
+
|
|
158
|
+
<div className="flex items-center gap-1.5 pt-0.5">
|
|
159
|
+
<span className="min-w-0 flex-1" />
|
|
160
|
+
{sessionId === null ? null : (
|
|
161
|
+
<Button
|
|
162
|
+
variant="danger-outline"
|
|
163
|
+
size="xs"
|
|
164
|
+
disabled={busy}
|
|
165
|
+
data-testid={`git-worktree-close-${worktree.id}`}
|
|
166
|
+
className="px-2 text-2xs font-bold"
|
|
167
|
+
onClick={() => requestWorktreeClose(sessionId, worktree.id)}
|
|
168
|
+
>
|
|
169
|
+
close
|
|
170
|
+
</Button>
|
|
171
|
+
)}
|
|
172
|
+
</div>
|
|
173
|
+
</li>
|
|
174
|
+
);
|
|
175
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import type { ToolRendererContribution } from '@agimon-ai/doompi-web
|
|
2
|
-
|
|
1
|
+
import type { ToolRendererContribution } from '@agimon-ai/doompi-core/web';
|
|
2
|
+
|
|
3
|
+
import { RunWorktreeToolMessage } from './RunWorktreeToolMessage';
|
|
3
4
|
|
|
4
5
|
/** The timeline items for this package's tools. */
|
|
5
6
|
export const gitToolRenderers: ToolRendererContribution[] = [
|
|
@@ -17,8 +17,9 @@
|
|
|
17
17
|
* - `sendSessionFrame` for a command. It envelopes the frame as a session
|
|
18
18
|
* command bound for the agent, which never reaches a channel's `receive`.
|
|
19
19
|
*/
|
|
20
|
-
import { defineGlobalStore, defineSessionStore, type WebPluginRuntime } from '@agimon-ai/doompi-web
|
|
21
|
-
|
|
20
|
+
import { defineGlobalStore, defineSessionStore, type WebPluginRuntime } from '@agimon-ai/doompi-core/web';
|
|
21
|
+
|
|
22
|
+
import { GIT_WORKTREES_TYPE, type GitWorktreesCommand, type WorktreeView } from '../../types/webWorktrees';
|
|
22
23
|
|
|
23
24
|
export interface WorktreesSession {
|
|
24
25
|
/** The worktrees the hub last reported for this session's repository. */
|
package/src/web/tsconfig.json
CHANGED
|
@@ -18,5 +18,5 @@
|
|
|
18
18
|
"allowImportingTsExtensions": true,
|
|
19
19
|
"forceConsistentCasingInFileNames": true
|
|
20
20
|
},
|
|
21
|
-
"include": [".", "../types/worktreeRegistry.ts", "../types/webWorktrees.ts", "../
|
|
21
|
+
"include": [".", "../types/worktreeRegistry.ts", "../types/webWorktrees.ts", "../extensions/web.ts"]
|
|
22
22
|
}
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
const e=require("../../_virtual/_rolldown/runtime.cjs");let t=require("node:fs");t=e.__toESM(t,1);let n=require("node:crypto"),r=require("node:path");r=e.__toESM(r,1);const i=`.json`,a=`.claim-`;let o=-1,s=0;function c(e,t){return r.default.join(e,t)}function l(e){let t;try{t=JSON.parse(e)}catch{return}if(typeof t!=`object`||!t)return;let n=t;if(n.version===1&&(n.from===`parent`||n.from===`child`)&&typeof n.text==`string`&&n.text!==``&&typeof n.sentAt==`string`)return{version:1,from:n.from,text:n.text,sentAt:n.sentAt}}function u(){let e=Date.now();return e===o?s+=1:(o=e,s=0),`${String(e).padStart(14,`0`)}-${String(s).padStart(6,`0`)}-${(0,n.randomBytes)(6).toString(`hex`)}`}function d(e){return{send(n,a){if(Buffer.byteLength(a,`utf8`)>65536)throw Error(`A message may not exceed 65536 bytes.`);let o=c(e,n);t.default.mkdirSync(o,{recursive:!0,mode:448});let s={version:1,from:n===`parent`?`child`:`parent`,text:a,sentAt:new Date().toISOString()},l=u(),d=r.default.join(o,`.tmp-${l}`);t.default.writeFileSync(d,JSON.stringify(s),{mode:384}),t.default.renameSync(d,r.default.join(o,`${l}${i}`))},receive(n){let o=c(e,n),s;try{s=t.default.readdirSync(o)}catch{return[]}let u=[];for(let e of s.filter(e=>e.endsWith(i)).sort()){let n=r.default.join(o,`${a}${String(process.pid)}-${e}`);try{t.default.renameSync(r.default.join(o,e),n)}catch{continue}let i;try{i=l(t.default.readFileSync(n,`utf8`))}catch{i=void 0}i!==void 0&&(u.push(i),t.default.rmSync(n,{force:!0}))}return u},sweep(n=Date.now()){let i=0;for(let o of[`parent`,`child`]){let s=c(e,o),l;try{l=t.default.readdirSync(s)}catch{continue}for(let e of l.filter(e=>e.startsWith(a))){let a=r.default.join(s,e);try{if(n-t.default.statSync(a).mtimeMs<6e4)continue;let o=e.slice(e.indexOf(`-`,7)+1);t.default.renameSync(a,r.default.join(s,o)),i+=1}catch{}}}return i}}}exports.createWorktreeChannel=d;
|
|
2
|
-
//# sourceMappingURL=worktreeChannel.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"worktreeChannel.cjs","names":["path","randomBytes","fs"],"sources":["../../../src/adapters/channel/worktreeChannel.ts"],"sourcesContent":["/**\n * Messages between a parent session and one worktree session.\n *\n * A two-party mirror of doompi-team's channel, kept private to this package\n * rather than imported: a layer must not depend on another layer, and two\n * parties need none of the membership, heartbeat or fanout machinery that makes\n * that module large.\n *\n * THE INVARIANTS WORTH COPYING, AND WHAT BREAKS WITHOUT THEM:\n *\n * 1. Write to a temp name and rename into place. A reader polling a directory\n * will otherwise read a file that is still being written and parse half a\n * message.\n * 2. Claim by rename before reading. Rename is atomic, so exactly one reader\n * wins a message even when a session polls twice concurrently. Reading first\n * and deleting after delivers the same message twice.\n * 3. Deliver, then delete. Deleting first loses the message permanently if the\n * delivery throws; a duplicate is recoverable, a loss is not.\n * 4. A claim that outlives its reader is swept. Otherwise a crash mid-delivery\n * strands the message in a claimed state nobody will ever look at again.\n *\n * AVOID:\n * - Treating an atomic write as a lock. It prevents a torn read, nothing else.\n * - Deleting a file that failed to parse. It may belong to a newer build, and\n * destroying it turns a version skew into data loss.\n */\n\nimport fs from 'node:fs';\nimport path from 'node:path';\nimport { randomBytes } from 'node:crypto';\n\nexport const CHANNEL_MESSAGE_VERSION = 1;\n\nconst PRIVATE_DIRECTORY_MODE = 0o700;\nconst PRIVATE_FILE_MODE = 0o600;\nconst MESSAGE_SUFFIX = '.json';\nconst CLAIM_PREFIX = '.claim-';\nconst MAX_MESSAGE_BYTES = 64 * 1024;\n/** A claim older than this belonged to a reader that is not coming back. */\nconst CLAIM_STALE_MS = 60_000;\nconst MESSAGE_SEQUENCE_WIDTH = 6;\nlet lastMessageTimestamp = -1;\nlet messageSequence = 0;\n\n/** Which side of the pair a message is for. */\nexport type ChannelParty = 'parent' | 'child';\n\nexport interface ChannelMessage {\n version: typeof CHANNEL_MESSAGE_VERSION;\n /** Who sent it, so a reader never has to infer it from the directory. */\n from: ChannelParty;\n text: string;\n sentAt: string;\n}\n\nexport interface WorktreeChannel {\n send(to: ChannelParty, text: string): void;\n /** Claims and returns everything waiting for a party, oldest first. */\n receive(as: ChannelParty): ChannelMessage[];\n /** Releases claims abandoned by a reader that died mid-delivery. */\n sweep(now?: number): number;\n}\n\nfunction inboxDirectory(root: string, party: ChannelParty): string {\n return path.join(root, party);\n}\n\nfunction parse(raw: string): ChannelMessage | undefined {\n let value: unknown;\n try {\n value = JSON.parse(raw);\n } catch {\n return undefined;\n }\n if (typeof value !== 'object' || value === null) return undefined;\n const record = value as Partial<ChannelMessage>;\n if (record.version !== CHANNEL_MESSAGE_VERSION) return undefined;\n if (record.from !== 'parent' && record.from !== 'child') return undefined;\n if (typeof record.text !== 'string' || record.text === '') return undefined;\n if (typeof record.sentAt !== 'string') return undefined;\n return { version: CHANNEL_MESSAGE_VERSION, from: record.from, text: record.text, sentAt: record.sentAt };\n}\n\nfunction nextMessageName(): string {\n const timestamp = Date.now();\n if (timestamp === lastMessageTimestamp) {\n messageSequence += 1;\n } else {\n lastMessageTimestamp = timestamp;\n messageSequence = 0;\n }\n return `${String(timestamp).padStart(14, '0')}-${String(messageSequence).padStart(MESSAGE_SEQUENCE_WIDTH, '0')}-${randomBytes(6).toString('hex')}`;\n}\n\n/** The channel rooted at a directory, created on demand. */\nexport function createWorktreeChannel(root: string): WorktreeChannel {\n return {\n send(to, text) {\n if (Buffer.byteLength(text, 'utf8') > MAX_MESSAGE_BYTES) {\n throw new Error(`A message may not exceed ${String(MAX_MESSAGE_BYTES)} bytes.`);\n }\n const directory = inboxDirectory(root, to);\n fs.mkdirSync(directory, { recursive: true, mode: PRIVATE_DIRECTORY_MODE });\n const message: ChannelMessage = {\n version: CHANNEL_MESSAGE_VERSION,\n from: to === 'parent' ? 'child' : 'parent',\n text,\n sentAt: new Date().toISOString(),\n };\n // A process-local sequence preserves send order when several messages share\n // a millisecond. The random suffix still prevents cross-process collisions.\n const name = nextMessageName();\n const temporary = path.join(directory, `.tmp-${name}`);\n fs.writeFileSync(temporary, JSON.stringify(message), { mode: PRIVATE_FILE_MODE });\n fs.renameSync(temporary, path.join(directory, `${name}${MESSAGE_SUFFIX}`));\n },\n\n receive(as) {\n const directory = inboxDirectory(root, as);\n let names: string[];\n try {\n names = fs.readdirSync(directory);\n } catch {\n return [];\n }\n const delivered: ChannelMessage[] = [];\n for (const name of names.filter((entry) => entry.endsWith(MESSAGE_SUFFIX)).sort()) {\n const claim = path.join(directory, `${CLAIM_PREFIX}${String(process.pid)}-${name}`);\n try {\n // Whoever wins this rename owns the message. A loser gets ENOENT and\n // simply moves on, which is why this is not wrapped in an existence\n // check: the check and the rename would not be atomic together.\n fs.renameSync(path.join(directory, name), claim);\n } catch {\n continue;\n }\n let message: ChannelMessage | undefined;\n try {\n message = parse(fs.readFileSync(claim, 'utf8'));\n } catch {\n message = undefined;\n }\n if (message === undefined) {\n // Left claimed rather than deleted. An unreadable message may come\n // from a newer build, and the sweep will surface it again rather than\n // this reader destroying something it did not understand.\n continue;\n }\n delivered.push(message);\n fs.rmSync(claim, { force: true });\n }\n return delivered;\n },\n\n sweep(now = Date.now()) {\n let released = 0;\n for (const party of ['parent', 'child'] as const) {\n const directory = inboxDirectory(root, party);\n let names: string[];\n try {\n names = fs.readdirSync(directory);\n } catch {\n continue;\n }\n for (const name of names.filter((entry) => entry.startsWith(CLAIM_PREFIX))) {\n const claimed = path.join(directory, name);\n try {\n if (now - fs.statSync(claimed).mtimeMs < CLAIM_STALE_MS) continue;\n // Returned to the inbox rather than deleted, because the message\n // was claimed but never delivered.\n const original = name.slice(name.indexOf('-', CLAIM_PREFIX.length) + 1);\n fs.renameSync(claimed, path.join(directory, original));\n released += 1;\n } catch {\n // Another sweeper got there first.\n }\n }\n }\n return released;\n },\n };\n}\n"],"mappings":"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"}
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
//#region src/adapters/channel/worktreeChannel.d.ts
|
|
2
|
-
/**
|
|
3
|
-
* Messages between a parent session and one worktree session.
|
|
4
|
-
*
|
|
5
|
-
* A two-party mirror of doompi-team's channel, kept private to this package
|
|
6
|
-
* rather than imported: a layer must not depend on another layer, and two
|
|
7
|
-
* parties need none of the membership, heartbeat or fanout machinery that makes
|
|
8
|
-
* that module large.
|
|
9
|
-
*
|
|
10
|
-
* THE INVARIANTS WORTH COPYING, AND WHAT BREAKS WITHOUT THEM:
|
|
11
|
-
*
|
|
12
|
-
* 1. Write to a temp name and rename into place. A reader polling a directory
|
|
13
|
-
* will otherwise read a file that is still being written and parse half a
|
|
14
|
-
* message.
|
|
15
|
-
* 2. Claim by rename before reading. Rename is atomic, so exactly one reader
|
|
16
|
-
* wins a message even when a session polls twice concurrently. Reading first
|
|
17
|
-
* and deleting after delivers the same message twice.
|
|
18
|
-
* 3. Deliver, then delete. Deleting first loses the message permanently if the
|
|
19
|
-
* delivery throws; a duplicate is recoverable, a loss is not.
|
|
20
|
-
* 4. A claim that outlives its reader is swept. Otherwise a crash mid-delivery
|
|
21
|
-
* strands the message in a claimed state nobody will ever look at again.
|
|
22
|
-
*
|
|
23
|
-
* AVOID:
|
|
24
|
-
* - Treating an atomic write as a lock. It prevents a torn read, nothing else.
|
|
25
|
-
* - Deleting a file that failed to parse. It may belong to a newer build, and
|
|
26
|
-
* destroying it turns a version skew into data loss.
|
|
27
|
-
*/
|
|
28
|
-
declare const CHANNEL_MESSAGE_VERSION = 1;
|
|
29
|
-
/** Which side of the pair a message is for. */
|
|
30
|
-
type ChannelParty = 'parent' | 'child';
|
|
31
|
-
interface ChannelMessage {
|
|
32
|
-
version: typeof CHANNEL_MESSAGE_VERSION;
|
|
33
|
-
/** Who sent it, so a reader never has to infer it from the directory. */
|
|
34
|
-
from: ChannelParty;
|
|
35
|
-
text: string;
|
|
36
|
-
sentAt: string;
|
|
37
|
-
}
|
|
38
|
-
//#endregion
|
|
39
|
-
export { CHANNEL_MESSAGE_VERSION, ChannelMessage, ChannelParty };
|
|
40
|
-
//# sourceMappingURL=worktreeChannel.d.cts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"worktreeChannel.d.cts","names":[],"sources":["../../../src/adapters/channel/worktreeChannel.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;cA+Ba;;KAcD;UAEK;EACf,gBAAgB;;EAEhB,MAAM;EACN;EACA"}
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
//#region src/adapters/channel/worktreeChannel.d.ts
|
|
2
|
-
/**
|
|
3
|
-
* Messages between a parent session and one worktree session.
|
|
4
|
-
*
|
|
5
|
-
* A two-party mirror of doompi-team's channel, kept private to this package
|
|
6
|
-
* rather than imported: a layer must not depend on another layer, and two
|
|
7
|
-
* parties need none of the membership, heartbeat or fanout machinery that makes
|
|
8
|
-
* that module large.
|
|
9
|
-
*
|
|
10
|
-
* THE INVARIANTS WORTH COPYING, AND WHAT BREAKS WITHOUT THEM:
|
|
11
|
-
*
|
|
12
|
-
* 1. Write to a temp name and rename into place. A reader polling a directory
|
|
13
|
-
* will otherwise read a file that is still being written and parse half a
|
|
14
|
-
* message.
|
|
15
|
-
* 2. Claim by rename before reading. Rename is atomic, so exactly one reader
|
|
16
|
-
* wins a message even when a session polls twice concurrently. Reading first
|
|
17
|
-
* and deleting after delivers the same message twice.
|
|
18
|
-
* 3. Deliver, then delete. Deleting first loses the message permanently if the
|
|
19
|
-
* delivery throws; a duplicate is recoverable, a loss is not.
|
|
20
|
-
* 4. A claim that outlives its reader is swept. Otherwise a crash mid-delivery
|
|
21
|
-
* strands the message in a claimed state nobody will ever look at again.
|
|
22
|
-
*
|
|
23
|
-
* AVOID:
|
|
24
|
-
* - Treating an atomic write as a lock. It prevents a torn read, nothing else.
|
|
25
|
-
* - Deleting a file that failed to parse. It may belong to a newer build, and
|
|
26
|
-
* destroying it turns a version skew into data loss.
|
|
27
|
-
*/
|
|
28
|
-
declare const CHANNEL_MESSAGE_VERSION = 1;
|
|
29
|
-
/** Which side of the pair a message is for. */
|
|
30
|
-
type ChannelParty = 'parent' | 'child';
|
|
31
|
-
interface ChannelMessage {
|
|
32
|
-
version: typeof CHANNEL_MESSAGE_VERSION;
|
|
33
|
-
/** Who sent it, so a reader never has to infer it from the directory. */
|
|
34
|
-
from: ChannelParty;
|
|
35
|
-
text: string;
|
|
36
|
-
sentAt: string;
|
|
37
|
-
}
|
|
38
|
-
//#endregion
|
|
39
|
-
export { CHANNEL_MESSAGE_VERSION, ChannelMessage, ChannelParty };
|
|
40
|
-
//# sourceMappingURL=worktreeChannel.d.mts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"worktreeChannel.d.mts","names":[],"sources":["../../../src/adapters/channel/worktreeChannel.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;cA+Ba;;KAcD;UAEK;EACf,gBAAgB;;EAEhB,MAAM;EACN;EACA"}
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import e from"node:fs";import{randomBytes as t}from"node:crypto";import n from"node:path";const r=`.json`,i=`.claim-`;let a=-1,o=0;function s(e,t){return n.join(e,t)}function c(e){let t;try{t=JSON.parse(e)}catch{return}if(typeof t!=`object`||!t)return;let n=t;if(n.version===1&&(n.from===`parent`||n.from===`child`)&&typeof n.text==`string`&&n.text!==``&&typeof n.sentAt==`string`)return{version:1,from:n.from,text:n.text,sentAt:n.sentAt}}function l(){let e=Date.now();return e===a?o+=1:(a=e,o=0),`${String(e).padStart(14,`0`)}-${String(o).padStart(6,`0`)}-${t(6).toString(`hex`)}`}function u(t){return{send(i,a){if(Buffer.byteLength(a,`utf8`)>65536)throw Error(`A message may not exceed 65536 bytes.`);let o=s(t,i);e.mkdirSync(o,{recursive:!0,mode:448});let c={version:1,from:i===`parent`?`child`:`parent`,text:a,sentAt:new Date().toISOString()},u=l(),d=n.join(o,`.tmp-${u}`);e.writeFileSync(d,JSON.stringify(c),{mode:384}),e.renameSync(d,n.join(o,`${u}${r}`))},receive(a){let o=s(t,a),l;try{l=e.readdirSync(o)}catch{return[]}let u=[];for(let t of l.filter(e=>e.endsWith(r)).sort()){let r=n.join(o,`${i}${String(process.pid)}-${t}`);try{e.renameSync(n.join(o,t),r)}catch{continue}let a;try{a=c(e.readFileSync(r,`utf8`))}catch{a=void 0}a!==void 0&&(u.push(a),e.rmSync(r,{force:!0}))}return u},sweep(r=Date.now()){let a=0;for(let o of[`parent`,`child`]){let c=s(t,o),l;try{l=e.readdirSync(c)}catch{continue}for(let t of l.filter(e=>e.startsWith(i))){let i=n.join(c,t);try{if(r-e.statSync(i).mtimeMs<6e4)continue;let o=t.slice(t.indexOf(`-`,7)+1);e.renameSync(i,n.join(c,o)),a+=1}catch{}}}return a}}}export{u as createWorktreeChannel};
|
|
2
|
-
//# sourceMappingURL=worktreeChannel.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"worktreeChannel.mjs","names":[],"sources":["../../../src/adapters/channel/worktreeChannel.ts"],"sourcesContent":["/**\n * Messages between a parent session and one worktree session.\n *\n * A two-party mirror of doompi-team's channel, kept private to this package\n * rather than imported: a layer must not depend on another layer, and two\n * parties need none of the membership, heartbeat or fanout machinery that makes\n * that module large.\n *\n * THE INVARIANTS WORTH COPYING, AND WHAT BREAKS WITHOUT THEM:\n *\n * 1. Write to a temp name and rename into place. A reader polling a directory\n * will otherwise read a file that is still being written and parse half a\n * message.\n * 2. Claim by rename before reading. Rename is atomic, so exactly one reader\n * wins a message even when a session polls twice concurrently. Reading first\n * and deleting after delivers the same message twice.\n * 3. Deliver, then delete. Deleting first loses the message permanently if the\n * delivery throws; a duplicate is recoverable, a loss is not.\n * 4. A claim that outlives its reader is swept. Otherwise a crash mid-delivery\n * strands the message in a claimed state nobody will ever look at again.\n *\n * AVOID:\n * - Treating an atomic write as a lock. It prevents a torn read, nothing else.\n * - Deleting a file that failed to parse. It may belong to a newer build, and\n * destroying it turns a version skew into data loss.\n */\n\nimport fs from 'node:fs';\nimport path from 'node:path';\nimport { randomBytes } from 'node:crypto';\n\nexport const CHANNEL_MESSAGE_VERSION = 1;\n\nconst PRIVATE_DIRECTORY_MODE = 0o700;\nconst PRIVATE_FILE_MODE = 0o600;\nconst MESSAGE_SUFFIX = '.json';\nconst CLAIM_PREFIX = '.claim-';\nconst MAX_MESSAGE_BYTES = 64 * 1024;\n/** A claim older than this belonged to a reader that is not coming back. */\nconst CLAIM_STALE_MS = 60_000;\nconst MESSAGE_SEQUENCE_WIDTH = 6;\nlet lastMessageTimestamp = -1;\nlet messageSequence = 0;\n\n/** Which side of the pair a message is for. */\nexport type ChannelParty = 'parent' | 'child';\n\nexport interface ChannelMessage {\n version: typeof CHANNEL_MESSAGE_VERSION;\n /** Who sent it, so a reader never has to infer it from the directory. */\n from: ChannelParty;\n text: string;\n sentAt: string;\n}\n\nexport interface WorktreeChannel {\n send(to: ChannelParty, text: string): void;\n /** Claims and returns everything waiting for a party, oldest first. */\n receive(as: ChannelParty): ChannelMessage[];\n /** Releases claims abandoned by a reader that died mid-delivery. */\n sweep(now?: number): number;\n}\n\nfunction inboxDirectory(root: string, party: ChannelParty): string {\n return path.join(root, party);\n}\n\nfunction parse(raw: string): ChannelMessage | undefined {\n let value: unknown;\n try {\n value = JSON.parse(raw);\n } catch {\n return undefined;\n }\n if (typeof value !== 'object' || value === null) return undefined;\n const record = value as Partial<ChannelMessage>;\n if (record.version !== CHANNEL_MESSAGE_VERSION) return undefined;\n if (record.from !== 'parent' && record.from !== 'child') return undefined;\n if (typeof record.text !== 'string' || record.text === '') return undefined;\n if (typeof record.sentAt !== 'string') return undefined;\n return { version: CHANNEL_MESSAGE_VERSION, from: record.from, text: record.text, sentAt: record.sentAt };\n}\n\nfunction nextMessageName(): string {\n const timestamp = Date.now();\n if (timestamp === lastMessageTimestamp) {\n messageSequence += 1;\n } else {\n lastMessageTimestamp = timestamp;\n messageSequence = 0;\n }\n return `${String(timestamp).padStart(14, '0')}-${String(messageSequence).padStart(MESSAGE_SEQUENCE_WIDTH, '0')}-${randomBytes(6).toString('hex')}`;\n}\n\n/** The channel rooted at a directory, created on demand. */\nexport function createWorktreeChannel(root: string): WorktreeChannel {\n return {\n send(to, text) {\n if (Buffer.byteLength(text, 'utf8') > MAX_MESSAGE_BYTES) {\n throw new Error(`A message may not exceed ${String(MAX_MESSAGE_BYTES)} bytes.`);\n }\n const directory = inboxDirectory(root, to);\n fs.mkdirSync(directory, { recursive: true, mode: PRIVATE_DIRECTORY_MODE });\n const message: ChannelMessage = {\n version: CHANNEL_MESSAGE_VERSION,\n from: to === 'parent' ? 'child' : 'parent',\n text,\n sentAt: new Date().toISOString(),\n };\n // A process-local sequence preserves send order when several messages share\n // a millisecond. The random suffix still prevents cross-process collisions.\n const name = nextMessageName();\n const temporary = path.join(directory, `.tmp-${name}`);\n fs.writeFileSync(temporary, JSON.stringify(message), { mode: PRIVATE_FILE_MODE });\n fs.renameSync(temporary, path.join(directory, `${name}${MESSAGE_SUFFIX}`));\n },\n\n receive(as) {\n const directory = inboxDirectory(root, as);\n let names: string[];\n try {\n names = fs.readdirSync(directory);\n } catch {\n return [];\n }\n const delivered: ChannelMessage[] = [];\n for (const name of names.filter((entry) => entry.endsWith(MESSAGE_SUFFIX)).sort()) {\n const claim = path.join(directory, `${CLAIM_PREFIX}${String(process.pid)}-${name}`);\n try {\n // Whoever wins this rename owns the message. A loser gets ENOENT and\n // simply moves on, which is why this is not wrapped in an existence\n // check: the check and the rename would not be atomic together.\n fs.renameSync(path.join(directory, name), claim);\n } catch {\n continue;\n }\n let message: ChannelMessage | undefined;\n try {\n message = parse(fs.readFileSync(claim, 'utf8'));\n } catch {\n message = undefined;\n }\n if (message === undefined) {\n // Left claimed rather than deleted. An unreadable message may come\n // from a newer build, and the sweep will surface it again rather than\n // this reader destroying something it did not understand.\n continue;\n }\n delivered.push(message);\n fs.rmSync(claim, { force: true });\n }\n return delivered;\n },\n\n sweep(now = Date.now()) {\n let released = 0;\n for (const party of ['parent', 'child'] as const) {\n const directory = inboxDirectory(root, party);\n let names: string[];\n try {\n names = fs.readdirSync(directory);\n } catch {\n continue;\n }\n for (const name of names.filter((entry) => entry.startsWith(CLAIM_PREFIX))) {\n const claimed = path.join(directory, name);\n try {\n if (now - fs.statSync(claimed).mtimeMs < CLAIM_STALE_MS) continue;\n // Returned to the inbox rather than deleted, because the message\n // was claimed but never delivered.\n const original = name.slice(name.indexOf('-', CLAIM_PREFIX.length) + 1);\n fs.renameSync(claimed, path.join(directory, original));\n released += 1;\n } catch {\n // Another sweeper got there first.\n }\n }\n }\n return released;\n },\n };\n}\n"],"mappings":"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"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"atomicJson.cjs","names":["path","fs"],"sources":["../../../src/adapters/filesystem/atomicJson.ts"],"sourcesContent":["import fs from 'node:fs';\nimport path from 'node:path';\n\nconst OWNER_ONLY_FILE = 0o600;\n\n/**\n * Writes JSON so a reader never sees a half-written file.\n *\n * The registry is read by the same process that writes it, and by a later\n * process after a crash. A plain write can be interrupted between the truncate\n * and the last byte, which leaves a file that parses as nothing and loses every\n * record in it. Writing beside the target and renaming makes the swap atomic on\n * the same filesystem, so a reader sees either the old file or the new one.\n */\nexport function writeJsonAtomic(file: string, value: unknown): void {\n const directory = path.dirname(file);\n fs.mkdirSync(directory, { recursive: true });\n const temporary = path.join(directory, `.${path.basename(file)}.${String(process.pid)}.tmp`);\n fs.writeFileSync(temporary, `${JSON.stringify(value, null, 2)}\\n`, { mode: OWNER_ONLY_FILE });\n fs.renameSync(temporary, file);\n}\n\n/**\n * Reads JSON, treating every failure as absent.\n *\n * A missing file and an unparseable one mean the same thing to every caller\n * here: there is nothing to act on. Distinguishing them would only offer a\n * choice no caller wants to make.\n */\nexport function readJson<T>(file: string): T | undefined {\n try {\n return JSON.parse(fs.readFileSync(file, 'utf8')) as T;\n } catch {\n return undefined;\n }\n}\n"],"mappings":"8IAcA,SAAgB,EAAgB,EAAc,EAAsB,CAClE,IAAM,EAAYA,EAAAA,QAAK,QAAQ,CAAI,EACnC,EAAA,QAAG,UAAU,EAAW,CAAE,UAAW,EAAK,CAAC,EAC3C,IAAM,EAAYA,EAAAA,QAAK,KAAK,EAAW,IAAIA,EAAAA,QAAK,SAAS,CAAI,EAAE,GAAG,OAAO,QAAQ,GAAG,EAAE,KAAK,EAC3F,EAAA,QAAG,cAAc,EAAW,GAAG,KAAK,UAAU,EAAO,KAAM,CAAC,EAAE,IAAK,CAAE,KAAM,GAAgB,CAAC,EAC5F,EAAA,QAAG,WAAW,EAAW,CAAI,CAC/B,CASA,SAAgB,EAAY,EAA6B,CACvD,GAAI,CACF,OAAO,KAAK,MAAMC,EAAAA,QAAG,aAAa,EAAM,MAAM,CAAC,CACjD,MAAQ,CACN,MACF,CACF"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"atomicJson.mjs","names":[],"sources":["../../../src/adapters/filesystem/atomicJson.ts"],"sourcesContent":["import fs from 'node:fs';\nimport path from 'node:path';\n\nconst OWNER_ONLY_FILE = 0o600;\n\n/**\n * Writes JSON so a reader never sees a half-written file.\n *\n * The registry is read by the same process that writes it, and by a later\n * process after a crash. A plain write can be interrupted between the truncate\n * and the last byte, which leaves a file that parses as nothing and loses every\n * record in it. Writing beside the target and renaming makes the swap atomic on\n * the same filesystem, so a reader sees either the old file or the new one.\n */\nexport function writeJsonAtomic(file: string, value: unknown): void {\n const directory = path.dirname(file);\n fs.mkdirSync(directory, { recursive: true });\n const temporary = path.join(directory, `.${path.basename(file)}.${String(process.pid)}.tmp`);\n fs.writeFileSync(temporary, `${JSON.stringify(value, null, 2)}\\n`, { mode: OWNER_ONLY_FILE });\n fs.renameSync(temporary, file);\n}\n\n/**\n * Reads JSON, treating every failure as absent.\n *\n * A missing file and an unparseable one mean the same thing to every caller\n * here: there is nothing to act on. Distinguishing them would only offer a\n * choice no caller wants to make.\n */\nexport function readJson<T>(file: string): T | undefined {\n try {\n return JSON.parse(fs.readFileSync(file, 'utf8')) as T;\n } catch {\n return undefined;\n }\n}\n"],"mappings":"gDAcA,SAAgB,EAAgB,EAAc,EAAsB,CAClE,IAAM,EAAY,EAAK,QAAQ,CAAI,EACnC,EAAG,UAAU,EAAW,CAAE,UAAW,EAAK,CAAC,EAC3C,IAAM,EAAY,EAAK,KAAK,EAAW,IAAI,EAAK,SAAS,CAAI,EAAE,GAAG,OAAO,QAAQ,GAAG,EAAE,KAAK,EAC3F,EAAG,cAAc,EAAW,GAAG,KAAK,UAAU,EAAO,KAAM,CAAC,EAAE,IAAK,CAAE,KAAM,GAAgB,CAAC,EAC5F,EAAG,WAAW,EAAW,CAAI,CAC/B,CASA,SAAgB,EAAY,EAA6B,CACvD,GAAI,CACF,OAAO,KAAK,MAAM,EAAG,aAAa,EAAM,MAAM,CAAC,CACjD,MAAQ,CACN,MACF,CACF"}
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
const e=require("../../_virtual/_rolldown/runtime.cjs"),t=require("../worktree/repositoryIdentity.cjs");let n=require("node:path");n=e.__toESM(n,1);let r=require("@agimon-ai/doompi-web-contracts"),i=require("node:os");i=e.__toESM(i,1);function a(e=i.default.homedir()){return n.default.join(e,`.pi`,`.doom`,`git`)}function o(e=i.default.homedir()){return n.default.join(a(e),`worktrees`)}function s(e,t=i.default.homedir()){return`${a(t)}/channels/${e}`}function c(e,r=i.default.homedir()){let o=`${t.repositoryLabel(e)}--${t.repositoryId(e)}`;return n.default.join(a(r),`registry`,o,`worktrees.json`)}function l(e=process.argv,t=process.env,n=i.default.homedir()){let a=e.indexOf(`--registry-dir`),o=a>=0?e[a+1]:void 0;return(0,r.resolveRegistryDir)({...o===void 0?{}:{flagValue:o},...t[r.REGISTRY_DIR_ENV]===void 0?{}:{envValue:t[r.REGISTRY_DIR_ENV]},homeDir:n})}exports.channelRoot=s,exports.doomGitRoot=a,exports.hubRegistryDir=l,exports.registryFile=c,exports.worktreesRoot=o;
|
|
2
|
-
//# sourceMappingURL=paths.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"paths.cjs","names":["os","path","repositoryLabel","repositoryId","resolveRegistryDir","REGISTRY_DIR_ENV"],"sources":["../../../src/adapters/filesystem/paths.ts"],"sourcesContent":["import os from 'node:os';\nimport path from 'node:path';\nimport { REGISTRY_DIR_ENV, resolveRegistryDir } from '@agimon-ai/doompi-web-contracts';\nimport { repositoryId, repositoryLabel } from '../worktree/repositoryIdentity.ts';\n\nconst REGISTRY_DIR_FLAG = '--registry-dir';\n\n/**\n * Where this package keeps its own state.\n *\n * Outside the repository on purpose. A worktree directory inside the checkout\n * would be found by every glob the repository's own tooling runs, and would\n * resolve workspace imports against the parent checkout rather than the\n * worktree, so a session there would build the wrong source while appearing to\n * work.\n */\nexport function doomGitRoot(homeDir: string = os.homedir()): string {\n return path.join(homeDir, '.pi', '.doom', 'git');\n}\n\n/** The directory every worktree for every repository is created under. */\nexport function worktreesRoot(homeDir: string = os.homedir()): string {\n return path.join(doomGitRoot(homeDir), 'worktrees');\n}\n\n/** One registry file per repository, keyed by the shared git directory. */\n/** Where a worktree's parent/child channel lives, outside the worktree itself. */\nexport function channelRoot(worktreeId: string, homeDir: string = os.homedir()): string {\n // Outside the worktree on purpose: closing a worktree deletes its directory,\n // and a channel inside it would take undelivered messages down with it.\n return `${doomGitRoot(homeDir)}/channels/${worktreeId}`;\n}\n\nexport function registryFile(repositoryRoot: string, homeDir: string = os.homedir()): string {\n const key = `${repositoryLabel(repositoryRoot)}--${repositoryId(repositoryRoot)}`;\n return path.join(doomGitRoot(homeDir), 'registry', key, 'worktrees.json');\n}\n\n/**\n * The session registry directory this process's hub is watching.\n *\n * A spawned session only appears in the rail if it registers in the same\n * directory the hub watches, and the hub passes that directory to its children\n * as `--registry-dir` while also inheriting the env var. Recovering it from\n * this process's own argv and env, in the same precedence the hub and the\n * session server use, is what makes a worktree session visible rather than\n * silently invisible.\n */\nexport function hubRegistryDir(\n argv: readonly string[] = process.argv,\n env: NodeJS.ProcessEnv = process.env,\n homeDir: string = os.homedir(),\n): string {\n const index = argv.indexOf(REGISTRY_DIR_FLAG);\n const flagValue = index >= 0 ? argv[index + 1] : undefined;\n return resolveRegistryDir({\n ...(flagValue === undefined ? {} : { flagValue }),\n ...(env[REGISTRY_DIR_ENV] === undefined ? {} : { envValue: env[REGISTRY_DIR_ENV] }),\n homeDir,\n });\n}\n"],"mappings":"2OAgBA,SAAgB,EAAY,EAAkBA,EAAAA,QAAG,QAAQ,EAAW,CAClE,OAAOC,EAAAA,QAAK,KAAK,EAAS,MAAO,QAAS,KAAK,CACjD,CAGA,SAAgB,EAAc,EAAkBD,EAAAA,QAAG,QAAQ,EAAW,CACpE,OAAOC,EAAAA,QAAK,KAAK,EAAY,CAAO,EAAG,WAAW,CACpD,CAIA,SAAgB,EAAY,EAAoB,EAAkBD,EAAAA,QAAG,QAAQ,EAAW,CAGtF,MAAO,GAAG,EAAY,CAAO,EAAE,YAAY,GAC7C,CAEA,SAAgB,EAAa,EAAwB,EAAkBA,EAAAA,QAAG,QAAQ,EAAW,CAC3F,IAAM,EAAM,GAAGE,EAAAA,gBAAgB,CAAc,EAAE,IAAIC,EAAAA,aAAa,CAAc,IAC9E,OAAOF,EAAAA,QAAK,KAAK,EAAY,CAAO,EAAG,WAAY,EAAK,gBAAgB,CAC1E,CAYA,SAAgB,EACd,EAA0B,QAAQ,KAClC,EAAyB,QAAQ,IACjC,EAAkBD,EAAAA,QAAG,QAAQ,EACrB,CACR,IAAM,EAAQ,EAAK,QAAQ,gBAAiB,EACtC,EAAY,GAAS,EAAI,EAAK,EAAQ,GAAK,IAAA,GACjD,OAAA,EAAOI,EAAAA,mBAAAA,CAAmB,CACxB,GAAI,IAAc,IAAA,GAAY,CAAC,EAAI,CAAE,WAAU,EAC/C,GAAI,EAAIC,EAAAA,oBAAsB,IAAA,GAAY,CAAC,EAAI,CAAE,SAAU,EAAIA,EAAAA,iBAAkB,EACjF,SACF,CAAC,CACH"}
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import{repositoryId as e,repositoryLabel as t}from"../worktree/repositoryIdentity.mjs";import n from"node:path";import{REGISTRY_DIR_ENV as r,resolveRegistryDir as i}from"@agimon-ai/doompi-web-contracts";import a from"node:os";function o(e=a.homedir()){return n.join(e,`.pi`,`.doom`,`git`)}function s(e=a.homedir()){return n.join(o(e),`worktrees`)}function c(e,t=a.homedir()){return`${o(t)}/channels/${e}`}function l(r,i=a.homedir()){let s=`${t(r)}--${e(r)}`;return n.join(o(i),`registry`,s,`worktrees.json`)}function u(e=process.argv,t=process.env,n=a.homedir()){let o=e.indexOf(`--registry-dir`),s=o>=0?e[o+1]:void 0;return i({...s===void 0?{}:{flagValue:s},...t[r]===void 0?{}:{envValue:t[r]},homeDir:n})}export{c as channelRoot,o as doomGitRoot,u as hubRegistryDir,l as registryFile,s as worktreesRoot};
|
|
2
|
-
//# sourceMappingURL=paths.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"paths.mjs","names":[],"sources":["../../../src/adapters/filesystem/paths.ts"],"sourcesContent":["import os from 'node:os';\nimport path from 'node:path';\nimport { REGISTRY_DIR_ENV, resolveRegistryDir } from '@agimon-ai/doompi-web-contracts';\nimport { repositoryId, repositoryLabel } from '../worktree/repositoryIdentity.ts';\n\nconst REGISTRY_DIR_FLAG = '--registry-dir';\n\n/**\n * Where this package keeps its own state.\n *\n * Outside the repository on purpose. A worktree directory inside the checkout\n * would be found by every glob the repository's own tooling runs, and would\n * resolve workspace imports against the parent checkout rather than the\n * worktree, so a session there would build the wrong source while appearing to\n * work.\n */\nexport function doomGitRoot(homeDir: string = os.homedir()): string {\n return path.join(homeDir, '.pi', '.doom', 'git');\n}\n\n/** The directory every worktree for every repository is created under. */\nexport function worktreesRoot(homeDir: string = os.homedir()): string {\n return path.join(doomGitRoot(homeDir), 'worktrees');\n}\n\n/** One registry file per repository, keyed by the shared git directory. */\n/** Where a worktree's parent/child channel lives, outside the worktree itself. */\nexport function channelRoot(worktreeId: string, homeDir: string = os.homedir()): string {\n // Outside the worktree on purpose: closing a worktree deletes its directory,\n // and a channel inside it would take undelivered messages down with it.\n return `${doomGitRoot(homeDir)}/channels/${worktreeId}`;\n}\n\nexport function registryFile(repositoryRoot: string, homeDir: string = os.homedir()): string {\n const key = `${repositoryLabel(repositoryRoot)}--${repositoryId(repositoryRoot)}`;\n return path.join(doomGitRoot(homeDir), 'registry', key, 'worktrees.json');\n}\n\n/**\n * The session registry directory this process's hub is watching.\n *\n * A spawned session only appears in the rail if it registers in the same\n * directory the hub watches, and the hub passes that directory to its children\n * as `--registry-dir` while also inheriting the env var. Recovering it from\n * this process's own argv and env, in the same precedence the hub and the\n * session server use, is what makes a worktree session visible rather than\n * silently invisible.\n */\nexport function hubRegistryDir(\n argv: readonly string[] = process.argv,\n env: NodeJS.ProcessEnv = process.env,\n homeDir: string = os.homedir(),\n): string {\n const index = argv.indexOf(REGISTRY_DIR_FLAG);\n const flagValue = index >= 0 ? argv[index + 1] : undefined;\n return resolveRegistryDir({\n ...(flagValue === undefined ? {} : { flagValue }),\n ...(env[REGISTRY_DIR_ENV] === undefined ? {} : { envValue: env[REGISTRY_DIR_ENV] }),\n homeDir,\n });\n}\n"],"mappings":"kOAgBA,SAAgB,EAAY,EAAkB,EAAG,QAAQ,EAAW,CAClE,OAAO,EAAK,KAAK,EAAS,MAAO,QAAS,KAAK,CACjD,CAGA,SAAgB,EAAc,EAAkB,EAAG,QAAQ,EAAW,CACpE,OAAO,EAAK,KAAK,EAAY,CAAO,EAAG,WAAW,CACpD,CAIA,SAAgB,EAAY,EAAoB,EAAkB,EAAG,QAAQ,EAAW,CAGtF,MAAO,GAAG,EAAY,CAAO,EAAE,YAAY,GAC7C,CAEA,SAAgB,EAAa,EAAwB,EAAkB,EAAG,QAAQ,EAAW,CAC3F,IAAM,EAAM,GAAG,EAAgB,CAAc,EAAE,IAAI,EAAa,CAAc,IAC9E,OAAO,EAAK,KAAK,EAAY,CAAO,EAAG,WAAY,EAAK,gBAAgB,CAC1E,CAYA,SAAgB,EACd,EAA0B,QAAQ,KAClC,EAAyB,QAAQ,IACjC,EAAkB,EAAG,QAAQ,EACrB,CACR,IAAM,EAAQ,EAAK,QAAQ,gBAAiB,EACtC,EAAY,GAAS,EAAI,EAAK,EAAQ,GAAK,IAAA,GACjD,OAAO,EAAmB,CACxB,GAAI,IAAc,IAAA,GAAY,CAAC,EAAI,CAAE,WAAU,EAC/C,GAAI,EAAI,KAAsB,IAAA,GAAY,CAAC,EAAI,CAAE,SAAU,EAAI,EAAkB,EACjF,SACF,CAAC,CACH"}
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
const e=require("../../_virtual/_rolldown/runtime.cjs");let t=require("node:fs");t=e.__toESM(t,1);let n=require("@agimon-ai/doompi-web-contracts");const r=`/api/sessions`;var i=class extends Error{constructor(e){super(e),this.name=`HubUnavailableError`}};function a(e,n){return t.default.existsSync(`${e}/sessions/${n}.json`)}async function o(e,t){let n=s(e);if(n!==void 0&&await c(n.url))try{let e=await fetch(`${n.url}${r}/${encodeURIComponent(t)}`,{method:`DELETE`,signal:AbortSignal.timeout(3e4)});if(!e.ok&&e.status!==404)throw new i((await e.json().catch(()=>({}))).error??`The cockpit could not stop the session (${String(e.status)}).`)}catch(e){throw e instanceof i?e:new i(`Could not reach the cockpit: ${e.message}`)}}function s(e){let r;try{r=t.default.readFileSync((0,n.hubAdvertisementPath)(e),`utf8`)}catch{return}return(0,n.parseHubAdvertisement)(r)}async function c(e){try{let t=await fetch(`${e}/api/health`,{signal:AbortSignal.timeout(1e3)});if(!t.ok)return!1;let n=await t.json();return n.ok===!0&&n.role===`hub`}catch{return!1}}async function l(e){let t=s(e.registryDir);if(t===void 0)throw new i(`No cockpit is running. Worktree sessions are created by the cockpit, so start it and try again.`);if(!await c(t.url))throw new i(`The cockpit that advertised ${t.url} is no longer answering. Start it and try again.`);let n;try{n=await fetch(`${t.url}${r}`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({cwd:e.cwd,name:e.name,parentSessionId:e.parentSessionId,provenance:`worktree`}),signal:AbortSignal.timeout(6e5)})}catch(e){throw new i(`Could not reach the cockpit: ${e.message}`)}let a=await n.json().catch(()=>({}));if(!n.ok)throw new i(a.error??`The cockpit refused the session (${String(n.status)}).`);if(typeof a.sessionId!=`string`||a.sessionId===``)throw new i(`The cockpit accepted the session but did not name it.`);return a.sessionId}exports.HubUnavailableError=i,exports.createWorktreeSession=l,exports.readHubAdvertisement=s,exports.sessionIsLive=a,exports.stopWorktreeSession=o;
|
|
2
|
-
//# sourceMappingURL=hubClient.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"hubClient.cjs","names":["fs","hubAdvertisementPath","parseHubAdvertisement"],"sources":["../../../src/adapters/hub/hubClient.ts"],"sourcesContent":["import fs from 'node:fs';\nimport { hubAdvertisementPath, parseHubAdvertisement } from '@agimon-ai/doompi-web-contracts';\nimport type { HubAdvertisement } from '@agimon-ai/doompi-web-contracts';\n\nconst HEALTH_ROUTE = '/api/health';\nconst SESSIONS_ROUTE = '/api/sessions';\nconst PROBE_TIMEOUT_MS = 1000;\n/**\n * Creating a session is not a quick call.\n *\n * The hub validates, then runs `ensureSessionSynced`, then spawns. A cockpit\n * that has never synced the composition builds it first, which is minutes on a\n * cold cache, and a fresh worktree also installs its dependencies. A 30s\n * timeout was measured aborting a create that the hub then completed anyway,\n * leaving the caller told it failed while a session started behind it.\n */\nconst CREATE_TIMEOUT_MS = 600_000;\n/** Stopping is just a signal and a record removal, so it stays short. */\nconst STOP_TIMEOUT_MS = 30_000;\nconst HUB_ROLE = 'hub';\n\n/** Raised when the cockpit that owns session lifecycle is not reachable. */\nexport class HubUnavailableError extends Error {\n constructor(message: string) {\n super(message);\n this.name = 'HubUnavailableError';\n }\n}\n\n/**\n * Whether the hub still has a record for a session.\n *\n * The session server writes its record into the shared registry directory and\n * removes it on exit, so the file's presence is the liveness signal. A pid is\n * not available here: the hub spawns the process, so this package never learns\n * one, and a pid it invented would be a field that always lies.\n */\nexport function sessionIsLive(registryDir: string, sessionId: string): boolean {\n return fs.existsSync(`${registryDir}/sessions/${sessionId}.json`);\n}\n\n/**\n * Asks the hub to stop a session it started.\n *\n * Stopping is the hub's job for the same reason starting is. Signalling the\n * process directly would leave the hub's own record of it behind and race the\n * cleanup it does on the way down.\n *\n * A session the hub does not know about is already stopped, which is the\n * outcome the caller wanted, so a 404 is success.\n */\nexport async function stopWorktreeSession(registryDir: string, sessionId: string): Promise<void> {\n const advertisement = readHubAdvertisement(registryDir);\n if (advertisement === undefined) return;\n if (!(await hubAnswers(advertisement.url))) return;\n try {\n const response = await fetch(`${advertisement.url}${SESSIONS_ROUTE}/${encodeURIComponent(sessionId)}`, {\n method: 'DELETE',\n signal: AbortSignal.timeout(STOP_TIMEOUT_MS),\n });\n if (!response.ok && response.status !== 404) {\n const body = (await response.json().catch(() => ({}))) as { error?: string };\n throw new HubUnavailableError(\n body.error ?? `The cockpit could not stop the session (${String(response.status)}).`,\n );\n }\n } catch (error) {\n if (error instanceof HubUnavailableError) throw error;\n throw new HubUnavailableError(`Could not reach the cockpit: ${(error as Error).message}`);\n }\n}\n\nexport interface CreateWorktreeSessionInput {\n /** The worktree directory; must already exist. */\n cwd: string;\n /** Rail display name for the new session. */\n name: string;\n /** The session asking for this one, so the rail can nest them. */\n parentSessionId: string;\n registryDir: string;\n}\n\n/** Reads the hub's published address, if it published one. */\nexport function readHubAdvertisement(registryDir: string): HubAdvertisement | undefined {\n let raw: string;\n try {\n raw = fs.readFileSync(hubAdvertisementPath(registryDir), 'utf8');\n } catch {\n return undefined;\n }\n return parseHubAdvertisement(raw);\n}\n\n/**\n * Confirms a live cockpit hub answers at the address, rather than a leftover.\n *\n * The advertisement file outlives a crash and a port gets reused, so finding it\n * proves nothing. Only a hub that answers /api/health and calls itself a hub is\n * worth sending a session-create to; anything else is something else's port.\n */\nasync function hubAnswers(url: string): Promise<boolean> {\n try {\n const response = await fetch(`${url}${HEALTH_ROUTE}`, { signal: AbortSignal.timeout(PROBE_TIMEOUT_MS) });\n if (!response.ok) return false;\n const body = (await response.json()) as { ok?: boolean; role?: string };\n return body.ok === true && body.role === HUB_ROLE;\n } catch {\n return false;\n }\n}\n\n/**\n * Asks the cockpit hub to start a session in a worktree.\n *\n * The hub owns session lifecycle: it validates the directory, syncs the\n * composition, spawns the server and records the lineage. This package only\n * asks. Creating the process here instead would put a second spawn path beside\n * the hub's, with its own idea of what a session needs, and a session server is\n * bound to one session anyway so it has no business starting another.\n *\n * The panel and the agent both come through here, so there is one route to keep\n * correct rather than two that drift.\n */\nexport async function createWorktreeSession(input: CreateWorktreeSessionInput): Promise<string> {\n const advertisement = readHubAdvertisement(input.registryDir);\n if (advertisement === undefined) {\n throw new HubUnavailableError(\n 'No cockpit is running. Worktree sessions are created by the cockpit, so start it and try again.',\n );\n }\n if (!(await hubAnswers(advertisement.url))) {\n throw new HubUnavailableError(\n `The cockpit that advertised ${advertisement.url} is no longer answering. Start it and try again.`,\n );\n }\n\n let response: Response;\n try {\n response = await fetch(`${advertisement.url}${SESSIONS_ROUTE}`, {\n method: 'POST',\n headers: { 'content-type': 'application/json' },\n body: JSON.stringify({\n cwd: input.cwd,\n name: input.name,\n parentSessionId: input.parentSessionId,\n provenance: 'worktree',\n }),\n signal: AbortSignal.timeout(CREATE_TIMEOUT_MS),\n });\n } catch (error) {\n throw new HubUnavailableError(`Could not reach the cockpit: ${(error as Error).message}`);\n }\n\n const body = (await response.json().catch(() => ({}))) as { sessionId?: string; error?: string };\n if (!response.ok) {\n throw new HubUnavailableError(body.error ?? `The cockpit refused the session (${String(response.status)}).`);\n }\n if (typeof body.sessionId !== 'string' || body.sessionId === '') {\n throw new HubUnavailableError('The cockpit accepted the session but did not name it.');\n }\n return body.sessionId;\n}\n"],"mappings":"mJAIA,MACM,EAAiB,gBAiBvB,IAAa,EAAb,cAAyC,KAAM,CAC7C,YAAY,EAAiB,CAC3B,MAAM,CAAO,EACb,KAAK,KAAO,qBACd,CACF,EAUA,SAAgB,EAAc,EAAqB,EAA4B,CAC7E,OAAOA,EAAAA,QAAG,WAAW,GAAG,EAAY,YAAY,EAAU,MAAM,CAClE,CAYA,eAAsB,EAAoB,EAAqB,EAAkC,CAC/F,IAAM,EAAgB,EAAqB,CAAW,EAClD,OAAkB,IAAA,IAChB,MAAM,EAAW,EAAc,GAAG,EACxC,GAAI,CACF,IAAM,EAAW,MAAM,MAAM,GAAG,EAAc,MAAM,EAAe,GAAG,mBAAmB,CAAS,IAAK,CACrG,OAAQ,SACR,OAAQ,YAAY,QAAQ,GAAe,CAC7C,CAAC,EACD,GAAI,CAAC,EAAS,IAAM,EAAS,SAAW,IAEtC,MAAM,IAAI,GACR,MAFkB,EAAS,KAAK,CAAC,CAAC,WAAa,CAAC,EAAE,EAElD,CAAK,OAAS,2CAA2C,OAAO,EAAS,MAAM,EAAE,GACnF,CAEJ,OAAS,EAAO,CAEd,MADI,aAAiB,EAA2B,EAC1C,IAAI,EAAoB,gCAAiC,EAAgB,SAAS,CAC1F,CACF,CAaA,SAAgB,EAAqB,EAAmD,CACtF,IAAI,EACJ,GAAI,CACF,EAAMA,EAAAA,QAAG,cAAA,EAAaC,EAAAA,qBAAAA,CAAqB,CAAW,EAAG,MAAM,CACjE,MAAQ,CACN,MACF,CACA,OAAA,EAAOC,EAAAA,sBAAAA,CAAsB,CAAG,CAClC,CASA,eAAe,EAAW,EAA+B,CACvD,GAAI,CACF,IAAM,EAAW,MAAM,MAAM,GAAG,eAAsB,CAAE,OAAQ,YAAY,QAAQ,GAAgB,CAAE,CAAC,EACvG,GAAI,CAAC,EAAS,GAAI,MAAO,GACzB,IAAM,EAAQ,MAAM,EAAS,KAAK,EAClC,OAAO,EAAK,KAAO,IAAQ,EAAK,OAAS,KAC3C,MAAQ,CACN,MAAO,EACT,CACF,CAcA,eAAsB,EAAsB,EAAoD,CAC9F,IAAM,EAAgB,EAAqB,EAAM,WAAW,EAC5D,GAAI,IAAkB,IAAA,GACpB,MAAM,IAAI,EACR,iGACF,EAEF,GAAI,CAAE,MAAM,EAAW,EAAc,GAAG,EACtC,MAAM,IAAI,EACR,+BAA+B,EAAc,IAAI,iDACnD,EAGF,IAAI,EACJ,GAAI,CACF,EAAW,MAAM,MAAM,GAAG,EAAc,MAAM,IAAkB,CAC9D,OAAQ,OACR,QAAS,CAAE,eAAgB,kBAAmB,EAC9C,KAAM,KAAK,UAAU,CACnB,IAAK,EAAM,IACX,KAAM,EAAM,KACZ,gBAAiB,EAAM,gBACvB,WAAY,UACd,CAAC,EACD,OAAQ,YAAY,QAAQ,GAAiB,CAC/C,CAAC,CACH,OAAS,EAAO,CACd,MAAM,IAAI,EAAoB,gCAAiC,EAAgB,SAAS,CAC1F,CAEA,IAAM,EAAQ,MAAM,EAAS,KAAK,CAAC,CAAC,WAAa,CAAC,EAAE,EACpD,GAAI,CAAC,EAAS,GACZ,MAAM,IAAI,EAAoB,EAAK,OAAS,oCAAoC,OAAO,EAAS,MAAM,EAAE,GAAG,EAE7G,GAAI,OAAO,EAAK,WAAc,UAAY,EAAK,YAAc,GAC3D,MAAM,IAAI,EAAoB,uDAAuD,EAEvF,OAAO,EAAK,SACd"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import "@agimon-ai/doompi-web-contracts";
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import "@agimon-ai/doompi-web-contracts";
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import e from"node:fs";import{hubAdvertisementPath as t,parseHubAdvertisement as n}from"@agimon-ai/doompi-web-contracts";const r=`/api/sessions`;var i=class extends Error{constructor(e){super(e),this.name=`HubUnavailableError`}};function a(t,n){return e.existsSync(`${t}/sessions/${n}.json`)}async function o(e,t){let n=s(e);if(n!==void 0&&await c(n.url))try{let e=await fetch(`${n.url}${r}/${encodeURIComponent(t)}`,{method:`DELETE`,signal:AbortSignal.timeout(3e4)});if(!e.ok&&e.status!==404)throw new i((await e.json().catch(()=>({}))).error??`The cockpit could not stop the session (${String(e.status)}).`)}catch(e){throw e instanceof i?e:new i(`Could not reach the cockpit: ${e.message}`)}}function s(r){let i;try{i=e.readFileSync(t(r),`utf8`)}catch{return}return n(i)}async function c(e){try{let t=await fetch(`${e}/api/health`,{signal:AbortSignal.timeout(1e3)});if(!t.ok)return!1;let n=await t.json();return n.ok===!0&&n.role===`hub`}catch{return!1}}async function l(e){let t=s(e.registryDir);if(t===void 0)throw new i(`No cockpit is running. Worktree sessions are created by the cockpit, so start it and try again.`);if(!await c(t.url))throw new i(`The cockpit that advertised ${t.url} is no longer answering. Start it and try again.`);let n;try{n=await fetch(`${t.url}${r}`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({cwd:e.cwd,name:e.name,parentSessionId:e.parentSessionId,provenance:`worktree`}),signal:AbortSignal.timeout(6e5)})}catch(e){throw new i(`Could not reach the cockpit: ${e.message}`)}let a=await n.json().catch(()=>({}));if(!n.ok)throw new i(a.error??`The cockpit refused the session (${String(n.status)}).`);if(typeof a.sessionId!=`string`||a.sessionId===``)throw new i(`The cockpit accepted the session but did not name it.`);return a.sessionId}export{i as HubUnavailableError,l as createWorktreeSession,s as readHubAdvertisement,a as sessionIsLive,o as stopWorktreeSession};
|
|
2
|
-
//# sourceMappingURL=hubClient.mjs.map
|