@tiagojct/subsub 0.7.0 → 0.9.0

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/docs/Subsub.md CHANGED
@@ -1,18 +1,19 @@
1
- Sub-Sub is a Zotero librarian and research assistant that runs in pi. It uses the same Python servers as the OpenCode setup ([[Zotero MCP]]), so the library safety is the same: previews, version checks, journal and undo, the tag vocabulary. The OpenCode setup keeps working in parallel.
1
+ Sub-Sub is a Zotero librarian and research assistant that runs in pi. It uses the Python servers of zotero-local-mcp for the library: previews, version checks, journal and undo, the tag vocabulary.
2
2
 
3
3
  - Code: ~/Projects/subsub (git). Servers: ~/Projects/zotero-local-mcp
4
4
  - Shared rules: [[Zotero agent]]. Tag vocabulary: [[Zotero tags]]
5
- - Settings: ~/.config/subsub/config.json (written by `subsub init`) and ~/.config/opencode/zotero.env (same file as OpenCode)
5
+ - Settings: ~/.config/subsub/config.json (written by `subsub init`) and ~/.config/zotero-local-mcp/env (also read by the weekly alerts in launchd)
6
+ - Sub-Sub folder: ~/Obsidian/Powerslave/Sub-Sub, with Inbox/, Literature/, Syntheses/, Research/ and Zotero/ (tag list, note formats, alert searches). Sub-Sub writes only there without asking.
6
7
  - Models: librarian opencode-go/glm-5.3-flash, researcher opencode-go/mimo-v2.6-pro
7
8
  - Public docs: the README in ~/Projects/subsub (source for subsub.tiagojacinto.eu)
8
9
 
9
- ## Differences from the OpenCode setup
10
+ ## Safety
10
11
 
11
12
  - Approval is enforced in code. Before any library change, Sub-Sub asks the server for the preview and shows it in a dialog. The change runs only after you select Yes. The model cannot skip this.
12
13
  - The model does not need to do a dry run first. You see one dialog per change.
13
14
  - Library tools run one at a time, so each preview includes the effect of earlier changes in the same step.
14
15
  - The researcher does not have the library write tools at all. It can only add a linked note (with a dialog) and add works to the import queue.
15
- - bash is off in both modes. File writes outside the vault, and writes to the rule files, config folders and code folders, need a Yes.
16
+ - bash is off in both modes. File writes outside the Sub-Sub folder, and writes to the rule files, config folders and code folders, need a Yes.
16
17
 
17
18
  ## Install
18
19
 
@@ -20,9 +21,9 @@ Sub-Sub is a Zotero librarian and research assistant that runs in pi. It uses th
20
21
  2. Type `cd ~/Projects/subsub && npm install --omit=dev`.
21
22
  3. Type `npm link`. This adds the `subsub` command.
22
23
  4. Optional: type `pi remove ~/Projects/subsub`. Then plain `pi` stays a plain coding agent without Sub-Sub.
23
- 5. Type `subsub`. If pi already has your OpenCode Go key, Sub-Sub uses the same key. If not, type `/login`, select OpenCode Zen and Go, and paste the key.
24
+ 5. Type `subsub`. If pi has no OpenCode Go key yet, type `/login`, select OpenCode Zen and Go, and paste the key.
24
25
  6. Type `/subsub`. Make sure that the result shows "Zotero: reachable" and the model mimo-v2.6-pro.
25
- 7. Type `subsub init` once. Keep the notes folder (the vault), the tag list, the email and the models. For the profile, select Editor.
26
+ 7. Type `subsub init` once. Keep the Sub-Sub folder, the tag list, the email and the models. For the profile, select Editor.
26
27
  8. Type `subsub doctor`. Make sure that no line shows FIX.
27
28
 
28
29
  If you change the Node version with fnm, do step 3 again.
@@ -30,7 +31,7 @@ If you change the Node version with fnm, do step 3 again.
30
31
  ## Use
31
32
 
32
33
  1. Start Zotero.
33
- 2. Type `subsub`. From the home folder, Sub-Sub starts in the vault. From a different folder (for example a manuscript folder), it starts in that folder. To stay in the home folder, type `subsub --here`.
34
+ 2. Type `subsub`. From the home folder, Sub-Sub starts in the Sub-Sub folder. From a different folder (for example a manuscript folder), it starts in that folder. To stay in the home folder, type `subsub --here`.
34
35
  3. Sub-Sub starts in the researcher mode. To start in the librarian mode, type `subsub --librarian`.
35
36
  4. To change the mode, type `/librarian` or `/researcher`. The mode also changes the model.
36
37
  5. When a dialog shows a preview, read it. Select Yes to apply the change, or No to stop it. After No, tell Sub-Sub what to change.
@@ -105,7 +106,7 @@ The themes are in ~/Projects/subsub/themes. To make them again after a change in
105
106
 
106
107
  ## Model test
107
108
 
108
- The model test runs several models on the same tasks against your library and compares them. Nothing in the library changes: each library change is recorded with its preview and then blocked. Notes go to ~/Projects/subsub/bench-results/<date>/, not to the vault.
109
+ The model test runs several models on the same tasks against your library and compares them. Nothing in the library changes: each library change is recorded with its preview and then blocked. Notes go to ~/Projects/subsub/bench-results/<date>/, not to the Sub-Sub folder.
109
110
 
110
111
  Tasks:
111
112
 
@@ -131,7 +132,7 @@ Each model gets a code (for example M417), so the notes can be judged blind. key
131
132
  - "command not found: subsub": type `cd ~/Projects/subsub && npm link`.
132
133
  - To update Sub-Sub after new code arrives, type `cd ~/Projects/subsub && npm install --omit=dev`. Do not use `subsub update`.
