@andrioid/paseo-attention-span 0.3.0 → 0.3.1

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.
@@ -1,4 +1,4 @@
1
- import { openExternalUrl, usePaseo, useRpc } from "@getpaseo/plugin/client";
1
+ import { openExternalUrl, type PluginClientContext, usePaseo, useRpc } from "@getpaseo/plugin/client";
2
2
  import { Modal, TextInput, useToast } from "@getpaseo/plugin/client/ui";
3
3
  import { useState } from "react";
4
4
  import { Pressable, Text, View } from "react-native";
@@ -97,11 +97,11 @@ export function FeedbackAsk({
97
97
  setStarting(true);
98
98
  try {
99
99
  const info = await fetchInfo({});
100
- const prompt = feedbackPrompt(kind, { ...screen, message, dir: info.hasSource ? info.cwd : null, version: info.version });
100
+ const prompt = feedbackPrompt(kind, { ...screen, message, dir: info.source, version: info.version });
101
101
  const { agent } = await resolveAgentConfig(paseo, "start", config);
102
102
  const workspace = await paseo.workspaces.open({ cwd: info.cwd });
103
103
  const created = await workspace.agents.create({
104
- config: { ...agent, modeId: (await readOnlyMode(paseo, agent.provider)) ?? agent.modeId },
104
+ config: agent,
105
105
  title: `Feedback: ${KINDS[kind].label}`,
106
106
  prompt,
107
107
  labels: { [LABEL]: "1", [ITEM_LABEL]: feedbackItemKey(kind), [KIND_LABEL]: `feedback-${kind}` },
@@ -142,10 +142,32 @@ export function FeedbackAsk({
142
142
  );
143
143
  }
144
144
 
145
- // The provider's plan or read-only mode, where it has one, so the session reads but doesn't change files.
146
- async function readOnlyMode(paseo: ReturnType<typeof usePaseo>, provider: string): Promise<string | undefined> {
147
- const name = provider.split("/")[0];
148
- const snapshot = await paseo.providers.snapshot();
149
- const modes = snapshot.entries.find((entry) => entry.provider === name)?.modes ?? [];
150
- return modes.find((mode) => /plan|read.?only/i.test(`${mode.id} ${mode.label}`))?.id;
145
+ const isFeedbackDir = (dir: string | undefined) => !!dir && /attention-span-feedback-[^/]*$/.test(dir);
146
+
147
+ // Once a feedback session posts, it archives its scratch workspace; that would leave "workspace unavailable"
148
+ // on screen, so open Attention Span instead [FB-01]. A removed workspace comes with only its ID,
149
+ // so the feedback ones are remembered as they're seen.
150
+ export function returnFromFeedback(client: Pick<PluginClientContext, "paseo" | "openScreen">): () => void {
151
+ const feedback = new Set<string>();
152
+ const remember = (workspace: { id: string; workspaceDirectory?: string; projectRootPath?: string }) => {
153
+ if (isFeedbackDir(workspace.workspaceDirectory ?? workspace.projectRootPath)) feedback.add(workspace.id);
154
+ };
155
+ let stop = () => {};
156
+ try {
157
+ stop = client.paseo.workspaces.subscribe((update) => {
158
+ if (update.kind === "upsert") remember(update.workspace);
159
+ else if (update.kind === "remove" && feedback.delete(update.id)) client.openScreen({ screenId: "attention" });
160
+ });
161
+ } catch {
162
+ // An older host without workspace updates: the screen just stays where it is.
163
+ }
164
+ // Listing with a subscription is what makes the daemon stream workspace updates.
165
+ const listing = Promise.resolve().then(() => client.paseo.workspaces.list({ subscribe: {} })).then(
166
+ (result) => (result.entries.forEach(remember), result.subscription),
167
+ () => null,
168
+ );
169
+ return () => {
170
+ stop();
171
+ void listing.then((subscription) => subscription?.release());
172
+ };
151
173
  }
@@ -142,9 +142,9 @@ While an item has an open session, its main action is **Open session** instead,
142
142
  - **Something's wrong…** and **I have an idea…** *(agent)* ask for the first words in the sheet, then start a session with them in the prompt (`shared/feedback.ts`), so the agent's first message is already a follow-up. While one runs, its line becomes Continue, like an item's [SES-03]; the session is labelled with the item key `feedback:problem` or `feedback:idea`.
143
143
  - **I'll star it on GitHub** opens the repo on GitHub. No agent.
144
144
 
145
- The session runs read-only in the plugin's own installed source, found from the server's location, which is why the npm package ships `requirements.yaml` and this file. It starts in the provider's plan or read-only mode where there is one, with the default profile. Without the source it runs in the home directory and reads the repo through `gh api`. The prompt carries the version (`package.json`, or the commit in a checkout), phone or desktop, theme, tab and a failed refresh's error.
145
+ Each session gets its own workspace on an empty scratch directory, so archiving that workspace closes it cleanly and nothing is written into the plugin. The agent reads the plugin's installed source by its path, which is why the npm package ships `requirements.yaml` and this file. Paseo evaluates the server as a bundle with no file location, so the source is the path Paseo's `config.json` records for the plugin whose manifest ID is `attention-span`, preferring the install under that ID. It uses the default profile and its mode, like other sessions: a plan mode would ask before nearly every step. Without the source it reads the repo through `gh api`. The prompt carries the version (`package.json`, or the commit in a checkout), phone or desktop, theme, tab and a failed refresh's error.
146
146
 
147
- 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 itself. The prompts are built in: `config.json` can't replace them, since they carry those rules.
147
+ 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.
148
148
 
149
149
  ## GitHub requests
150
150
 
package/index.client.tsx CHANGED
@@ -4,6 +4,7 @@ import { Text, View } from "react-native";
4
4
  import { AttentionScreen } from "./client/attention-screen";
5
5
  import { CoverageSettings } from "./client/coverage-settings";
6
6
  import { useAttention } from "./client/data";
7
+ import { returnFromFeedback } from "./client/feedback";
7
8
  import { useHostLabel } from "./client/host";
8
9
  import { ICONS } from "./client/icons";
9
10
 
@@ -42,5 +43,5 @@ export default function contribute(client: PluginClientContext) {
42
43
  const Screen = (props: PluginScreenProps) => <AttentionScreen {...props} openSettings={() => client.openSettings("coverage")} />;
43
44
  client.addScreen({ id: "attention", title: "Attention Span", Component: Screen });
44
45
  client.addSidebarHeaderItem({ id: "attention", title: "Attention Span", Component: SidebarItem });
45
- return () => {};
46
+ return returnFromFeedback(client);
46
47
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@andrioid/paseo-attention-span",
3
- "version": "0.3.0",
3
+ "version": "0.3.1",
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": {
@@ -1,26 +1,41 @@
1
1
  import { execFile } from "node:child_process";
2
- import { existsSync, readFileSync } from "node:fs";
3
- import { homedir } from "node:os";
4
- import { dirname, join } from "node:path";
5
- import { fileURLToPath } from "node:url";
2
+ import { mkdtempSync, readFileSync } from "node:fs";
3
+ import { homedir, tmpdir } from "node:os";
4
+ import { join } from "node:path";
6
5
  import { promisify } from "node:util";
7
6
  import type { FeedbackInfo } from "../shared/feedback";
8
7
 
9
8
  const run = promisify(execFile);
10
9
 
11
- // Where this plugin is installed and which version it is [FB-01].
10
+ // A scratch directory for the session, where this plugin is installed and which version it is [FB-01].
12
11
  export async function feedbackInfo(): Promise<FeedbackInfo> {
13
- const dir = pluginDir();
14
- if (!dir) return { cwd: homedir(), hasSource: false, version: null };
15
- return { cwd: dir, hasSource: true, version: await version(dir) };
12
+ const cwd = mkdtempSync(join(tmpdir(), "attention-span-feedback-"));
13
+ const source = pluginDir();
14
+ return { cwd, source, version: source ? await version(source) : null };
16
15
  }
17
16
 
18
- function pluginDir(): string | null {
19
- let dir = dirname(fileURLToPath(import.meta.url));
20
- for (let depth = 0; depth < 4; depth++, dir = dirname(dir)) {
21
- if (existsSync(join(dir, "paseo-plugin.json"))) return dir;
17
+ // Paseo evaluates the server as a bundle, so it has no file location of its own (import.meta.url is undefined).
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 = process.env.PASEO_HOME || join(homedir(), ".paseo")): string | null {
20
+ try {
21
+ const { plugins = {} } = JSON.parse(readFileSync(join(paseoHome, "config.json"), "utf8")) as { plugins?: Record<string, { path?: string }> };
22
+ const ours = Object.entries(plugins)
23
+ .filter(([, source]) => source.path && manifestId(source.path) === PLUGIN_ID)
24
+ .sort(([a], [b]) => Number(b === PLUGIN_ID) - Number(a === PLUGIN_ID));
25
+ return ours[0]?.[1].path ?? null;
26
+ } catch {
27
+ return null;
28
+ }
29
+ }
30
+
31
+ const PLUGIN_ID = "attention-span";
32
+
33
+ function manifestId(dir: string): string | null {
34
+ try {
35
+ return (JSON.parse(readFileSync(join(dir, "paseo-plugin.json"), "utf8")) as { id?: string }).id ?? null;
36
+ } catch {
37
+ return null;
22
38
  }
23
- return null;
24
39
  }
25
40
 
26
41
  // package.json's version, which is a placeholder in a checkout: then the commit.
@@ -5,9 +5,10 @@
5
5
  export const FEEDBACK_REPO = "andrioid/paseo-attention-span";
6
6
 
7
7
  export interface FeedbackInfo {
8
- // The plugin's own source, where a feedback session runs read-only; the home directory when it can't be found.
8
+ // An empty directory made for the session, so archiving its workspace closes it and nothing lands in the source.
9
9
  cwd: string;
10
- hasSource: boolean;
10
+ // The plugin's own source, which the agent reads; null when it can't be found.
11
+ source: string | null;
11
12
  version: string | null;
12
13
  }
13
14
 
@@ -18,7 +19,7 @@ export const feedbackItemKey = (kind: FeedbackKind) => `feedback:${kind}`;
18
19
 
19
20
  export interface FeedbackContext {
20
21
  message: string;
21
- // The plugin's source on this host, where the session runs, and its version.
22
+ // The plugin's source on this host, and its version.
22
23
  dir: string | null;
23
24
  version: string | null;
24
25
  device: "phone" | "desktop";
@@ -37,7 +38,7 @@ They wrote:
37
38
  Context: {{context}}
38
39
 
39
40
  How to work:
40
- - {{where}} Do not edit any file.
41
+ - You are in an empty scratch directory made for this session: put temporary files here. {{where}}
41
42
  - Reply in the language they write in. Write the post in English, in their voice ("I …").
42
43
  - Ask one question at a time, and only what the checklist below still needs. Offer likely answers when you can. After about five questions, draft with what you have and say what's missing.
43
44
  - Read requirements.yaml, docs/architecture.md and the code to understand what they describe. Find the Paseo version with \`paseo --version\`.
@@ -48,11 +49,11 @@ Where it goes: an issue if a maintainer could finish it and close it. Otherwise
48
49
 
49
50
  Keep posts skimmable: a few short lines up front, and anything longer (environment, logs, error text, likely cause, background) in a collapsed \`<details><summary>…</summary>\` block.
50
51
 
51
- Show the whole draft, title included, then ask with your question tool: Post it / Change something / Cancel. Without a question tool, ask in plain text and post only after they reply "post". If you're in a plan or read-only mode, leave it only to post.
52
- - Issue: \`gh issue create --repo ${FEEDBACK_REPO} --title … --body-file …\`, with the body in a temporary file outside this directory.
52
+ Show the whole draft, title included, then ask with your question tool: Post it / Change something / Cancel. Without a question tool, ask in plain text and post only after they reply "post".
53
+ - Issue: \`gh issue create --repo ${FEEDBACK_REPO} --title … --body-file …\`, with the body in a file in the scratch directory.
53
54
  - Discussion: look up the repository ID and the category by its slug (\`ideas\` or \`q-a\`) with \`gh api graphql\` (\`repository { id discussionCategories { nodes { id slug } } }\`), then call the \`createDiscussion\` mutation.
54
55
 
55
- Reply with the link, then archive this session with Paseo's archive_agent tool if you have it.`;
56
+ Reply with the link, then close this session: archive its workspace with Paseo's archive_workspace tool (find its ID with list_workspaces by the scratch directory). It was made only for this session. Without that tool, use archive_agent.`;
56
57
 
57
58
  const PROBLEM = `This is a problem. Work out which kind it is, then cover its checklist:
58
59
  - Broken: what they did, step by step; what they expected; what happened, with any error text; every time or only sometimes.
@@ -75,7 +76,7 @@ export function feedbackPrompt(kind: FeedbackKind, input: FeedbackContext): stri
75
76
  input.refreshError ? `the last refresh failed: ${input.refreshError}` : null,
76
77
  ].filter(Boolean);
77
78
  const where = input.dir
78
- ? `You are in the plugin's installed source, read-only.`
79
+ ? `The plugin's installed source is at ${input.dir}: read it there, and don't change anything in it.`
79
80
  : `The plugin's source isn't on this host: read it from GitHub with \`gh api repos/${FEEDBACK_REPO}/contents/<path>\`.`;
80
81
  const values: Record<string, string> = { message: input.message.trim().replace(/\n/g, "\n> "), context: `${facts.join(", ")}.`, where };
81
82
  const shared = SHARED.replace(/\{\{(\w+)\}\}/g, (match, name: string) => values[name] ?? match);