@andrioid/paseo-attention-span 0.3.3 → 0.3.5
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/client/attention-screen.tsx +8 -4
- package/client/feedback.tsx +2 -1
- package/client/sessions.ts +20 -30
- package/docs/architecture.md +2 -2
- package/index.server.ts +3 -0
- package/package.json +1 -1
- package/requirements.yaml +1 -0
- package/server/fixture.ts +2 -0
- package/shared/linked-sessions.ts +69 -0
- package/shared/providers.ts +69 -0
- package/shared/rpc.ts +3 -0
|
@@ -18,7 +18,7 @@ import { NextUpList } from "./next-up";
|
|
|
18
18
|
import { agentSignal, sessionEntry, startAnotherEntry } from "./session-menu";
|
|
19
19
|
import { ActionSheet, DetailLines, type SheetEntry } from "./sheet";
|
|
20
20
|
import { FeedbackAsk, FeedbackLine, type FeedbackScreen, FeedbackSheet } from "./feedback";
|
|
21
|
-
import { branchWorkspaces, findCheckout, githubProjects, itemAgents, listProfiles, noProjectMessage, resolveAgentConfig, startSession } from "./sessions";
|
|
21
|
+
import { branchWorkspaces, type FetchProviders, findCheckout, githubProjects, itemAgents, listProfiles, noProjectMessage, resolveAgentConfig, startSession } from "./sessions";
|
|
22
22
|
import { SetupChecklist } from "./setup";
|
|
23
23
|
import { Avatar, Button, KeepStyles, Loading, Meta, SectionHeader, SpinningIcon, StylesProvider, TablerIcon, Toggle, useCopy, useHover, useStyles } from "./ui";
|
|
24
24
|
|
|
@@ -202,6 +202,8 @@ function AttentionList({
|
|
|
202
202
|
const fetchDetails = useRpc(rpc.itemDetails);
|
|
203
203
|
const setCodeRepo = useRpc(rpc.setCodeRepo);
|
|
204
204
|
const fetchDefaultBranch = useRpc(rpc.defaultBranch);
|
|
205
|
+
const fetchReadyProviders = useRpc(rpc.readyProviders);
|
|
206
|
+
const fetchProviders: FetchProviders = () => fetchReadyProviders({}).then((result) => result.providers);
|
|
205
207
|
const defaultBranch: DefaultBranch = async (repo) => (await fetchDefaultBranch({ repo })).name;
|
|
206
208
|
const [tab, setTab] = useState<TabId>("doing");
|
|
207
209
|
// Every card with a change still running: each runs on its own.
|
|
@@ -263,7 +265,7 @@ function AttentionList({
|
|
|
263
265
|
await before?.();
|
|
264
266
|
const { context } = await fetchContext({ kind, target });
|
|
265
267
|
const prompt = renderPrompt(kind, target, context, config);
|
|
266
|
-
await started(await startSession(paseo, { itemKey, kind, target, prompt, config, checkout }));
|
|
268
|
+
await started(await startSession(paseo, { itemKey, kind, target, prompt, config, fetchProviders, checkout }));
|
|
267
269
|
}
|
|
268
270
|
|
|
269
271
|
function place(codeRepo: string) {
|
|
@@ -320,6 +322,7 @@ function AttentionList({
|
|
|
320
322
|
fetchDetails,
|
|
321
323
|
fetchReviewers,
|
|
322
324
|
defaultBranch,
|
|
325
|
+
fetchProviders,
|
|
323
326
|
openAgent,
|
|
324
327
|
started,
|
|
325
328
|
act: (item, action) => {
|
|
@@ -518,6 +521,7 @@ interface Actions {
|
|
|
518
521
|
fetchDetails: FetchDetails;
|
|
519
522
|
fetchReviewers: FetchReviewers;
|
|
520
523
|
defaultBranch: DefaultBranch;
|
|
524
|
+
fetchProviders: FetchProviders;
|
|
521
525
|
act: (item: Item, action: ActionId) => void;
|
|
522
526
|
requestReviewers: (item: Item, reviewers: string[]) => void;
|
|
523
527
|
rerun: (item: Item, runIds: number[]) => void;
|
|
@@ -1037,7 +1041,7 @@ function SessionOptions({ spec, actions, onClose }: { spec: OptionsSpec; actions
|
|
|
1037
1041
|
listProfiles(paseo),
|
|
1038
1042
|
findCheckout(paseo, actions.config, target, actions.defaultBranch),
|
|
1039
1043
|
// Without a ready provider, still show the options; starting reports the error.
|
|
1040
|
-
resolveAgentConfig(paseo, kind, actions.config).catch(() => ({ label: "No agent provider is ready" })),
|
|
1044
|
+
resolveAgentConfig(paseo, actions.fetchProviders, kind, actions.config).catch(() => ({ label: "No agent provider is ready" })),
|
|
1041
1045
|
]);
|
|
1042
1046
|
const workspaces = checkout.project ? await branchWorkspaces(paseo, checkout.project.projectId, target.headRefName) : [];
|
|
1043
1047
|
return { prompt: renderPrompt(kind, target, context, actions.config), profiles, checkout, workspaces, defaultLabel: defaults.label };
|
|
@@ -1055,7 +1059,7 @@ function SessionOptions({ spec, actions, onClose }: { spec: OptionsSpec; actions
|
|
|
1055
1059
|
setStarting(true);
|
|
1056
1060
|
try {
|
|
1057
1061
|
await spec.before?.();
|
|
1058
|
-
await actions.started(await startSession(paseo, { itemKey, kind, target, prompt: prompt ?? data.prompt, config: actions.config, checkout: data.checkout, profileId, workspaceId }));
|
|
1062
|
+
await actions.started(await startSession(paseo, { itemKey, kind, target, prompt: prompt ?? data.prompt, config: actions.config, fetchProviders: actions.fetchProviders, checkout: data.checkout, profileId, workspaceId }));
|
|
1059
1063
|
onClose();
|
|
1060
1064
|
} catch (error) {
|
|
1061
1065
|
toast.error(`Starting the session failed: ${(error as Error).message}`);
|
package/client/feedback.tsx
CHANGED
|
@@ -90,6 +90,7 @@ export function FeedbackAsk({
|
|
|
90
90
|
const paseo = usePaseo();
|
|
91
91
|
const toast = useToast();
|
|
92
92
|
const fetchInfo = useRpc(rpc.feedbackInfo);
|
|
93
|
+
const fetchProviders = useRpc(rpc.readyProviders);
|
|
93
94
|
const [message, setMessage] = useState("");
|
|
94
95
|
const [starting, setStarting] = useState(false);
|
|
95
96
|
|
|
@@ -98,7 +99,7 @@ export function FeedbackAsk({
|
|
|
98
99
|
try {
|
|
99
100
|
const info = await fetchInfo({});
|
|
100
101
|
const prompt = feedbackPrompt(kind, { ...screen, message, dir: info.source, version: info.version });
|
|
101
|
-
const { agent } = await resolveAgentConfig(paseo, "start", config);
|
|
102
|
+
const { agent } = await resolveAgentConfig(paseo, () => fetchProviders({}).then((result) => result.providers), "start", config);
|
|
102
103
|
const workspace = await paseo.workspaces.open({ cwd: info.cwd });
|
|
103
104
|
const created = await workspace.agents.create({
|
|
104
105
|
config: agent,
|
package/client/sessions.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import type { usePaseo } from "@getpaseo/plugin/client";
|
|
2
2
|
import type { AgentSummary, Target } from "../shared/attention";
|
|
3
|
+
import { linkedSessions } from "../shared/linked-sessions";
|
|
4
|
+
import { chooseAgent, type ReadyProvider } from "../shared/providers";
|
|
3
5
|
import { type AttentionConfig, codeRepoFor, githubRepoOf, SessionKind } from "../shared/config";
|
|
4
6
|
|
|
5
7
|
type Paseo = ReturnType<typeof usePaseo>;
|
|
@@ -12,10 +14,15 @@ export const KIND_LABEL = "attention-span-kind";
|
|
|
12
14
|
// Sessions started under the plugin's earlier names, "GitHub attention" and "GitHub inbox".
|
|
13
15
|
const OLD_LABELS = ["github-attention", "github-inbox"];
|
|
14
16
|
|
|
15
|
-
// Agents started from Attention Span, each with the item it was started on
|
|
17
|
+
// Agents started from Attention Span, each with the item it was started on, and the agents
|
|
18
|
+
// started outside it in a workspace that belongs to an item [SES-08].
|
|
16
19
|
export async function itemAgents(paseo: Paseo): Promise<AgentSummary[]> {
|
|
17
20
|
const labels = [LABEL, ...OLD_LABELS];
|
|
18
|
-
const lists = await Promise.all(
|
|
21
|
+
const [lists, all, workspaces] = await Promise.all([
|
|
22
|
+
Promise.all(labels.map((label) => paseo.agents.list({ filter: { labels: { [label]: "1" } } }))),
|
|
23
|
+
paseo.agents.list(),
|
|
24
|
+
paseo.workspaces.list(),
|
|
25
|
+
]);
|
|
19
26
|
const byId = new Map<string, AgentSummary>();
|
|
20
27
|
for (const { agent } of lists.flatMap((list) => list.entries)) {
|
|
21
28
|
const itemKey = labels.map((label) => agent.labels?.[`${label}-item`]).find(Boolean);
|
|
@@ -31,7 +38,9 @@ export async function itemAgents(paseo: Paseo): Promise<AgentSummary[]> {
|
|
|
31
38
|
lastActivityAt: agent.updatedAt ?? null,
|
|
32
39
|
});
|
|
33
40
|
}
|
|
34
|
-
|
|
41
|
+
const labelled = [...byId.values()];
|
|
42
|
+
const unlabelled = all.entries.map((entry) => entry.agent).filter((agent) => !labels.some((label) => agent.labels?.[label]));
|
|
43
|
+
return [...labelled, ...linkedSessions(labelled, unlabelled, workspaces.entries)];
|
|
35
44
|
}
|
|
36
45
|
|
|
37
46
|
export interface ProjectMatch {
|
|
@@ -107,10 +116,13 @@ export async function listProfiles(paseo: Paseo): Promise<ProfileChoice[]> {
|
|
|
107
116
|
}
|
|
108
117
|
|
|
109
118
|
type AgentConfig = Parameters<Paseo["agents"]["create"]>[0]["config"];
|
|
119
|
+
// Asks the plugin's server, whose snapshot always has the entries [SES-06].
|
|
120
|
+
export type FetchProviders = () => Promise<ReadyProvider[]>;
|
|
110
121
|
|
|
111
122
|
// The profile configured for the session type, then "default", then Paseo's defaults [SES-01, SES-06].
|
|
112
123
|
export async function resolveAgentConfig(
|
|
113
124
|
paseo: Paseo,
|
|
125
|
+
fetchProviders: FetchProviders,
|
|
114
126
|
kind: SessionKind,
|
|
115
127
|
config: AttentionConfig,
|
|
116
128
|
profileId?: string,
|
|
@@ -120,32 +132,9 @@ export async function resolveAgentConfig(
|
|
|
120
132
|
const byName = (name: string | undefined) =>
|
|
121
133
|
name ? profiles.find((p) => p.id === name || p.name.toLowerCase() === name.toLowerCase()) : undefined;
|
|
122
134
|
const profile = profileId ? byName(profileId) : (byName(config.profiles[kind]) ?? byName(config.profiles.default));
|
|
123
|
-
|
|
124
|
-
const
|
|
125
|
-
|
|
126
|
-
const defaultModel = (provider: string) => {
|
|
127
|
-
const entry = providers.find((candidate) => candidate.provider === provider);
|
|
128
|
-
return (entry?.models ?? []).find((model) => model.isDefault)?.id ?? entry?.models?.[0]?.id;
|
|
129
|
-
};
|
|
130
|
-
|
|
131
|
-
if (profile) {
|
|
132
|
-
const model = profile.model ?? defaultModel(profile.provider);
|
|
133
|
-
return {
|
|
134
|
-
label: profile.name,
|
|
135
|
-
agent: {
|
|
136
|
-
provider: model ? `${profile.provider}/${model}` : profile.provider,
|
|
137
|
-
modeId: profile.modeId,
|
|
138
|
-
thinkingOptionId: profile.thinkingOptionId,
|
|
139
|
-
featureValues: profile.featureValues,
|
|
140
|
-
},
|
|
141
|
-
};
|
|
142
|
-
}
|
|
143
|
-
const fallback = providers.find((entry) => defaultModel(entry.provider));
|
|
144
|
-
if (!fallback) throw new Error("No agent provider is ready on this host.");
|
|
145
|
-
return {
|
|
146
|
-
label: `Paseo default (${fallback.label})`,
|
|
147
|
-
agent: { provider: `${fallback.provider}/${defaultModel(fallback.provider)}`, modeId: fallback.defaultModeId ?? undefined },
|
|
148
|
-
};
|
|
135
|
+
// A profile that names its model needs no provider lookup.
|
|
136
|
+
const providers = profile?.model ? [] : await fetchProviders();
|
|
137
|
+
return chooseAgent(profile, providers);
|
|
149
138
|
}
|
|
150
139
|
|
|
151
140
|
function slug(text: string): string {
|
|
@@ -162,6 +151,7 @@ export interface StartSession {
|
|
|
162
151
|
target: Target;
|
|
163
152
|
prompt: string;
|
|
164
153
|
config: AttentionConfig;
|
|
154
|
+
fetchProviders: FetchProviders;
|
|
165
155
|
checkout: Checkout;
|
|
166
156
|
profileId?: string;
|
|
167
157
|
workspaceId?: string; // an existing workspace; otherwise a new worktree
|
|
@@ -172,7 +162,7 @@ export async function startSession(paseo: Paseo, input: StartSession): Promise<s
|
|
|
172
162
|
const { target, checkout } = input;
|
|
173
163
|
const project = checkout.project;
|
|
174
164
|
if (!project) throw new Error(noProjectMessage(checkout, target));
|
|
175
|
-
const { agent: agentConfig } = await resolveAgentConfig(paseo, input.kind, input.config, input.profileId);
|
|
165
|
+
const { agent: agentConfig } = await resolveAgentConfig(paseo, input.fetchProviders, input.kind, input.config, input.profileId);
|
|
176
166
|
const title = `${target.kind === "pr" ? "PR" : "Issue"} ${target.number}: ${target.title}`.slice(0, 120);
|
|
177
167
|
|
|
178
168
|
const workspace = input.workspaceId
|
package/docs/architecture.md
CHANGED
|
@@ -125,14 +125,14 @@ An agent icon (Tabler's `message-ai`, a speech bubble with "AI") marks every act
|
|
|
125
125
|
|
|
126
126
|
A tap starts with defaults. An existing workspace for the branch or PR is resumed instead of creating a new one.
|
|
127
127
|
|
|
128
|
-
While an item has an open session, its main action is **Open session** instead, in every tab [SES-03, ATT-07]. A session belongs to an item when it was started on the item or on any PR under it, and isn't archived; none do once the item is merged or closed. With several, it opens one that needs me, else the most recent. In the sheet each session sits in the line of the action that started it, named after it ("Fix CI", "Rebase stack"), one line per session: a session's kind is saved as the `attention-span-kind` label when it starts. Sessions none of the item's actions would start lead the sheet: those started before kinds were saved, as "Continue session", and those whose action is gone, like Fix CI once checks pass. Next up's sheet does the same with Start: "Claim & start…" or "Start…" until there's a session, then the sessions as "Continue session" and a muted "Start another session…". Collapsed, a stack shows only the PRs that need attention [ATT-04].
|
|
128
|
+
While an item has an open session, its main action is **Open session** instead, in every tab [SES-03, ATT-07]. A session belongs to an item when it was started on the item or on any PR under it, and isn't archived; none do once the item is merged or closed. With several, it opens one that needs me, else the most recent. In the sheet each session sits in the line of the action that started it, named after it ("Fix CI", "Rebase stack"), one line per session: a session's kind is saved as the `attention-span-kind` label when it starts. Sessions none of the item's actions would start lead the sheet: those started before kinds were saved, as "Continue session", and those whose action is gone, like Fix CI once checks pass. Sessions started outside Attention Span count too, with no kind, so they lead as "Continue session" [SES-08]: an agent in a workspace Paseo linked to a PR (`githubRuntime.pullRequest`) belongs to that PR, and one in a worktree belongs to the item of the Attention Span session there, unless the worktree has sessions for two items. Main and local checkouts never pass an item on, a labelled session keeps its own item, and agents another agent started belong to that agent. Issues get only the sessions Attention Span started: Paseo doesn't record which issue a workspace was started from. Next up's sheet does the same with Start: "Claim & start…" or "Start…" until there's a session, then the sessions as "Continue session" and a muted "Start another session…". Collapsed, a stack shows only the PRs that need attention [ATT-04].
|
|
129
129
|
|
|
130
130
|
## Sessions
|
|
131
131
|
|
|
132
132
|
- **Repo to checkout** [SES-05]: match the PR's or issue's repository against the git remotes of registered Paseo projects. Repos without a project can only open GitHub.
|
|
133
133
|
- **Issues kept apart from the code** [SES-07]: an issue starts in the repo `codeRepos` maps its repo to, from that repo's default branch (one `gh repo view`). When neither has a project, Start asks which project holds the code, saves the answer to `codeRepos` and carries on. Claim waits until then, so a start that can't go anywhere doesn't leave the issue taken. The prompt and Claim keep using the issue's own repo.
|
|
134
134
|
- **Workspace**: a worktree with `checkout-pr` for PRs, or `branch-off` from the default branch for issues.
|
|
135
|
-
- **Profile**: looked up per reason in `config.json`, then materialised into `create_agent` from `list_profiles`. A missing `review` profile falls back to `default`; a missing `default` starts the agent with Paseo's defaults. Options ▾ still offers provider and model [SES-06].
|
|
135
|
+
- **Profile**: looked up per reason in `config.json`, then materialised into `create_agent` from `list_profiles`. A missing `review` profile falls back to `default`; a missing `default` starts the agent with Paseo's defaults: the first ready provider and its default model. The plugin's server reads the provider list (`providers.ready`), because the app's own snapshot can arrive compact, with no entries. Options ▾ still offers provider and model [SES-06].
|
|
136
136
|
- **Prompt**: a built-in template per session type, filled with the item's context. A template in `config.json` replaces the built-in one [SES-04]. The context is fetched when the session starts, mostly from `gh`'s JSON output: `gh pr checks` and `gh run view --log-failed` for Fix, `gh pr view`/`gh issue view` for Review and Start, one GraphQL query for unresolved threads for Address. Rebase uses the stack already in the item.
|
|
137
137
|
|
|
138
138
|
## Feedback
|
package/index.server.ts
CHANGED
|
@@ -22,6 +22,7 @@ import { FIXTURE } from "./server/gh";
|
|
|
22
22
|
import { checkCoverage, configStatus, myOrgs, setupStatus } from "./server/setup";
|
|
23
23
|
import { AttentionService, type Change } from "./server/service";
|
|
24
24
|
import type { Chip } from "./shared/attention";
|
|
25
|
+
import { readyProviders } from "./shared/providers";
|
|
25
26
|
import * as rpc from "./shared/rpc";
|
|
26
27
|
|
|
27
28
|
export default function contribute(server: PluginServerContext) {
|
|
@@ -71,6 +72,8 @@ export default function contribute(server: PluginServerContext) {
|
|
|
71
72
|
server.handle(rpc.itemDetails, ({ subject, target, checks }) => (FIXTURE ? Promise.resolve(fixtureDetails(subject, target, checks)) : itemDetails(subject, target, checks)));
|
|
72
73
|
server.handle(rpc.defaultBranch, async ({ repo }) => ({ name: FIXTURE ? "main" : await defaultBranch(repo) }));
|
|
73
74
|
server.handle(rpc.feedbackInfo, () => feedbackInfo());
|
|
75
|
+
// The server's Paseo connection expands the snapshot; the app's may not (getpaseo compact snapshots) [SES-06].
|
|
76
|
+
server.handle(rpc.readyProviders, async (_input, { paseo }) => ({ providers: readyProviders((await paseo.providers.snapshot()).entries) }));
|
|
74
77
|
server.handle(rpc.sessionContext, async ({ kind, target }) => ({ context: FIXTURE ? FIXTURE_CONTEXT : await sessionContext(kind, target) }));
|
|
75
78
|
|
|
76
79
|
return () => attention.stop();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@andrioid/paseo-attention-span",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.5",
|
|
4
4
|
"description": "For when your attention is spread thin: the GitHub issues and pull requests waiting on you, grouped by why, with one-tap Paseo sessions.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
package/requirements.yaml
CHANGED
|
@@ -78,6 +78,7 @@ functional:
|
|
|
78
78
|
SES-05: start sessions in my local checkout of the item's repository without configuring paths; so that new repositories work without setup.
|
|
79
79
|
SES-06: start sessions even when no agent profiles are configured; so that Attention Span works before I've set anything up.
|
|
80
80
|
SES-07: start a session on an issue in the repository its code lives in, chosen right there the first time; so that issues kept in a separate repository work without editing files.
|
|
81
|
+
SES-08: see sessions started outside Attention Span on the item of the pull request their workspace is linked to, or of the session whose worktree they share, as "Continue session"; so that I don't start duplicate work.
|
|
81
82
|
next_up:
|
|
82
83
|
As a developer, I can:
|
|
83
84
|
NXT-01: see open issues nobody is assigned to, apart from the work that needs me; so that I can get an idea of what to do next.
|
package/server/fixture.ts
CHANGED
|
@@ -238,6 +238,7 @@ export function fixture(now: Date): { data: SearchResult; details: Details } {
|
|
|
238
238
|
// Sessions the preview shows as started from items: working, needs me, failed, idle.
|
|
239
239
|
// Each sits in its action's line in the sheet. Issue 90 has two: an old one with no kind, which leads, and Rebase stack on its PR.
|
|
240
240
|
// #113 waits on CI while its Fix CI session works, though Fix CI isn't one of its actions any more.
|
|
241
|
+
// #120's was started outside Attention Span, in a workspace Paseo linked to the PR, so it has no kind [SES-08].
|
|
241
242
|
const agent = (id: string, itemKey: string, kind: SessionKind | undefined, status: string, minutesAgo: number, requiresAttention = false): AgentSummary => ({
|
|
242
243
|
id,
|
|
243
244
|
itemKey,
|
|
@@ -256,6 +257,7 @@ export const FIXTURE_AGENTS: AgentSummary[] = [
|
|
|
256
257
|
agent("agent-90", `${REPO}#90`, undefined, "idle", 120, true),
|
|
257
258
|
agent("agent-103", `${REPO}#103`, "rebase", "running", 6),
|
|
258
259
|
agent("agent-113", `${REPO}#113`, "fix", "running", 2),
|
|
260
|
+
agent("agent-120", `${REPO}#120`, undefined, "running", 3),
|
|
259
261
|
];
|
|
260
262
|
|
|
261
263
|
export const FIXTURE_CONTEXT = "Context from GitHub would go here (fixture mode).";
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
// Sessions started outside Attention Span, on the item their workspace belongs to [SES-08].
|
|
2
|
+
import type { AgentSummary } from "./attention";
|
|
3
|
+
|
|
4
|
+
// The parts of a Paseo agent entry this needs.
|
|
5
|
+
export interface PaseoAgentEntry {
|
|
6
|
+
id: string;
|
|
7
|
+
labels?: Record<string, string>;
|
|
8
|
+
archivedAt?: string | null;
|
|
9
|
+
status: string;
|
|
10
|
+
requiresAttention?: boolean;
|
|
11
|
+
title?: string | null;
|
|
12
|
+
workspaceId?: string | null;
|
|
13
|
+
updatedAt?: string | null;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
// The parts of a Paseo workspace entry this needs.
|
|
17
|
+
export interface PaseoWorkspaceEntry {
|
|
18
|
+
id: string;
|
|
19
|
+
workspaceKind: string;
|
|
20
|
+
archivingAt?: string | null;
|
|
21
|
+
githubRuntime?: { pullRequest?: { url: string; number?: number } | null } | null;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// Agents another agent started belong to that agent's session, not to the item.
|
|
25
|
+
const PARENT_AGENT_LABEL = "paseo.parent-agent-id";
|
|
26
|
+
|
|
27
|
+
// "owner/name#number" for a GitHub pull request URL.
|
|
28
|
+
export function pullRequestKey(url: string): string | null {
|
|
29
|
+
const match = /^https?:\/\/github\.com\/([^/]+\/[^/]+)\/pull\/(\d+)/i.exec(url);
|
|
30
|
+
return match ? `${match[1]}#${match[2]}` : null;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// Unlabelled agents, keyed to the PR Paseo linked their workspace to, or else to the item of the
|
|
34
|
+
// Attention Span session whose worktree they share. Main and local checkouts never pass an item on,
|
|
35
|
+
// and a worktree with sessions for two items passes on neither.
|
|
36
|
+
export function linkedSessions(labelled: AgentSummary[], agents: PaseoAgentEntry[], workspaces: PaseoWorkspaceEntry[]): AgentSummary[] {
|
|
37
|
+
const known = new Set(labelled.map((agent) => agent.id));
|
|
38
|
+
const items = new Map<string, Set<string>>();
|
|
39
|
+
for (const agent of labelled) {
|
|
40
|
+
if (!agent.workspaceId) continue;
|
|
41
|
+
const keys = items.get(agent.workspaceId) ?? new Set<string>();
|
|
42
|
+
keys.add(agent.itemKey.toLowerCase());
|
|
43
|
+
items.set(agent.workspaceId, keys);
|
|
44
|
+
}
|
|
45
|
+
const itemOf = new Map<string, string>();
|
|
46
|
+
for (const workspace of workspaces) {
|
|
47
|
+
if (workspace.archivingAt) continue;
|
|
48
|
+
const pr = workspace.githubRuntime?.pullRequest;
|
|
49
|
+
const linked = pr ? pullRequestKey(pr.url) : null;
|
|
50
|
+
const shared = workspace.workspaceKind === "worktree" ? items.get(workspace.id) : undefined;
|
|
51
|
+
const key = linked ?? (shared?.size === 1 ? [...shared][0] : null);
|
|
52
|
+
if (key) itemOf.set(workspace.id, key);
|
|
53
|
+
}
|
|
54
|
+
return agents.flatMap((agent) => {
|
|
55
|
+
const itemKey = agent.workspaceId ? itemOf.get(agent.workspaceId) : undefined;
|
|
56
|
+
if (!itemKey || known.has(agent.id) || agent.archivedAt || agent.labels?.[PARENT_AGENT_LABEL]) return [];
|
|
57
|
+
return [
|
|
58
|
+
{
|
|
59
|
+
id: agent.id,
|
|
60
|
+
itemKey,
|
|
61
|
+
status: agent.status,
|
|
62
|
+
requiresAttention: !!agent.requiresAttention,
|
|
63
|
+
title: agent.title ?? null,
|
|
64
|
+
workspaceId: agent.workspaceId ?? null,
|
|
65
|
+
lastActivityAt: agent.updatedAt ?? null,
|
|
66
|
+
},
|
|
67
|
+
];
|
|
68
|
+
});
|
|
69
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
// The agent providers a session can start with, and the agent config chosen from them [SES-01, SES-06].
|
|
2
|
+
|
|
3
|
+
// A provider that is ready and enabled on the host, with the model a session gets when nothing names one.
|
|
4
|
+
export interface ReadyProvider {
|
|
5
|
+
provider: string;
|
|
6
|
+
label: string;
|
|
7
|
+
defaultModel?: string;
|
|
8
|
+
defaultModeId?: string;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
// The parts of Paseo's provider snapshot entry this needs.
|
|
12
|
+
interface SnapshotEntry {
|
|
13
|
+
provider: string;
|
|
14
|
+
status: string;
|
|
15
|
+
enabled: boolean;
|
|
16
|
+
label?: string;
|
|
17
|
+
models?: { id: string; isDefault?: boolean }[];
|
|
18
|
+
defaultModeId?: string | null;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function readyProviders(entries: SnapshotEntry[]): ReadyProvider[] {
|
|
22
|
+
return entries
|
|
23
|
+
.filter((entry) => entry.status === "ready" && entry.enabled)
|
|
24
|
+
.map((entry) => ({
|
|
25
|
+
provider: entry.provider,
|
|
26
|
+
label: entry.label ?? entry.provider,
|
|
27
|
+
defaultModel: (entry.models ?? []).find((model) => model.isDefault)?.id ?? entry.models?.[0]?.id,
|
|
28
|
+
defaultModeId: entry.defaultModeId ?? undefined,
|
|
29
|
+
}));
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// The parts of a Paseo agent profile this needs.
|
|
33
|
+
interface Profile {
|
|
34
|
+
name: string;
|
|
35
|
+
provider: string;
|
|
36
|
+
model?: string | null;
|
|
37
|
+
modeId?: string | null;
|
|
38
|
+
thinkingOptionId?: string | null;
|
|
39
|
+
featureValues?: Record<string, unknown> | null;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export interface ChosenAgent<P extends Profile> {
|
|
43
|
+
label: string;
|
|
44
|
+
agent: { provider: string; modeId?: P["modeId"]; thinkingOptionId?: P["thinkingOptionId"]; featureValues?: P["featureValues"] };
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export const NO_PROVIDER = "No agent provider is ready on this host.";
|
|
48
|
+
|
|
49
|
+
// The profile with its provider's default model when it names none; without a profile, the first ready provider that has a model.
|
|
50
|
+
export function chooseAgent<P extends Profile>(profile: P | undefined, providers: ReadyProvider[]): ChosenAgent<P> {
|
|
51
|
+
if (profile) {
|
|
52
|
+
const model = profile.model ?? providers.find((entry) => entry.provider === profile.provider)?.defaultModel;
|
|
53
|
+
return {
|
|
54
|
+
label: profile.name,
|
|
55
|
+
agent: {
|
|
56
|
+
provider: model ? `${profile.provider}/${model}` : profile.provider,
|
|
57
|
+
modeId: profile.modeId,
|
|
58
|
+
thinkingOptionId: profile.thinkingOptionId,
|
|
59
|
+
featureValues: profile.featureValues,
|
|
60
|
+
},
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
const fallback = providers.find((entry) => entry.defaultModel);
|
|
64
|
+
if (!fallback) throw new Error(NO_PROVIDER);
|
|
65
|
+
return {
|
|
66
|
+
label: `Paseo default (${fallback.label})`,
|
|
67
|
+
agent: { provider: `${fallback.provider}/${fallback.defaultModel}`, modeId: fallback.defaultModeId },
|
|
68
|
+
};
|
|
69
|
+
}
|
package/shared/rpc.ts
CHANGED
|
@@ -4,6 +4,7 @@ import type { AttentionView, ItemDetails, ReviewerChoices, Target } from "./atte
|
|
|
4
4
|
import { SessionKind } from "./config";
|
|
5
5
|
import type { ConfigStatus, CoverageCheck, SetupStatus } from "./setup";
|
|
6
6
|
import type { FeedbackInfo } from "./feedback";
|
|
7
|
+
import type { ReadyProvider } from "./providers";
|
|
7
8
|
|
|
8
9
|
// Both sides are this plugin, so the types are checked by TypeScript, not repeated as schemas.
|
|
9
10
|
const view = z.custom<AttentionView>();
|
|
@@ -73,3 +74,5 @@ export const sessionContext = defineRpc({
|
|
|
73
74
|
|
|
74
75
|
// Where a feedback session runs and the version it reports [FB-01].
|
|
75
76
|
export const feedbackInfo = defineRpc({ name: "feedback.info", input: z.object({}), output: z.custom<FeedbackInfo>() });
|
|
77
|
+
// The host's ready providers, read by the plugin's server: the app's own snapshot can arrive compact, with no entries [SES-06].
|
|
78
|
+
export const readyProviders = defineRpc({ name: "providers.ready", input: z.object({}), output: z.custom<{ providers: ReadyProvider[] }>() });
|