@andrioid/paseo-attention-span 0.4.3 → 0.4.4
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/OVERVIEW.md +1 -0
- package/client/attention-screen.tsx +2 -0
- package/client/update.tsx +85 -0
- package/docs/architecture.md +13 -1
- package/index.server.ts +9 -0
- package/package.json +1 -1
- package/requirements.yaml +3 -0
- package/server/feedback.ts +8 -2
- package/server/service.ts +10 -0
- package/server/store.ts +2 -0
- package/server/update.ts +106 -0
- package/shared/rpc.ts +7 -0
- package/shared/update.ts +48 -0
package/OVERVIEW.md
CHANGED
|
@@ -135,6 +135,7 @@ Everything else lives in `~/.config/paseo-attention-span/config.json` on the dae
|
|
|
135
135
|
|
|
136
136
|
- **GitHub:** it reads your PRs, review requests, mentions and issues through `gh`, limited to the orgs and repos you've configured. By default it refreshes every 15 minutes, which uses about 7% of GitHub's hourly API allowance. I checked.
|
|
137
137
|
- **Local files:** a cache of what it shows, your dismissals and your Next up filter live in `~/.config/paseo-attention-span/state.json` on the daemon host. That's it.
|
|
138
|
+
- **Paseo:** about twice a day it asks Paseo whether a newer version of Attention Span is out, the same check `paseo plugin update --check` makes. Paseo looks it up in its plugin registry, on npm or on GitHub, depending on how you installed it. If there is one, the screen says so, with a link to what changed. Update installs it and restarts Attention Span. Nothing updates until you tap it.
|
|
138
139
|
- **Agent providers:** when a session starts, the item's context goes into the agent's prompt: descriptions, comments, review threads, failing CI logs. That prompt goes to whichever provider your agent profile uses, so it's worth knowing which one that is.
|
|
139
140
|
|
|
140
141
|
## What it doesn't do (yet)
|
|
@@ -20,6 +20,7 @@ import { ActionSheet, DetailLines, type SheetEntry } from "./sheet";
|
|
|
20
20
|
import { FeedbackAsk, FeedbackLine, type FeedbackScreen, FeedbackSheet } from "./feedback";
|
|
21
21
|
import { branchWorkspaces, type FetchProviders, findCheckout, githubProjects, itemAgents, listProfiles, noProjectMessage, resolveAgentConfig, startSession } from "./sessions";
|
|
22
22
|
import { SetupChecklist } from "./setup";
|
|
23
|
+
import { UpdateNotice } from "./update";
|
|
23
24
|
import { Avatar, Button, KeepStyles, Loading, Meta, SectionHeader, SpinningIcon, StylesProvider, TablerIcon, Toggle, useCopy, useHover, useStyles } from "./ui";
|
|
24
25
|
|
|
25
26
|
// The agent icon marks every action that starts an agent session; the rest act on GitHub right away [ATT-13].
|
|
@@ -397,6 +398,7 @@ function AttentionList({
|
|
|
397
398
|
</View>
|
|
398
399
|
</View>
|
|
399
400
|
{feed.error ? <Text style={styles.danger}>{feed.error}</Text> : null}
|
|
401
|
+
<UpdateNotice />
|
|
400
402
|
|
|
401
403
|
{undoable.map((row) => (
|
|
402
404
|
<View key={row.id} style={[styles.panel, styles.row, { justifyContent: "space-between" }]}>
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { openExternalUrl, useRpc } from "@getpaseo/plugin/client";
|
|
2
|
+
import { useToast } from "@getpaseo/plugin/client/ui";
|
|
3
|
+
import { useQuery, useQueryClient } from "@tanstack/react-query";
|
|
4
|
+
import { useState } from "react";
|
|
5
|
+
import { Platform, Text, View } from "react-native";
|
|
6
|
+
import * as rpc from "../shared/rpc";
|
|
7
|
+
import type { UpdateNotice as Notice } from "../shared/update";
|
|
8
|
+
import { Button, TablerIcon, useCopy, useStyles } from "./ui";
|
|
9
|
+
|
|
10
|
+
const UPDATE_QUERY_KEY = ["attention-span", "update"] as const;
|
|
11
|
+
// The server caches Paseo's answer for 12 hours, so asking it often costs nothing.
|
|
12
|
+
const EVERY_MS = 60 * 60 * 1000;
|
|
13
|
+
// While an update runs: soon enough to show a failure, and the restart's result.
|
|
14
|
+
const UPDATING_MS = 2000;
|
|
15
|
+
const MONO = Platform.select({ ios: "Menlo", default: "monospace" });
|
|
16
|
+
const FROM: Record<Notice["source"], string> = { registry: "the Paseo plugin registry", npm: "npm", git: "GitHub" };
|
|
17
|
+
|
|
18
|
+
// A newer version, what changed, Update, and Not now until the next one [UPD-01].
|
|
19
|
+
// Update runs `paseo plugin update` on the daemon, which installs it and restarts the plugin; the app then loads the new
|
|
20
|
+
// version. Once the restart is done, the check says it's current and the notice goes.
|
|
21
|
+
export function UpdateNotice() {
|
|
22
|
+
const styles = useStyles();
|
|
23
|
+
const toast = useToast();
|
|
24
|
+
const copy = useCopy();
|
|
25
|
+
const queryClient = useQueryClient();
|
|
26
|
+
const check = useRpc(rpc.checkUpdate);
|
|
27
|
+
const apply = useRpc(rpc.applyUpdate);
|
|
28
|
+
const skip = useRpc(rpc.skipUpdate);
|
|
29
|
+
const [updating, setUpdating] = useState(false);
|
|
30
|
+
const { data: notice } = useQuery({
|
|
31
|
+
queryKey: UPDATE_QUERY_KEY,
|
|
32
|
+
// While the plugin restarts, its server isn't there to answer: keep what's on screen.
|
|
33
|
+
queryFn: () => check({}).catch((error: Error) => (updating ? (queryClient.getQueryData<Notice | null>(UPDATE_QUERY_KEY) ?? null) : Promise.reject(error))),
|
|
34
|
+
staleTime: updating ? 0 : EVERY_MS,
|
|
35
|
+
refetchInterval: (query) => (updating && !query.state.data?.error ? UPDATING_MS : EVERY_MS),
|
|
36
|
+
});
|
|
37
|
+
if (!notice) return null;
|
|
38
|
+
const busy = updating && !notice.error;
|
|
39
|
+
|
|
40
|
+
const update = async () => {
|
|
41
|
+
setUpdating(true);
|
|
42
|
+
try {
|
|
43
|
+
await apply({ latest: notice.latest });
|
|
44
|
+
await queryClient.invalidateQueries({ queryKey: UPDATE_QUERY_KEY });
|
|
45
|
+
} catch (error) {
|
|
46
|
+
setUpdating(false);
|
|
47
|
+
toast.error(`Updating failed: ${(error as Error).message}`);
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
const notNow = () => {
|
|
52
|
+
queryClient.setQueryData(UPDATE_QUERY_KEY, null);
|
|
53
|
+
skip({ latest: notice.latest }).catch((error: Error) => toast.error(`Couldn't put it off: ${error.message}`));
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
return (
|
|
57
|
+
<View style={styles.panel} accessibilityRole="summary" accessibilityLiveRegion="polite">
|
|
58
|
+
<View style={styles.row}>
|
|
59
|
+
<TablerIcon name="update" size={16} color={styles.action} />
|
|
60
|
+
<Text style={styles.title}>Attention Span {notice.latest} is out</Text>
|
|
61
|
+
</View>
|
|
62
|
+
{notice.error ? (
|
|
63
|
+
<>
|
|
64
|
+
<Text style={styles.danger}>Updating failed: {notice.error}</Text>
|
|
65
|
+
<Text style={styles.muted}>To see more, run this where Paseo's daemon runs:</Text>
|
|
66
|
+
<Text selectable style={[styles.text, { fontFamily: MONO, fontSize: 13 }]}>
|
|
67
|
+
{notice.command}
|
|
68
|
+
</Text>
|
|
69
|
+
</>
|
|
70
|
+
) : (
|
|
71
|
+
<Text style={styles.muted}>
|
|
72
|
+
{busy
|
|
73
|
+
? `Installing it from ${FROM[notice.source]}. Attention Span restarts when it's done.`
|
|
74
|
+
: `You have ${notice.current}. Update installs it from ${FROM[notice.source]} and restarts Attention Span, which takes a few seconds.`}
|
|
75
|
+
</Text>
|
|
76
|
+
)}
|
|
77
|
+
<View style={styles.wrap}>
|
|
78
|
+
<Button label={busy ? "Updating…" : notice.error ? "Try again" : "Update"} icon="update" variant="solid" busy={busy} onPress={() => void update()} />
|
|
79
|
+
{notice.error ? <Button label="Copy command" icon="copy" onPress={() => copy(notice.command, "Copied the update command")} /> : null}
|
|
80
|
+
<Button label="What's new" icon="github" onPress={() => void openExternalUrl(notice.notes)} />
|
|
81
|
+
{busy ? null : <Button label="Not now" variant="ghost" accessibilityLabel={`Not now: hide until a version newer than ${notice.latest}`} onPress={notNow} />}
|
|
82
|
+
</View>
|
|
83
|
+
</View>
|
|
84
|
+
);
|
|
85
|
+
}
|
package/docs/architecture.md
CHANGED
|
@@ -40,7 +40,7 @@ flowchart LR
|
|
|
40
40
|
- optional merge method per repo [PRS-04]
|
|
41
41
|
- `codeRepos`: where an issue repo's code lives, for issues kept in their own repo [SES-07]
|
|
42
42
|
- `nextUp`: where unclaimed issues come from (`mine`, `orgs`, `repos`, set in Settings) and the org issue fields for priority, effort and scope [NXT-04]
|
|
43
|
-
- `state.json`: dismissals [ATT-08], the scopes and sources ticked in Next up's filter [NXT-03, NXT-09], my Paseo projects' GitHub repos [NXT-08] and the last fetch of each feed, so the screen shows instantly after a restart [PRIV-01].
|
|
43
|
+
- `state.json`: dismissals [ATT-08], the scopes and sources ticked in Next up's filter [NXT-03, NXT-09], my Paseo projects' GitHub repos [NXT-08], the update put off with Not now [UPD-01] and the last fetch of each feed, so the screen shows instantly after a restart [PRIV-01].
|
|
44
44
|
|
|
45
45
|
## Tabs
|
|
46
46
|
|
|
@@ -148,6 +148,18 @@ Each session gets its own workspace on an empty scratch directory, so archiving
|
|
|
148
148
|
|
|
149
149
|
The agent asks one question at a time from its kind's checklist, and checks the report against the requirements and docs, `config.json` and `state.json`, and open issues and discussions. A match gets its link and nothing else. It files an issue if a maintainer could finish and close it, otherwise a discussion in Q&A or Ideas, and says which and why. Posts are short up front, with the rest in collapsed `<details>` blocks, in English, in the user's voice, with nothing from their own setup they didn't write. It posts only after Post it in its question tool, or the reply "post" [SAFE-01], then archives its workspace (`archive_workspace`, or `archive_agent` without it). The client watches workspace updates, remembers the scratch ones by their directory, and opens Attention Span when one is removed, instead of leaving "workspace unavailable" on screen. The prompts are built in: `config.json` can't replace them, since they carry those rules.
|
|
150
150
|
|
|
151
|
+
## Updates
|
|
152
|
+
|
|
153
|
+
A notice above the list says when a newer version is out, and Update installs it [UPD-01].
|
|
154
|
+
|
|
155
|
+
**Check.** Paseo has no update signal for plugins and doesn't tell a plugin its version. So the server asks Paseo's CLI the same thing `paseo plugin update` would: `$PASEO_CLI plugin update <id> --check --json --home $PASEO_HOME`. Paseo gives every plugin subprocess both variables, so this reaches the daemon the plugin runs in. The ID is the one Paseo's `config.json` lists this plugin under, found as Feedback finds the source. The answer covers each kind of install: a registry install's reviewed pin, npm's `latest`, or a Git remote's HEAD. Directory installs report `local` and get no notice, since Paseo never updates them. The server caches the answer for 12 hours, since the registry picks up npm releases twice a day, and retries a failed check after an hour.
|
|
156
|
+
|
|
157
|
+
**Notice.** It shows the version, or the short commit for Git, where it comes from, and What's new: GitHub Releases, or Paseo's compare link for Git. Not now saves that version in `state.json` and hides the notice until a newer one comes out.
|
|
158
|
+
|
|
159
|
+
**Update** is a tap on the version shown [SAFE-01]. The server runs `paseo plugin update <id>` pinned to it where Paseo allows: `--version` for npm and `--ref <commit>` for Git. A registry install accepts only `--yes`, which takes the reviewed pin. Paseo installs it and restarts the plugin itself, so no separate reload is needed. The restart ends the server process, so the CLI runs detached and outlives it. The app loads the new client on its own, with no page reload. While it runs, the notice polls every 2 seconds. Once the new version is running, the check says it's current and the notice goes. If the CLI fails, the server, still running, keeps the reason, and the notice shows it with Try again and the command to run by hand.
|
|
160
|
+
|
|
161
|
+
In previews, `PASEO_ATTENTION_SPAN_FIXTURE_UPDATE=1` makes up an update from 0.4.3 to 0.5.0, and Update fails with "Previews don't update."
|
|
162
|
+
|
|
151
163
|
## GitHub requests
|
|
152
164
|
|
|
153
165
|
Light on GitHub's API [GH-01], and quick when I press ⟳. Attention Span has two feeds, each with its own cache, schedule and error:
|
package/index.server.ts
CHANGED
|
@@ -21,12 +21,14 @@ import { FIXTURE_CONTEXT, fixtureDetails, fixtureReviewerChoices } from "./serve
|
|
|
21
21
|
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
|
+
import { UpdateCheck } from "./server/update";
|
|
24
25
|
import type { Chip } from "./shared/attention";
|
|
25
26
|
import { readyProviders } from "./shared/providers";
|
|
26
27
|
import * as rpc from "./shared/rpc";
|
|
27
28
|
|
|
28
29
|
export default function contribute(server: PluginServerContext) {
|
|
29
30
|
const attention = new AttentionService();
|
|
31
|
+
const updates = new UpdateCheck();
|
|
30
32
|
const started = attention.start().catch((error) => console.error("Attention Span failed to start:", error));
|
|
31
33
|
const ready = <T>(work: () => Promise<T>) => started.then(work);
|
|
32
34
|
|
|
@@ -72,6 +74,13 @@ export default function contribute(server: PluginServerContext) {
|
|
|
72
74
|
server.handle(rpc.itemDetails, ({ subject, target, checks }) => (FIXTURE ? Promise.resolve(fixtureDetails(subject, target, checks)) : itemDetails(subject, target, checks)));
|
|
73
75
|
server.handle(rpc.defaultBranch, async ({ repo }) => ({ name: FIXTURE ? "main" : await defaultBranch(repo) }));
|
|
74
76
|
server.handle(rpc.feedbackInfo, () => feedbackInfo());
|
|
77
|
+
// [UPD-01]
|
|
78
|
+
server.handle(rpc.checkUpdate, () => ready(async () => {
|
|
79
|
+
const notice = await updates.get();
|
|
80
|
+
return notice && notice.latest !== attention.skippedUpdate ? notice : null;
|
|
81
|
+
}));
|
|
82
|
+
server.handle(rpc.applyUpdate, ({ latest }) => updates.apply(latest).then(() => ({ ok: true as const })));
|
|
83
|
+
server.handle(rpc.skipUpdate, ({ latest }) => ready(() => attention.skipUpdate(latest)).then(() => ({ ok: true as const })));
|
|
75
84
|
// The server's Paseo connection expands the snapshot; the app's may not (getpaseo compact snapshots) [SES-06].
|
|
76
85
|
server.handle(rpc.readyProviders, async (_input, { paseo }) => ({ providers: readyProviders((await paseo.providers.snapshot()).entries) }));
|
|
77
86
|
server.handle(rpc.sessionContext, async ({ kind, target }) => ({ context: FIXTURE ? FIXTURE_CONTEXT : await sessionContext(kind, target) }));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@andrioid/paseo-attention-span",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.4",
|
|
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
|
@@ -107,6 +107,9 @@ functional:
|
|
|
107
107
|
feedback:
|
|
108
108
|
As a developer, I can:
|
|
109
109
|
FB-01: tell the Attention Span project what to improve from the bottom of any tab, picking a problem, an idea or that I like it, with an agent that asks until it's clear, checks it against what's planned and already reported, and files it as an issue or a discussion, saying which and why, only once I approve the draft; so that feedback costs a minute and lands where it can be acted on or talked through.
|
|
110
|
+
updates:
|
|
111
|
+
As a developer, I can:
|
|
112
|
+
UPD-01: see when a newer version of Attention Span is out than the one I have, with what changed, and update to it with one tap or put it off until the next one; so that I get fixes without checking for them or going to a terminal.
|
|
110
113
|
|
|
111
114
|
non_functional:
|
|
112
115
|
github_usage:
|
package/server/feedback.ts
CHANGED
|
@@ -16,13 +16,19 @@ export async function feedbackInfo(): Promise<FeedbackInfo> {
|
|
|
16
16
|
|
|
17
17
|
// Paseo evaluates the server as a bundle, so it has no file location of its own (import.meta.url is undefined).
|
|
18
18
|
// Paseo's config.json records where each plugin's source is: take this plugin's, by its manifest's ID.
|
|
19
|
-
export function pluginDir(paseoHome
|
|
19
|
+
export function pluginDir(paseoHome?: string): string | null {
|
|
20
|
+
return ourInstall(paseoHome)?.path ?? null;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// The runtime ID this plugin is installed under, and its source. The update check names the ID [UPD-01].
|
|
24
|
+
export function ourInstall(paseoHome = process.env.PASEO_HOME || join(homedir(), ".paseo")): { id: string; path: string } | null {
|
|
20
25
|
try {
|
|
21
26
|
const { plugins = {} } = JSON.parse(readFileSync(join(paseoHome, "config.json"), "utf8")) as { plugins?: Record<string, { path?: string }> };
|
|
22
27
|
const ours = Object.entries(plugins)
|
|
23
28
|
.filter(([, source]) => source.path && manifestId(source.path) === PLUGIN_ID)
|
|
24
29
|
.sort(([a], [b]) => Number(b === PLUGIN_ID) - Number(a === PLUGIN_ID));
|
|
25
|
-
|
|
30
|
+
const [id, source] = ours[0] ?? [];
|
|
31
|
+
return id && source?.path ? { id, path: source.path } : null;
|
|
26
32
|
} catch {
|
|
27
33
|
return null;
|
|
28
34
|
}
|
package/server/service.ts
CHANGED
|
@@ -123,6 +123,16 @@ export class AttentionService {
|
|
|
123
123
|
await this.save();
|
|
124
124
|
}
|
|
125
125
|
|
|
126
|
+
// "Not now" on an update notice holds until a newer one [UPD-01].
|
|
127
|
+
get skippedUpdate(): string | null {
|
|
128
|
+
return this.state.skippedUpdate;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
async skipUpdate(latest: string): Promise<void> {
|
|
132
|
+
this.state.skippedUpdate = latest;
|
|
133
|
+
await this.save();
|
|
134
|
+
}
|
|
135
|
+
|
|
126
136
|
// Who reviewed or was asked on my PRs in a repo, from the last fetch, and who I am [PRS-12].
|
|
127
137
|
reviewers(repo: string): { recent: Reviewer[]; login: string | null } {
|
|
128
138
|
const live = this.state.live?.attention;
|
package/server/store.ts
CHANGED
|
@@ -23,6 +23,8 @@ export const State = z.object({
|
|
|
23
23
|
scopes: z.array(z.string()).default([]),
|
|
24
24
|
// Sources ticked in Next up's filter; none means all [NXT-09].
|
|
25
25
|
sources: z.array(z.string()).default([]),
|
|
26
|
+
// The update notice put off with Not now, by the version it offered [UPD-01].
|
|
27
|
+
skippedUpdate: z.string().nullable().default(null).catch(null),
|
|
26
28
|
// My Paseo projects' GitHub repos when last listed, for refreshes before the app has connected [NXT-08].
|
|
27
29
|
projectRepos: z.array(z.string()).default([]),
|
|
28
30
|
// The last fetch of each feed. A cache from an older version is dropped rather than shown wrong.
|
package/server/update.ts
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { execFile, spawn } from "node:child_process";
|
|
2
|
+
import { promisify } from "node:util";
|
|
3
|
+
import { type UpdateNotice, updateNotice } from "../shared/update";
|
|
4
|
+
import { ourInstall } from "./feedback";
|
|
5
|
+
import { FIXTURE } from "./gh";
|
|
6
|
+
|
|
7
|
+
const run = promisify(execFile);
|
|
8
|
+
|
|
9
|
+
// Paseo's registry checks npm twice a day, so a release reaches its listing within about 12 hours [UPD-01].
|
|
10
|
+
const EVERY_MS = 12 * 60 * 60 * 1000;
|
|
11
|
+
// A check that failed (offline, an older Paseo) is tried again sooner.
|
|
12
|
+
const RETRY_MS = 60 * 60 * 1000;
|
|
13
|
+
|
|
14
|
+
// Previews have nothing to update; PASEO_ATTENTION_SPAN_FIXTURE_UPDATE=1 makes one up to show the notice.
|
|
15
|
+
const FIXTURE_UPDATE: UpdateNotice = {
|
|
16
|
+
id: "attention-span",
|
|
17
|
+
current: "0.4.3",
|
|
18
|
+
latest: "0.5.0",
|
|
19
|
+
source: "registry",
|
|
20
|
+
args: ["--yes"],
|
|
21
|
+
command: "paseo plugin update attention-span",
|
|
22
|
+
notes: "https://github.com/andrioid/paseo-attention-span/releases",
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
// Asks Paseo itself, so the answer is what `paseo plugin update` would install: a registry install's
|
|
26
|
+
// reviewed pin, npm's latest, or a Git remote's HEAD. Directory installs are never updated, so they say nothing.
|
|
27
|
+
export class UpdateCheck {
|
|
28
|
+
private last: { at: number; ttl: number; notice: UpdateNotice | null } | null = null;
|
|
29
|
+
private inFlight: Promise<UpdateNotice | null> | null = null;
|
|
30
|
+
// Why the last Update failed. A successful one restarts this process, so nothing needs remembering then.
|
|
31
|
+
private failed: { latest: string; error: string } | null = null;
|
|
32
|
+
|
|
33
|
+
async get(): Promise<UpdateNotice | null> {
|
|
34
|
+
const notice = await this.cached();
|
|
35
|
+
return notice && this.failed?.latest === notice.latest ? { ...notice, error: this.failed.error } : notice;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
private cached(): Promise<UpdateNotice | null> {
|
|
39
|
+
if (this.last && Date.now() - this.last.at < this.last.ttl) return Promise.resolve(this.last.notice);
|
|
40
|
+
this.inFlight ??= check()
|
|
41
|
+
.then(
|
|
42
|
+
(notice) => (this.last = { at: Date.now(), ttl: EVERY_MS, notice }),
|
|
43
|
+
(error) => {
|
|
44
|
+
console.error("Checking for an Attention Span update failed:", (error as Error).message);
|
|
45
|
+
return (this.last = { at: Date.now(), ttl: RETRY_MS, notice: null });
|
|
46
|
+
},
|
|
47
|
+
)
|
|
48
|
+
.then((last) => last.notice)
|
|
49
|
+
.finally(() => (this.inFlight = null));
|
|
50
|
+
return this.inFlight;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// Update, from an explicit tap on the version it names [SAFE-01]. `paseo plugin update` installs it and
|
|
54
|
+
// restarts the plugin, which ends this process, so it runs detached and outlives it. Until then, a failure
|
|
55
|
+
// is kept for the notice to show.
|
|
56
|
+
async apply(latest: string): Promise<void> {
|
|
57
|
+
const notice = await this.cached();
|
|
58
|
+
if (!notice || notice.latest !== latest) throw new Error(`${latest} isn't the update on offer any more. Check again.`);
|
|
59
|
+
this.failed = null;
|
|
60
|
+
// Previews show how a failed update looks.
|
|
61
|
+
if (FIXTURE) return void (this.failed = { latest, error: "Previews don't update." });
|
|
62
|
+
const cli = process.env.PASEO_CLI || "paseo";
|
|
63
|
+
const child = spawn(cli, ["plugin", "update", notice.id, ...notice.args, "--json", ...home()], { detached: true, stdio: ["ignore", "pipe", "pipe"] });
|
|
64
|
+
let output = "";
|
|
65
|
+
child.stdout.on("data", (chunk) => (output += chunk));
|
|
66
|
+
child.stderr.on("data", (chunk) => (output += chunk));
|
|
67
|
+
child.on("error", (error) => (this.failed = { latest, error: error.message }));
|
|
68
|
+
child.on("close", (code) => {
|
|
69
|
+
const error = failure(notice.id, output, code);
|
|
70
|
+
if (error) {
|
|
71
|
+
console.error("Updating Attention Span failed:", error);
|
|
72
|
+
this.failed = { latest, error };
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
child.unref();
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
async function check(): Promise<UpdateNotice | null> {
|
|
80
|
+
if (FIXTURE) return process.env.PASEO_ATTENTION_SPAN_FIXTURE_UPDATE === "1" ? FIXTURE_UPDATE : null;
|
|
81
|
+
const ours = ourInstall();
|
|
82
|
+
if (!ours) return null;
|
|
83
|
+
// Paseo gives its plugins the path of its CLI and its home, so this asks the daemon the plugin runs in.
|
|
84
|
+
const cli = process.env.PASEO_CLI || "paseo";
|
|
85
|
+
try {
|
|
86
|
+
const { stdout } = await run(cli, ["plugin", "update", ours.id, "--check", "--json", ...home()], { timeout: 60_000 });
|
|
87
|
+
return updateNotice(ours.id, JSON.parse(stdout));
|
|
88
|
+
} catch (error) {
|
|
89
|
+
// An "error" outcome exits 1 but still prints its JSON.
|
|
90
|
+
throw new Error(failure(ours.id, (error as { stdout?: string }).stdout ?? "", 1) ?? (error as Error).message);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
const home = () => (process.env.PASEO_HOME ? ["--home", process.env.PASEO_HOME] : []);
|
|
95
|
+
|
|
96
|
+
// The CLI's reason for this plugin, from its JSON, or its output; null when it worked.
|
|
97
|
+
export function failure(id: string, output: string, code: number | null): string | null {
|
|
98
|
+
try {
|
|
99
|
+
const entry = (JSON.parse(output) as { id?: string; outcome?: string; error?: string }[]).find((candidate) => candidate.id === id);
|
|
100
|
+
if (entry?.outcome === "error") return entry.error ?? "paseo plugin update failed";
|
|
101
|
+
if (entry && code === 0) return null;
|
|
102
|
+
} catch {
|
|
103
|
+
// Not JSON: an older CLI, or it failed before it got that far.
|
|
104
|
+
}
|
|
105
|
+
return code === 0 ? null : output.trim().split("\n").pop() || `paseo plugin update exited with ${code}`;
|
|
106
|
+
}
|
package/shared/rpc.ts
CHANGED
|
@@ -5,6 +5,7 @@ import { SessionKind } from "./config";
|
|
|
5
5
|
import type { ConfigStatus, CoverageCheck, SetupStatus } from "./setup";
|
|
6
6
|
import type { FeedbackInfo } from "./feedback";
|
|
7
7
|
import type { ReadyProvider } from "./providers";
|
|
8
|
+
import type { UpdateNotice } from "./update";
|
|
8
9
|
|
|
9
10
|
// Both sides are this plugin, so the types are checked by TypeScript, not repeated as schemas.
|
|
10
11
|
const view = z.custom<AttentionView>();
|
|
@@ -76,3 +77,9 @@ export const sessionContext = defineRpc({
|
|
|
76
77
|
export const feedbackInfo = defineRpc({ name: "feedback.info", input: z.object({}), output: z.custom<FeedbackInfo>() });
|
|
77
78
|
// 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
79
|
export const readyProviders = defineRpc({ name: "providers.ready", input: z.object({}), output: z.custom<{ providers: ReadyProvider[] }>() });
|
|
80
|
+
|
|
81
|
+
// A newer Attention Span, by Paseo's own update check; null when there's none or it was put off [UPD-01].
|
|
82
|
+
export const checkUpdate = defineRpc({ name: "update.check", input: z.object({}), output: z.custom<UpdateNotice | null>() });
|
|
83
|
+
// Starts `paseo plugin update` for the version on offer; it restarts the plugin when it's done.
|
|
84
|
+
export const applyUpdate = defineRpc({ name: "update.apply", input: z.object({ latest: z.string() }), output: done });
|
|
85
|
+
export const skipUpdate = defineRpc({ name: "update.skip", input: z.object({ latest: z.string() }), output: done });
|
package/shared/update.ts
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { FEEDBACK_REPO } from "./feedback";
|
|
2
|
+
|
|
3
|
+
// A newer Attention Span than the one installed, as Paseo's own update check sees it [UPD-01].
|
|
4
|
+
export interface UpdateNotice {
|
|
5
|
+
// The runtime ID it's installed under, which the command names.
|
|
6
|
+
id: string;
|
|
7
|
+
// A version for npm and registry installs, a short commit for Git ones.
|
|
8
|
+
current: string;
|
|
9
|
+
latest: string;
|
|
10
|
+
// Where it comes from, said next to Update.
|
|
11
|
+
source: "registry" | "npm" | "git";
|
|
12
|
+
// What Update adds to `paseo plugin update <id>`, pinned to what was offered where Paseo allows it.
|
|
13
|
+
args: string[];
|
|
14
|
+
// To run by hand when Update fails.
|
|
15
|
+
command: string;
|
|
16
|
+
// Where to read what changed.
|
|
17
|
+
notes: string;
|
|
18
|
+
// Why the last Update failed, if it did.
|
|
19
|
+
error?: string;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// The entry for one plugin in `paseo plugin update <id> --check --json`. Only what's read here.
|
|
23
|
+
interface CheckEntry {
|
|
24
|
+
id?: string;
|
|
25
|
+
outcome?: string;
|
|
26
|
+
current?: { currentRevision?: string; identity?: { registry?: unknown } };
|
|
27
|
+
target?: { kind?: string; version?: string; commit?: string };
|
|
28
|
+
links?: string[];
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// Only "update" is news; "current", "local" (a directory install, which Paseo never updates) and "error" aren't.
|
|
32
|
+
export function updateNotice(id: string, checked: unknown): UpdateNotice | null {
|
|
33
|
+
const entries = (Array.isArray(checked) ? checked : []) as CheckEntry[];
|
|
34
|
+
const entry = entries.find((candidate) => candidate?.id === id);
|
|
35
|
+
if (entry?.outcome !== "update") return null;
|
|
36
|
+
const current = entry.current?.currentRevision;
|
|
37
|
+
const latest = entry.target?.kind === "git" ? entry.target.commit : entry.target?.version;
|
|
38
|
+
if (!current || !latest || current === latest) return null;
|
|
39
|
+
const git = entry.target?.kind === "git";
|
|
40
|
+
const source = git ? "git" : entry.current?.identity?.registry ? "registry" : "npm";
|
|
41
|
+
// A registry install takes only its reviewed pin, so it can't be named; npm and Git can, so a newer one can't slip in.
|
|
42
|
+
const args = source === "registry" ? ["--yes"] : git ? ["--ref", latest] : ["--version", latest];
|
|
43
|
+
// A Git install moves by commit, so Paseo's compare link is what changed; a release has notes on GitHub.
|
|
44
|
+
const compare = git ? entry.links?.find((link) => link.includes("/compare/")) : undefined;
|
|
45
|
+
return { id, current: short(current), latest: short(latest), source, args, command: `paseo plugin update ${id}`, notes: compare ?? `https://github.com/${FEEDBACK_REPO}/releases` };
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const short = (revision: string) => (/^[0-9a-f]{40}$/.test(revision) ? revision.slice(0, 7) : revision);
|