133
134
  - A tool call is refused with "not available in researcher mode": type `/librarian`.
134
- - `subsub review` says "No note matches": check the note numbers in Inbox/. A path is written from the vault folder, in quotes (for example "Inbox/Zotero tag review 13.md").
135
+ - `subsub review` says "No note matches": check the note numbers in Inbox/. A path is written from the Sub-Sub folder, in quotes (for example "Inbox/Zotero tag review 13.md").
135
136
 
136
137
  ## Tests
137
138
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tiagojct/subsub",
3
- "version": "0.7.0",
3
+ "version": "0.9.0",
4
4
  "description": "Sub-Sub: a Zotero librarian and research assistant in the browser or the terminal, built on pi",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -29,7 +29,7 @@
29
29
  "@modelcontextprotocol/sdk": "^1.30.1"
30
30
  },
31
31
  "peerDependencies": {
32
- "@earendil-works/pi-coding-agent": "^1.0.2"
32
+ "@earendil-works/pi-coding-agent": "^1.0.4"
33
33
  },
34
34
  "engines": {
35
35
  "node": ">=22.19.0"
@@ -61,7 +61,7 @@
61
61
  "THIRD_PARTY_NOTICES"
62
62
  ],
63
63
  "devDependencies": {
64
- "@earendil-works/pi-coding-agent": "1.0.2",
64
+ "@earendil-works/pi-coding-agent": "1.0.4",
65
65
  "@types/node": "^24.19.0",
66
66
  "typescript": "^5.9.3"
67
67
  },
@@ -17,7 +17,7 @@ Make a short slug: lower case, hyphens, at most five words. Use today's date (YY
17
17
  - Confidence: high, moderate or low, with one reason.
18
18
  4. Below the matrix, write: where the sources agree; where they disagree and the most likely reason (population, design, outcome definition, analysis); what no source answers. Cite source numbers in every sentence. Write "inference:" before a statement that no single source makes.
19
19
  5. Check the sources: verify_check_references when the verify_ tools are available, otherwise scholar_get_work for each identifier. Never write "verified" for a check you did not run.
20
- 6. Write one note: `Research/<date> <slug> comparison.md` in the notes folder (do not overwrite; add -2). Front matter: title, date, type: comparison, sources (the identifiers), verification (PASS, PASS WITH NOTES or BLOCKED), reference_check (path of the Starbuck report, or none). End with a Sources section: [@citekey] for library items, full reference with DOI and "(not in library)" for the others.
20
+ 6. Write one note: `Research/<date> <slug> comparison.md` in the Sub-Sub folder (do not overwrite; add -2). Front matter: title, date, type: comparison, sources (the identifiers), verification (PASS, PASS WITH NOTES or BLOCKED), reference_check (path of the Starbuck report, or none). End with a Sources section: [@citekey] for library items, full reference with DOI and "(not in library)" for the others.
21
21
  7. If a step fails, finish the note anyway and mark the step "BLOCKED: <what failed>".
22
22
 
23
23
  Give the user the path and three lines on what the comparison shows.
package/prompts/digest.md CHANGED
@@ -4,7 +4,7 @@ argument-hint: "[days, default 7] [topic]"
4
4
  ---
5
5
  Write a digest of the last ${1:-7} days. Topic, if given: ${@:2}
6
6
 
7
- 1. Collect, in the notes folder:
7
+ 1. Collect, in the Sub-Sub folder:
8
8
  - the alert notes `Inbox/Literature alerts YYYY-MM-DD.md` dated in the period (the date is in the file name);
9
9
  - the notes in `Research/` whose front matter `date:` is in the period;
10
10
  - the literature notes whose front matter `created:` is in the period.
package/prompts/lit.md CHANGED
@@ -11,7 +11,7 @@ Make a short slug from the topic: lower case, hyphens, at most five words. Use t
11
11
  1. Write the question in one sentence. If it is a clinical question, state population, exposure or intervention, comparison and outcome when they apply.
12
12
  2. Decide the scale:
13
13
  - Narrow question ("what is X", one fact, one test): at most 10 tool calls, a short answer, no plan file.
14
- - Review question: write the plan to `Research/.plans/<slug>.md` in the notes folder: the question, the search phrasings, the study designs that answer it (for example randomised trials, cohorts, diagnostic accuracy studies, systematic reviews), the years, and a task list.
14
+ - Review question: write the plan to `Research/.plans/<slug>.md` in the Sub-Sub folder: the question, the search phrasings, the study designs that answer it (for example randomised trials, cohorts, diagnostic accuracy studies, systematic reviews), the years, and a task list.
15
15
  3. Tell the user the plan in three lines. Then continue at once. Do not wait for an answer unless the user asked to see the plan first.
16
16
 
17
17
  ## 2. Gather
@@ -47,7 +47,7 @@ Make a short slug from the topic: lower case, hyphens, at most five words. Use t
47
47
 
48
48
  ## 6. Deliver
49
49
 
50
- Write one note: `Research/<date> <slug>.md` in the notes folder. Do not overwrite an existing note; add -2 to the name. Use this structure:
50
+ Write one note: `Research/<date> <slug>.md` in the Sub-Sub folder. Do not overwrite an existing note; add -2 to the name. Use this structure:
51
51
 
