@bridgebrew/sessions 0.0.14 → 0.0.21
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/browser/children.tsx +15 -2
- package/browser/conversation.tsx +2 -0
- package/browser/decision-questions.tsx +21 -2
- package/browser/index.tsx +36 -12
- package/browser/tsconfig.json +3 -3
- package/git.ts +82 -22
- package/package.json +2 -2
- package/pull-requests.ts +3 -3
- package/server.ts +24 -10
package/browser/children.tsx
CHANGED
|
@@ -67,6 +67,8 @@ export interface Lineage {
|
|
|
67
67
|
parent?: string | undefined;
|
|
68
68
|
/** Where a link to session `id` goes. */
|
|
69
69
|
to: (id: string) => FollowTarget;
|
|
70
|
+
/** Whether session `id` can be opened (an archived one cannot: the list shows none); without it, every one can. */
|
|
71
|
+
opens?: ((id: string) => boolean) | undefined;
|
|
70
72
|
/** Stops child session `id` (its session Stop); without it, no Stop. */
|
|
71
73
|
stop?: ((id: string) => void) | undefined;
|
|
72
74
|
/** Where a link to the shown session's sub-agent `id` goes (bridge#212 S8, ./subagents.tsx); without it, none. */
|
|
@@ -587,11 +589,22 @@ export function BackgroundWork() {
|
|
|
587
589
|
);
|
|
588
590
|
}
|
|
589
591
|
|
|
590
|
-
/** A child session's parent, beside its title: a link to it. */
|
|
592
|
+
/** A child session's parent, beside its title: a link to it; an archived one, its name only. */
|
|
591
593
|
export function ParentLink({ parent }: { parent: string }) {
|
|
592
594
|
const lineage = React.useContext(LineageContext);
|
|
593
595
|
if (!lineage) return null;
|
|
594
596
|
const title = lineage.sessions.get(parent)?.title;
|
|
597
|
+
if (lineage.opens?.(parent) === false)
|
|
598
|
+
return (
|
|
599
|
+
<span
|
|
600
|
+
data-who="parent"
|
|
601
|
+
className="inline-flex min-w-0 max-w-56 shrink items-center gap-1 text-xs text-muted"
|
|
602
|
+
>
|
|
603
|
+
<Icon name="arrow-up" size={13} className="shrink-0" />
|
|
604
|
+
<span className="shrink-0">Parent (archived)</span>
|
|
605
|
+
{title && <span className="truncate text-secondary">{title}</span>}
|
|
606
|
+
</span>
|
|
607
|
+
);
|
|
595
608
|
return (
|
|
596
609
|
<ScreenLink
|
|
597
610
|
to={lineage.to(parent)}
|
|
@@ -637,7 +650,7 @@ export function TaskFrom({
|
|
|
637
650
|
<p data-who="task-from" className="mb-1 flex min-w-0 items-center gap-1.5 text-xs text-muted">
|
|
638
651
|
<Icon name={kind === 'delegation' ? 'users' : 'mail'} size={12} className="shrink-0" />
|
|
639
652
|
<span className="shrink-0">{kind === 'delegation' ? 'Task from' : 'Message from'}</span>
|
|
640
|
-
{from && lineage ? (
|
|
653
|
+
{from && lineage && lineage.opens?.(from) !== false ? (
|
|
641
654
|
<ScreenLink to={lineage.to(from)} className="min-w-0 truncate text-secondary">
|
|
642
655
|
{title}
|
|
643
656
|
</ScreenLink>
|
package/browser/conversation.tsx
CHANGED
|
@@ -1764,6 +1764,7 @@ const PendingDecision = React.memo(function PendingDecision({
|
|
|
1764
1764
|
busy={busy}
|
|
1765
1765
|
onAnswer={answer}
|
|
1766
1766
|
primary={primary}
|
|
1767
|
+
draft={event.id}
|
|
1767
1768
|
/>
|
|
1768
1769
|
</div>
|
|
1769
1770
|
)}
|
|
@@ -2130,6 +2131,7 @@ export function DecisionDock({
|
|
|
2130
2131
|
busy={busy}
|
|
2131
2132
|
onAnswer={onAnswer}
|
|
2132
2133
|
primary={primary}
|
|
2134
|
+
draft={event.id}
|
|
2133
2135
|
/>
|
|
2134
2136
|
</section>
|
|
2135
2137
|
);
|
|
@@ -6,11 +6,21 @@ import * as React from 'react';
|
|
|
6
6
|
import { Button, Checkbox, Icon, Textarea, cn, isComposing } from '@bridge/ui';
|
|
7
7
|
import { checkAnswer, type Answers, type Question } from '../answers.ts';
|
|
8
8
|
|
|
9
|
+
/** What was chosen and typed in a decision's card, not sent yet. */
|
|
10
|
+
export interface Draft {
|
|
11
|
+
chosen: Record<string, string[]>;
|
|
12
|
+
texts: Record<string, string>;
|
|
13
|
+
}
|
|
14
|
+
/** The shown session's drafts by decision id (#111): a card's answers belong to its decision, not to the card, so they
|
|
15
|
+
* follow it from the dock to its row and never show on another decision. */
|
|
16
|
+
export const DecisionDrafts = React.createContext<Map<string, Draft> | undefined>(undefined);
|
|
17
|
+
|
|
9
18
|
export function DecisionQuestions({
|
|
10
19
|
questions,
|
|
11
20
|
busy,
|
|
12
21
|
onAnswer,
|
|
13
22
|
primary,
|
|
23
|
+
draft,
|
|
14
24
|
}: {
|
|
15
25
|
questions: Question[];
|
|
16
26
|
busy: boolean;
|
|
@@ -18,9 +28,18 @@ export function DecisionQuestions({
|
|
|
18
28
|
onAnswer: (answer: Answers | null) => void;
|
|
19
29
|
/** Its first control, focused when nothing else is. */
|
|
20
30
|
primary?: React.Ref<HTMLButtonElement> | undefined;
|
|
31
|
+
/** The decision's id: its draft is kept in `DecisionDrafts` under it. */
|
|
32
|
+
draft?: string | undefined;
|
|
21
33
|
}) {
|
|
22
|
-
const
|
|
23
|
-
const
|
|
34
|
+
const drafts = React.useContext(DecisionDrafts);
|
|
35
|
+
const kept = draft === undefined ? undefined : drafts?.get(draft);
|
|
36
|
+
const [chosen, setChosen] = React.useState<Record<string, string[]>>(kept?.chosen ?? {});
|
|
37
|
+
const [texts, setTexts] = React.useState<Record<string, string>>(kept?.texts ?? {});
|
|
38
|
+
// Kept even once sent: a submission that fails leaves the decision open with its answer, still edited. A closed
|
|
39
|
+
// decision draws no card again, and the map goes with the session shown.
|
|
40
|
+
React.useEffect(() => {
|
|
41
|
+
if (draft !== undefined) drafts?.set(draft, { chosen, texts });
|
|
42
|
+
}, [drafts, draft, chosen, texts]);
|
|
24
43
|
const answers: Answers = {
|
|
25
44
|
answers: questions.flatMap((question) => {
|
|
26
45
|
const options = chosen[question.id] ?? [];
|
package/browser/index.tsx
CHANGED
|
@@ -164,6 +164,7 @@ import { Elapsed } from './elapsed.tsx';
|
|
|
164
164
|
import { showLink } from './open-link.tsx';
|
|
165
165
|
import { viewerActivity } from '../viewer-activity.ts';
|
|
166
166
|
import { answerBody, type Answer } from '../answers.ts';
|
|
167
|
+
import { DecisionDrafts, type Draft } from './decision-questions.tsx';
|
|
167
168
|
|
|
168
169
|
export const name = 'sessions';
|
|
169
170
|
export const inject = ['slots', 'workspace', 'nodes', 'sidebar', 'shell', 'screen'];
|
|
@@ -1168,6 +1169,9 @@ function Sessions({
|
|
|
1168
1169
|
const { session: asked, subagent: shownSub } = itemParts(
|
|
1169
1170
|
override && override.over === item ? override.id : (item ?? fallback),
|
|
1170
1171
|
);
|
|
1172
|
+
/** The session asked here now, read by an action that answers after the person may have opened another. */
|
|
1173
|
+
const shown = React.useRef(asked);
|
|
1174
|
+
shown.current = asked;
|
|
1171
1175
|
// A session that is gone (archived, another node's) shows a new chat.
|
|
1172
1176
|
const current =
|
|
1173
1177
|
asked && listing && !listing.sessions.some((each) => each.id === asked) ? undefined : asked;
|
|
@@ -1762,13 +1766,25 @@ function Sessions({
|
|
|
1762
1766
|
kin.has(id)
|
|
1763
1767
|
? { item: id }
|
|
1764
1768
|
: { node: 'root', screen: { plugin: name, id: screen }, item: id },
|
|
1769
|
+
// The workspace's whole list holds every session not archived; a project's or a worktree's holds its own.
|
|
1770
|
+
opens: (id) => kin.has(id) || node !== 'root' || worktree !== undefined,
|
|
1765
1771
|
stop: (id) => stopChild.current(id),
|
|
1766
1772
|
// Its sub-agents' views are this window's items too (bridge#212 S8).
|
|
1767
1773
|
subagentTo: (sub) => ({ item: subagentItem(session.id, sub) }),
|
|
1768
1774
|
stopSubagent: (sub) => stopSub.current(sub),
|
|
1769
1775
|
}
|
|
1770
1776
|
: undefined,
|
|
1771
|
-
[
|
|
1777
|
+
[
|
|
1778
|
+
kin,
|
|
1779
|
+
session?.id,
|
|
1780
|
+
session?.delegations,
|
|
1781
|
+
session?.parent,
|
|
1782
|
+
session?.subagents,
|
|
1783
|
+
shownSub,
|
|
1784
|
+
screen,
|
|
1785
|
+
node,
|
|
1786
|
+
worktree,
|
|
1787
|
+
],
|
|
1772
1788
|
);
|
|
1773
1789
|
// Its tabs beside the chat (./tabs.tsx: `sessions.tab`, an agent's browser).
|
|
1774
1790
|
const tabs = useSessionTabs(current);
|
|
@@ -1842,6 +1858,8 @@ function Sessions({
|
|
|
1842
1858
|
),
|
|
1843
1859
|
[renderSlot, node, sessionNode, current, post],
|
|
1844
1860
|
);
|
|
1861
|
+
/** What was typed in the shown session's question cards, by decision (#111): a new map on a switch of session. */
|
|
1862
|
+
const drafts = React.useMemo(() => new Map<string, Draft>(), [current]);
|
|
1845
1863
|
const galleryPins = React.useMemo(
|
|
1846
1864
|
() =>
|
|
1847
1865
|
current && session
|
|
@@ -1913,9 +1931,10 @@ function Sessions({
|
|
|
1913
1931
|
choose(undefined);
|
|
1914
1932
|
promptHandle.current?.focus();
|
|
1915
1933
|
};
|
|
1916
|
-
const answer = async (
|
|
1934
|
+
const answer = async (decision: string, option: Answer) => {
|
|
1917
1935
|
if (!current) return;
|
|
1918
|
-
|
|
1936
|
+
// By the decision, not its seq: a docked one's (-1) is the next one's once it is answered (#111).
|
|
1937
|
+
const key = `${current}:${decision}`;
|
|
1919
1938
|
setError('');
|
|
1920
1939
|
setAnswering((was) => ({ ...was, [key]: true }));
|
|
1921
1940
|
try {
|
|
@@ -2059,13 +2078,15 @@ function Sessions({
|
|
|
2059
2078
|
failed(`Could not ${action === 'unread' ? 'mark it unread' : action} the session`)(cause);
|
|
2060
2079
|
return;
|
|
2061
2080
|
}
|
|
2062
|
-
|
|
2081
|
+
// Another session opened while the request ran stays shown: only the one acted on gives way to the next.
|
|
2082
|
+
const moved = leaving && shown.current === each.id;
|
|
2083
|
+
if (moved) choose(next);
|
|
2063
2084
|
/** Undoing a settle or an archive that left the open session opens it again, and snoozes it again when that ended
|
|
2064
2085
|
* its snooze (and its time is still ahead). */
|
|
2065
2086
|
const back = async () => {
|
|
2066
2087
|
if (each.snoozedUntil && Date.parse(each.snoozedUntil) > Date.now())
|
|
2067
2088
|
await triage(each.id, 'snooze', { until: each.snoozedUntil });
|
|
2068
|
-
if (
|
|
2089
|
+
if (moved) choose(each.id);
|
|
2069
2090
|
};
|
|
2070
2091
|
if (action === 'settle') {
|
|
2071
2092
|
offerUndo('Session settled', each.title, async () => {
|
|
@@ -2115,12 +2136,13 @@ function Sessions({
|
|
|
2115
2136
|
failed('Could not snooze the session')(cause);
|
|
2116
2137
|
return;
|
|
2117
2138
|
}
|
|
2118
|
-
|
|
2139
|
+
const moved = leaving && shown.current === each.id;
|
|
2140
|
+
if (moved) choose(next);
|
|
2119
2141
|
offerUndo('Session snoozed', `${each.title}, until ${when(until)}`, async () => {
|
|
2120
2142
|
await triage(each.id, 'wake');
|
|
2121
2143
|
if (each.settledAt && !each.pinnedAt) await triage(each.id, 'settle');
|
|
2122
2144
|
if (unpin && each.pinnedAt) await triage(each.id, 'pin', { order: each.pinOrder });
|
|
2123
|
-
if (
|
|
2145
|
+
if (moved) choose(each.id);
|
|
2124
2146
|
});
|
|
2125
2147
|
await load();
|
|
2126
2148
|
};
|
|
@@ -2550,13 +2572,13 @@ function Sessions({
|
|
|
2550
2572
|
)}
|
|
2551
2573
|
{docked && (
|
|
2552
2574
|
<DecisionDock
|
|
2553
|
-
key={docked.
|
|
2575
|
+
key={`${current}:${docked.id}`}
|
|
2554
2576
|
event={docked}
|
|
2555
2577
|
relative={relative}
|
|
2556
|
-
busy={!!answering[`${current}:${docked.
|
|
2578
|
+
busy={!!answering[`${current}:${docked.id}`]}
|
|
2557
2579
|
more={waiting.length - 1}
|
|
2558
2580
|
onRow={onRows[docked.seq] === false}
|
|
2559
|
-
onAnswer={(option) => void answer(docked.
|
|
2581
|
+
onAnswer={(option) => void answer(docked.id!, option)}
|
|
2560
2582
|
/>
|
|
2561
2583
|
)}
|
|
2562
2584
|
</>
|
|
@@ -2697,7 +2719,7 @@ function Sessions({
|
|
|
2697
2719
|
</Tooltip>
|
|
2698
2720
|
);
|
|
2699
2721
|
|
|
2700
|
-
|
|
2722
|
+
const page = (
|
|
2701
2723
|
<section
|
|
2702
2724
|
aria-label="Screen"
|
|
2703
2725
|
className={cn('flex min-h-0 flex-1 overflow-hidden', reset)}
|
|
@@ -3140,7 +3162,7 @@ function Sessions({
|
|
|
3140
3162
|
onReview={() => {
|
|
3141
3163
|
if (!details) toggleDetails();
|
|
3142
3164
|
}}
|
|
3143
|
-
onAnswer={(event, option) => answer(event.
|
|
3165
|
+
onAnswer={(event, option) => answer(event.id!, option)}
|
|
3144
3166
|
onDecisionShown={onDecisionShown}
|
|
3145
3167
|
onOpenChange={(path) => {
|
|
3146
3168
|
setChangeAsked({ session: current, path, at: Date.now() });
|
|
@@ -3268,6 +3290,8 @@ function Sessions({
|
|
|
3268
3290
|
</Dialog>
|
|
3269
3291
|
</section>
|
|
3270
3292
|
);
|
|
3293
|
+
// The conversation's cards and the dock above the prompt share the drafts.
|
|
3294
|
+
return <DecisionDrafts.Provider value={drafts}>{page}</DecisionDrafts.Provider>;
|
|
3271
3295
|
}
|
|
3272
3296
|
|
|
3273
3297
|
/** The keys Sessions handles itself (its `onKey`), declared to the shell for the help and for clashes while a Sessions
|
package/browser/tsconfig.json
CHANGED
|
@@ -4,9 +4,9 @@
|
|
|
4
4
|
"include": [
|
|
5
5
|
".",
|
|
6
6
|
"../../bridge/packages/browser-boot/src/workspace.d.ts",
|
|
7
|
-
"../../
|
|
8
|
-
"../../
|
|
9
|
-
"../../
|
|
7
|
+
"../../shell/browser/shell.d.ts",
|
|
8
|
+
"../../session-prompt/browser/session-prompt.d.ts",
|
|
9
|
+
"../../commands/browser/commands.d.ts",
|
|
10
10
|
"../../bridge/vendor/types/client-build-environment.d.ts"
|
|
11
11
|
],
|
|
12
12
|
"exclude": [
|
package/git.ts
CHANGED
|
@@ -32,6 +32,51 @@ export const runner =
|
|
|
32
32
|
return { code, stdout, stderr };
|
|
33
33
|
};
|
|
34
34
|
|
|
35
|
+
/** How long `ssh -G` may take to name an alias's host before the remote is read as written. */
|
|
36
|
+
export const SSH_RESOLVE_MS = 5000;
|
|
37
|
+
|
|
38
|
+
/** The host name ssh connects to for `alias` (`ssh -G`, which reads `~/.ssh/config` and connects nowhere), run in
|
|
39
|
+
* `cwd` through the host's processes; `undefined` when ssh fails or has not answered within `timeoutMs`. */
|
|
40
|
+
export const sshHostname = async (owner: Context, cwd: string, alias: string, timeoutMs = SSH_RESOLVE_MS) => {
|
|
41
|
+
try {
|
|
42
|
+
const child = await owner.processes.spawn(owner, { command: 'ssh', args: ['-G', alias], cwd });
|
|
43
|
+
let stdout = '';
|
|
44
|
+
child.onOutput((stream, chunk) => {
|
|
45
|
+
if (stream === 'stdout') stdout += chunk;
|
|
46
|
+
});
|
|
47
|
+
let timer: ReturnType<typeof setTimeout> | undefined;
|
|
48
|
+
const late = new Promise<'late'>((done) => {
|
|
49
|
+
timer = setTimeout(() => done('late'), timeoutMs);
|
|
50
|
+
});
|
|
51
|
+
const end = await Promise.race([child.exited, late]);
|
|
52
|
+
clearTimeout(timer);
|
|
53
|
+
if (end === 'late') {
|
|
54
|
+
void child.kill();
|
|
55
|
+
return undefined;
|
|
56
|
+
}
|
|
57
|
+
return end.code === 0 ? /^hostname (\S+)$/m.exec(stdout)?.[1] : undefined;
|
|
58
|
+
} catch {
|
|
59
|
+
return undefined;
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
/** `remote` with its ssh host alias replaced by the host `hostOf` resolves it to (`sshHostname`): a remote
|
|
64
|
+
* `git@github-work:o/r.git` whose `~/.ssh/config` says `HostName github.com` reads as GitHub's (plugins#114). Any other
|
|
65
|
+
* form (https, a path) and GitHub's own hosts come back as they are. */
|
|
66
|
+
export const resolveRemote = async (
|
|
67
|
+
remote: string,
|
|
68
|
+
hostOf: (alias: string) => Promise<string | undefined>,
|
|
69
|
+
) => {
|
|
70
|
+
const found =
|
|
71
|
+
/^(ssh:\/\/(?:[^@/]+@)?)([^/:@]+)(?::\d+)?\//i.exec(remote) ?? /^((?:[^@/:]+@)?)([^/:@]+):(?!\/)/.exec(remote);
|
|
72
|
+
const alias = found?.[2];
|
|
73
|
+
// A name only, never an option for ssh (`-…`).
|
|
74
|
+
if (!found || !alias || !/^[A-Za-z0-9][A-Za-z0-9._-]*$/.test(alias) || /^(?:ssh\.)?github\.com$/i.test(alias))
|
|
75
|
+
return remote;
|
|
76
|
+
const host = await hostOf(alias);
|
|
77
|
+
return host ? `${found[1]}${host}${remote.slice(found[1]!.length + alias.length)}` : remote;
|
|
78
|
+
};
|
|
79
|
+
|
|
35
80
|
/** The branches of the repository at `folder` that have a folder, as git lists them (`git worktree list`): its own
|
|
36
81
|
* checkout first, then each worktree under its `.worktrees/` (research-083). A folder's name is never read as a branch's
|
|
37
82
|
* name (`feat/x` and `feat-x` share one). */
|
|
@@ -67,12 +112,17 @@ export const branchSlug = (text: string) =>
|
|
|
67
112
|
'',
|
|
68
113
|
);
|
|
69
114
|
|
|
70
|
-
/**
|
|
115
|
+
/** The example of the prompt that asks a model for a branch name: never taken as its answer (plugins#110). */
|
|
116
|
+
export const BRANCH_EXAMPLE = 'fix/e2e-shards';
|
|
117
|
+
|
|
118
|
+
/** A model's answer as a `type/topic` branch name (`fix/login-timeout`), `undefined` when it is not one or is the prompt's
|
|
119
|
+
* own example (a model echoing it would name every branch the same). */
|
|
71
120
|
export const typedBranch = (answer: string) => {
|
|
72
121
|
// Its first line: a model may go on after the name (plugins#84).
|
|
73
122
|
const name = (answer.trim().split('\n')[0] ?? '').trim().replace(/^`+|`+$/g, '');
|
|
74
123
|
return name.length <= 40 &&
|
|
75
|
-
/^(feat|fix|chore|ci|docs|refactor|test)\/[a-z0-9]+(-[a-z0-9]+)*$/.test(name)
|
|
124
|
+
/^(feat|fix|chore|ci|docs|refactor|test)\/[a-z0-9]+(-[a-z0-9]+)*$/.test(name) &&
|
|
125
|
+
name !== BRANCH_EXAMPLE
|
|
76
126
|
? name
|
|
77
127
|
: undefined;
|
|
78
128
|
};
|
|
@@ -101,6 +151,10 @@ export interface Repository {
|
|
|
101
151
|
/** Past this size a file's fingerprint is its size and mtime, not its content: a turn's snapshot never reads a huge file
|
|
102
152
|
* whole (#112). ponytail: an edit of such a file that keeps both is not seen. */
|
|
103
153
|
const HASH_MAX = 16 * 1024 * 1024;
|
|
154
|
+
/** A snapshot reads (stat and content) this many files at most, in `git status`'s order (tracked changes first): a
|
|
155
|
+
* folder of thousands of untracked files (a `node_modules` not ignored) costs no more (#121). The others are `unread`:
|
|
156
|
+
* one that appears or goes is still a change. ponytail: an edit of an unread file is not seen. */
|
|
157
|
+
const READ_MAX = 2_000;
|
|
104
158
|
|
|
105
159
|
/** The files of `top` that differ (read as `owner`) from `HEAD` (untracked ones included, ignored ones not), each with a fingerprint of
|
|
106
160
|
* its content now (`deleted` when gone): two states compared give what changed between them. */
|
|
@@ -108,7 +162,7 @@ export const stateOf = async (
|
|
|
108
162
|
owner: Context,
|
|
109
163
|
run: Run,
|
|
110
164
|
top: string,
|
|
111
|
-
{ hashMax = HASH_MAX }: { hashMax?: number } = {},
|
|
165
|
+
{ hashMax = HASH_MAX, readMax = READ_MAX }: { hashMax?: number; readMax?: number } = {},
|
|
112
166
|
) => {
|
|
113
167
|
const { code, stdout } = await run(top, [
|
|
114
168
|
'status',
|
|
@@ -125,8 +179,11 @@ export const stateOf = async (
|
|
|
125
179
|
.map((field) => field.slice(3));
|
|
126
180
|
const state = new Map<string, string>();
|
|
127
181
|
await Promise.all(
|
|
128
|
-
paths
|
|
182
|
+
paths
|
|
183
|
+
.slice(0, readMax)
|
|
184
|
+
.map(async (path) => state.set(path, await fingerprint(owner, join(top, path), hashMax))),
|
|
129
185
|
);
|
|
186
|
+
for (const path of paths.slice(readMax)) state.set(path, 'unread');
|
|
130
187
|
return state;
|
|
131
188
|
};
|
|
132
189
|
|
|
@@ -146,11 +203,20 @@ const fingerprint = async (owner: Context, file: string, hashMax: number) => {
|
|
|
146
203
|
}
|
|
147
204
|
};
|
|
148
205
|
|
|
149
|
-
/** The paths whose fingerprint differs between `before` and `after`.
|
|
206
|
+
/** The paths whose fingerprint differs between `before` and `after`. An `unread` file's content is unknown: in both
|
|
207
|
+
* states and gone from neither, it is no change (a path that entered before the cap pushed it past, #121). */
|
|
150
208
|
export const changed = (before: Map<string, string>, after: Map<string, string>) =>
|
|
151
|
-
[...new Set([...before.keys(), ...after.keys()])].filter(
|
|
152
|
-
|
|
153
|
-
|
|
209
|
+
[...new Set([...before.keys(), ...after.keys()])].filter((path) => {
|
|
210
|
+
const was = before.get(path);
|
|
211
|
+
const now = after.get(path);
|
|
212
|
+
const unknown =
|
|
213
|
+
(was === 'unread' || now === 'unread') &&
|
|
214
|
+
was !== undefined &&
|
|
215
|
+
now !== undefined &&
|
|
216
|
+
was !== 'deleted' &&
|
|
217
|
+
now !== 'deleted';
|
|
218
|
+
return !unknown && was !== now;
|
|
219
|
+
});
|
|
154
220
|
|
|
155
221
|
/** `path` (absolute, or relative to `folder`, a folder of `repository`) relative to the repository's top, `/`-separated
|
|
156
222
|
* (`''`: the top itself); `undefined` outside it. The top git gives may be another spelling of `folder`'s (symbolic links resolved): a path in
|
|
@@ -165,23 +231,17 @@ export const within = ({ top, prefix }: Repository, folder: string, path: string
|
|
|
165
231
|
return local === undefined ? inside(top, file) : `${prefix}${local}`.replace(/\/$/, '');
|
|
166
232
|
};
|
|
167
233
|
|
|
168
|
-
/**
|
|
169
|
-
*
|
|
170
|
-
const PATCH = [
|
|
171
|
-
|
|
172
|
-
'core.quotePath=false',
|
|
173
|
-
'diff',
|
|
174
|
-
'--no-color',
|
|
175
|
-
'--no-ext-diff',
|
|
176
|
-
'--no-textconv',
|
|
177
|
-
'--src-prefix=a/',
|
|
178
|
-
'--dst-prefix=b/',
|
|
179
|
-
];
|
|
234
|
+
/** Git's own patch whatever the person's config: no external tool or textconv, the `a/` and `b/` prefixes the Changes
|
|
235
|
+
* panel reads (not `diff.mnemonicPrefix`'s `w/`, `i/`…), paths not quoted for their non-ASCII. */
|
|
236
|
+
const PATCH = ['--no-color', '--no-ext-diff', '--no-textconv', '--src-prefix=a/', '--dst-prefix=b/'];
|
|
237
|
+
const QUOTE = ['-c', 'core.quotePath=false'];
|
|
180
238
|
|
|
181
239
|
/** The diff of `files` against `HEAD` in `top` (an untracked file shown whole, as new), cut past `max` characters. */
|
|
182
240
|
export const diffOf = async (run: Run, top: string, files: string[], max: number) => {
|
|
183
241
|
if (!files.length) return '';
|
|
184
|
-
|
|
242
|
+
// `diff-index`, not `diff`: `diff` refreshes the index of a file whose stat moved (a `touch`), rewriting it through
|
|
243
|
+
// `index.lock` even under `GIT_OPTIONAL_LOCKS=0`, and the session's agent's own `git add` then fails on that lock.
|
|
244
|
+
const tracked = await run(top, [...QUOTE, 'diff-index', '-p', ...PATCH, 'HEAD', '--', ...files]);
|
|
185
245
|
let text = tracked.stdout;
|
|
186
246
|
const listed = await run(top, [
|
|
187
247
|
'ls-files',
|
|
@@ -193,7 +253,7 @@ export const diffOf = async (run: Run, top: string, files: string[], max: number
|
|
|
193
253
|
]);
|
|
194
254
|
for (const path of listed.stdout.split('\0').filter(Boolean)) {
|
|
195
255
|
if (text.length > max) break;
|
|
196
|
-
const added = await run(top, [...PATCH, '--no-index', '--', '/dev/null', path]);
|
|
256
|
+
const added = await run(top, [...QUOTE, 'diff', ...PATCH, '--no-index', '--', '/dev/null', path]);
|
|
197
257
|
text += added.stdout;
|
|
198
258
|
}
|
|
199
259
|
return text.length > max ? `${cutText(text, max)}\n… [truncated]` : text;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bridgebrew/sessions",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.21",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "Conversations with agents, in the workspace or in a project, through the Profile.",
|
|
6
6
|
"keywords": [
|
|
@@ -1027,6 +1027,6 @@
|
|
|
1027
1027
|
},
|
|
1028
1028
|
"releaseStage": "dev",
|
|
1029
1029
|
"engines": {
|
|
1030
|
-
"bridge": ">=0.0.1-nightly.
|
|
1030
|
+
"bridge": ">=0.0.1-nightly.20261117.1"
|
|
1031
1031
|
}
|
|
1032
1032
|
}
|
package/pull-requests.ts
CHANGED
|
@@ -105,7 +105,7 @@ const withWake = <V extends Value>(value: V, text: string, at: number): V => ({
|
|
|
105
105
|
{ id: `${WAKE}${crypto.randomUUID()}`, text, at: new Date(at).toISOString(), from: 'bridge' as const },
|
|
106
106
|
],
|
|
107
107
|
});
|
|
108
|
-
/** `value` without the pull request news still queued: merged or
|
|
108
|
+
/** `value` without the pull request news still queued: merged, closed, unwatched or unlinked, it is no longer news. */
|
|
109
109
|
const withoutWakes = <V extends Value>(value: V): V => {
|
|
110
110
|
if (!value.queue?.some((each) => each.id.startsWith(WAKE))) return value;
|
|
111
111
|
const { queue, ...rest } = value;
|
|
@@ -516,7 +516,7 @@ export function createPullRequests<V extends Value>(deps: {
|
|
|
516
516
|
if (!was.pullRequest) return was;
|
|
517
517
|
const { pullRequest, ...rest } = was;
|
|
518
518
|
return {
|
|
519
|
-
...rest,
|
|
519
|
+
...withoutWakes(rest),
|
|
520
520
|
pullRequestUnlinked: [...(was.pullRequestUnlinked ?? []).filter((each) => each !== pullRequest.url), pullRequest.url].slice(-20),
|
|
521
521
|
} as V;
|
|
522
522
|
});
|
|
@@ -586,7 +586,7 @@ export function createPullRequests<V extends Value>(deps: {
|
|
|
586
586
|
"Stops watching a session's pull request (it stays linked): { id? }",
|
|
587
587
|
async ({ actor, body }) => {
|
|
588
588
|
const found = await target(actor, parse(idBody, body, 'POST /sessions/pull-request/unwatch takes { id? }'));
|
|
589
|
-
const value = await change(found.id, unwatched);
|
|
589
|
+
const value = await change(found.id, (was) => withoutWakes(unwatched(was)));
|
|
590
590
|
deps.changed(found.id);
|
|
591
591
|
return { id: found.id, pullRequest: value.pullRequest ?? null };
|
|
592
592
|
},
|
package/server.ts
CHANGED
|
@@ -166,7 +166,9 @@ import {
|
|
|
166
166
|
commit,
|
|
167
167
|
diffOf,
|
|
168
168
|
repositoryAt,
|
|
169
|
+
resolveRemote,
|
|
169
170
|
runner,
|
|
171
|
+
sshHostname,
|
|
170
172
|
stateOf,
|
|
171
173
|
type Repository,
|
|
172
174
|
within,
|
|
@@ -174,6 +176,7 @@ import {
|
|
|
174
176
|
branchSlug,
|
|
175
177
|
freeBranch,
|
|
176
178
|
typedBranch,
|
|
179
|
+
BRANCH_EXAMPLE,
|
|
177
180
|
} from './git.ts';
|
|
178
181
|
import { changeOf, type Change } from './diff.ts';
|
|
179
182
|
import { active, actsAs, createPeers, release } from './peers.ts';
|
|
@@ -1367,7 +1370,7 @@ export async function apply(ctx: Context, config?: unknown) {
|
|
|
1367
1370
|
// waited for, a model may go on with the work itself (plugins#84).
|
|
1368
1371
|
answered: (text, more) =>
|
|
1369
1372
|
(more || text.trimStart().includes('\n')) && typedBranch(text) !== undefined,
|
|
1370
|
-
prompt: `Name the git branch of this work. Answer with the name only, \`type/topic\`: type is one of feat, fix, chore, ci, docs, refactor, test; topic is 2 to 4 lowercase words saying what the work does, joined by \`-\` (a-z, 0-9 only), never the words of a URL; 40 characters at most. For example:
|
|
1373
|
+
prompt: `Name the git branch of this work. Answer with the name only, \`type/topic\`: type is one of feat, fix, chore, ci, docs, refactor, test; topic is 2 to 4 lowercase words saying what the work does, joined by \`-\` (a-z, 0-9 only), never the words of a URL; 40 characters at most. For example: ${BRANCH_EXAMPLE}. Do not do the work: only name it.\n\nThe work, as the user asked it:\n\n${cutText(text, 4000)}`,
|
|
1371
1374
|
}),
|
|
1372
1375
|
new Promise<never>((_, reject) =>
|
|
1373
1376
|
signal.addEventListener(
|
|
@@ -4468,6 +4471,16 @@ export async function apply(ctx: Context, config?: unknown) {
|
|
|
4468
4471
|
log,
|
|
4469
4472
|
});
|
|
4470
4473
|
|
|
4474
|
+
// An ssh alias's host, once per alias: `ssh -G` reads ~/.ssh/config (plugins#114). A failure is asked again.
|
|
4475
|
+
const hosts = new Map<string, Promise<string | undefined>>();
|
|
4476
|
+
const hostOf = (folder: string, alias: string) => {
|
|
4477
|
+
let host = hosts.get(alias);
|
|
4478
|
+
if (!host) {
|
|
4479
|
+
hosts.set(alias, (host = sshHostname(ctx, folder, alias)));
|
|
4480
|
+
void host.then((name) => name || hosts.delete(alias));
|
|
4481
|
+
}
|
|
4482
|
+
return host;
|
|
4483
|
+
};
|
|
4471
4484
|
// A session's pull request (research-086): linked, read, settled on merge, watched; `pull-requests.ts`.
|
|
4472
4485
|
const pullRequests = createPullRequests<Session>({
|
|
4473
4486
|
route: (method, path, description, handle) =>
|
|
@@ -4491,7 +4504,7 @@ export async function apply(ctx: Context, config?: unknown) {
|
|
|
4491
4504
|
return undefined;
|
|
4492
4505
|
const remote = await run(folder, ['remote', 'get-url', 'origin']);
|
|
4493
4506
|
return remote.code === 0 && remote.stdout.trim()
|
|
4494
|
-
? { branch, remote: remote.stdout.trim() }
|
|
4507
|
+
? { branch, remote: await resolveRemote(remote.stdout.trim(), (alias) => hostOf(folder, alias)) }
|
|
4495
4508
|
: undefined;
|
|
4496
4509
|
},
|
|
4497
4510
|
// A wake already in the queue: sent as after a turn (at once when none runs, held after the user's Stop).
|
|
@@ -5430,14 +5443,15 @@ export async function apply(ctx: Context, config?: unknown) {
|
|
|
5430
5443
|
// Its turn ends once this answer is on its way: its agent opens again in the branch's folder at the next turn,
|
|
5431
5444
|
// which `prompt` starts.
|
|
5432
5445
|
setTimeout(() => {
|
|
5433
|
-
const
|
|
5434
|
-
|
|
5435
|
-
|
|
5436
|
-
|
|
5437
|
-
|
|
5438
|
-
|
|
5439
|
-
|
|
5440
|
-
|
|
5446
|
+
const { prompt } = input;
|
|
5447
|
+
const deliver = (text: string, delivery: Delivery) =>
|
|
5448
|
+
sendOrQueue({ id, node: found.node, value }, text, [], { from: 'bridge' }, false, delivery);
|
|
5449
|
+
const next = prompt
|
|
5450
|
+
? deliver(prompt, running.has(id) ? 'restart' : 'queue').catch((error: unknown) =>
|
|
5451
|
+
// The turn ended before the prompt took the session's lock: the prompt starts a turn of its own (#120).
|
|
5452
|
+
(error as { code?: unknown } | null)?.code === 'turn_not_running'
|
|
5453
|
+
? deliver(prompt, 'queue')
|
|
5454
|
+
: Promise.reject(error),
|
|
5441
5455
|
)
|
|
5442
5456
|
: (async () => {
|
|
5443
5457
|
if (!running.has(id)) return;
|