52
52
  ```markdown
53
53
  ---
@@ -6,7 +6,7 @@ Draft an email to ask the corresponding author of $1 for a copy of the paper.
6
6
 
7
7
  1. Find the work: zotero_get_item for a citekey or Zotero key, otherwise scholar_get_work. If it is open access (open_access, or scholar_read_oa_fulltext gives the full text), tell the user where to read it and stop: no email is needed.
8
8
  2. Find the address with scholar_find_contact. Use only an address it returns. Never guess or build an address from a name. If it returns none, give the user the article link and say: look for "Correspondence" on the article page; then stop.
9
- 3. Write the draft to `Inbox/Copy request <citekey or DOI>.md` in the notes folder (do not overwrite; add -2):
9
+ 3. Write the draft to `Inbox/Copy request <citekey or DOI>.md` in the Sub-Sub folder (do not overwrite; add -2):
10
10
 
11
11
  ```markdown
12
12
  ---
@@ -1,6 +1,6 @@
1
1
  You are Sub-Sub, the research assistant for {{user}}. {{about}} Reply briefly. No emojis.
2
2
 
3
- You read the Zotero library (zotero_ read tools), search PubMed, Europe PMC and OpenAlex (scholar_ tools) and write notes in the notes folder. You cannot change the library, with one exception: scholar_attach_note adds a short child note (summary plus obsidian:// link). To add works, use scholar_queue_imports; {{user}} ticks them and the librarian (/librarian) imports them.
3
+ You read the Zotero library (zotero_ read tools), search PubMed, Europe PMC and OpenAlex (scholar_ tools) and write notes in the Sub-Sub folder. You cannot change the library, with one exception: scholar_attach_note adds a short child note (summary plus obsidian:// link). To add works, use scholar_queue_imports; {{user}} ticks them and the librarian (/librarian) imports them.
4
4
 
5
5
  ## Always
6
6
 
@@ -32,7 +32,7 @@ You read the Zotero library (zotero_ read tools), search PubMed, Europe PMC and
32
32
  ## Literature notes and syntheses
33
33
 
34
34
  - Follow the formats in the shared rules.
35
- - After a literature note is written, offer scholar_attach_note with 3 to 4 lines of summary and the path of the vault note.
35
+ - After a literature note is written, offer scholar_attach_note with 3 to 4 lines of summary and the path of the note.
36
36
  - For a synthesis: show the candidate list first and let {{user}} choose. Read full texts only for the chosen items.
37
37
  - For a synthesis of a tag ("what does my library say about X"): find the items with zotero_find_items tags=["topic/x"] and include every one. The table has one row per item; if you leave an item out, say which and why.
38
38
  - Say for each item whether you used the full text or the abstract. Never state a number or a claim that is not in what you read.
package/src/config.ts CHANGED
@@ -5,7 +5,7 @@
5
5
  * {
6
6
  * "profile": "scholar",
7
7
  * "userName": "Ana", "about": "a master's student in health informatics", "language": "English",
8
- * "vault": "~/Notes",
8
+ * "vault": "~/Documents/Sub-Sub",
9
9
  * "models": { "librarian": "opencode-go/glm-5.3-flash", "researcher": "opencode-go/mimo-v2.6-pro" },
10
10
  * "defaultMode": "researcher"
11
11
  * }
@@ -22,6 +22,7 @@
22
22
  import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
23
23
  import { homedir } from "node:os";
24
24
  import { dirname, join, resolve } from "node:path";
25
+ import { isObsidianVault, settingsFile } from "./layout.ts";
25
26
 
26
27
  export type Mode = "librarian" | "researcher";
27
28
  export type Profile = "reader" | "scholar" | "author" | "editor";
@@ -160,11 +161,15 @@ export function loadConfig(env: NodeJS.ProcessEnv = process.env): SubsubConfig {
160
161
  researcher: "opencode-go/mimo-v2.6-pro",
161
162
  },
162
163
  defaultMode: mode,
163
- vaultContext: (user.vaultContext ?? (vault ? [join(vault, ".claude", "CLAUDE.md")] : [])).map((p) => expand(p, home)),
164
+ // A Sub-Sub folder inside an Obsidian vault also reads the vault's context file.
165
+ vaultContext: (
166
+ user.vaultContext ??
167
+ (vault ? [join(vault, ".claude", "CLAUDE.md"), ...(isObsidianVault(dirname(vault)) ? [join(dirname(vault), ".claude", "CLAUDE.md")] : [])] : [])
168
+ ).map((p) => expand(p, home)),
164
169
  sharedRules: user.sharedRules
165
170
  ? expand(user.sharedRules, home)
166
171
  : vault
167
- ? join(vault, "Systems", "Zotero agent.md")
172
+ ? settingsFile(vault, "rules")
168
173
  : undefined,
169
174
  startTimeout: user.startTimeout ?? 45,
170
175
  uvPath: user.uvPath ? expand(user.uvPath, home) : undefined,
package/src/doctor.ts CHANGED
@@ -21,6 +21,7 @@ import {
21
21
  starbuckEnabled,
22
22
  type SubsubConfig,
23
23
  } from "./config.ts";
24
+ import { isObsidianVault, LEGACY_SETTINGS_DIR, SETTINGS_FILES, settingsFile } from "./layout.ts";
24
25
  import { profileSpec } from "./profiles.ts";
25
26
 
26
27
  export interface Check {
@@ -137,11 +138,7 @@ export function runChecks(
137
138
  : undefined,
138
139
  });
139
140
  }
140
- out.push(
141
- cfg.vault && existsSync(cfg.vault)
142
- ? { name: "Notes folder", ok: true, detail: cfg.vault }
143
- : { name: "Notes folder", ok: false, detail: cfg.vault ? `${cfg.vault} does not exist` : "not set", fix: "Type subsub init." },
144
- );
141
+ out.push(folderCheck(cfg.vault));
145
142
  out.push(
146
143
  st.contact_email_set
147
144
  ? { name: "Contact email", ok: true, detail: "set" }
@@ -199,3 +196,19 @@ export async function doctorMain(env: NodeJS.ProcessEnv = process.env): Promise<
199
196
  console.log(bad ? `\n${bad} problem(s) to fix.` : "\nEverything needed is in place.");
200
197
  return bad ? 1 : 0;
201
198
  }
199
+
200
+ /** The Sub-Sub folder: it exists, it is not a whole vault, and its settings files are in Zotero/. */
201
+ export function folderCheck(folder: string | undefined): Check {
202
+ const name = "Sub-Sub folder";
203
+ if (!folder || !existsSync(folder)) {
204
+ return { name, ok: false, detail: folder ? `${folder} does not exist` : "not set", fix: "Type subsub init." };
205
+ }
206
+ if (isObsidianVault(folder)) {
207
+ return { name, ok: true, warn: true, detail: `${folder} is a whole Obsidian vault`, fix: "Type subsub init: it moves Sub-Sub's files into a Sub-Sub folder inside the vault." };
208
+ }
209
+ const legacy = (["rules", "tags", "alerts"] as const).some((w) => settingsFile(folder, w) === join(folder, LEGACY_SETTINGS_DIR, SETTINGS_FILES[w]));
210
+ if (legacy) {
211
+ return { name, ok: true, warn: true, detail: `${folder}; the settings files are still in ${LEGACY_SETTINGS_DIR}/`, fix: "Type subsub init: it moves them to Zotero/." };
212
+ }
213
+ return { name, ok: true, detail: folder };
214
+ }
package/src/init.ts CHANGED
@@ -6,14 +6,20 @@
6
6
  * - the settings file (~/.config/subsub/config.json): profile, name, language,
7
7
  * notes folder, models;
8
8
  * - the server settings file (~/.config/zotero-local-mcp/env, or the one that
9
- * already exists): notes folder, tag list, contact email. Other lines stay;
10
- * - in the notes folder: Inbox/, Systems/Zotero tags.md (a starter list) and
11
- * Systems/Zotero agent.md (note formats). Existing files are never replaced.
9
+ * already exists): the Sub-Sub folder, tag list, alerts file, contact email.
10
+ * Other lines stay;
11
+ * - the Sub-Sub folder (see layout.ts): Inbox/, Literature/, Syntheses/,
12
+ * Research/, and Zotero/ with Zotero tags.md (a starter list) and Zotero
13
+ * agent.md (note formats). Existing files are never replaced.
14
+ *
15
+ * An Obsidian vault given as the folder becomes <vault>/Sub-Sub. Files of the old
16
+ * layout (Systems/, or Sub-Sub's notes in the Inbox/ of a whole vault) are moved
17
+ * when the user agrees.
12
18
  *
13
19
  * Flags (for scripts and tests): --yes (take every default), --setup
14
- * standard|fmup, --name, --about, --language, --notes, --profile, --tags
15
- * health-sciences|health-informatics|any-field, --email, --starbuck on|off,
16
- * --models keep|later|opencode-go.
20
+ * standard|fmup, --name, --about, --language, --folder (or --notes), --move
21
+ * yes|no, --profile, --tags health-sciences|health-informatics|any-field,
22
+ * --email, --starbuck on|off, --models keep|later|opencode-go.
17
23
  */
18
24
 
19
25
  import { copyFileSync, existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
@@ -35,6 +41,7 @@ import {
35
41
  withStarbuck,
36
42
  } from "./config.ts";
37
43
  import { defaultRunner, starbuckCheck } from "./doctor.ts";
44
+ import { applyMoves, FOLDER_NAME, leftBehind, NOTE_DIRS, planMoves, SETTINGS_DIR, SETTINGS_FILES, subsubFolder } from "./layout.ts";
38
45
  import { PROFILE_SPECS } from "./profiles.ts";
39
46
 
40
47
  const TEMPLATES = resolve(dirname(fileURLToPath(import.meta.url)), "..", "templates");
@@ -58,6 +65,7 @@ export interface InitResult {
58
65
  envFile: string;
59
66
  notes: string;
60
67
  created: string[];
68
+ moved: number;
61
69
  zotero: boolean;
62
70
  }
63
71
 
@@ -108,8 +116,18 @@ export async function runInit(
108
116
  const envValues = existsSync(envFile) ? parseEnvFile(envFile) : {};
109
117
  const created: string[] = [];
110
118
 
111
- io.say(existsSync(configFile) ? `Sub-Sub settings (${configFile}). Press Enter to keep the value in brackets.` : "Sub-Sub setup. Press Enter to take the value in brackets.");
119
+ const first = !existsSync(configFile);
120
+ io.say(
121
+ first
122
+ ? "Sub-Sub setup. A few questions; press Enter to take the value in brackets. To change an answer later, type subsub init again."
123
+ : `Sub-Sub settings (${configFile}). Press Enter to keep the value in brackets.`,
124
+ );
125
+ const explain = (title: string, text: string) => {
126
+ io.say("");
127
+ io.say(`${title}. ${text}`);
128
+ };
112
129
 
130
+ explain("Setup", "Standard works for any field. FMUP / U.Porto starts with health-sciences tags and the Reader profile.");
113
131
  const setup = await io.choose(
114
132
  "Setup",
115
133
  [
@@ -119,45 +137,92 @@ export async function runInit(
119
137
  flags.setup ?? existing.setup ?? "standard",
120
138
  );
121
139
  const fmup = setup === "fmup";
122
- const userName = (await io.ask("Your name, for Sub-Sub's replies (Enter for none)", flags.name ?? existing.userName ?? "")).trim();
140
+
141
+ explain("About you", "Sub-Sub uses your name and one line about you in its replies. Both are optional and stay on this computer, except in the messages to the model provider.");
142
+ const userName = (await io.ask("Your name (Enter for none)", flags.name ?? existing.userName ?? "")).trim();
123
143
  const about = (await io.ask('One line about you, e.g. "a master\'s student in health informatics" (optional)', flags.about ?? existing.about ?? "")).trim();
124
144
  const language = (await io.ask("Language for replies and notes (a language, or auto for the language you write in)", flags.language ?? existing.language ?? "English")).trim() || "English";
125
- const notes = expand(
126
- (await io.ask("Notes folder (Markdown files; an Obsidian vault works)", flags.notes ?? current.vault ?? envValues.ZOTERO_VAULT ?? join(home, "Documents", "Sub-Sub"))).trim(),
127
- home,
145
+
146
+ explain(
147
+ "Sub-Sub folder",
148
+ `Sub-Sub keeps everything it writes in one folder: Inbox/ (review notes, the import queue, alerts), Literature/, Syntheses/, Research/, and ${SETTINGS_DIR}/ (your tag list and note formats). If you use Obsidian, give the vault folder: Sub-Sub then works in a ${FOLDER_NAME} folder inside the vault and leaves the rest of the vault alone.`,
128
149
  );
150
+ const oldFolder = current.vault;
151
+ // Without questions (--yes), an existing folder stays exactly as it is.
152
+ const keepAsIs = Boolean(flags.yes) && !flags.folder && !flags.notes && oldFolder !== undefined;
153
+ const folderDefault = flags.folder ?? flags.notes ?? (oldFolder ? (keepAsIs ? oldFolder : subsubFolder(oldFolder)) : join(home, "Documents", FOLDER_NAME));
154
+ const answer = expand((await io.ask("Sub-Sub folder (or an Obsidian vault)", folderDefault)).trim() || folderDefault, home);
155
+ const notes = keepAsIs && answer === oldFolder ? answer : subsubFolder(answer);
156
+ if (notes !== answer) io.say(`That is an Obsidian vault. Sub-Sub will use ${notes}.`);
157
+
158
+ // ---- files of the old layout
159
+ const from = oldFolder && existsSync(oldFolder) ? oldFolder : notes;
160
+ const moves = planMoves(from, notes);
161
+ let move = "no";
162
+ if (moves.length) {
163
+ explain(
164
+ "Earlier files",
165
+ `${moves.length} file(s) from an earlier Sub-Sub layout can move into ${notes}: the settings files go to ${SETTINGS_DIR}/, and Sub-Sub's review notes, alerts and import queue go to Inbox/. Nothing is replaced.`,
166
+ );
167
+ for (const m of moves.slice(0, 6)) io.say(` ${m.from}`);
168
+ if (moves.length > 6) io.say(` and ${moves.length - 6} more`);
169
+ move = await io.choose(
170
+ "Move them",
171
+ [
172
+ { value: "yes", label: "Move them (recommended)" },
173
+ { value: "no", label: from === notes ? "Leave them; Sub-Sub still reads them from Systems/" : "Leave them where they are" },
174
+ ],
175
+ flags.move ?? (flags.yes ? "no" : "yes"),
176
+ );
177
+ }
178
+
179
+ explain("Profile", "The profile sets how much Sub-Sub writes for you and which tools it offers. Change it at any time with /profile.");
129
180
  const profileDefault = flags.profile ?? existing.profile ?? (fmup ? "reader" : "scholar");
130
181
  const profile = await io.choose(
131
- "Profile (change it later with /profile)",
182
+ "Profile",
132
183
  PROFILES.map((p) => ({ value: p, label: `${PROFILE_SPECS[p].label}: ${PROFILE_SPECS[p].summary}` })),
133
184
  isProfile(profileDefault) ? profileDefault : "scholar",
134
185
  );
135
186
 
136
- const vocab = envValues.ZOTERO_VOCAB ? expand(envValues.ZOTERO_VOCAB, home) : join(notes, "Systems", "Zotero tags.md");
187
+ // The tag list: a custom path in the server settings stays; otherwise Zotero/Zotero tags.md (moved, kept or new).
188
+ const vocabTarget = join(notes, SETTINGS_DIR, SETTINGS_FILES.tags);
189
+ const oldDefaults = new Set([join(from, "Systems", SETTINGS_FILES.tags), join(from, SETTINGS_DIR, SETTINGS_FILES.tags)]);
190
+ const envVocab = envValues.ZOTERO_VOCAB ? expand(envValues.ZOTERO_VOCAB, home) : undefined;
191
+ const customVocab = envVocab && existsSync(envVocab) && !oldDefaults.has(envVocab) && envVocab !== vocabTarget ? envVocab : undefined;
192
+ const movingVocab = move === "yes" && moves.some((m) => m.to === vocabTarget);
193
+ // An old tag list counts only in the same folder; a new folder gets the moved list or a new one.
194
+ const legacyVocab = !movingVocab && from === notes && [...oldDefaults].find((p) => existsSync(p));
195
+ const vocab = customVocab ?? (movingVocab || existsSync(vocabTarget) ? vocabTarget : legacyVocab || vocabTarget);
137
196
  let tags = "keep";
138
- if (existsSync(vocab)) {
197
+ if (existsSync(vocab) || movingVocab) {
198
+ io.say("");
139
199
  io.say(`Tag list: keeping ${vocab}.`);
140
200
  } else {
201
+ explain("Tag list", `The librarian tags items only with the tags in this list. Pick a start; you edit the list later in ${SETTINGS_DIR}/${SETTINGS_FILES.tags}.`);
141
202
  tags = await io.choose(
142
- "Starter tag list (edit it later in the notes folder)",
203
+ "Starter tag list",
143
204
  Object.entries(STARTER_TAGS).map(([value, label]) => ({ value, label })),
144
205
  flags.tags ?? (fmup ? "health-sciences" : "any-field"),
145
206
  );
146
207
  }
147
- const email = (
148
- await io.ask("Email for Unpaywall and Crossref, to find open-access PDFs (optional)", flags.email ?? envValues.ZOTERO_CONTACT_EMAIL ?? "")
149
- ).trim();
208
+
209
+ explain("Contact email", "Unpaywall needs an email address to find open-access PDFs. Sub-Sub sends it only to Unpaywall, Crossref, OpenAlex and PubMed, as they ask.");
210
+ const email = (await io.ask("Email (optional)", flags.email ?? envValues.ZOTERO_CONTACT_EMAIL ?? "")).trim();
211
+
212
+ explain("Reference checks (Starbuck)", "An optional add-on for manuscripts: it checks that each cited work exists, matches its citation and was not retracted. The researcher then has /verify.");
150
213
  const starbuck = await io.choose(
151
- "Reference checks (Starbuck): check that cited works exist, match their citation and were not retracted",
214
+ "Reference checks",
152
215
  [
153
216
  { value: "off", label: "Off" },
154
- { value: "on", label: "On (the researcher gets /verify; uses the email above)" },
217
+ { value: "on", label: "On (downloads Starbuck now; uses the email above)" },
155
218
  ],
156
219
  flags.starbuck ?? (starbuckEnabled(current) ? "on" : "off"),
157
220
  );
221
+
222
+ explain("Models", "Sub-Sub needs an account with a model provider. You can connect one later in Sub-Sub with the model button (or /login in the terminal).");
158
223
  const modelOptions = [
159
224
  ...(existing.models ? [{ value: "keep", label: `Keep: ${JSON.stringify(existing.models)}` }] : []),
160
- { value: "later", label: "Choose later in Sub-Sub (/login, then /model)" },
225
+ { value: "later", label: "Choose later in Sub-Sub" },
161
226
  { value: "opencode-go", label: `OpenCode Go, tested: ${TESTED_MODELS.librarian} for the librarian, ${TESTED_MODELS.researcher} for the researcher` },
162
227
  ];
163
228
  const agentDir = initEnv.SUBSUB_AGENT_DIR ? expand(initEnv.SUBSUB_AGENT_DIR, home) : join(home, ".subsub", "agent");
@@ -165,7 +230,8 @@ export async function runInit(
165
230
  const models = await io.choose("Models", modelOptions, flags.models ?? modelDefault);
166
231
 
167
232
  // ---- write
168
- for (const dir of [notes, join(notes, "Inbox"), join(notes, "Systems")]) {
233
+ if (move === "yes") applyMoves(moves);
234
+ for (const dir of [notes, ...NOTE_DIRS.map((d) => join(notes, d)), join(notes, SETTINGS_DIR)]) {
169
235
  if (!existsSync(dir)) {
170
236
  mkdirSync(dir, { recursive: true });
171
237
  created.push(dir);
@@ -176,14 +242,18 @@ export async function runInit(
176
242
  copyFileSync(join(TEMPLATES, "vocabularies", `${tags}.md`), vocab);
177
243
  created.push(vocab);
178
244
  }
179
- const rules = join(notes, "Systems", "Zotero agent.md");
180
- if (!existsSync(rules)) {
181
- copyFileSync(join(TEMPLATES, "Zotero agent.md"), rules);
182
- created.push(rules);
245
+ const rulesTarget = join(notes, SETTINGS_DIR, SETTINGS_FILES.rules);
246
+ const legacyRules = join(notes, "Systems", SETTINGS_FILES.rules);
247
+ if (!existsSync(rulesTarget) && !existsSync(legacyRules)) {
248
+ copyFileSync(join(TEMPLATES, "Zotero agent.md"), rulesTarget);
249
+ created.push(rulesTarget);
183
250
  }
251
+ const alertsTarget = join(notes, SETTINGS_DIR, SETTINGS_FILES.alerts);
252
+ const legacyAlerts = join(notes, "Systems", SETTINGS_FILES.alerts);
253
+ const alerts = !existsSync(alertsTarget) && existsSync(legacyAlerts) ? legacyAlerts : alertsTarget;
184
254
  mkdirSync(dirname(envFile), { recursive: true });
185
255
  const before = existsSync(envFile) ? readFileSync(envFile, "utf8") : "# Settings for the Sub-Sub Zotero servers (zotero-local-mcp). Written by subsub init.\n";
186
- writeFileSync(envFile, upsertEnv(before, { ZOTERO_VAULT: notes, ZOTERO_VOCAB: vocab, ZOTERO_CONTACT_EMAIL: email || undefined }));
256
+ writeFileSync(envFile, upsertEnv(before, { ZOTERO_VAULT: notes, ZOTERO_VOCAB: vocab, ZOTERO_ALERTS: alerts, ZOTERO_CONTACT_EMAIL: email || undefined }));
187
257
 
188
258
  const patch: Record<string, unknown> = {
189
259
  profile,
@@ -205,6 +275,8 @@ export async function runInit(
205
275
  io.say(`Saved: ${configFile}`);
206
276
  io.say(`Saved: ${envFile}`);
207
277
  for (const c of created) io.say(`Created: ${c}`);
278
+ if (move === "yes") io.say(`Moved: ${moves.length} file(s) into ${notes}`);
279
+ for (const d of leftBehind(from, notes)) io.say(`Not moved: ${d}. If Sub-Sub wrote these notes, move them into ${notes} yourself.`);
208
280
  io.say(
209
281
  zotero
210
282
  ? "Zotero: reachable."
@@ -213,7 +285,7 @@ export async function runInit(
213
285
  if (starbuck === "on") io.say(starbuckNote || "Reference checks: on. The first start downloads Starbuck.");
214
286
  if (fmup) io.say("FMUP / U.Porto: the FMUP model service will come in a later version. Until then, connect a model provider yourself.");
215
287
  io.say("Next: type subsub web to open Sub-Sub in your browser (or subsub for the terminal). Connect a model provider with the model button (or /login in the terminal). To check the setup, type subsub doctor.");
216
- return { configFile, envFile, notes, created, zotero };
288
+ return { configFile, envFile, notes, created, moved: move === "yes" ? moves.length : 0, zotero };
217
289
  }
218
290
 
219
291
  export function parseFlags(args: string[]): Record<string, string> {
@@ -266,7 +338,8 @@ function terminalIO(): InitIO & { close(): void } {
266
338
 
267
339
  export async function initMain(args: string[], env: NodeJS.ProcessEnv = process.env): Promise<number> {
268
340
  const flags = parseFlags(args);
269
- const io = flags.yes || !process.stdin.isTTY ? defaultsIO((l) => console.log(l)) : terminalIO();
341
+ if (!process.stdin.isTTY) flags.yes ??= "true";
342
+ const io = flags.yes ? defaultsIO((l) => console.log(l)) : terminalIO();
270
343
  try {
271
344
  await runInit(io, flags, env, { prepareStarbuck: (cfg) => {
272
345
  // Download Starbuck now, so that the first start of Sub-Sub does not wait for it.
package/src/layout.ts ADDED
@@ -0,0 +1,103 @@
1
+ /**
2
+ * The Sub-Sub folder: everything Sub-Sub writes lives in one folder, by default
3
+ * "Sub-Sub" (~/Documents/Sub-Sub, or <vault>/Sub-Sub inside an Obsidian vault):
4
+ *
5
+ * Sub-Sub/
6
+ * Inbox/ tag review notes, the import queue, alerts, drafts
7
+ * Literature/ one note per item
8
+ * Syntheses/ notes on several items
9
+ * Research/ literature reviews, comparisons, digests (.plans/ for plans and logs)
10
+ * Zotero/ Zotero tags.md, Zotero agent.md, Literature alerts.md
11
+ *
12
+ * Before 0.9, the settings files were in Systems/ and the folder could be a whole
13
+ * vault. Those files are still found there until they are moved (subsub init).
14
+ */
15
+
16
+ import { existsSync, mkdirSync, readdirSync, renameSync, rmdirSync, statSync } from "node:fs";
17
+ import { basename, dirname, join } from "node:path";
18
+
19
+ export const FOLDER_NAME = "Sub-Sub";
20
+ export const SETTINGS_DIR = "Zotero";
21
+ export const LEGACY_SETTINGS_DIR = "Systems";
22
+ export const NOTE_DIRS = ["Inbox", "Literature", "Syntheses", "Research"];
23
+
24
+ /** The files in Zotero/ that Sub-Sub and the Zotero server read. */
25
+ export const SETTINGS_FILES = { tags: "Zotero tags.md", rules: "Zotero agent.md", alerts: "Literature alerts.md" } as const;
26
+ type SettingsFile = keyof typeof SETTINGS_FILES;
27
+
28
+ /** True when the folder is the root of an Obsidian vault. */
29
+ export function isObsidianVault(dir: string): boolean {
30
+ return existsSync(join(dir, ".obsidian"));
31
+ }
32
+
33
+ /** The folder that a user's answer means: a vault root becomes <vault>/Sub-Sub. */
34
+ export function subsubFolder(answer: string): string {
35
+ return isObsidianVault(answer) && basename(answer) !== FOLDER_NAME ? join(answer, FOLDER_NAME) : answer;
36
+ }
37
+
38
+ /** The path of a settings file: Zotero/<file>, or Systems/<file> while only the old one exists. */
39
+ export function settingsFile(folder: string, which: SettingsFile): string {
40
+ const name = SETTINGS_FILES[which];
41
+ const current = join(folder, SETTINGS_DIR, name);
42
+ const legacy = join(folder, LEGACY_SETTINGS_DIR, name);
43
+ return !existsSync(current) && existsSync(legacy) ? legacy : current;
44
+ }
45
+
46
+ /** Every place a settings file may be, for the write gate. */
47
+ export function settingsPaths(folder: string): string[] {
48
+ return Object.values(SETTINGS_FILES).flatMap((n) => [join(folder, SETTINGS_DIR, n), join(folder, LEGACY_SETTINGS_DIR, n)]);
49
+ }
50
+
51
+ export interface Move {
52
+ from: string;
53
+ to: string;
54
+ }
55
+
56
+ /** Inbox notes that Sub-Sub and the Zotero server write. */
57
+ const SUBSUB_INBOX = /^(Zotero |Literature alerts|Copy request )/;
58
+
59
+ /**
60
+ * What to move from the old layout (`from`: the old notes folder) to the new one
61
+ * (`to`: the Sub-Sub folder). Only files that Sub-Sub made, and never over an
62
+ * existing file:
63
+ * - the settings files, from Systems/ to Zotero/;
64
+ * - when the Sub-Sub folder is new (the old folder was a whole vault): Sub-Sub's
65
+ * notes in Inbox/. Literature/, Syntheses/ and Research/ of a vault may hold the
66
+ * user's own notes, so they stay; the user moves them.
67
+ */
68
+ export function planMoves(from: string, to: string): Move[] {
69
+ const moves: Move[] = [];
70
+ const add = (src: string, dest: string) => {
71
+ if (existsSync(src) && !existsSync(dest) && !moves.some((m) => m.to === dest)) moves.push({ from: src, to: dest });
72
+ };
73
+ for (const name of Object.values(SETTINGS_FILES)) {
74
+ add(join(from, LEGACY_SETTINGS_DIR, name), join(to, SETTINGS_DIR, name));
75
+ if (from !== to) add(join(from, SETTINGS_DIR, name), join(to, SETTINGS_DIR, name));
76
+ }
77
+ if (from !== to) {
78
+ const inbox = join(from, "Inbox");
79
+ if (existsSync(inbox)) {
80
+ for (const f of readdirSync(inbox).sort()) {
81
+ if (SUBSUB_INBOX.test(f) && statSync(join(inbox, f)).isFile()) add(join(inbox, f), join(to, "Inbox", f));
82
+ }
83
+ }
84
+ }
85
+ return moves;
86
+ }
87
+
88
+ /** Folders of the old layout that may hold Sub-Sub's notes but are left for the user. */
89
+ export function leftBehind(from: string, to: string): string[] {
90
+ if (from === to) return [];
91
+ return ["Literature", "Syntheses", "Research"].map((d) => join(from, d)).filter((d) => existsSync(d) && readdirSync(d).length > 0);
92
+ }
93
+
94
+ /** Do the moves. An old Systems/ folder that is now empty is removed. */
95
+ export function applyMoves(moves: Move[]): void {
96
+ for (const m of moves) {
97
+ mkdirSync(dirname(m.to), { recursive: true });
98
+ renameSync(m.from, m.to);
99
+ }
100
+ for (const dir of new Set(moves.map((m) => dirname(m.from)))) {
101
+ if (basename(dir) === LEGACY_SETTINGS_DIR && existsSync(dir) && readdirSync(dir).length === 0) rmdirSync(dir);
102
+ }
103
+ }
package/src/paths.ts CHANGED
@@ -10,6 +10,7 @@ import { existsSync, realpathSync } from "node:fs";
10
10
  import { homedir } from "node:os";
11
11
  import { basename, dirname, isAbsolute, join, relative, resolve, sep } from "node:path";
12
12
  import { fileURLToPath } from "node:url";
13
+ import { settingsPaths } from "./layout.ts";
13
14
 
14
15
  export function normalizeToolPath(raw: string, cwd: string): string {
15
16
  let p = String(raw ?? "").trim();
@@ -80,11 +81,7 @@ export function buildPolicy(opts: { vault?: string; cwd: string; serverDir: stri
80
81
  join(v, ".claude"),
81
82
  join(v, ".opencode"),
82
83
  join(v, ".obsidian"),
83
- join(v, "Systems", "Zotero agent.md"),
84
- join(v, "Systems", "Zotero tags.md"),
85
- join(v, "Systems", "Zotero librarian.md"),
86
- join(v, "Systems", "Zotero researcher.md"),
87
- join(v, "Systems", "Literature alerts.md"),
84
+ ...settingsPaths(v),
88
85
  );
89
86
  }
90
87
  return { allowed, protectedPaths };
package/src/prompt.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * The Sub-Sub part of the system prompt: role text for the current mode, the
3
- * profile rules, the shared Zotero rules from the notes folder, the vault
4
- * conventions when pi runs inside the notes folder, and the language rule.
3
+ * profile rules, the shared Zotero rules from the Sub-Sub folder, the vault
4
+ * conventions when pi runs inside the Sub-Sub folder, and the language rule.
5
5
  *
6
6
  * Role and profile texts use placeholders: {{user}} / {{User}} (the user's name,
7
7
  * or "the user"), {{about}} (one line about the user) and {{batch}}.
@@ -63,7 +63,7 @@ export function systemAddition(mode: Mode, cfg: SubsubConfig, cwd: string): stri
63
63
  const shared = readIf(cfg.sharedRules);
64
64
  if (shared) {
65
65
  parts.push(
66
- "# Shared Zotero rules (from the notes folder)",
66
+ "# Shared Zotero rules (from the Sub-Sub folder)",
67
67
  shared,
68
68
  `Sub-Sub note: in Sub-Sub you do not need a separate dry run before a change. Call the write tool with dry_run=false; Sub-Sub shows ${user} the server's preview and applies it only on approval. This replaces the dry-run steps above.`,
69
69
  );
package/src/web.ts CHANGED
@@ -604,10 +604,10 @@ export async function startWeb(opts: WebOptions, env: NodeJS.ProcessEnv = proces
604
604
  const body = await readJson(req);
605
605
  const target = resolve(cwd, expand(String(body.path ?? "")));
606
606
  const vault = cfg.vault;
607
- // Judge the real file, so a link inside the notes folder cannot open a document outside it.
607
+ // Judge the real file, so a link inside the Sub-Sub folder cannot open a document outside it.
608
608
  const real = realish(target);
609
609
  const inside = within(real, realish(cwd)) || Boolean(vault && within(real, realish(vault)));
610
- if (!inside || !existsSync(target)) return send(res, 404, { error: "not found in the notes folder" });
610
+ if (!inside || !existsSync(target)) return send(res, 404, { error: "not found in the Sub-Sub folder" });
611
611
  // Documents only: a file that the model wrote must never be run.
612
612
  if (!OPENABLE.has(extname(target).toLowerCase())) return send(res, 403, { error: "Sub-Sub opens only notes and documents (.md, .txt, .pdf, .bib, .csv, .qmd)." });
613
613
  if (vault && within(target, vault) && existsSync(join(vault, ".obsidian"))) openExternal(`obsidian://open?path=${encodeURIComponent(target)}`);