From 508355b8fcc56e2ff41317944d36fc0882628c68 Mon Sep 17 00:00:00 2001 From: Dotta <34892728+cryppadotta@users.noreply.github.com> Date: Mon, 11 May 2026 20:45:41 -0500 Subject: [PATCH] [codex] Add LLM Wiki plugin package to master (#5716) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Thinking Path > - Paperclip orchestrates AI agents for zero-human companies. > - The plugin system is the extension surface for optional product capabilities without baking every workflow into core. > - The LLM Wiki plugin package was reviewed in stacked PR #5592, which targeted `pap-9173-llm-wiki-rest`. > - The stack base PR #5597 merged to `master` before #5592 was merged into that branch, so the plugin package never reached `master`. > - A direct PR from `pap-9173-llm-wiki-rest` back to `master` would be noisy because that branch has diverged from current `master`. > - This pull request reapplies the reviewed `packages/plugins/plugin-llm-wiki/` package onto current `master` and updates Docker deps-stage manifest coverage. > - The branch intentionally no longer changes `pnpm-workspace.yaml` after maintainer feedback; because the new package is now a root workspace importer, the remaining integration question is how maintainers want the root lockfile handled under the current PR policy. ## What Changed - Added the LLM Wiki plugin package under `packages/plugins/plugin-llm-wiki/` from the merged PR #5592 head. - Preserved the post-review cleanup from #5592: generated design/screenshot artifacts are not committed, and `src/ui/index.tsx` / `src/wiki.ts` are small public entrypoints. - Added the new plugin package manifest to the Docker deps stage so policy can validate package manifest coverage. - Removed the earlier `pnpm-workspace.yaml` exclusion per maintainer request, so the plugin is included by the existing `packages/plugins/*` workspace glob. ## Verification Current head: - PGlite migration harness: ran migrations 001-003, verified old non-space distillation unique constraints were removed, inserted duplicate cursor and work-item keys in a second space, then reran migration 003 successfully - `node ./scripts/check-docker-deps-stage.mjs` - `git diff --check` Known current-head install result after removing the workspace exclusion: - `pnpm install --frozen-lockfile` fails because `pnpm-lock.yaml` has no importer for `packages/plugins/plugin-llm-wiki/package.json`. Previously verified on the same plugin source before the workspace-exclusion removal: - `pnpm --filter @paperclipai/plugin-sdk build` - `cd packages/plugins/plugin-llm-wiki && pnpm install --lockfile=false && pnpm test` ## Risks - The branch now includes `packages/plugins/plugin-llm-wiki` in the root workspace but does not update `pnpm-lock.yaml`. Root frozen install will fail until maintainers choose a lockfile path that fits repo policy. - Committing `pnpm-lock.yaml` directly on this PR conflicts with the current PR policy check, while excluding the package from `pnpm-workspace.yaml` was rejected in maintainer feedback. - The package includes UI code already reviewed in #5592; generated screenshot/design artifacts were intentionally removed per maintainer request, so visual review should regenerate screenshots locally if needed. - The package depends on plugin host support from #5597, which is already merged to `master`. > For core feature work, check [`ROADMAP.md`](ROADMAP.md) first and discuss it in `#dev` before opening the PR. Feature PRs that overlap with planned core work may need to be redirected — check the roadmap first. See `CONTRIBUTING.md`. ## Model Used - OpenAI GPT-5 Codex via Codex CLI, tool use and local code execution enabled; context window not exposed. ## Checklist - [x] I have included a thinking path that traces from project context to this change - [x] I have specified the model used (with version and capability details) - [x] I have checked ROADMAP.md and confirmed this PR does not duplicate planned core work - [x] I have run the targeted checks listed above - [x] I have added or updated tests where applicable - [ ] If this change affects the UI, I have included before/after screenshots - [x] I have updated relevant documentation to reflect my changes - [x] I have considered and documented any risks above - [x] I will address all Greptile and reviewer comments before requesting merge Stack context: #5592 was merged into `pap-9173-llm-wiki-rest` after #5597 had already merged that branch to `master`, so this follow-up PR is needed to carry the plugin package itself into `master`. Co-authored-by: Paperclip --- Dockerfile | 1 + packages/plugins/plugin-llm-wiki/.gitignore | 4 + packages/plugins/plugin-llm-wiki/README.md | 160 + .../agents/wiki-maintainer/AGENTS.md | 65 + .../plugin-llm-wiki/esbuild.config.mjs | 17 + .../fixtures/basic-root/.gitignore | 3 + .../fixtures/basic-root/AGENTS.md | 137 + .../fixtures/basic-root/IDEA.md | 75 + .../fixtures/basic-root/raw/.gitkeep | 0 .../basic-root/raw/plugin-boundaries.md | 3 + .../basic-root/wiki/areas/knowledge.md | 3 + .../basic-root/wiki/concepts/.gitkeep | 0 .../wiki/concepts/plugin-boundaries.md | 3 + .../basic-root/wiki/entities/.gitkeep | 0 .../fixtures/basic-root/wiki/index.md | 23 + .../fixtures/basic-root/wiki/log.md | 10 + .../basic-root/wiki/projects/.gitkeep | 1 + .../fixtures/basic-root/wiki/sources/.gitkeep | 0 .../basic-root/wiki/synthesis/.gitkeep | 0 .../migrations/001_llm_wiki.sql | 101 + .../migrations/002_paperclip_distillation.sql | 88 + .../plugin-llm-wiki/migrations/003_spaces.sql | 236 + packages/plugins/plugin-llm-wiki/package.json | 47 + .../plugins/plugin-llm-wiki/rollup.config.mjs | 28 + .../plugins/plugin-llm-wiki/skills/README.md | 34 + .../skills/index-refresh/SKILL.md | 65 + .../skills/paperclip-distill/SKILL.md | 125 + .../skills/wiki-ingest/SKILL.md | 57 + .../plugin-llm-wiki/skills/wiki-lint/SKILL.md | 57 + .../skills/wiki-maintainer/SKILL.md | 12 + .../skills/wiki-query/SKILL.md | 44 + .../plugins/plugin-llm-wiki/src/manifest.ts | 601 ++ .../plugins/plugin-llm-wiki/src/templates.ts | 73 + .../plugins/plugin-llm-wiki/src/ui/app.tsx | 7120 +++++++++++++++++ .../plugins/plugin-llm-wiki/src/ui/index.tsx | 1 + .../src/ui/issue-attachments.ts | 49 + packages/plugins/plugin-llm-wiki/src/wiki.ts | 1 + .../plugins/plugin-llm-wiki/src/wiki/core.ts | 4976 ++++++++++++ .../plugins/plugin-llm-wiki/src/worker.ts | 1081 +++ .../plugin-llm-wiki/templates/.gitignore | 3 + .../plugin-llm-wiki/templates/AGENTS.md | 137 + .../plugins/plugin-llm-wiki/templates/IDEA.md | 75 + .../plugin-llm-wiki/templates/raw/.gitkeep | 0 .../templates/wiki/concepts/.gitkeep | 0 .../templates/wiki/entities/.gitkeep | 0 .../plugin-llm-wiki/templates/wiki/index.md | 23 + .../plugin-llm-wiki/templates/wiki/log.md | 10 + .../templates/wiki/projects/.gitkeep | 1 + .../templates/wiki/sources/.gitkeep | 0 .../templates/wiki/synthesis/.gitkeep | 0 .../tests/issue-attachments.spec.ts | 60 + .../plugin-llm-wiki/tests/plugin.spec.ts | 3746 +++++++++ .../tests/screenshots/capture.mjs | 167 + .../tests/screenshots/entry.tsx | 6 + .../tests/screenshots/harness.tsx | 1061 +++ .../tests/screenshots/index.html | 84 + .../tests/wiki-route-sidebar-ui.spec.ts | 781 ++ .../plugins/plugin-llm-wiki/tsconfig.json | 27 + .../plugins/plugin-llm-wiki/vitest.config.ts | 8 + 59 files changed, 21490 insertions(+) create mode 100644 packages/plugins/plugin-llm-wiki/.gitignore create mode 100644 packages/plugins/plugin-llm-wiki/README.md create mode 100644 packages/plugins/plugin-llm-wiki/agents/wiki-maintainer/AGENTS.md create mode 100644 packages/plugins/plugin-llm-wiki/esbuild.config.mjs create mode 100644 packages/plugins/plugin-llm-wiki/fixtures/basic-root/.gitignore create mode 100644 packages/plugins/plugin-llm-wiki/fixtures/basic-root/AGENTS.md create mode 100644 packages/plugins/plugin-llm-wiki/fixtures/basic-root/IDEA.md create mode 100644 packages/plugins/plugin-llm-wiki/fixtures/basic-root/raw/.gitkeep create mode 100644 packages/plugins/plugin-llm-wiki/fixtures/basic-root/raw/plugin-boundaries.md create mode 100644 packages/plugins/plugin-llm-wiki/fixtures/basic-root/wiki/areas/knowledge.md create mode 100644 packages/plugins/plugin-llm-wiki/fixtures/basic-root/wiki/concepts/.gitkeep create mode 100644 packages/plugins/plugin-llm-wiki/fixtures/basic-root/wiki/concepts/plugin-boundaries.md create mode 100644 packages/plugins/plugin-llm-wiki/fixtures/basic-root/wiki/entities/.gitkeep create mode 100644 packages/plugins/plugin-llm-wiki/fixtures/basic-root/wiki/index.md create mode 100644 packages/plugins/plugin-llm-wiki/fixtures/basic-root/wiki/log.md create mode 100644 packages/plugins/plugin-llm-wiki/fixtures/basic-root/wiki/projects/.gitkeep create mode 100644 packages/plugins/plugin-llm-wiki/fixtures/basic-root/wiki/sources/.gitkeep create mode 100644 packages/plugins/plugin-llm-wiki/fixtures/basic-root/wiki/synthesis/.gitkeep create mode 100644 packages/plugins/plugin-llm-wiki/migrations/001_llm_wiki.sql create mode 100644 packages/plugins/plugin-llm-wiki/migrations/002_paperclip_distillation.sql create mode 100644 packages/plugins/plugin-llm-wiki/migrations/003_spaces.sql create mode 100644 packages/plugins/plugin-llm-wiki/package.json create mode 100644 packages/plugins/plugin-llm-wiki/rollup.config.mjs create mode 100644 packages/plugins/plugin-llm-wiki/skills/README.md create mode 100644 packages/plugins/plugin-llm-wiki/skills/index-refresh/SKILL.md create mode 100644 packages/plugins/plugin-llm-wiki/skills/paperclip-distill/SKILL.md create mode 100644 packages/plugins/plugin-llm-wiki/skills/wiki-ingest/SKILL.md create mode 100644 packages/plugins/plugin-llm-wiki/skills/wiki-lint/SKILL.md create mode 100644 packages/plugins/plugin-llm-wiki/skills/wiki-maintainer/SKILL.md create mode 100644 packages/plugins/plugin-llm-wiki/skills/wiki-query/SKILL.md create mode 100644 packages/plugins/plugin-llm-wiki/src/manifest.ts create mode 100644 packages/plugins/plugin-llm-wiki/src/templates.ts create mode 100644 packages/plugins/plugin-llm-wiki/src/ui/app.tsx create mode 100644 packages/plugins/plugin-llm-wiki/src/ui/index.tsx create mode 100644 packages/plugins/plugin-llm-wiki/src/ui/issue-attachments.ts create mode 100644 packages/plugins/plugin-llm-wiki/src/wiki.ts create mode 100644 packages/plugins/plugin-llm-wiki/src/wiki/core.ts create mode 100644 packages/plugins/plugin-llm-wiki/src/worker.ts create mode 100644 packages/plugins/plugin-llm-wiki/templates/.gitignore create mode 100644 packages/plugins/plugin-llm-wiki/templates/AGENTS.md create mode 100644 packages/plugins/plugin-llm-wiki/templates/IDEA.md create mode 100644 packages/plugins/plugin-llm-wiki/templates/raw/.gitkeep create mode 100644 packages/plugins/plugin-llm-wiki/templates/wiki/concepts/.gitkeep create mode 100644 packages/plugins/plugin-llm-wiki/templates/wiki/entities/.gitkeep create mode 100644 packages/plugins/plugin-llm-wiki/templates/wiki/index.md create mode 100644 packages/plugins/plugin-llm-wiki/templates/wiki/log.md create mode 100644 packages/plugins/plugin-llm-wiki/templates/wiki/projects/.gitkeep create mode 100644 packages/plugins/plugin-llm-wiki/templates/wiki/sources/.gitkeep create mode 100644 packages/plugins/plugin-llm-wiki/templates/wiki/synthesis/.gitkeep create mode 100644 packages/plugins/plugin-llm-wiki/tests/issue-attachments.spec.ts create mode 100644 packages/plugins/plugin-llm-wiki/tests/plugin.spec.ts create mode 100644 packages/plugins/plugin-llm-wiki/tests/screenshots/capture.mjs create mode 100644 packages/plugins/plugin-llm-wiki/tests/screenshots/entry.tsx create mode 100644 packages/plugins/plugin-llm-wiki/tests/screenshots/harness.tsx create mode 100644 packages/plugins/plugin-llm-wiki/tests/screenshots/index.html create mode 100644 packages/plugins/plugin-llm-wiki/tests/wiki-route-sidebar-ui.spec.ts create mode 100644 packages/plugins/plugin-llm-wiki/tsconfig.json create mode 100644 packages/plugins/plugin-llm-wiki/vitest.config.ts diff --git a/Dockerfile b/Dockerfile index 95c452c9..e367910e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -34,6 +34,7 @@ COPY packages/adapters/pi-local/package.json packages/adapters/pi-local/ COPY packages/plugins/sdk/package.json packages/plugins/sdk/ COPY --parents packages/plugins/sandbox-providers/./*/package.json packages/plugins/sandbox-providers/ COPY packages/plugins/paperclip-plugin-fake-sandbox/package.json packages/plugins/paperclip-plugin-fake-sandbox/ +COPY packages/plugins/plugin-llm-wiki/package.json packages/plugins/plugin-llm-wiki/ COPY patches/ patches/ RUN pnpm install --frozen-lockfile diff --git a/packages/plugins/plugin-llm-wiki/.gitignore b/packages/plugins/plugin-llm-wiki/.gitignore new file mode 100644 index 00000000..d9e2126a --- /dev/null +++ b/packages/plugins/plugin-llm-wiki/.gitignore @@ -0,0 +1,4 @@ +dist +node_modules +.paperclip-sdk +screenshots diff --git a/packages/plugins/plugin-llm-wiki/README.md b/packages/plugins/plugin-llm-wiki/README.md new file mode 100644 index 00000000..6e0aabd4 --- /dev/null +++ b/packages/plugins/plugin-llm-wiki/README.md @@ -0,0 +1,160 @@ +# LLM Wiki + +Local-file LLM Wiki plugin for source ingestion, wiki browsing, query, lint, and maintenance workflows. + +## Scope + +This package is the standalone home for LLM Wiki behavior. Wiki-specific routes, +UI, prompts, tools, local-folder templates, migrations, fixtures, and tests live +here rather than in Paperclip core. + +The alpha surface includes: + +- manifest-declared Wiki page, sidebar entry, and settings page +- trusted local folder declaration for `raw/`, `wiki/`, `AGENTS.md`, `IDEA.md`, `wiki/index.md`, and `wiki/log.md` +- plugin database namespace migration for wiki instances, sources, pages, operations, query sessions, and resource bindings +- managed `Wiki Maintainer` agent, managed `LLM Wiki` project, and paused managed routines for wiki update processing, lint, and index refresh +- plugin-operation issue creation using `surfaceVisibility: "plugin_operation"` +- local source capture into `raw/` with metadata rows in the plugin DB namespace +- opt-in company-scoped Paperclip event ingestion controls for issues, comments, and documents; event ingestion is disabled by default and routes captured raw provenance into the default space only +- manual Paperclip project/root issue distillation and bounded backfill actions with explicit work items, operation issues, source caps, and estimated cost recording +- Paperclip-derived distillation (cursor windows, manual `distill-now`, backfill) always writes into the default wiki space in Phase 1; non-default spaces remain on manual / raw-file ingest until per-space Paperclip ingestion profiles ship +- Paperclip-derived distillation maintains `wiki/projects//standup.md` as the executive current-state view for each represented project, alongside durable `wiki/projects//index.md` knowledge pages +- wiki page writes with plugin path validation, atomic local-folder writes, metadata/revision rows, backlink extraction, and optional stale-hash protection +- wiki tools for search/read/write/propose patch/source/log/index/backlinks workflows + +## Phase 5 Security Gate + +Paperclip-derived text ingestion stays limited to issue titles/descriptions, issue comments, and issue documents. + +- Issue attachments/assets are **metadata-only** in Phase 5. +- Issue work products are **metadata-only** in Phase 5. +- The wiki must not fetch `/api/assets/:id/content`, dereference work-product `url` fields, or store those capability-bearing links in source bundles/snapshots. + +The accepted policy lives in [doc/plans/2026-05-06-llm-wiki-paperclip-asset-security-gate.md](../../../doc/plans/2026-05-06-llm-wiki-paperclip-asset-security-gate.md). + +## Development + +```bash +pnpm install +pnpm dev # watch builds +pnpm dev:ui # local dev server with hot-reload events +pnpm test +``` + +From the Paperclip repo root: + +```bash +pnpm --filter @paperclipai/plugin-llm-wiki typecheck +pnpm --filter @paperclipai/plugin-llm-wiki test +pnpm --filter @paperclipai/plugin-llm-wiki build +``` + +## Alpha Verification + +Run these commands from the Paperclip repo root before handing off alpha plugin +changes: + +```bash +pnpm --filter @paperclipai/plugin-llm-wiki typecheck +pnpm --filter @paperclipai/plugin-llm-wiki test +pnpm --filter @paperclipai/plugin-llm-wiki build +``` + +The focused Vitest suite covers: + +- standalone package boundaries and package-local harness dependencies +- required local folder bootstrap writes +- raw source capture plus ingest metadata persistence +- hidden plugin-operation issue creation for ingest/query/file-as-page workflows +- disabled and enabled Paperclip event ingestion paths +- managed routine declarations, manual distill/backfill work items, source cap handling, and backfill project/date scoping +- atomic page writes, metadata/revision rows, backlinks, and stale-hash refusal +- query session creation, run-id recording, stream event forwarding, and completion updates +- filing a streamed query answer back into the wiki through a hidden operation + +Remaining alpha gaps: + +- Browser screenshot capture is maintained separately under `tests/screenshots`; + generated `screenshots/` outputs are local artifacts and are ignored by git. +- Host-level plugin install and live agent invocation still need Paperclip + server/runtime smoke coverage when preparing a release candidate. + + + +## Install Into Paperclip + +```bash +curl -X POST http://127.0.0.1:3100/api/plugins/install \ + -H "Content-Type: application/json" \ + -d '{"packageName":"/Users/dotta/paperclip/.paperclip/worktrees/PAP-3179-design-a-llm-wiki-plugin/packages/plugins/plugin-llm-wiki","isLocalPath":true}' +``` + +## Build Options + +- `pnpm build` uses esbuild presets from `@paperclipai/plugin-sdk/bundlers`. +- `pnpm build:rollup` uses rollup presets from the same SDK. + +After changing manifest-loaded assets such as skills, agent instructions, or +templates, recompile the local plugin before re-enabling it: + +```bash +pnpm --filter @paperclipai/plugin-llm-wiki build +``` + +The package-local `dist/` directory is ignored by git, but local Paperclip +installs load the compiled `dist/manifest.js` and `dist/worker.js` files at +runtime. If activation failed before the rebuild, re-enable the plugin or +restart the Paperclip dev server so the host imports the fresh bundle. + +## Local File Layout + +```text +/ + AGENTS.md + IDEA.md + .gitignore + raw/ + .gitkeep + wiki/ + index.md + log.md + sources/ + .gitkeep + projects/ + .gitkeep + / + index.md + standup.md + decisions.md + history.md + entities/ + .gitkeep + concepts/ + .gitkeep + synthesis/ + .gitkeep +``` + +Use the settings page or `bootstrap-root` action to configure the folder and +write the starter files. The plugin uses Paperclip's local folder API for path +containment, symlink checks, read/write validation, and atomic writes. + +Bootstrap preserves existing files rather than overwriting operator edits. The +default first-install skeleton is copied from the vanilla LLM Wiki layout, with +`CLAUDE.md` renamed to `AGENTS.md` and Paperclip project overviews, standups, +decisions, and history kept together under `wiki/projects//`. + +## Managed Agent Instructions + +Plugin-managed agent instruction bundles live under: + +```text +agents//AGENTS.md +``` + +For this plugin the Wiki Maintainer source bundle is `agents/wiki-maintainer/AGENTS.md`. +Any additional files in that folder are installed as sibling instruction files +for the managed agent. The settings health check reports drift from these +defaults, and resetting the managed agent asks for confirmation before replacing +customized instructions. diff --git a/packages/plugins/plugin-llm-wiki/agents/wiki-maintainer/AGENTS.md b/packages/plugins/plugin-llm-wiki/agents/wiki-maintainer/AGENTS.md new file mode 100644 index 00000000..3c8b6e88 --- /dev/null +++ b/packages/plugins/plugin-llm-wiki/agents/wiki-maintainer/AGENTS.md @@ -0,0 +1,65 @@ +# LLM Wiki Maintainer + +You are the maintainer of this personal wiki. The wiki is a persistent, interlinked knowledge base built from raw source documents. You read sources, extract knowledge, and integrate it into evolving wiki pages. The user curates sources, directs analysis, and asks questions; you handle the bookkeeping. + +## Wiki Root + +The wiki root folder is: + +`{{localFolders.wiki-root.path}}` + +The wiki's default operating schema is: + +`{{localFolders.wiki-root.agentsPath}}` + +Before ingest, query, lint, index, or maintenance work, read that wiki-root `AGENTS.md` file. It is the source of truth for page layout, citation style, log format, and wiki conventions. If the path above says `(not configured)`, stop and ask for the LLM Wiki root folder to be configured in plugin settings before doing file work. + +## Identity + +- You maintain the LLM Wiki, not the application codebase. +- You keep raw source material in `raw/` immutable. +- You keep Paperclip project operating summaries current in `wiki/projects//standup.md`. +- You create and update durable wiki pages under `wiki/`. +- You keep `wiki/index.md` and `wiki/log.md` accurate after changes. +- You cite wiki pages and raw sources in answers. + +## Operating Loop + +1. Resolve the configured wiki root folder and the target space named in the operation issue. +2. Read the target space's `AGENTS.md`. +3. Read the target space's `wiki/index.md` and recent `wiki/log.md` entries before choosing files. +4. Pick the right operation skill (see below) and follow it. +5. Use the LLM Wiki plugin tools for file reads, file writes, search, and logging. Always pass the operation issue's `wikiId` and `spaceSlug` arguments. +6. Keep changes focused and append a concise log entry for durable updates. + +All operation paths are relative to the target space root. Paperclip-derived operations (`distill`, `backfill`, cursor-window distillation, event capture) always target the default space in Phase 1 — pass `spaceSlug: "default"` and reject any prompt that asks you to write Paperclip-derived pages into a non-default space. Manual ingest (`ingest`, `query`, `lint`, `index`, `file-as-page`) follows whatever space the operation issue names; do not cross into another space unless the operation issue explicitly requests a multi-space sweep. + +For Paperclip-derived project work, maintain two layers: + +- `wiki/projects//standup.md` — the executive standup for live project status, recent work, blockers/risks, and next actions. Rewrite it to the current truth instead of appending dated diary sections. +- `wiki/projects//index.md` and optional `wiki/projects//decisions.md` / `history.md` — durable knowledge pages for context, decisions, and meaningful history. + +Project pages and standups should read like human executive synthesis. Group work by concept, decision, blocker, and next action; use readable Paperclip issue links as evidence, but do not dump UUIDs, dates, statuses, or one-line issue inventories into the wiki narrative. + +## Skills + +Each operation has a dedicated LLM Wiki skill installed on this agent. Use the matching skill before improvising — they encode the page conventions, voice, and verification checklist for each operation. + +- `wiki-ingest` — a captured `raw/` source needs to become durable wiki pages. +- `wiki-query` — answer a question from the wiki with citations; offer durable synthesis. +- `wiki-lint` — read-only audit for contradictions, orphans, weak provenance, missing concept pages. +- `paperclip-distill` — turn a Paperclip source bundle (cursor-window, distill, or backfill) into wiki-insightful project pages, decisions, and history. Replaces the stiff, datestamp-heavy templated output. +- `index-refresh` — keep `wiki/index.md` accurate and scannable. + +The operation issue's `originKind` (`plugin:llm-wiki:operation:`) tells you which skill to load: + +| `operationType` | Skill | +| --------------------- | ---------------------------------------------- | +| `ingest` | `wiki-ingest` | +| `query` | `wiki-query` | +| `lint` | `wiki-lint` | +| `distill`, `backfill` | `paperclip-distill` | +| `index` | `index-refresh` | +| `file-as-page` | `wiki-query` (filing synthesis from an answer) | + +If a skill conflicts with this file, follow this file for identity. If a skill conflicts with the wiki-root `AGENTS.md`, follow that for page structure and voice. diff --git a/packages/plugins/plugin-llm-wiki/esbuild.config.mjs b/packages/plugins/plugin-llm-wiki/esbuild.config.mjs new file mode 100644 index 00000000..b5cfd36e --- /dev/null +++ b/packages/plugins/plugin-llm-wiki/esbuild.config.mjs @@ -0,0 +1,17 @@ +import esbuild from "esbuild"; +import { createPluginBundlerPresets } from "@paperclipai/plugin-sdk/bundlers"; + +const presets = createPluginBundlerPresets({ uiEntry: "src/ui/index.tsx" }); +const watch = process.argv.includes("--watch"); + +const workerCtx = await esbuild.context(presets.esbuild.worker); +const manifestCtx = await esbuild.context(presets.esbuild.manifest); +const uiCtx = await esbuild.context(presets.esbuild.ui); + +if (watch) { + await Promise.all([workerCtx.watch(), manifestCtx.watch(), uiCtx.watch()]); + console.log("esbuild watch mode enabled for worker, manifest, and ui"); +} else { + await Promise.all([workerCtx.rebuild(), manifestCtx.rebuild(), uiCtx.rebuild()]); + await Promise.all([workerCtx.dispose(), manifestCtx.dispose(), uiCtx.dispose()]); +} diff --git a/packages/plugins/plugin-llm-wiki/fixtures/basic-root/.gitignore b/packages/plugins/plugin-llm-wiki/fixtures/basic-root/.gitignore new file mode 100644 index 00000000..ef42c26d --- /dev/null +++ b/packages/plugins/plugin-llm-wiki/fixtures/basic-root/.gitignore @@ -0,0 +1,3 @@ +.DS_Store +.obsidian/workspace* +.obsidian/cache diff --git a/packages/plugins/plugin-llm-wiki/fixtures/basic-root/AGENTS.md b/packages/plugins/plugin-llm-wiki/fixtures/basic-root/AGENTS.md new file mode 100644 index 00000000..3c2aa273 --- /dev/null +++ b/packages/plugins/plugin-llm-wiki/fixtures/basic-root/AGENTS.md @@ -0,0 +1,137 @@ +# AGENTS.md — LLM Wiki Schema + +You are the maintainer of this personal wiki. The wiki is a persistent, interlinked knowledge base built from raw source documents. You read sources, extract knowledge, and integrate it into evolving wiki pages. The user curates sources, directs analysis, and asks questions; you handle the bookkeeping. + +The underlying pattern is described in `IDEA.md` (Karpathy's "LLM Wiki" gist). Read it if you need the philosophy; this file is the operational schema. + +## Layout + +``` +. +├── AGENTS.md # this file — your operating instructions +├── IDEA.md # the pattern this wiki follows +├── raw/ # immutable source documents (you read, never write) +└── wiki/ # generated, owned by you + ├── index.md # catalog of all pages + ├── log.md # append-only timeline of operations + ├── sources/ # one summary page per source + ├── projects/ # Paperclip project overviews, standups, decisions, and history + │ └── / + │ ├── index.md + │ ├── standup.md + │ ├── decisions.md + │ └── history.md + ├── entities/ # people, organizations, products, places + ├── concepts/ # ideas, frameworks, definitions + └── synthesis/ # cross-cutting analysis, comparisons, theses +``` + +The subdirectories under `wiki/` are conventional, not enforced. Add new categories (e.g. `wiki/papers/`) as the domain demands — and update this file when you do. + +Paperclip project material lives only under `wiki/projects//`. Do not create a top-level `projects/` directory. + +- `wiki/projects//standup.md` is the executive-level project standup. It answers where the project stands today, what changed recently, current blockers/risks, and the next concrete actions. +- `wiki/projects//index.md` is the durable knowledge page. It explains what the project is, why it exists, decisions made, history, and long-lived context. +- Keep the two linked. A standup should link to the durable project page, and the durable project page should point at the current standup for live status. +- Update `standup.md` whenever Paperclip project, issue, plan, comment, blocker, approval, or status history materially changes the project's current state. Do not append endless dated sections; rewrite it as today's concise status. +- Project writing should be editorial and concept-grouped. Do not dump issue queues, UUIDs, raw metadata, or date-heavy ledgers into project pages. Reference Paperclip tasks with human issue links where useful, but make headings and paragraphs explain the concepts, decisions, completed work, next work, and blockers in plain executive language. + +## Page conventions + +- **Filename:** kebab-case, `.md`. Treat filenames as stable; do not rename without updating backlinks. +- **Frontmatter:** YAML at the top of every wiki page. + ```yaml + --- + title: Human-readable title + type: source | project | entity | concept | synthesis + tags: [tag-a, tag-b] + sources: [raw/doc.pdf] # for source pages and synthesis pages + created: YYYY-MM-DD + updated: YYYY-MM-DD + --- + ``` +- **Cross-links:** Obsidian-style `[[wiki/entities/some-page]]` (or `[[some-page]]` when unambiguous). When you mention a concept or entity that has — or should have — its own page, link it. +- **Citations:** cite the source inline whenever a claim comes from one: `(see [[wiki/sources/some-slug]])`. +- **Voice:** terse, factual, neutral. The wiki is reference material, not narrative. + +## Operations + +### Ingest + +Triggered when the user drops a file in `raw/` and asks to process it (or just says "ingest"). + +1. Read the source end to end. +2. Briefly discuss key takeaways with the user before writing — confirm what to emphasize. +3. Create `wiki/sources/.md`: a summary page (~300–800 words) covering the source's main claims, structure, and notable quotes or data. +4. Update or create relevant pages in `entities/`, `concepts/`, `synthesis/`. A typical ingest touches 5–15 pages. +5. Add any new pages to `wiki/index.md`. +6. Append a log entry: + ``` + ## [YYYY-MM-DD] ingest | + - source: raw/ + - new pages: [[...]], [[...]] + - updated pages: [[...]], [[...]] + - notes: + ``` + +When new information contradicts an existing page, do **not** silently overwrite. Flag the contradiction on the page (a `> ⚠ contradicted by [[...]] (YYYY-MM-DD)` callout) and note it in the log. + +### Project updates + +Triggered when Paperclip project, issue, plan, comment, blocker, or status history is distilled into the wiki. + +1. Create or update `wiki/projects//standup.md` first. Every Paperclip project represented in the wiki must have one. Keep stable sections for executive readout, what changed, decisions, blockers/risks, next actions, and links. +2. Create or update `wiki/projects//index.md` as the durable project overview. Keep stable sections for overview, current direction, workstreams, decisions, open risks/blockers, and references. +3. Use `wiki/projects//decisions.md` for accepted/rejected plans, architectural decisions, approval outcomes, and reversals when a project has enough decision history to warrant a separate page. +4. Use `wiki/projects//history.md` for compact narrative history of meaningful project movement. Group by phase or concept; do not mirror every issue comment. +5. Always cite Paperclip source material with readable links to issue identifiers, document keys, issue documents, approvals, and raw/source pages. Do not put UUIDs in prose unless the UUID itself is the subject. +6. Update `wiki/index.md` under Projects and append a `project` log entry to `wiki/log.md`. + +### Query + +The user asks a question. You: + +1. Read `wiki/index.md` to find candidate pages. +2. Read those pages; follow links as needed. +3. Answer with citations back to wiki pages, and ultimately to raw sources. +4. If the answer is substantial (a comparison, analysis, new synthesis), offer to file it under `wiki/synthesis/` so the work compounds rather than disappearing into chat history. + +If the wiki lacks what the question needs, say so plainly and suggest sources to ingest or web searches to run. + +### Lint + +On request ("lint", "health check"), scan for: + +- contradictions across pages +- claims a newer source has superseded +- orphan pages (not linked from `index.md` or any other page) +- concepts mentioned in multiple places but lacking a dedicated page +- broken `[[wiki-links]]` +- gaps where a web search or new source would help + +Report findings as a checklist and ask the user which to act on. + +## index.md format + +A catalog organized by category. Each line: `- [[path]] — one-line summary`. Keep it scannable; this is your primary navigation aid before opening pages. + +## log.md format + +Append new entries to the bottom. Every entry header follows: + +``` +## [YYYY-MM-DD] | +``` + +so `grep "^## \[" wiki/log.md | tail -10` always returns recent activity. Operations: `ingest`, `query`, `lint`, `setup`, `refactor`. + +## Customization + +This schema is intentionally generic. As the wiki's domain becomes clear, evolve it: + +- add domain-specific page types and subdirectories +- adjust frontmatter fields +- specify preferred output formats for queries (Marp slides, charts, tables) +- record workflow preferences (one-at-a-time vs batch ingest, level of human supervision) + +When you and the user agree on a convention, **write it into this file**. The schema is the wiki's source of truth for how the wiki is built. diff --git a/packages/plugins/plugin-llm-wiki/fixtures/basic-root/IDEA.md b/packages/plugins/plugin-llm-wiki/fixtures/basic-root/IDEA.md new file mode 100644 index 00000000..35ef0712 --- /dev/null +++ b/packages/plugins/plugin-llm-wiki/fixtures/basic-root/IDEA.md @@ -0,0 +1,75 @@ +# LLM Wiki + +A pattern for building personal knowledge bases using LLMs. + +This is an idea file, it is designed to be copy pasted to your own LLM Agent (e.g. OpenAI Codex, Claude Code, OpenCode / Pi, or etc.). Its goal is to communicate the high level idea, but your agent will build out the specifics in collaboration with you. + +## The core idea + +Most people's experience with LLMs and documents looks like RAG: you upload a collection of files, the LLM retrieves relevant chunks at query time, and generates an answer. This works, but the LLM is rediscovering knowledge from scratch on every question. There's no accumulation. Ask a subtle question that requires synthesizing five documents, and the LLM has to find and piece together the relevant fragments every time. Nothing is built up. NotebookLM, ChatGPT file uploads, and most RAG systems work this way. + +The idea here is different. Instead of just retrieving from raw documents at query time, the LLM **incrementally builds and maintains a persistent wiki** — a structured, interlinked collection of markdown files that sits between you and the raw sources. When you add a new source, the LLM doesn't just index it for later retrieval. It reads it, extracts the key information, and integrates it into the existing wiki — updating entity pages, revising topic summaries, noting where new data contradicts old claims, strengthening or challenging the evolving synthesis. The knowledge is compiled once and then *kept current*, not re-derived on every query. + +This is the key difference: **the wiki is a persistent, compounding artifact.** The cross-references are already there. The contradictions have already been flagged. The synthesis already reflects everything you've read. The wiki keeps getting richer with every source you add and every question you ask. + +You never (or rarely) write the wiki yourself — the LLM writes and maintains all of it. You're in charge of sourcing, exploration, and asking the right questions. The LLM does all the grunt work — the summarizing, cross-referencing, filing, and bookkeeping that makes a knowledge base actually useful over time. In practice, I have the LLM agent open on one side and Obsidian open on the other. The LLM makes edits based on our conversation, and I browse the results in real time — following links, checking the graph view, reading the updated pages. Obsidian is the IDE; the LLM is the programmer; the wiki is the codebase. + +This can apply to a lot of different contexts. A few examples: + +- **Personal**: tracking your own goals, health, psychology, self-improvement — filing journal entries, articles, podcast notes, and building up a structured picture of yourself over time. +- **Research**: going deep on a topic over weeks or months — reading papers, articles, reports, and incrementally building a comprehensive wiki with an evolving thesis. +- **Reading a book**: filing each chapter as you go, building out pages for characters, themes, plot threads, and how they connect. By the end you have a rich companion wiki. Think of fan wikis like [Tolkien Gateway](https://tolkiengateway.net/wiki/Main_Page) — thousands of interlinked pages covering characters, places, events, languages, built by a community of volunteers over years. You could build something like that personally as you read, with the LLM doing all the cross-referencing and maintenance. +- **Business/team**: an internal wiki maintained by LLMs, fed by Slack threads, meeting transcripts, project documents, customer calls. Possibly with humans in the loop reviewing updates. The wiki stays current because the LLM does the maintenance that no one on the team wants to do. +- **Competitive analysis, due diligence, trip planning, course notes, hobby deep-dives** — anything where you're accumulating knowledge over time and want it organized rather than scattered. + +## Architecture + +There are three layers: + +**Raw sources** — your curated collection of source documents. Articles, papers, images, data files. These are immutable — the LLM reads from them but never modifies them. This is your source of truth. + +**The wiki** — a directory of LLM-generated markdown files. Summaries, entity pages, concept pages, comparisons, an overview, a synthesis. The LLM owns this layer entirely. It creates pages, updates them when new sources arrive, maintains cross-references, and keeps everything consistent. You read it; the LLM writes it. + +**The schema** — a document (e.g. AGENTS.md for Paperclip agents) that tells the LLM how the wiki is structured, what the conventions are, and what workflows to follow when ingesting sources, answering questions, or maintaining the wiki. This is the key configuration file — it's what makes the LLM a disciplined wiki maintainer rather than a generic chatbot. You and the LLM co-evolve this over time as you figure out what works for your domain. + +## Operations + +**Ingest.** You drop a new source into the raw collection and tell the LLM to process it. An example flow: the LLM reads the source, discusses key takeaways with you, writes a summary page in the wiki, updates the index, updates relevant entity and concept pages across the wiki, and appends an entry to the log. A single source might touch 10-15 wiki pages. Personally I prefer to ingest sources one at a time and stay involved — I read the summaries, check the updates, and guide the LLM on what to emphasize. But you could also batch-ingest many sources at once with less supervision. It's up to you to develop the workflow that fits your style and document it in the schema for future sessions. + +**Query.** You ask questions against the wiki. The LLM searches for relevant pages, reads them, and synthesizes an answer with citations. Answers can take different forms depending on the question — a markdown page, a comparison table, a slide deck (Marp), a chart (matplotlib), a canvas. The important insight: **good answers can be filed back into the wiki as new pages.** A comparison you asked for, an analysis, a connection you discovered — these are valuable and shouldn't disappear into chat history. This way your explorations compound in the knowledge base just like ingested sources do. + +**Lint.** Periodically, ask the LLM to health-check the wiki. Look for: contradictions between pages, stale claims that newer sources have superseded, orphan pages with no inbound links, important concepts mentioned but lacking their own page, missing cross-references, data gaps that could be filled with a web search. The LLM is good at suggesting new questions to investigate and new sources to look for. This keeps the wiki healthy as it grows. + +## Indexing and logging + +Two special files help the LLM (and you) navigate the wiki as it grows. They serve different purposes: + +**index.md** is content-oriented. It's a catalog of everything in the wiki — each page listed with a link, a one-line summary, and optionally metadata like date or source count. Organized by category (entities, concepts, sources, etc.). The LLM updates it on every ingest. When answering a query, the LLM reads the index first to find relevant pages, then drills into them. This works surprisingly well at moderate scale (~100 sources, ~hundreds of pages) and avoids the need for embedding-based RAG infrastructure. + +**log.md** is chronological. It's an append-only record of what happened and when — ingests, queries, lint passes. A useful tip: if each entry starts with a consistent prefix (e.g. `## [2026-04-02] ingest | Article Title`), the log becomes parseable with simple unix tools — `grep "^## \[" log.md | tail -5` gives you the last 5 entries. The log gives you a timeline of the wiki's evolution and helps the LLM understand what's been done recently. + +## Optional: CLI tools + +At some point you may want to build small tools that help the LLM operate on the wiki more efficiently. A search engine over the wiki pages is the most obvious one — at small scale the index file is enough, but as the wiki grows you want proper search. [qmd](https://github.com/tobi/qmd) is a good option: it's a local search engine for markdown files with hybrid BM25/vector search and LLM re-ranking, all on-device. It has both a CLI (so the LLM can shell out to it) and an MCP server (so the LLM can use it as a native tool). You could also build something simpler yourself — the LLM can help you vibe-code a naive search script as the need arises. + +## Tips and tricks + +- **Obsidian Web Clipper** is a browser extension that converts web articles to markdown. Very useful for quickly getting sources into your raw collection. +- **Download images locally.** In Obsidian Settings → Files and links, set "Attachment folder path" to a fixed directory (e.g. `raw/assets/`). Then in Settings → Hotkeys, search for "Download" to find "Download attachments for current file" and bind it to a hotkey (e.g. Ctrl+Shift+D). After clipping an article, hit the hotkey and all images get downloaded to local disk. This is optional but useful — it lets the LLM view and reference images directly instead of relying on URLs that may break. Note that LLMs can't natively read markdown with inline images in one pass — the workaround is to have the LLM read the text first, then view some or all of the referenced images separately to gain additional context. It's a bit clunky but works well enough. +- **Obsidian's graph view** is the best way to see the shape of your wiki — what's connected to what, which pages are hubs, which are orphans. +- **Marp** is a markdown-based slide deck format. Obsidian has a plugin for it. Useful for generating presentations directly from wiki content. +- **Dataview** is an Obsidian plugin that runs queries over page frontmatter. If your LLM adds YAML frontmatter to wiki pages (tags, dates, source counts), Dataview can generate dynamic tables and lists. +- The wiki is just a git repo of markdown files. You get version history, branching, and collaboration for free. + +## Why this works + +The tedious part of maintaining a knowledge base is not the reading or the thinking — it's the bookkeeping. Updating cross-references, keeping summaries current, noting when new data contradicts old claims, maintaining consistency across dozens of pages. Humans abandon wikis because the maintenance burden grows faster than the value. LLMs don't get bored, don't forget to update a cross-reference, and can touch 15 files in one pass. The wiki stays maintained because the cost of maintenance is near zero. + +The human's job is to curate sources, direct the analysis, ask good questions, and think about what it all means. The LLM's job is everything else. + +The idea is related in spirit to Vannevar Bush's Memex (1945) — a personal, curated knowledge store with associative trails between documents. Bush's vision was closer to this than to what the web became: private, actively curated, with the connections between documents as valuable as the documents themselves. The part he couldn't solve was who does the maintenance. The LLM handles that. + + +## Note + +This document is intentionally abstract. It describes the idea, not a specific implementation. The exact directory structure, the schema conventions, the page formats, the tooling — all of that will depend on your domain, your preferences, and your LLM of choice. Everything mentioned above is optional and modular — pick what's useful, ignore what isn't. For example: your sources might be text-only, so you don't need image handling at all. Your wiki might be small enough that the index file is all you need, no search engine required. You might not care about slide decks and just want markdown pages. You might want a completely different set of output formats. The right way to use this is to share it with your LLM agent and work together to instantiate a version that fits your needs. The document's only job is to communicate the pattern. Your LLM can figure out the rest. diff --git a/packages/plugins/plugin-llm-wiki/fixtures/basic-root/raw/.gitkeep b/packages/plugins/plugin-llm-wiki/fixtures/basic-root/raw/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/packages/plugins/plugin-llm-wiki/fixtures/basic-root/raw/plugin-boundaries.md b/packages/plugins/plugin-llm-wiki/fixtures/basic-root/raw/plugin-boundaries.md new file mode 100644 index 00000000..89d8a8d9 --- /dev/null +++ b/packages/plugins/plugin-llm-wiki/fixtures/basic-root/raw/plugin-boundaries.md @@ -0,0 +1,3 @@ +# Raw Source + +LLM Wiki code must live in the standalone plugin package. diff --git a/packages/plugins/plugin-llm-wiki/fixtures/basic-root/wiki/areas/knowledge.md b/packages/plugins/plugin-llm-wiki/fixtures/basic-root/wiki/areas/knowledge.md new file mode 100644 index 00000000..46462345 --- /dev/null +++ b/packages/plugins/plugin-llm-wiki/fixtures/basic-root/wiki/areas/knowledge.md @@ -0,0 +1,3 @@ +# Knowledge + +The wiki stores durable knowledge as local markdown files. diff --git a/packages/plugins/plugin-llm-wiki/fixtures/basic-root/wiki/concepts/.gitkeep b/packages/plugins/plugin-llm-wiki/fixtures/basic-root/wiki/concepts/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/packages/plugins/plugin-llm-wiki/fixtures/basic-root/wiki/concepts/plugin-boundaries.md b/packages/plugins/plugin-llm-wiki/fixtures/basic-root/wiki/concepts/plugin-boundaries.md new file mode 100644 index 00000000..595ee78c --- /dev/null +++ b/packages/plugins/plugin-llm-wiki/fixtures/basic-root/wiki/concepts/plugin-boundaries.md @@ -0,0 +1,3 @@ +# Plugin Boundaries + +LLM Wiki routes, prompts, UI, tools, and migrations belong inside the plugin. diff --git a/packages/plugins/plugin-llm-wiki/fixtures/basic-root/wiki/entities/.gitkeep b/packages/plugins/plugin-llm-wiki/fixtures/basic-root/wiki/entities/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/packages/plugins/plugin-llm-wiki/fixtures/basic-root/wiki/index.md b/packages/plugins/plugin-llm-wiki/fixtures/basic-root/wiki/index.md new file mode 100644 index 00000000..54f1f8a3 --- /dev/null +++ b/packages/plugins/plugin-llm-wiki/fixtures/basic-root/wiki/index.md @@ -0,0 +1,23 @@ +# Index + +Catalog of durable wiki pages and linked project standups. Updated on every ingest or Paperclip distill. + +## Sources + +_(none yet)_ + +## Projects + +_(none yet)_ + +## Entities + +_(none yet)_ + +## Concepts + +_(none yet)_ + +## Synthesis + +_(none yet)_ diff --git a/packages/plugins/plugin-llm-wiki/fixtures/basic-root/wiki/log.md b/packages/plugins/plugin-llm-wiki/fixtures/basic-root/wiki/log.md new file mode 100644 index 00000000..6b101ab1 --- /dev/null +++ b/packages/plugins/plugin-llm-wiki/fixtures/basic-root/wiki/log.md @@ -0,0 +1,10 @@ +# Log + +Append-only chronological record of wiki operations. + +## [2026-05-03] setup | wiki initialized +- created `AGENTS.md` (schema) +- created `raw/` for source documents +- created `wiki/` skeleton: `index.md`, `log.md`, `sources/`, `projects/`, `entities/`, `concepts/`, `synthesis/` +- created `wiki/projects/` for Paperclip project overviews and standups +- pattern reference: `IDEA.md` (Karpathy "LLM Wiki" gist, https://gist.github.com/karpathy/442a6bf555914893e9891c11519de94f) diff --git a/packages/plugins/plugin-llm-wiki/fixtures/basic-root/wiki/projects/.gitkeep b/packages/plugins/plugin-llm-wiki/fixtures/basic-root/wiki/projects/.gitkeep new file mode 100644 index 00000000..8b137891 --- /dev/null +++ b/packages/plugins/plugin-llm-wiki/fixtures/basic-root/wiki/projects/.gitkeep @@ -0,0 +1 @@ + diff --git a/packages/plugins/plugin-llm-wiki/fixtures/basic-root/wiki/sources/.gitkeep b/packages/plugins/plugin-llm-wiki/fixtures/basic-root/wiki/sources/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/packages/plugins/plugin-llm-wiki/fixtures/basic-root/wiki/synthesis/.gitkeep b/packages/plugins/plugin-llm-wiki/fixtures/basic-root/wiki/synthesis/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/packages/plugins/plugin-llm-wiki/migrations/001_llm_wiki.sql b/packages/plugins/plugin-llm-wiki/migrations/001_llm_wiki.sql new file mode 100644 index 00000000..01d5067c --- /dev/null +++ b/packages/plugins/plugin-llm-wiki/migrations/001_llm_wiki.sql @@ -0,0 +1,101 @@ +CREATE TABLE plugin_llm_wiki_8f50da974f.wiki_instances ( + id uuid PRIMARY KEY, + company_id uuid NOT NULL REFERENCES public.companies(id) ON DELETE CASCADE, + wiki_id text NOT NULL, + root_folder_key text NOT NULL DEFAULT 'wiki-root', + configured_root_path text, + schema_version integer NOT NULL DEFAULT 1, + settings jsonb NOT NULL DEFAULT '{}'::jsonb, + managed_agent_key text, + managed_project_key text, + created_at timestamptz NOT NULL DEFAULT now(), + updated_at timestamptz NOT NULL DEFAULT now(), + UNIQUE (company_id, wiki_id) +); + +CREATE TABLE plugin_llm_wiki_8f50da974f.wiki_sources ( + id uuid PRIMARY KEY, + company_id uuid NOT NULL REFERENCES public.companies(id) ON DELETE CASCADE, + wiki_id text NOT NULL, + source_type text NOT NULL, + title text, + url text, + raw_path text NOT NULL, + content_hash text NOT NULL, + status text NOT NULL DEFAULT 'captured', + metadata jsonb NOT NULL DEFAULT '{}'::jsonb, + created_at timestamptz NOT NULL DEFAULT now(), + updated_at timestamptz NOT NULL DEFAULT now() +); + +CREATE TABLE plugin_llm_wiki_8f50da974f.wiki_pages ( + id uuid PRIMARY KEY, + company_id uuid NOT NULL REFERENCES public.companies(id) ON DELETE CASCADE, + wiki_id text NOT NULL, + path text NOT NULL, + title text, + page_type text, + frontmatter jsonb NOT NULL DEFAULT '{}'::jsonb, + source_refs jsonb NOT NULL DEFAULT '[]'::jsonb, + backlinks jsonb NOT NULL DEFAULT '[]'::jsonb, + content_hash text, + current_revision_id uuid, + created_at timestamptz NOT NULL DEFAULT now(), + updated_at timestamptz NOT NULL DEFAULT now(), + UNIQUE (company_id, wiki_id, path) +); + +CREATE TABLE plugin_llm_wiki_8f50da974f.wiki_page_revisions ( + id uuid PRIMARY KEY, + company_id uuid NOT NULL REFERENCES public.companies(id) ON DELETE CASCADE, + wiki_id text NOT NULL, + page_id uuid REFERENCES plugin_llm_wiki_8f50da974f.wiki_pages(id) ON DELETE CASCADE, + operation_id uuid, + path text NOT NULL, + content_hash text NOT NULL, + summary text, + metadata jsonb NOT NULL DEFAULT '{}'::jsonb, + created_at timestamptz NOT NULL DEFAULT now() +); + +CREATE TABLE plugin_llm_wiki_8f50da974f.wiki_operations ( + id uuid PRIMARY KEY, + company_id uuid NOT NULL REFERENCES public.companies(id) ON DELETE CASCADE, + wiki_id text NOT NULL, + operation_type text NOT NULL, + status text NOT NULL, + hidden_issue_id uuid REFERENCES public.issues(id) ON DELETE SET NULL, + project_id uuid REFERENCES public.projects(id) ON DELETE SET NULL, + run_ids jsonb NOT NULL DEFAULT '[]'::jsonb, + cost_cents integer NOT NULL DEFAULT 0, + warnings jsonb NOT NULL DEFAULT '[]'::jsonb, + affected_pages jsonb NOT NULL DEFAULT '[]'::jsonb, + metadata jsonb NOT NULL DEFAULT '{}'::jsonb, + created_at timestamptz NOT NULL DEFAULT now(), + updated_at timestamptz NOT NULL DEFAULT now() +); + +CREATE TABLE plugin_llm_wiki_8f50da974f.wiki_query_sessions ( + id uuid PRIMARY KEY, + company_id uuid NOT NULL REFERENCES public.companies(id) ON DELETE CASCADE, + wiki_id text NOT NULL, + hidden_issue_id uuid REFERENCES public.issues(id) ON DELETE SET NULL, + agent_session_id text, + status text NOT NULL DEFAULT 'active', + filed_outputs jsonb NOT NULL DEFAULT '[]'::jsonb, + created_at timestamptz NOT NULL DEFAULT now(), + updated_at timestamptz NOT NULL DEFAULT now() +); + +CREATE TABLE plugin_llm_wiki_8f50da974f.wiki_resource_bindings ( + id uuid PRIMARY KEY, + company_id uuid NOT NULL REFERENCES public.companies(id) ON DELETE CASCADE, + wiki_id text NOT NULL, + resource_kind text NOT NULL, + resource_key text NOT NULL, + resolved_id uuid, + metadata jsonb NOT NULL DEFAULT '{}'::jsonb, + created_at timestamptz NOT NULL DEFAULT now(), + updated_at timestamptz NOT NULL DEFAULT now(), + UNIQUE (company_id, wiki_id, resource_kind, resource_key) +); diff --git a/packages/plugins/plugin-llm-wiki/migrations/002_paperclip_distillation.sql b/packages/plugins/plugin-llm-wiki/migrations/002_paperclip_distillation.sql new file mode 100644 index 00000000..aa8c269b --- /dev/null +++ b/packages/plugins/plugin-llm-wiki/migrations/002_paperclip_distillation.sql @@ -0,0 +1,88 @@ +CREATE TABLE plugin_llm_wiki_8f50da974f.paperclip_distillation_cursors ( + id uuid PRIMARY KEY, + company_id uuid NOT NULL REFERENCES public.companies(id) ON DELETE CASCADE, + wiki_id text NOT NULL, + source_scope text NOT NULL, + scope_key text NOT NULL, + project_id uuid REFERENCES public.projects(id) ON DELETE CASCADE, + root_issue_id uuid REFERENCES public.issues(id) ON DELETE CASCADE, + source_kind text NOT NULL DEFAULT 'paperclip_issue_history', + last_processed_at timestamptz, + last_observed_at timestamptz, + pending_event_count integer NOT NULL DEFAULT 0, + last_successful_run_id uuid, + last_source_hash text, + metadata jsonb NOT NULL DEFAULT '{}'::jsonb, + created_at timestamptz NOT NULL DEFAULT now(), + updated_at timestamptz NOT NULL DEFAULT now(), + UNIQUE (company_id, wiki_id, source_scope, scope_key, source_kind) +); + +CREATE TABLE plugin_llm_wiki_8f50da974f.paperclip_distillation_work_items ( + id uuid PRIMARY KEY, + company_id uuid NOT NULL REFERENCES public.companies(id) ON DELETE CASCADE, + wiki_id text NOT NULL, + work_item_kind text NOT NULL, + status text NOT NULL DEFAULT 'pending', + priority text NOT NULL DEFAULT 'medium', + project_id uuid REFERENCES public.projects(id) ON DELETE CASCADE, + root_issue_id uuid REFERENCES public.issues(id) ON DELETE CASCADE, + requested_by_issue_id uuid REFERENCES public.issues(id) ON DELETE SET NULL, + idempotency_key text, + metadata jsonb NOT NULL DEFAULT '{}'::jsonb, + created_at timestamptz NOT NULL DEFAULT now(), + updated_at timestamptz NOT NULL DEFAULT now(), + UNIQUE (company_id, wiki_id, idempotency_key) +); + +CREATE TABLE plugin_llm_wiki_8f50da974f.paperclip_distillation_runs ( + id uuid PRIMARY KEY, + company_id uuid NOT NULL REFERENCES public.companies(id) ON DELETE CASCADE, + wiki_id text NOT NULL, + cursor_id uuid REFERENCES plugin_llm_wiki_8f50da974f.paperclip_distillation_cursors(id) ON DELETE SET NULL, + work_item_id uuid REFERENCES plugin_llm_wiki_8f50da974f.paperclip_distillation_work_items(id) ON DELETE SET NULL, + project_id uuid REFERENCES public.projects(id) ON DELETE SET NULL, + root_issue_id uuid REFERENCES public.issues(id) ON DELETE SET NULL, + source_window_start timestamptz, + source_window_end timestamptz, + source_hash text, + status text NOT NULL, + operation_issue_id uuid REFERENCES public.issues(id) ON DELETE SET NULL, + retry_count integer NOT NULL DEFAULT 0, + cost_cents integer NOT NULL DEFAULT 0, + warnings jsonb NOT NULL DEFAULT '[]'::jsonb, + metadata jsonb NOT NULL DEFAULT '{}'::jsonb, + created_at timestamptz NOT NULL DEFAULT now(), + updated_at timestamptz NOT NULL DEFAULT now() +); + +CREATE TABLE plugin_llm_wiki_8f50da974f.paperclip_source_snapshots ( + id uuid PRIMARY KEY, + company_id uuid NOT NULL REFERENCES public.companies(id) ON DELETE CASCADE, + wiki_id text NOT NULL, + distillation_run_id uuid REFERENCES plugin_llm_wiki_8f50da974f.paperclip_distillation_runs(id) ON DELETE CASCADE, + project_id uuid REFERENCES public.projects(id) ON DELETE SET NULL, + root_issue_id uuid REFERENCES public.issues(id) ON DELETE SET NULL, + source_hash text NOT NULL, + max_characters integer NOT NULL, + clipped boolean NOT NULL DEFAULT false, + source_refs jsonb NOT NULL DEFAULT '[]'::jsonb, + bundle_markdown text NOT NULL, + metadata jsonb NOT NULL DEFAULT '{}'::jsonb, + created_at timestamptz NOT NULL DEFAULT now() +); + +CREATE TABLE plugin_llm_wiki_8f50da974f.paperclip_page_bindings ( + id uuid PRIMARY KEY, + company_id uuid NOT NULL REFERENCES public.companies(id) ON DELETE CASCADE, + wiki_id text NOT NULL, + project_id uuid REFERENCES public.projects(id) ON DELETE CASCADE, + root_issue_id uuid REFERENCES public.issues(id) ON DELETE CASCADE, + page_path text NOT NULL, + last_applied_source_hash text, + last_distillation_run_id uuid REFERENCES plugin_llm_wiki_8f50da974f.paperclip_distillation_runs(id) ON DELETE SET NULL, + metadata jsonb NOT NULL DEFAULT '{}'::jsonb, + created_at timestamptz NOT NULL DEFAULT now(), + updated_at timestamptz NOT NULL DEFAULT now(), + UNIQUE (company_id, wiki_id, page_path) +); diff --git a/packages/plugins/plugin-llm-wiki/migrations/003_spaces.sql b/packages/plugins/plugin-llm-wiki/migrations/003_spaces.sql new file mode 100644 index 00000000..e9c4a0fd --- /dev/null +++ b/packages/plugins/plugin-llm-wiki/migrations/003_spaces.sql @@ -0,0 +1,236 @@ +CREATE TABLE IF NOT EXISTS plugin_llm_wiki_8f50da974f.wiki_spaces ( + id uuid PRIMARY KEY, + company_id uuid NOT NULL REFERENCES public.companies(id) ON DELETE CASCADE, + wiki_id text NOT NULL DEFAULT 'default', + slug text NOT NULL, + display_name text NOT NULL, + space_type text NOT NULL DEFAULT 'local_folder', + folder_mode text NOT NULL DEFAULT 'managed_subfolder', + root_folder_key text NOT NULL DEFAULT 'wiki-root', + path_prefix text, + configured_root_path text, + access_scope text NOT NULL DEFAULT 'shared', + owner_user_id text, + owner_agent_id uuid REFERENCES public.agents(id) ON DELETE SET NULL, + team_key text, + settings jsonb NOT NULL DEFAULT '{}'::jsonb, + status text NOT NULL DEFAULT 'active', + created_at timestamptz NOT NULL DEFAULT now(), + updated_at timestamptz NOT NULL DEFAULT now(), + UNIQUE (company_id, wiki_id, slug) +); + +CREATE INDEX IF NOT EXISTS wiki_spaces_company_status_idx + ON plugin_llm_wiki_8f50da974f.wiki_spaces (company_id, wiki_id, status); + +WITH wiki_pairs AS ( + SELECT company_id, wiki_id FROM plugin_llm_wiki_8f50da974f.wiki_instances + UNION + SELECT company_id, wiki_id FROM plugin_llm_wiki_8f50da974f.wiki_sources + UNION + SELECT company_id, wiki_id FROM plugin_llm_wiki_8f50da974f.wiki_pages + UNION + SELECT company_id, wiki_id FROM plugin_llm_wiki_8f50da974f.wiki_page_revisions + UNION + SELECT company_id, wiki_id FROM plugin_llm_wiki_8f50da974f.wiki_operations + UNION + SELECT company_id, wiki_id FROM plugin_llm_wiki_8f50da974f.wiki_query_sessions + UNION + SELECT company_id, wiki_id FROM plugin_llm_wiki_8f50da974f.paperclip_distillation_cursors + UNION + SELECT company_id, wiki_id FROM plugin_llm_wiki_8f50da974f.paperclip_distillation_work_items + UNION + SELECT company_id, wiki_id FROM plugin_llm_wiki_8f50da974f.paperclip_distillation_runs + UNION + SELECT company_id, wiki_id FROM plugin_llm_wiki_8f50da974f.paperclip_source_snapshots + UNION + SELECT company_id, wiki_id FROM plugin_llm_wiki_8f50da974f.paperclip_page_bindings +) +INSERT INTO plugin_llm_wiki_8f50da974f.wiki_spaces + (id, company_id, wiki_id, slug, display_name, space_type, folder_mode, root_folder_key, path_prefix, access_scope, status) +SELECT ( + substr(md5(company_id::text || ':' || wiki_id || ':default'), 1, 8) || '-' || + substr(md5(company_id::text || ':' || wiki_id || ':default'), 9, 4) || '-' || + '4' || substr(md5(company_id::text || ':' || wiki_id || ':default'), 14, 3) || '-' || + '8' || substr(md5(company_id::text || ':' || wiki_id || ':default'), 18, 3) || '-' || + substr(md5(company_id::text || ':' || wiki_id || ':default'), 21, 12) + )::uuid, + company_id, + wiki_id, + 'default', + 'default', + 'local_folder', + 'managed_subfolder', + 'wiki-root', + NULL, + 'shared', + 'active' +FROM wiki_pairs +ON CONFLICT (company_id, wiki_id, slug) DO NOTHING; + +ALTER TABLE plugin_llm_wiki_8f50da974f.wiki_sources ADD COLUMN IF NOT EXISTS space_id uuid; +ALTER TABLE plugin_llm_wiki_8f50da974f.wiki_pages ADD COLUMN IF NOT EXISTS space_id uuid; +ALTER TABLE plugin_llm_wiki_8f50da974f.wiki_page_revisions ADD COLUMN IF NOT EXISTS space_id uuid; +ALTER TABLE plugin_llm_wiki_8f50da974f.wiki_operations ADD COLUMN IF NOT EXISTS space_id uuid; +ALTER TABLE plugin_llm_wiki_8f50da974f.wiki_query_sessions ADD COLUMN IF NOT EXISTS space_id uuid; +ALTER TABLE plugin_llm_wiki_8f50da974f.paperclip_distillation_cursors ADD COLUMN IF NOT EXISTS space_id uuid; +ALTER TABLE plugin_llm_wiki_8f50da974f.paperclip_distillation_work_items ADD COLUMN IF NOT EXISTS space_id uuid; +ALTER TABLE plugin_llm_wiki_8f50da974f.paperclip_distillation_runs ADD COLUMN IF NOT EXISTS space_id uuid; +ALTER TABLE plugin_llm_wiki_8f50da974f.paperclip_source_snapshots ADD COLUMN IF NOT EXISTS space_id uuid; +ALTER TABLE plugin_llm_wiki_8f50da974f.paperclip_page_bindings ADD COLUMN IF NOT EXISTS space_id uuid; + +UPDATE plugin_llm_wiki_8f50da974f.wiki_sources t +SET space_id = s.id +FROM plugin_llm_wiki_8f50da974f.wiki_spaces s +WHERE t.company_id = s.company_id AND t.wiki_id = s.wiki_id AND s.slug = 'default' AND t.space_id IS NULL; + +UPDATE plugin_llm_wiki_8f50da974f.wiki_pages t +SET space_id = s.id +FROM plugin_llm_wiki_8f50da974f.wiki_spaces s +WHERE t.company_id = s.company_id AND t.wiki_id = s.wiki_id AND s.slug = 'default' AND t.space_id IS NULL; + +UPDATE plugin_llm_wiki_8f50da974f.wiki_page_revisions t +SET space_id = s.id +FROM plugin_llm_wiki_8f50da974f.wiki_spaces s +WHERE t.company_id = s.company_id AND t.wiki_id = s.wiki_id AND s.slug = 'default' AND t.space_id IS NULL; + +UPDATE plugin_llm_wiki_8f50da974f.wiki_operations t +SET space_id = s.id +FROM plugin_llm_wiki_8f50da974f.wiki_spaces s +WHERE t.company_id = s.company_id AND t.wiki_id = s.wiki_id AND s.slug = 'default' AND t.space_id IS NULL; + +UPDATE plugin_llm_wiki_8f50da974f.wiki_query_sessions t +SET space_id = s.id +FROM plugin_llm_wiki_8f50da974f.wiki_spaces s +WHERE t.company_id = s.company_id AND t.wiki_id = s.wiki_id AND s.slug = 'default' AND t.space_id IS NULL; + +UPDATE plugin_llm_wiki_8f50da974f.paperclip_distillation_cursors t +SET space_id = s.id +FROM plugin_llm_wiki_8f50da974f.wiki_spaces s +WHERE t.company_id = s.company_id AND t.wiki_id = s.wiki_id AND s.slug = 'default' AND t.space_id IS NULL; + +UPDATE plugin_llm_wiki_8f50da974f.paperclip_distillation_work_items t +SET space_id = s.id +FROM plugin_llm_wiki_8f50da974f.wiki_spaces s +WHERE t.company_id = s.company_id AND t.wiki_id = s.wiki_id AND s.slug = 'default' AND t.space_id IS NULL; + +UPDATE plugin_llm_wiki_8f50da974f.paperclip_distillation_runs t +SET space_id = s.id +FROM plugin_llm_wiki_8f50da974f.wiki_spaces s +WHERE t.company_id = s.company_id AND t.wiki_id = s.wiki_id AND s.slug = 'default' AND t.space_id IS NULL; + +UPDATE plugin_llm_wiki_8f50da974f.paperclip_source_snapshots t +SET space_id = s.id +FROM plugin_llm_wiki_8f50da974f.wiki_spaces s +WHERE t.company_id = s.company_id AND t.wiki_id = s.wiki_id AND s.slug = 'default' AND t.space_id IS NULL; + +UPDATE plugin_llm_wiki_8f50da974f.paperclip_page_bindings t +SET space_id = s.id +FROM plugin_llm_wiki_8f50da974f.wiki_spaces s +WHERE t.company_id = s.company_id AND t.wiki_id = s.wiki_id AND s.slug = 'default' AND t.space_id IS NULL; + +ALTER TABLE plugin_llm_wiki_8f50da974f.wiki_sources ALTER COLUMN space_id SET NOT NULL; +ALTER TABLE plugin_llm_wiki_8f50da974f.wiki_pages ALTER COLUMN space_id SET NOT NULL; +ALTER TABLE plugin_llm_wiki_8f50da974f.wiki_page_revisions ALTER COLUMN space_id SET NOT NULL; +ALTER TABLE plugin_llm_wiki_8f50da974f.wiki_operations ALTER COLUMN space_id SET NOT NULL; +ALTER TABLE plugin_llm_wiki_8f50da974f.wiki_query_sessions ALTER COLUMN space_id SET NOT NULL; +ALTER TABLE plugin_llm_wiki_8f50da974f.paperclip_distillation_cursors ALTER COLUMN space_id SET NOT NULL; +ALTER TABLE plugin_llm_wiki_8f50da974f.paperclip_distillation_work_items ALTER COLUMN space_id SET NOT NULL; +ALTER TABLE plugin_llm_wiki_8f50da974f.paperclip_distillation_runs ALTER COLUMN space_id SET NOT NULL; +ALTER TABLE plugin_llm_wiki_8f50da974f.paperclip_source_snapshots ALTER COLUMN space_id SET NOT NULL; +ALTER TABLE plugin_llm_wiki_8f50da974f.paperclip_page_bindings ALTER COLUMN space_id SET NOT NULL; + +DO $$ +DECLARE + target record; + constraint_name text; +BEGIN + FOR target IN + SELECT * FROM (VALUES + ('wiki_pages', ARRAY['company_id', 'wiki_id', 'path']::text[]), + ('paperclip_distillation_cursors', ARRAY['company_id', 'wiki_id', 'source_scope', 'scope_key', 'source_kind']::text[]), + ('paperclip_distillation_work_items', ARRAY['company_id', 'wiki_id', 'idempotency_key']::text[]), + ('paperclip_page_bindings', ARRAY['company_id', 'wiki_id', 'page_path']::text[]) + ) AS targets(table_name, column_names) + LOOP + FOR constraint_name IN + SELECT c.conname + FROM pg_constraint c + JOIN pg_class t ON t.oid = c.conrelid + JOIN pg_namespace n ON n.oid = t.relnamespace + WHERE n.nspname = 'plugin_llm_wiki_8f50da974f' + AND t.relname = target.table_name + AND c.contype = 'u' + AND ( + SELECT array_agg(a.attname ORDER BY constraint_columns.ordinality)::text[] + FROM unnest(c.conkey) WITH ORDINALITY AS constraint_columns(attnum, ordinality) + JOIN pg_attribute a ON a.attrelid = c.conrelid AND a.attnum = constraint_columns.attnum + ) = target.column_names + LOOP + EXECUTE format('ALTER TABLE %I.%I DROP CONSTRAINT %I', 'plugin_llm_wiki_8f50da974f', target.table_name, constraint_name); + END LOOP; + END LOOP; +END $$; + +ALTER TABLE plugin_llm_wiki_8f50da974f.wiki_pages + DROP CONSTRAINT IF EXISTS wiki_pages_company_wiki_space_path_key; +ALTER TABLE plugin_llm_wiki_8f50da974f.wiki_pages + ADD CONSTRAINT wiki_pages_company_wiki_space_path_key UNIQUE (company_id, wiki_id, space_id, path); +ALTER TABLE plugin_llm_wiki_8f50da974f.paperclip_distillation_cursors + DROP CONSTRAINT IF EXISTS distillation_cursors_company_wiki_space_scope_key; +ALTER TABLE plugin_llm_wiki_8f50da974f.paperclip_distillation_cursors + ADD CONSTRAINT distillation_cursors_company_wiki_space_scope_key UNIQUE (company_id, wiki_id, space_id, source_scope, scope_key, source_kind); +ALTER TABLE plugin_llm_wiki_8f50da974f.paperclip_distillation_work_items + DROP CONSTRAINT IF EXISTS distillation_work_items_company_wiki_space_idempotency_key; +ALTER TABLE plugin_llm_wiki_8f50da974f.paperclip_distillation_work_items + ADD CONSTRAINT distillation_work_items_company_wiki_space_idempotency_key UNIQUE (company_id, wiki_id, space_id, idempotency_key); +ALTER TABLE plugin_llm_wiki_8f50da974f.paperclip_page_bindings + DROP CONSTRAINT IF EXISTS page_bindings_company_wiki_space_page_path_key; +ALTER TABLE plugin_llm_wiki_8f50da974f.paperclip_page_bindings + ADD CONSTRAINT page_bindings_company_wiki_space_page_path_key UNIQUE (company_id, wiki_id, space_id, page_path); + +ALTER TABLE plugin_llm_wiki_8f50da974f.wiki_sources + DROP CONSTRAINT IF EXISTS wiki_sources_space_id_fk; +ALTER TABLE plugin_llm_wiki_8f50da974f.wiki_sources + ADD CONSTRAINT wiki_sources_space_id_fk FOREIGN KEY (space_id) REFERENCES plugin_llm_wiki_8f50da974f.wiki_spaces(id) ON DELETE CASCADE; +ALTER TABLE plugin_llm_wiki_8f50da974f.wiki_pages + DROP CONSTRAINT IF EXISTS wiki_pages_space_id_fk; +ALTER TABLE plugin_llm_wiki_8f50da974f.wiki_pages + ADD CONSTRAINT wiki_pages_space_id_fk FOREIGN KEY (space_id) REFERENCES plugin_llm_wiki_8f50da974f.wiki_spaces(id) ON DELETE CASCADE; +ALTER TABLE plugin_llm_wiki_8f50da974f.wiki_page_revisions + DROP CONSTRAINT IF EXISTS wiki_page_revisions_space_id_fk; +ALTER TABLE plugin_llm_wiki_8f50da974f.wiki_page_revisions + ADD CONSTRAINT wiki_page_revisions_space_id_fk FOREIGN KEY (space_id) REFERENCES plugin_llm_wiki_8f50da974f.wiki_spaces(id) ON DELETE CASCADE; +ALTER TABLE plugin_llm_wiki_8f50da974f.wiki_operations + DROP CONSTRAINT IF EXISTS wiki_operations_space_id_fk; +ALTER TABLE plugin_llm_wiki_8f50da974f.wiki_operations + ADD CONSTRAINT wiki_operations_space_id_fk FOREIGN KEY (space_id) REFERENCES plugin_llm_wiki_8f50da974f.wiki_spaces(id) ON DELETE CASCADE; +ALTER TABLE plugin_llm_wiki_8f50da974f.wiki_query_sessions + DROP CONSTRAINT IF EXISTS wiki_query_sessions_space_id_fk; +ALTER TABLE plugin_llm_wiki_8f50da974f.wiki_query_sessions + ADD CONSTRAINT wiki_query_sessions_space_id_fk FOREIGN KEY (space_id) REFERENCES plugin_llm_wiki_8f50da974f.wiki_spaces(id) ON DELETE CASCADE; +ALTER TABLE plugin_llm_wiki_8f50da974f.paperclip_distillation_cursors + DROP CONSTRAINT IF EXISTS paperclip_distillation_cursors_space_id_fk; +ALTER TABLE plugin_llm_wiki_8f50da974f.paperclip_distillation_cursors + ADD CONSTRAINT paperclip_distillation_cursors_space_id_fk FOREIGN KEY (space_id) REFERENCES plugin_llm_wiki_8f50da974f.wiki_spaces(id) ON DELETE CASCADE; +ALTER TABLE plugin_llm_wiki_8f50da974f.paperclip_distillation_work_items + DROP CONSTRAINT IF EXISTS paperclip_distillation_work_items_space_id_fk; +ALTER TABLE plugin_llm_wiki_8f50da974f.paperclip_distillation_work_items + ADD CONSTRAINT paperclip_distillation_work_items_space_id_fk FOREIGN KEY (space_id) REFERENCES plugin_llm_wiki_8f50da974f.wiki_spaces(id) ON DELETE CASCADE; +ALTER TABLE plugin_llm_wiki_8f50da974f.paperclip_distillation_runs + DROP CONSTRAINT IF EXISTS paperclip_distillation_runs_space_id_fk; +ALTER TABLE plugin_llm_wiki_8f50da974f.paperclip_distillation_runs + ADD CONSTRAINT paperclip_distillation_runs_space_id_fk FOREIGN KEY (space_id) REFERENCES plugin_llm_wiki_8f50da974f.wiki_spaces(id) ON DELETE CASCADE; +ALTER TABLE plugin_llm_wiki_8f50da974f.paperclip_source_snapshots + DROP CONSTRAINT IF EXISTS paperclip_source_snapshots_space_id_fk; +ALTER TABLE plugin_llm_wiki_8f50da974f.paperclip_source_snapshots + ADD CONSTRAINT paperclip_source_snapshots_space_id_fk FOREIGN KEY (space_id) REFERENCES plugin_llm_wiki_8f50da974f.wiki_spaces(id) ON DELETE CASCADE; +ALTER TABLE plugin_llm_wiki_8f50da974f.paperclip_page_bindings + DROP CONSTRAINT IF EXISTS paperclip_page_bindings_space_id_fk; +ALTER TABLE plugin_llm_wiki_8f50da974f.paperclip_page_bindings + ADD CONSTRAINT paperclip_page_bindings_space_id_fk FOREIGN KEY (space_id) REFERENCES plugin_llm_wiki_8f50da974f.wiki_spaces(id) ON DELETE CASCADE; + +CREATE INDEX IF NOT EXISTS wiki_sources_space_idx ON plugin_llm_wiki_8f50da974f.wiki_sources (company_id, wiki_id, space_id, created_at DESC); +CREATE INDEX IF NOT EXISTS wiki_operations_space_idx ON plugin_llm_wiki_8f50da974f.wiki_operations (company_id, wiki_id, space_id, created_at DESC); +CREATE INDEX IF NOT EXISTS wiki_query_sessions_space_idx ON plugin_llm_wiki_8f50da974f.wiki_query_sessions (company_id, wiki_id, space_id, updated_at DESC); +CREATE INDEX IF NOT EXISTS distillation_runs_space_idx ON plugin_llm_wiki_8f50da974f.paperclip_distillation_runs (company_id, wiki_id, space_id, created_at DESC); diff --git a/packages/plugins/plugin-llm-wiki/package.json b/packages/plugins/plugin-llm-wiki/package.json new file mode 100644 index 00000000..4461c845 --- /dev/null +++ b/packages/plugins/plugin-llm-wiki/package.json @@ -0,0 +1,47 @@ +{ + "name": "@paperclipai/plugin-llm-wiki", + "version": "0.1.0", + "type": "module", + "private": true, + "description": "Local-file LLM Wiki plugin for source ingestion, wiki browsing, query, lint, and maintenance workflows.", + "scripts": { + "prebuild": "pnpm --filter @paperclipai/plugin-sdk ensure-build-deps", + "build": "node ./esbuild.config.mjs", + "build:rollup": "rollup -c", + "dev": "node ./esbuild.config.mjs --watch", + "dev:ui": "paperclip-plugin-dev-server --root . --ui-dir dist/ui --port 4177", + "test": "vitest run --config ./vitest.config.ts", + "typecheck": "pnpm --filter @paperclipai/plugin-sdk ensure-build-deps && tsc --noEmit" + }, + "paperclipPlugin": { + "manifest": "./dist/manifest.js", + "worker": "./dist/worker.js", + "ui": "./dist/ui/" + }, + "keywords": [ + "paperclip", + "plugin", + "automation", + "wiki", + "knowledge" + ], + "author": "Paperclip", + "license": "MIT", + "devDependencies": { + "@paperclipai/plugin-sdk": "workspace:*", + "@rollup/plugin-node-resolve": "^16.0.1", + "@rollup/plugin-typescript": "^12.1.2", + "@types/node": "^24.6.0", + "@types/react": "^19.0.8", + "@types/react-dom": "^19.0.3", + "esbuild": "^0.27.3", + "react-dom": "^19.0.0", + "rollup": "^4.38.0", + "tslib": "^2.8.1", + "typescript": "^5.7.3", + "vitest": "^3.0.5" + }, + "peerDependencies": { + "react": ">=18" + } +} diff --git a/packages/plugins/plugin-llm-wiki/rollup.config.mjs b/packages/plugins/plugin-llm-wiki/rollup.config.mjs new file mode 100644 index 00000000..ccee40a7 --- /dev/null +++ b/packages/plugins/plugin-llm-wiki/rollup.config.mjs @@ -0,0 +1,28 @@ +import { nodeResolve } from "@rollup/plugin-node-resolve"; +import typescript from "@rollup/plugin-typescript"; +import { createPluginBundlerPresets } from "@paperclipai/plugin-sdk/bundlers"; + +const presets = createPluginBundlerPresets({ uiEntry: "src/ui/index.tsx" }); + +function withPlugins(config) { + if (!config) return null; + return { + ...config, + plugins: [ + nodeResolve({ + extensions: [".ts", ".tsx", ".js", ".jsx", ".mjs"], + }), + typescript({ + tsconfig: "./tsconfig.json", + declaration: false, + declarationMap: false, + }), + ], + }; +} + +export default [ + withPlugins(presets.rollup.manifest), + withPlugins(presets.rollup.worker), + withPlugins(presets.rollup.ui), +].filter(Boolean); diff --git a/packages/plugins/plugin-llm-wiki/skills/README.md b/packages/plugins/plugin-llm-wiki/skills/README.md new file mode 100644 index 00000000..cacfe3ca --- /dev/null +++ b/packages/plugins/plugin-llm-wiki/skills/README.md @@ -0,0 +1,34 @@ +# LLM Wiki Maintainer Skills + +This folder is the plugin-level source for LLM Wiki managed company skills. Paperclip installs these skills into the company skill library and syncs them onto the Wiki Maintainer agent. The Wiki Maintainer's identity and operating loop live in `agents/wiki-maintainer/AGENTS.md`; the wiki-root `AGENTS.md` remains the wiki schema for page layout, citation style, and log format. + +Each skill is an isolated SKILL.md describing one job — when to invoke it, the inputs that must be true before starting, the steps, and the durable output the operation must leave behind. + +## Skill registry + +| Skill | When to invoke | +|---|---| +| [`wiki-maintainer`](./wiki-maintainer/SKILL.md) | General LLM Wiki maintenance and tool-use guidance shared by the operation skills. | +| [`wiki-ingest`](./wiki-ingest/SKILL.md) | A new file landed in `raw/` and the operation issue says "ingest" — turn the source into durable wiki pages. | +| [`wiki-query`](./wiki-query/SKILL.md) | The user asked the wiki a question; answer with citations and offer to file durable synthesis back into `wiki/`. | +| [`wiki-lint`](./wiki-lint/SKILL.md) | A lint or health-check operation — audit for contradictions, orphan pages, weak provenance, broken links, missing concept pages. | +| [`paperclip-distill`](./paperclip-distill/SKILL.md) | Cursor-window, distill, or backfill operation on Paperclip activity — write a wiki-insightful project page, decisions log, and history note. | +| [`index-refresh`](./index-refresh/SKILL.md) | Refresh `wiki/index.md` so each entry has a tight, scannable summary; flag drift between the index and recent log activity. | + +## Layering + +``` +AGENTS.md (wiki root) ← schema for the wiki itself: page conventions, frontmatter, voice + agents/wiki-maintainer/AGENTS.md ← agent identity and operating loop + skills//SKILL.md ← plugin-managed company skills installed onto the maintainer +``` + +When a skill conflicts with the wiki-root `AGENTS.md`, the wiki schema wins for page format/voice and the skill wins for operation flow. When a skill conflicts with the agent's `AGENTS.md`, the agent file wins for identity and the skill wins for the operation procedure. + +## Skill conventions + +- Front matter has `name` (kebab-case) and `description` (one or two sentences with the trigger condition). +- Each skill names the input it expects (e.g. an operation issue with `originKind` ending in `:ingest`, a captured `raw/` path, a Paperclip source bundle). +- Each skill ends with a verification checklist — what must be true before the operation issue is closed `done`. +- Skills cite the wiki-plugin tools they rely on (`wiki_search`, `wiki_read_page`, `wiki_write_page`, `wiki_read_source`, `wiki_list_sources`). +- Skills do not duplicate the page conventions from the wiki root `AGENTS.md`. They reference it instead. diff --git a/packages/plugins/plugin-llm-wiki/skills/index-refresh/SKILL.md b/packages/plugins/plugin-llm-wiki/skills/index-refresh/SKILL.md new file mode 100644 index 00000000..e0380e67 --- /dev/null +++ b/packages/plugins/plugin-llm-wiki/skills/index-refresh/SKILL.md @@ -0,0 +1,65 @@ +--- +name: index-refresh +description: Use when an operation issue is an index refresh — typically the hourly index-refresh routine. Rebuild `wiki/index.md` so each entry has a tight, scannable one-line summary and the catalog tracks the actual contents of `wiki/`. Resolve drift between the index and recent log activity, but do not edit page content. +--- + +# Index Refresh + +Keep `wiki/index.md` accurate and scannable. The index is the maintainer's first stop for navigation — its quality determines how cheap every subsequent operation becomes. + +## Inputs + +- An operation issue with `operationType: "index"` (or the `index-refresh` routine title). +- The operation issue's target `wikiId`, `spaceSlug`, and space root. Refresh only that space unless the issue explicitly says this is a multi-space sweep. + +## Workflow + +1. **Read the target space's `wiki/index.md`** as it currently stands. +2. **Walk the target space's `wiki/`.** `wiki/projects//standup.md` entries are current-state companions for durable `wiki/projects//index.md` pages; index them only as links attached to the matching project entry. Walk `wiki/` by category (`sources/`, `projects/`, `entities/`, `concepts/`, `synthesis/`, plus any custom subdirectories the wiki schema added). +3. **Read the target space's last ~50 entries of `wiki/log.md`** to spot pages that were created or substantially changed but never made it to the index. +4. **Per category, produce sorted entries** of the form: + ``` + - [[]] — + ``` + The summary is one factual sentence pulled from the page's first paragraph or its title. **No status, no datestamps in the index** — those belong in the page itself or in the log. +5. **Drop entries whose page no longer exists.** Note the deletion in the log: + ``` + ## [YYYY-MM-DD] index-refresh | reconciled + - removed: [[wiki/old-page]] (page deleted) + - added: [[wiki/new-page]] — + ``` +6. **Add entries for pages that exist on disk but were missing from the index.** Skip `wiki/log.md` and `wiki/index.md` themselves. For standalone `wiki/projects//standup.md` without a matching durable project page, add it under Projects and flag it for later durable-page distillation. +7. **Write project entries editorially.** The Projects section should group work by the project's concept and purpose, not by issue ids, dates, statuses, UUIDs, or source metadata. Link task identifiers only as supporting evidence. +8. **Preserve custom categories.** If the wiki has added e.g. `wiki/papers/` or `wiki/runbooks/`, keep its index section. Do not collapse to the default five categories. +9. **Append a log entry** with counts: + ``` + ## [YYYY-MM-DD] index-refresh | added=N removed=M + - operation issue: + ``` + If the index was already accurate, the log entry says `added=0 removed=0` — still write it so future audits can see the run happened. + +## What this skill does NOT do + +- Does not change page content. +- Does not resolve contradictions, fix broken links, or fill concept gaps. Those go to the next `wiki-lint` run. +- Does not write summaries that are not already supported by the page itself. If a page lacks a clear first paragraph to summarise, flag it for `wiki-lint`. + +## Voice + +- Index entries are one factual line per page, present tense. +- No emojis, no statuses, no dates in `wiki/index.md`. Dates live in the log. + +## Verification + +Before closing the operation issue: + +- [ ] `wiki/index.md` matches the actual contents of `wiki/` — no missing pages, no dangling entries. +- [ ] Project entries include current `wiki/projects//standup.md` links when standups exist. +- [ ] Each index line has the form `- [[path]] — `. +- [ ] Custom category sections are preserved. +- [ ] `wiki/log.md` has the index-refresh entry with counts (even if the counts are zero). +- [ ] No page bodies were modified. No file under `raw/` was modified. + +## Tools + +`wiki_search`, `wiki_read_page`, `wiki_write_page` (for `wiki/index.md` and `wiki/log.md` only). Always include the operation issue's `wikiId` and `spaceSlug`. diff --git a/packages/plugins/plugin-llm-wiki/skills/paperclip-distill/SKILL.md b/packages/plugins/plugin-llm-wiki/skills/paperclip-distill/SKILL.md new file mode 100644 index 00000000..fa7b8d60 --- /dev/null +++ b/packages/plugins/plugin-llm-wiki/skills/paperclip-distill/SKILL.md @@ -0,0 +1,125 @@ +--- +name: paperclip-distill +description: Use when an operation issue is a Paperclip cursor-window, distill, or backfill — `operationType: "distill"` or `"backfill"` and the body references a Paperclip source bundle for a project or root issue. Turn raw Paperclip activity into a wiki-insightful project page, decisions log, and history note. This skill exists specifically to replace the stiff, datestamp-heavy templated output that the deterministic distiller produces. +--- + +# Paperclip Distill + +Distill Paperclip project, issue, comment, and document activity into durable wiki pages. The success criterion is **wiki-insightful, not procedural**: a reader who has never seen Paperclip should learn what the project is, what was decided, what is at risk, and what the current state is — without scanning a list of `## [YYYY-MM-DD]` headers. + +## When this skill is needed + +- Cursor-window distillation: the routine fed you a bounded source bundle of recent Paperclip activity for one project or root issue. +- Backfill: the user asked to seed the wiki with the historical activity of a project or root issue. Source window may be wide. +- Manual `distill-paperclip-now` request from the UI. + +If the operation issue is `operationType: "ingest"` (raw file) or `operationType: "query"`, this is the wrong skill — use `wiki-ingest` or `wiki-query`. + +## Destination space + +In Phase 1, every Paperclip distill, backfill, and cursor-window operation writes into the +default wiki space. The operation issue should always carry `spaceSlug: "default"`. If an +operation issue passes any other slug, stop and surface the mismatch in a comment — do not +write Paperclip-derived pages into a non-default space. + +This rule is destination-only. The Paperclip source scope (which projects, root issues, +comments, documents are read) is set elsewhere in the operation issue and is independent of +the destination. + +## Inputs + +- A Paperclip source bundle (issue list, comment refs, document refs, source hash, cursor window). +- An existing or planned `wiki/projects//standup.md` page path. +- An existing or planned `wiki/projects//index.md` page path. +- The operation issue's target `wikiId`, `spaceSlug`, space root, and the target space's `AGENTS.md` for page conventions. +- The current `wiki/projects//standup.md`, `wiki/projects//index.md`, `decisions.md`, and `history.md` if they already exist (so you write a *patch*, not a rewrite). + +## Paperclip Asset Gate + +Do not treat Paperclip assets/attachments or issue work products as source text for this skill. + +- Allowed Paperclip body text: issue descriptions, comment bodies, document bodies. +- Assets/attachments are metadata-only until a separate approved extraction policy exists. +- Work products are metadata-only until a separate approved extraction policy exists. +- Never fetch `/api/assets/:id/content`. +- Never dereference a work-product `url`, preview URL, artifact URL, or other linked destination from this skill. +- If an operator asks for attachment/work-product content distillation, stop and point them at the Phase 5 asset/work-product security gate policy instead of improvising. + +## Anti-patterns to avoid + +The deterministic templating this skill replaces produced these failure modes — do not reproduce them: + +1. **Datestamp-as-section-header.** Lines like `## [2026-04-15] paperclip-distill | proposed` belong in `wiki/log.md`, not in the project page. The project page is durable knowledge; the log is the audit trail. +2. **Procedural status lists.** `Issue mix: 3 todo, 5 in_progress, 2 done` tells the reader nothing they could not read off Paperclip directly. State *what is happening and why it matters*, then cite the issues that constitute the evidence. +3. **One-line-per-issue dumps.** A page that is mostly `- PAP-1234: title (in_progress, updated 2026-...)` is an issue list, not a wiki page. Group issues by what they are *about* (a decision, a risk, a workstream) and cite multiple issues per bullet when they share a story. +4. **Mechanical "Current as of" timestamps everywhere.** One `current_as_of` in frontmatter is enough. +5. **No interpretation.** "Active issues: PAP-A, PAP-B, PAP-C" is bookkeeping. "The team is concentrating on the schema migration ([PAP-A], [PAP-B]) and has parked the index work pending capacity ([PAP-C])." is wiki-insightful. +6. **Opaque identifiers in prose.** UUIDs, cursor ids, source hashes, run ids, and raw metadata belong in logs or frontmatter when needed, not in executive-facing project narrative. + +## Workflow + +1. **Read the bundle in full.** Don't sample. Read every issue title, every comment, every document key the bundle includes. Note: which issues are decisions, which are risks/blockers, which are recently completed, which are inflight. +2. **Read the existing project page** (if any) so you write a patch, not a rewrite. The "Decisions" section in particular accumulates over time — never wipe accepted decisions; supersede them with `> ⚠ reversed by ...` callouts when something later overrides them. +3. **Read the target space's `AGENTS.md`** for page conventions: filename style, YAML frontmatter shape, link style, voice. Always pass the operation issue's `wikiId` and `spaceSlug` to LLM Wiki tools. +4. **Write `wiki/projects//standup.md` first.** Every Paperclip project represented in the wiki must have this file. It is the executive standup: where the project stands today, what changed recently, what is blocked or risky, and what happens next. Use stable sections, in this order: + - Frontmatter (`type: project-standup`, `project: `, `current_as_of: YYYY-MM-DD`, `sources`). + - **Executive Readout** — one short paragraph that explains the current project posture in plain language. + - **What Changed** — the meaningful work completed or advanced since the last window. Group by concept; cite issues/comments/documents only as evidence. + - **Decisions** — accepted/rejected/reversed decisions that changed the project direction. Omit when none exist. + - **Blockers / Risks** — current blockers and risks with named owner or next action when the source provides one. + - **Next Actions** — concrete next actions and owners inferred from Paperclip issues, not vague aspirations. + - **Links** — durable wiki project page and relevant Paperclip project/issues/documents. + Rewrite the standup to today's state. Do not append endless dated sections; the audit trail belongs in `wiki/log.md` and Paperclip comments. +5. **Write `wiki/projects//index.md`** with these stable sections, in this order: + - Frontmatter (`type: project`, `current_as_of: YYYY-MM-DD`, `tags`, `sources`). + - **Overview** — 2–4 sentences saying what the project is and why it exists. Use the project description if it exists; otherwise synthesise it from the root issue. + - **Current Direction** — narrative paragraph naming the active workstreams, the immediate next concrete deliverable, and the stance on risks. Cite 2–4 issues, do not list 20. + - **Workstreams** — a short, grouped list. Each line is a workstream or idea, not an issue. + - **Decisions** — accepted and reversed decisions with one paragraph each. Each decision cites the issue / approval / comment that ratified it. Format: `### Decision — short title` then a paragraph; never a bare bullet list. + - **Open Risks / Blockers** — what could derail the project, with the issue ref that surfaces it. Skip this section when the bundle has no risk signal — do not pad with `_(none)_`. + - **References** — readable links to the current standup and supporting Paperclip tasks/documents. Keep hashes and cursor ids out of the narrative. +6. **Optionally write `wiki/projects//decisions.md`** when the project has accumulated more decisions than the project page can carry without becoming a wall of text. Each decision is a `## ` section with: short title, accepted/reversed/superseded status, one-paragraph rationale, citing the source. *Do not* duplicate decisions already on the project page — link instead. +7. **Optionally write `wiki/projects//history.md`** for a compact narrative timeline of meaningful project changes. **Not** an issue dump — group by phase ("Discovery", "Architecture", "Build", "Stabilisation"), not by date. Each phase is a paragraph that cites the 2–4 issues that defined it. +8. **Refresh `wiki/index.md`** under the `## Projects` section — one line per durable project page with a one-sentence summary of the project's purpose, plus a link to the current `wiki/projects//standup.md` when present. +9. **Append `wiki/log.md`** entry — this is where the datestamp belongs: + ``` + ## [YYYY-MM-DD] paperclip-distill | + - standup: wiki/projects//standup.md + - page: wiki/projects//index.md + - source hash: `` + - cursor window: + - notes: + ``` +10. **Surface bundle warnings** (clipped sources, low signal, stale hash). Bundle warnings → `human_review_required: true` on the patch. Do not paper over them. + +## Voice + +- Past-tense for completed work, present-tense for current state, future-tense only with citation ("the team plans to … per [[…]]"). +- Cite Paperclip source refs inline using their issue identifier (e.g. `PAP-3179`), not opaque UUIDs. +- Use issue links as evidence, not as the shape of the page. Headings and paragraphs should be organized by concepts, workstreams, decisions, and blockers. +- Wiki voice: terse, factual, neutral. No "the team is excited to" or "this initiative aims to". +- Headings are about *content*, not metadata. `## Schema migration` not `## Active Issues`. + +## When the bundle has no signal + +If the bundle has no durable signal — no decisions, no risk, no completed work, only routine status churn — do **not** write a project page. Instead: + +- Append a `paperclip-distill | low-signal skip` log entry naming the cursor window. +- Close the operation issue with a one-line "no durable change in this window" comment. +- Do not bump the source hash on a binding that has no proposed page. + +## Verification + +Before closing the operation issue: + +- [ ] The project page reads as wiki content, not as a Paperclip status report. A reader new to the company should understand what the project is. +- [ ] `wiki/projects//standup.md` exists for the represented project and reads as an executive current-state update, not a raw issue dump. +- [ ] Decisions section names decisions, not issues — every decision has a one-paragraph rationale and a citation. +- [ ] The page contains exactly one `current_as_of` (in frontmatter), zero `## [YYYY-MM-DD]` headings (those go to the log). +- [ ] Bundle warnings (clipped, low signal, stale hash) are surfaced; the patch carries `human_review_required: true` when the deployment is authenticated/public. +- [ ] `wiki/index.md` and `wiki/log.md` are updated. +- [ ] No file under `raw/` was modified. + +## Tools + +`wiki_search`, `wiki_read_page`, `wiki_write_page`, `wiki_list_sources`, `wiki_read_source`. Always include the operation issue's `wikiId` and `spaceSlug`. The Paperclip source bundle arrives as part of the operation context — you do not need to assemble it. diff --git a/packages/plugins/plugin-llm-wiki/skills/wiki-ingest/SKILL.md b/packages/plugins/plugin-llm-wiki/skills/wiki-ingest/SKILL.md new file mode 100644 index 00000000..3422af80 --- /dev/null +++ b/packages/plugins/plugin-llm-wiki/skills/wiki-ingest/SKILL.md @@ -0,0 +1,57 @@ +--- +name: wiki-ingest +description: Use when an operation issue asks you to ingest a captured source from `raw/` into the LLM Wiki, or when the user explicitly says "ingest ". The issue body will name a file under `raw/` (e.g. `raw/karpathy-llm-wiki.md`) and ask for durable wiki pages. Do not invoke this skill for Paperclip activity bundles — those use `paperclip-distill` instead. +--- + +# Wiki Ingest + +Turn one source document into durable, interlinked wiki knowledge. + +## Inputs + +- An operation issue with `operationType: "ingest"` assigned to you. +- A `raw/` path mentioned in the issue body (always treat `raw/` as immutable). +- The operation issue's target `wikiId`, `spaceSlug`, and space root (otherwise stop and surface the missing config to the requester). + +## Workflow + +1. **Read context first.** + - Read the target space's `AGENTS.md` for page conventions (filenames, frontmatter, voice, citation style). + - Read the target space's `wiki/index.md` to see what already exists. + - Read the target space's last ~20 entries of `wiki/log.md` to avoid re-ingesting a source or re-resolving a contradiction someone else already filed. +2. **Read the source end to end** with `wiki_read_source`, passing the operation issue's `wikiId` and `spaceSlug`. Do not skim. Note the source's structure, claims, dates, and anything that contradicts existing pages. +3. **Plan, then confirm — but only if the user is in the loop.** If the operation came from a routine (no live user), proceed. If a user is asking interactively, summarise the 3–5 takeaways you intend to file and ask which to emphasise before writing. +4. **Write the source page** at `wiki/sources/.md` — ~300–800 words, frontmatter per the wiki schema, neutral voice, key claims with quoted excerpts where they carry weight. The source page is the canonical citation target for everything else this skill writes. +5. **Update or create downstream pages** in `entities/`, `concepts/`, and `synthesis/`. A typical ingest touches 5–15 pages; resist creating pages for ideas that only appear once. +6. **Wire the cross-links.** Every claim that comes from the source cites it as `(see [[wiki/sources/]])`. Every entity / concept mentioned by name on more than one page links to its dedicated page. +7. **Flag contradictions; do not silently overwrite.** When new material disagrees with an existing page, append a `> ⚠ contradicted by [[wiki/sources/]] (YYYY-MM-DD)` callout to the older page and note the conflict in the log. +8. **Refresh `wiki/index.md`** with one-line summaries for any new pages. +9. **Append a log entry** in `wiki/log.md`: + ``` + ## [YYYY-MM-DD] ingest | + - source: raw/ + - new pages: [[...]], [[...]] + - updated pages: [[...]], [[...]] + - notes: + ``` + +## Voice + +- Terse, factual, neutral. Reference material, not narrative. +- No "Today I learned" or "This is interesting because" framing. +- Quote the source verbatim when paraphrasing would lose precision. + +## Verification + +Before closing the operation issue: + +- [ ] Source page exists at `wiki/sources/.md` with valid frontmatter and a `sources:` field pointing to the raw path. +- [ ] Every new or updated page links back to the source page or a downstream page that does. +- [ ] `wiki/index.md` lists every new page under the right category with a one-line summary. +- [ ] `wiki/log.md` has the ingest entry with the exact filename heading format (so `grep "^## \[" wiki/log.md` keeps working). +- [ ] Any contradiction between the new source and an older page is annotated, not silently overwritten. +- [ ] No file under `raw/` was modified. + +## Tools + +`wiki_list_sources`, `wiki_read_source`, `wiki_search`, `wiki_read_page`, `wiki_write_page`. Always include the operation issue's `wikiId` and `spaceSlug`. diff --git a/packages/plugins/plugin-llm-wiki/skills/wiki-lint/SKILL.md b/packages/plugins/plugin-llm-wiki/skills/wiki-lint/SKILL.md new file mode 100644 index 00000000..acaa0255 --- /dev/null +++ b/packages/plugins/plugin-llm-wiki/skills/wiki-lint/SKILL.md @@ -0,0 +1,57 @@ +--- +name: wiki-lint +description: Use when an operation issue is a lint or health-check (`operationType: "lint"`) — typically the nightly lint routine or a manual "Run lint" from the UI. Audit the wiki for contradictions, orphans, weak provenance, broken links, and missing concept pages, and return a triage list — do not auto-fix. +--- + +# Wiki Lint + +Audit, do not edit. Return findings the maintainer (human or agent) can triage. + +## Inputs + +- An operation issue with `operationType: "lint"`. +- The operation issue's target `wikiId`, `spaceSlug`, and space root. Lint only that space unless the issue explicitly says this is a multi-space sweep. + +## Workflow + +1. **Walk the target space's `wiki/index.md` and wiki tree** with `wiki_search` and `wiki_read_page`, always passing the operation issue's `wikiId` and `spaceSlug`. Build a mental map of: pages that exist, pages referenced from `index.md`, pages referenced from other pages, and raw sources. +2. **Check for the seven recurring issues**, in this order: + 1. **Contradictions** — two pages making incompatible claims about the same entity, decision, or status. Flag both pages, name the conflicting claims, and quote evidence. + 2. **Stale claims** — a page asserts X, but a newer source under `raw/` has superseded it. Flag the older page; never overwrite. + 3. **Orphan pages** — a `wiki/` page is not linked from `index.md` and not referenced from any other wiki page. Either it should be linked, removed, or merged. + 4. **Concept gaps** — a term appears on three or more pages but has no dedicated `wiki/concepts/.md`. Recommend creating one. + 5. **Broken `[[wiki-links]]`** — a link target file does not exist. + 6. **Weak provenance** — a non-trivial claim is uncited or cites only the wiki itself in a circle. The original source ref should be findable. + 7. **Index / log drift** — pages exist that are not in `index.md`, or `index.md` lists pages that no longer exist. Recent operations in `wiki/log.md` that did not produce a corresponding page change. +3. **Return a triage list**, grouped by severity: + - **critical**: contradictions, broken links to active pages, fabricated citations. + - **medium**: stale claims, weak provenance, large concept gaps. + - **low**: orphans, log drift, small index gaps. + Each item has: file path, evidence (a 1–2 line quote), suggested fix, and the operation that should follow up (`ingest`, `paperclip-distill`, `index-refresh`, manual review). +4. **Do not write to `wiki/`.** Lint is read-only by design — the maintainer or the routine that follows decides which findings to act on. +5. **Append a log entry** describing the run: + ``` + ## [YYYY-MM-DD] lint | + - operation issue: + - critical: + - medium: + - low: + ``` + +## Voice + +- Lead with the count by severity. +- Each finding is one bullet. Resist commentary. +- When in doubt about severity, say so and surface it as medium with a "verify" note. + +## Verification + +Before closing the operation issue: + +- [ ] Findings are grouped by severity with file paths, evidence, and suggested fix per item. +- [ ] No files under `raw/` were modified. No files under `wiki/` were modified except `wiki/log.md`. +- [ ] If the run found nothing, the issue is closed with "no findings" and the log entry still exists so future audits can see this run happened. + +## Tools + +`wiki_search`, `wiki_read_page`, `wiki_list_sources`, `wiki_read_source`, `wiki_write_page` (only `wiki/log.md`). Always include the operation issue's `wikiId` and `spaceSlug`. diff --git a/packages/plugins/plugin-llm-wiki/skills/wiki-maintainer/SKILL.md b/packages/plugins/plugin-llm-wiki/skills/wiki-maintainer/SKILL.md new file mode 100644 index 00000000..de701b76 --- /dev/null +++ b/packages/plugins/plugin-llm-wiki/skills/wiki-maintainer/SKILL.md @@ -0,0 +1,12 @@ +--- +name: "LLM Wiki Maintainer" +description: "Use the LLM Wiki plugin tools to maintain a cited local company wiki." +--- + +# LLM Wiki Maintainer + +Use this skill when maintaining the company LLM Wiki, answering questions from it, ingesting durable source material, refreshing the index, or linting wiki structure. + +Before changing wiki files, resolve the configured wiki root, read its AGENTS.md, inspect wiki/index.md and recent wiki/log.md entries, then use the LLM Wiki plugin tools for source reads, page writes, patch proposals, backlinks, and logging. + +Keep raw sources immutable, cite wiki pages and raw paths, update wiki/index.md when page navigation changes, and append a concise wiki/log.md entry for durable updates. For Paperclip project work, keep `wiki/projects//standup.md` current as the executive status view and use `wiki/projects//index.md` for durable project knowledge. Write project material as concept-grouped executive synthesis, not issue-id lists or metadata dumps. diff --git a/packages/plugins/plugin-llm-wiki/skills/wiki-query/SKILL.md b/packages/plugins/plugin-llm-wiki/skills/wiki-query/SKILL.md new file mode 100644 index 00000000..ccb2855a --- /dev/null +++ b/packages/plugins/plugin-llm-wiki/skills/wiki-query/SKILL.md @@ -0,0 +1,44 @@ +--- +name: wiki-query +description: Use when an operation issue asks you to answer a question from the LLM Wiki — `operationType: "query"` and a question in the issue body. Answer with citations to wiki pages and raw sources, and offer to file durable synthesis back into `wiki/synthesis/` so the work compounds instead of disappearing into a chat thread. +--- + +# Wiki Query + +Answer a question from what the wiki actually contains, with citations. + +## Inputs + +- An operation issue with `operationType: "query"` and the question in the body. +- The operation issue's target `wikiId`, `spaceSlug`, and space root. + +## Workflow + +1. **Open the target space's `wiki/index.md` first** — it is the navigation aid. Identify candidate pages. +2. **Read the candidate pages** end to end with `wiki_read_page`, always passing the operation issue's `wikiId` and `spaceSlug`. Follow `[[wiki-links]]` to neighbouring pages when the question spans entities or concepts. +3. **Inspect raw sources** when a wiki page's claim feels thin. The wiki points to `raw/` precisely so you can verify before answering. Use `wiki_read_source`. +4. **Answer the question** in the operation issue thread. Structure: + - Direct answer first, in 1–4 sentences. + - Then the supporting facts as bullet points, each with an inline citation: `(see [[wiki/concepts/managed-resources]])` or `(see raw/)`. + - If you needed to read a raw source the wiki did not summarise, name that as a gap. +5. **Decide whether the answer is durable.** If the question forced you to do real synthesis (a comparison, a tradeoff, a definition of something that isn't already a page), offer to file it under `wiki/synthesis/.md`. Do not write the synthesis page silently — it is opt-in. If the user accepts, write the page, link it from `wiki/index.md`, and append a `query | filed synthesis` log entry. +6. **When the wiki cannot answer**, say so plainly. Suggest a source the user should ingest, a Paperclip project that would help if distilled, or a web lookup. Never bluff. + +## Voice + +- Lead with the answer. +- Cite as you go, not in a footnote block at the end. +- Use the wiki's terse, factual voice. The query response is itself a candidate for filing into `wiki/synthesis/`. + +## Verification + +Before closing the operation issue: + +- [ ] Every claim in the answer cites a wiki page or raw source. +- [ ] If the wiki was insufficient, that is stated directly with a concrete next step (ingest source X, distill project Y, web search Z). +- [ ] If you wrote a synthesis page, `wiki/index.md` lists it and `wiki/log.md` has a `query | filed synthesis` entry. +- [ ] No file under `raw/` was modified. + +## Tools + +`wiki_search`, `wiki_read_page`, `wiki_list_sources`, `wiki_read_source`, `wiki_write_page` (only when filing synthesis). Always include the operation issue's `wikiId` and `spaceSlug`. diff --git a/packages/plugins/plugin-llm-wiki/src/manifest.ts b/packages/plugins/plugin-llm-wiki/src/manifest.ts new file mode 100644 index 00000000..de611ae6 --- /dev/null +++ b/packages/plugins/plugin-llm-wiki/src/manifest.ts @@ -0,0 +1,601 @@ +import { readFileSync } from "node:fs"; +import type { PaperclipPluginManifestV1 } from "@paperclipai/plugin-sdk"; +import { DEFAULT_AGENT_INSTRUCTION_FILES, DEFAULT_AGENT_INSTRUCTIONS } from "./templates.js"; + +export const PLUGIN_ID = "paperclipai.plugin-llm-wiki"; +export const WIKI_ROOT_FOLDER_KEY = "wiki-root"; +export const WIKI_MAINTAINER_AGENT_KEY = "wiki-maintainer"; +export const WIKI_MAINTAINER_SKILL_KEY = "wiki-maintainer"; +export const WIKI_INGEST_SKILL_KEY = "wiki-ingest"; +export const WIKI_QUERY_SKILL_KEY = "wiki-query"; +export const WIKI_LINT_SKILL_KEY = "wiki-lint"; +export const PAPERCLIP_DISTILL_SKILL_KEY = "paperclip-distill"; +export const INDEX_REFRESH_SKILL_KEY = "index-refresh"; +export const WIKI_PROJECT_KEY = "llm-wiki"; +export const CURSOR_WINDOW_ROUTINE_KEY = "cursor-window-processing"; +export const NIGHTLY_LINT_ROUTINE_KEY = "nightly-wiki-lint"; +export const INDEX_REFRESH_ROUTINE_KEY = "index-refresh"; +export const DEFAULT_MAX_SOURCE_BYTES = 250000; +export const DEFAULT_MAX_PAPERCLIP_ISSUE_SOURCE_CHARS = 12000; +export const DEFAULT_MAX_PAPERCLIP_CURSOR_WINDOW_CHARS = 60000; +export const DEFAULT_MAX_PAPERCLIP_ROUTINE_RUN_CHARS = 120000; +export const DEFAULT_PAPERCLIP_COST_CENTS_PER_1K_CHARS = 1; +export const WIKI_MAINTENANCE_ROUTINE_KEYS = [ + CURSOR_WINDOW_ROUTINE_KEY, + NIGHTLY_LINT_ROUTINE_KEY, + INDEX_REFRESH_ROUTINE_KEY, +] as const; +export const WIKI_MANAGED_SKILL_KEYS = [ + WIKI_MAINTAINER_SKILL_KEY, + WIKI_INGEST_SKILL_KEY, + WIKI_QUERY_SKILL_KEY, + WIKI_LINT_SKILL_KEY, + PAPERCLIP_DISTILL_SKILL_KEY, + INDEX_REFRESH_SKILL_KEY, +] as const; + +function canonicalSkillKey(skillKey: string) { + return `plugin/paperclipai-plugin-llm-wiki/${skillKey}`; +} + +function skillMarkdown(skillKey: (typeof WIKI_MANAGED_SKILL_KEYS)[number]) { + return readFileSync(new URL(`../skills/${skillKey}/SKILL.md`, import.meta.url), "utf8"); +} + +export const WIKI_MAINTAINER_SKILL_CANONICAL_KEY = canonicalSkillKey(WIKI_MAINTAINER_SKILL_KEY); +export const WIKI_MANAGED_SKILL_CANONICAL_KEYS = WIKI_MANAGED_SKILL_KEYS.map(canonicalSkillKey); + +const CURSOR_WINDOW_ROUTINE_DESCRIPTION = `Process bounded Paperclip issue-history windows into the LLM Wiki. + +Run procedure: +Target space: default (slug: default). Paperclip-derived indexing currently writes only into the default space, so this routine never sweeps other spaces. Per-space Paperclip ingestion profiles are a later phase; until they ship, treat any prompt to operate on a non-default space here as a bug and stop. +1. Resolve the configured wiki root, then read the default space AGENTS.md, wiki/index.md, and the recent entries in wiki/log.md. +2. Review recent Paperclip issue, comment, and document activity for non-plugin-operation work. Skip LLM Wiki operation issues so routine output does not feed back into itself. +3. Synthesize Paperclip project state into wiki/projects//standup.md for the executive current-state view, then durable project or root-issue knowledge into focused pages under wiki/projects//index.md, wiki/concepts/, or wiki/synthesis/. Keep transient run logs out of durable pages unless they change the project's state or decisions. +4. Write project material as concept-grouped executive synthesis. Link readable issue identifiers when useful, but do not turn project pages into issue-ID lists, UUID dumps, date ledgers, or metadata reports. Always pass wikiId \`default\` and spaceSlug \`default\` to LLM Wiki tools. +5. Refresh wiki/index.md and append a short wiki/log.md entry listing the source window, affected pages, skipped windows, warnings, and any follow-up issue needed. +6. If there is no new durable signal, record that in wiki/log.md and close the routine issue with a concise note.`; + +const NIGHTLY_LINT_ROUTINE_DESCRIPTION = `Lint the LLM Wiki for structure, provenance, and stale synthesis. + +Run procedure: +Target space: default (slug: default). Paperclip-derived indexing currently writes only into the default space, so this routine never sweeps other spaces. Per-space Paperclip ingestion profiles are a later phase; until they ship, treat any prompt to operate on a non-default space here as a bug and stop. +1. Resolve the configured wiki root, then read the default space AGENTS.md, wiki/index.md, wiki/log.md, and the current page list. +2. Check for orphan pages, missing backlinks, stale source provenance, weak citations, duplicate concepts, contradictory claims, and index/log drift. +3. Inspect the relevant wiki pages and raw sources before changing content. Do not invent missing provenance. +4. Apply low-risk fixes directly: refresh backlinks, repair index entries, add missing source links, and append a wiki/log.md lint entry. Always pass wikiId \`default\` and spaceSlug \`default\` to LLM Wiki tools. +5. For ambiguous contradictions or major rewrites, leave the pages unchanged and create or comment a follow-up Paperclip issue with the exact files and evidence. +6. Close the routine issue with counts by severity, files changed, and unresolved findings.`; + +const INDEX_REFRESH_ROUTINE_DESCRIPTION = `Refresh the LLM Wiki navigation and change log. + +Run procedure: +Target space: default (slug: default). Paperclip-derived indexing currently writes only into the default space, so this routine never sweeps other spaces. Per-space Paperclip ingestion profiles are a later phase; until they ship, treat any prompt to operate on a non-default space here as a bug and stop. +1. Resolve the configured wiki root, then read the default space AGENTS.md, wiki/index.md, wiki/log.md, and the current page list. +2. Rebuild wiki/index.md so it lists current wiki pages by category with concise summaries and valid wikilinks, and attaches wiki/projects//standup.md links to matching project entries. +3. Verify recently changed wiki pages and project standups are present in the index and that removed or renamed pages no longer appear. +4. Do not rewrite content pages unless a broken title or link prevents the index from being accurate. Always pass wikiId \`default\` and spaceSlug \`default\` to LLM Wiki tools. +5. Append a wiki/log.md entry with the index refresh time, page counts by category, and any unresolved indexing problems. +6. Close the routine issue with the index changes and any follow-up needed.`; + +const manifest: PaperclipPluginManifestV1 = { + id: PLUGIN_ID, + apiVersion: 1, + version: "0.1.0", + displayName: "LLM Wiki", + description: "Local-file LLM Wiki plugin for source ingestion, wiki browsing, query, lint, and maintenance workflows.", + author: "Paperclip", + categories: ["automation", "ui"], + capabilities: [ + "events.subscribe", + "api.routes.register", + "database.namespace.migrate", + "database.namespace.read", + "database.namespace.write", + "companies.read", + "projects.read", + "projects.managed", + "skills.managed", + "issues.read", + "issue.subtree.read", + "issues.create", + "issues.update", + "issues.wakeup", + "issues.orchestration.read", + "issue.comments.read", + "issue.comments.create", + "issue.documents.read", + "issue.documents.write", + "agents.read", + "agents.managed", + "agent.sessions.create", + "agent.sessions.list", + "agent.sessions.send", + "agent.sessions.close", + "routines.managed", + "local.folders", + "agent.tools.register", + "metrics.write", + "activity.log.write", + "plugin.state.read", + "plugin.state.write", + "ui.sidebar.register", + "ui.page.register" + ], + entrypoints: { + worker: "./dist/worker.js", + ui: "./dist/ui" + }, + database: { + namespaceSlug: "llm_wiki", + migrationsDir: "migrations", + coreReadTables: ["companies", "issues", "projects", "agents"] + }, + localFolders: [ + { + folderKey: WIKI_ROOT_FOLDER_KEY, + displayName: "Wiki root", + description: "Company-scoped local folder that stores raw sources, wiki pages, Paperclip project standups under wiki/projects/, AGENTS.md, IDEA.md, wiki/index.md, and wiki/log.md.", + access: "readWrite", + requiredDirectories: [ + "raw", + "wiki", + "wiki/sources", + "wiki/projects", + "wiki/entities", + "wiki/concepts", + "wiki/synthesis" + ], + requiredFiles: ["AGENTS.md", "IDEA.md", "wiki/index.md", "wiki/log.md"] + } + ], + agents: [ + { + agentKey: WIKI_MAINTAINER_AGENT_KEY, + displayName: "Wiki Maintainer", + role: "knowledge-maintainer", + title: "LLM Wiki Maintainer", + icon: "book-open", + capabilities: "Ingests source material, maintains local wiki pages, answers cited questions, and runs wiki lint/maintenance through plugin tools.", + adapterType: "claude_local", + adapterPreference: ["claude_local", "codex_local", "gemini_local", "opencode_local", "cursor", "pi_local"], + adapterConfig: { + dangerouslySkipPermissions: false, + dangerouslyBypassApprovalsAndSandbox: false, + sandbox: true, + paperclipSkillSync: { + desiredSkills: WIKI_MANAGED_SKILL_CANONICAL_KEYS + } + }, + runtimeConfig: { + modelProfiles: { + cheap: { + purpose: "classification, lint planning, index maintenance" + } + } + }, + permissions: { + pluginTools: [PLUGIN_ID] + }, + status: "paused", + budgetMonthlyCents: 0, + instructions: { + entryFile: "AGENTS.md", + content: DEFAULT_AGENT_INSTRUCTIONS, + files: DEFAULT_AGENT_INSTRUCTION_FILES, + assetPath: "agents/wiki-maintainer" + } + } + ], + projects: [ + { + projectKey: WIKI_PROJECT_KEY, + displayName: "LLM Wiki", + description: "Plugin-managed inspection area for LLM Wiki ingest, query, lint, and maintenance operation issues.", + status: "in_progress", + color: "#2563eb" + } + ], + skills: [ + { + skillKey: WIKI_MAINTAINER_SKILL_KEY, + displayName: "LLM Wiki Maintainer", + slug: "llm-wiki-maintainer", + description: "Use the LLM Wiki plugin tools to maintain a cited local company wiki.", + markdown: skillMarkdown(WIKI_MAINTAINER_SKILL_KEY) + }, + { + skillKey: WIKI_INGEST_SKILL_KEY, + displayName: "Wiki Ingest", + slug: WIKI_INGEST_SKILL_KEY, + description: "Turn captured raw source material into cited durable LLM Wiki pages.", + markdown: skillMarkdown(WIKI_INGEST_SKILL_KEY) + }, + { + skillKey: WIKI_QUERY_SKILL_KEY, + displayName: "Wiki Query", + slug: WIKI_QUERY_SKILL_KEY, + description: "Answer questions from the LLM Wiki with citations and optional durable synthesis.", + markdown: skillMarkdown(WIKI_QUERY_SKILL_KEY) + }, + { + skillKey: WIKI_LINT_SKILL_KEY, + displayName: "Wiki Lint", + slug: WIKI_LINT_SKILL_KEY, + description: "Audit the LLM Wiki for contradictions, orphan pages, weak provenance, broken links, and missing concepts.", + markdown: skillMarkdown(WIKI_LINT_SKILL_KEY) + }, + { + skillKey: PAPERCLIP_DISTILL_SKILL_KEY, + displayName: "Paperclip Distill", + slug: PAPERCLIP_DISTILL_SKILL_KEY, + description: "Turn Paperclip cursor-window, distill, or backfill source bundles into wiki-insightful project knowledge.", + markdown: skillMarkdown(PAPERCLIP_DISTILL_SKILL_KEY) + }, + { + skillKey: INDEX_REFRESH_SKILL_KEY, + displayName: "Index Refresh", + slug: INDEX_REFRESH_SKILL_KEY, + description: "Refresh wiki/index.md so it accurately catalogs current wiki pages.", + markdown: skillMarkdown(INDEX_REFRESH_SKILL_KEY) + } + ], + routines: [ + { + routineKey: CURSOR_WINDOW_ROUTINE_KEY, + title: "Process LLM Wiki updates", + description: CURSOR_WINDOW_ROUTINE_DESCRIPTION, + status: "paused", + priority: "low", + assigneeRef: { resourceKind: "agent", resourceKey: WIKI_MAINTAINER_AGENT_KEY }, + projectRef: { resourceKind: "project", resourceKey: WIKI_PROJECT_KEY }, + concurrencyPolicy: "skip_if_active", + catchUpPolicy: "skip_missed", + triggers: [ + { + kind: "schedule", + label: "Every 6 hours", + enabled: false, + cronExpression: "0 */6 * * *", + timezone: "UTC", + signingMode: null, + replayWindowSec: null + } + ], + issueTemplate: { + surfaceVisibility: "plugin_operation", + originId: "routine:cursor-window-processing", + billingCode: "plugin-llm-wiki:distillation" + } + }, + { + routineKey: NIGHTLY_LINT_ROUTINE_KEY, + title: "Run LLM Wiki lint", + description: NIGHTLY_LINT_ROUTINE_DESCRIPTION, + status: "paused", + priority: "low", + assigneeRef: { resourceKind: "agent", resourceKey: WIKI_MAINTAINER_AGENT_KEY }, + projectRef: { resourceKind: "project", resourceKey: WIKI_PROJECT_KEY }, + concurrencyPolicy: "skip_if_active", + catchUpPolicy: "skip_missed", + triggers: [ + { + kind: "schedule", + label: "Nightly", + enabled: false, + cronExpression: "0 3 * * *", + timezone: "UTC", + signingMode: null, + replayWindowSec: null + } + ], + issueTemplate: { + surfaceVisibility: "plugin_operation", + originId: "routine:nightly-wiki-lint", + billingCode: "plugin-llm-wiki:maintenance" + } + }, + { + routineKey: INDEX_REFRESH_ROUTINE_KEY, + title: "Refresh LLM Wiki index", + description: INDEX_REFRESH_ROUTINE_DESCRIPTION, + status: "paused", + priority: "low", + assigneeRef: { resourceKind: "agent", resourceKey: WIKI_MAINTAINER_AGENT_KEY }, + projectRef: { resourceKind: "project", resourceKey: WIKI_PROJECT_KEY }, + concurrencyPolicy: "skip_if_active", + catchUpPolicy: "skip_missed", + triggers: [ + { + kind: "schedule", + label: "Hourly", + enabled: false, + cronExpression: "0 * * * *", + timezone: "UTC", + signingMode: null, + replayWindowSec: null + } + ], + issueTemplate: { + surfaceVisibility: "plugin_operation", + originId: "routine:index-refresh", + billingCode: "plugin-llm-wiki:maintenance" + } + } + ], + tools: [ + { + name: "wiki_search", + displayName: "Search Wiki", + description: "Search indexed wiki page and source metadata for one wiki space. Operation agents should pass the issue's spaceSlug; omitting it uses the default space.", + parametersSchema: { + type: "object", + properties: { + companyId: { type: "string" }, + wikiId: { type: "string" }, + spaceSlug: { type: "string" }, + query: { type: "string" }, + limit: { type: "number" } + }, + required: ["companyId", "wikiId", "query"] + } + }, + { + name: "wiki_read_page", + displayName: "Read Wiki Page", + description: "Read a markdown wiki page from one wiki space. Operation agents should pass the issue's spaceSlug; omitting it uses the default space.", + parametersSchema: { + type: "object", + properties: { + companyId: { type: "string" }, + wikiId: { type: "string" }, + spaceSlug: { type: "string" }, + path: { type: "string" } + }, + required: ["companyId", "wikiId", "path"] + } + }, + { + name: "wiki_write_page", + displayName: "Write Wiki Page", + description: "Atomically write a markdown wiki page in one wiki space after plugin path validation and optional hash conflict checks. Operation agents should pass the issue's spaceSlug; omitting it uses the default space. Protected control files such as AGENTS.md and IDEA.md are excluded from agent-tool writes.", + parametersSchema: { + type: "object", + properties: { + companyId: { type: "string" }, + wikiId: { type: "string" }, + spaceSlug: { type: "string" }, + path: { type: "string" }, + contents: { type: "string" }, + expectedHash: { type: "string" }, + summary: { type: "string" } + }, + required: ["companyId", "wikiId", "path", "contents"] + } + }, + { + name: "wiki_propose_patch", + displayName: "Propose Wiki Patch", + description: "Return a structured proposed page write for one wiki space without changing files. Operation agents should pass the issue's spaceSlug; omitting it uses the default space.", + parametersSchema: { + type: "object", + properties: { + companyId: { type: "string" }, + wikiId: { type: "string" }, + spaceSlug: { type: "string" }, + path: { type: "string" }, + contents: { type: "string" }, + summary: { type: "string" } + }, + required: ["companyId", "wikiId", "path", "contents"] + } + }, + { + name: "wiki_list_sources", + displayName: "List Wiki Sources", + description: "Return captured raw source metadata from one wiki space. Operation agents should pass the issue's spaceSlug; omitting it uses the default space.", + parametersSchema: { + type: "object", + properties: { + companyId: { type: "string" }, + wikiId: { type: "string" }, + spaceSlug: { type: "string" }, + limit: { type: "number" } + }, + required: ["companyId", "wikiId"] + } + }, + { + name: "wiki_read_source", + displayName: "Read Wiki Source", + description: "Read a captured raw source from one wiki space. Operation agents should pass the issue's spaceSlug; omitting it uses the default space.", + parametersSchema: { + type: "object", + properties: { + companyId: { type: "string" }, + wikiId: { type: "string" }, + spaceSlug: { type: "string" }, + rawPath: { type: "string" } + }, + required: ["companyId", "wikiId", "rawPath"] + } + }, + { + name: "wiki_append_log", + displayName: "Append Wiki Log", + description: "Append a maintenance note to one wiki space's wiki/log.md. Operation agents should pass the issue's spaceSlug; omitting it uses the default space.", + parametersSchema: { + type: "object", + properties: { + companyId: { type: "string" }, + wikiId: { type: "string" }, + spaceSlug: { type: "string" }, + entry: { type: "string" } + }, + required: ["companyId", "wikiId", "entry"] + } + }, + { + name: "wiki_update_index", + displayName: "Update Wiki Index", + description: "Atomically replace one wiki space's wiki/index.md with optional hash conflict checks. Operation agents should pass the issue's spaceSlug; omitting it uses the default space.", + parametersSchema: { + type: "object", + properties: { + companyId: { type: "string" }, + wikiId: { type: "string" }, + spaceSlug: { type: "string" }, + contents: { type: "string" }, + expectedHash: { type: "string" } + }, + required: ["companyId", "wikiId", "contents"] + } + }, + { + name: "wiki_list_backlinks", + displayName: "List Wiki Backlinks", + description: "Return indexed backlinks for a wiki page in one wiki space. Operation agents should pass the issue's spaceSlug; omitting it uses the default space.", + parametersSchema: { + type: "object", + properties: { + companyId: { type: "string" }, + wikiId: { type: "string" }, + spaceSlug: { type: "string" }, + path: { type: "string" } + }, + required: ["companyId", "wikiId", "path"] + } + }, + { + name: "wiki_list_pages", + displayName: "List Wiki Pages", + description: "Return the known page index from one wiki space's plugin metadata. Operation agents should pass the issue's spaceSlug; omitting it uses the default space.", + parametersSchema: { + type: "object", + properties: { + companyId: { type: "string" }, + wikiId: { type: "string" }, + spaceSlug: { type: "string" } + }, + required: ["companyId", "wikiId"] + } + } + ], + apiRoutes: [ + { + routeKey: "overview", + method: "GET", + path: "/overview", + auth: "board-or-agent", + capability: "api.routes.register", + companyResolution: { from: "query", key: "companyId" } + }, + { + routeKey: "bootstrap", + method: "POST", + path: "/bootstrap", + auth: "board", + capability: "api.routes.register", + companyResolution: { from: "body", key: "companyId" } + }, + { + routeKey: "capture-source", + method: "POST", + path: "/sources", + auth: "board-or-agent", + capability: "api.routes.register", + companyResolution: { from: "body", key: "companyId" } + }, + { + routeKey: "spaces", + method: "GET", + path: "/spaces", + auth: "board-or-agent", + capability: "api.routes.register", + companyResolution: { from: "query", key: "companyId" } + }, + { + routeKey: "create-space", + method: "POST", + path: "/spaces", + auth: "board", + capability: "api.routes.register", + companyResolution: { from: "body", key: "companyId" } + }, + { + routeKey: "update-space", + method: "PATCH", + path: "/spaces/:spaceSlug", + auth: "board", + capability: "api.routes.register", + companyResolution: { from: "body", key: "companyId" } + }, + { + routeKey: "bootstrap-space", + method: "POST", + path: "/spaces/:spaceSlug/bootstrap", + auth: "board", + capability: "api.routes.register", + companyResolution: { from: "body", key: "companyId" } + }, + { + routeKey: "archive-space", + method: "POST", + path: "/spaces/:spaceSlug/archive", + auth: "board", + capability: "api.routes.register", + companyResolution: { from: "body", key: "companyId" } + }, + { + routeKey: "operations", + method: "GET", + path: "/operations", + auth: "board-or-agent", + capability: "api.routes.register", + companyResolution: { from: "query", key: "companyId" } + }, + { + routeKey: "start-query", + method: "POST", + path: "/query-sessions", + auth: "board", + capability: "api.routes.register", + companyResolution: { from: "body", key: "companyId" } + }, + { + routeKey: "file-as-page", + method: "POST", + path: "/file-as-page", + auth: "board", + capability: "api.routes.register", + companyResolution: { from: "body", key: "companyId" } + } + ], + ui: { + slots: [ + { + type: "sidebar", + id: "wiki-sidebar", + displayName: "Wiki", + exportName: "SidebarLink", + order: 35 + }, + { + type: "page", + id: "wiki-page", + displayName: "Wiki", + exportName: "WikiPage", + routePath: "wiki" + }, + { + type: "routeSidebar", + id: "wiki-route-sidebar", + displayName: "Wiki", + exportName: "WikiRouteSidebar", + routePath: "wiki" + } + ] + } +}; + +export default manifest; diff --git a/packages/plugins/plugin-llm-wiki/src/templates.ts b/packages/plugins/plugin-llm-wiki/src/templates.ts new file mode 100644 index 00000000..c07bf6f6 --- /dev/null +++ b/packages/plugins/plugin-llm-wiki/src/templates.ts @@ -0,0 +1,73 @@ +import { readdirSync, readFileSync, statSync } from "node:fs"; + +export const REQUIRED_WIKI_DIRECTORIES = [ + "raw", + "wiki", + "wiki/sources", + "wiki/projects", + "wiki/entities", + "wiki/concepts", + "wiki/synthesis", +] as const; + +export const REQUIRED_WIKI_FILES = ["AGENTS.md", "IDEA.md", "wiki/index.md", "wiki/log.md"] as const; +export const KARPATHY_LLM_WIKI_GIST_URL = "https://gist.github.com/karpathy/442a6bf555914893e9891c11519de94f"; + +function templateFile(path: string): string { + return readFileSync(new URL(`../templates/${path}`, import.meta.url), "utf8"); +} + +function agentInstructionFiles(agentKey: string): Record { + const root = new URL(`../agents/${agentKey}/`, import.meta.url); + const files: Record = {}; + + function walk(relativeDir: string) { + const dirUrl = new URL(relativeDir ? `${relativeDir}/` : "./", root); + for (const entry of readdirSync(dirUrl)) { + if (entry === ".DS_Store") continue; + const relativePath = relativeDir ? `${relativeDir}/${entry}` : entry; + const entryUrl = new URL(relativePath, root); + const stat = statSync(entryUrl); + if (stat.isDirectory()) { + walk(relativePath); + } else if (stat.isFile()) { + files[relativePath] = readFileSync(entryUrl, "utf8"); + } + } + } + + walk(""); + return Object.fromEntries(Object.entries(files).sort(([left], [right]) => left.localeCompare(right))); +} + +export const DEFAULT_WIKI_SCHEMA = templateFile("AGENTS.md"); +export const DEFAULT_AGENT_INSTRUCTION_FILES = agentInstructionFiles("wiki-maintainer"); +export const DEFAULT_AGENT_INSTRUCTIONS = DEFAULT_AGENT_INSTRUCTION_FILES["AGENTS.md"] ?? ""; +export const DEFAULT_IDEA = templateFile("IDEA.md"); +export const DEFAULT_INDEX = templateFile("wiki/index.md"); +export const DEFAULT_LOG = templateFile("wiki/log.md"); +export const DEFAULT_GITIGNORE = templateFile(".gitignore"); + +export const QUERY_PROMPT = `Answer from the LLM Wiki using the installed wiki-query skill. + +Read the target space's wiki/index.md first, inspect relevant pages and raw/source references in that same space, cite the wiki page paths and raw source paths used, and say when the wiki does not contain enough evidence. Useful durable synthesis should be filed back into wiki/synthesis/ inside that same space. Always pass the operation issue's wikiId and spaceSlug to LLM Wiki tools. +`; + +export const LINT_PROMPT = `Lint the LLM Wiki using the installed wiki-lint skill. + +Audit the target space only for contradictions, stale claims, orphan pages, missing backlinks, weak provenance, and wiki/index.md / wiki/log.md drift. Also look for important concepts mentioned without pages and answers that should have been filed back into wiki/. Return findings grouped by severity with concrete file paths, evidence, and suggested fixes — do not auto-apply edits. Always pass the operation issue's wikiId and spaceSlug to LLM Wiki tools. +`; + +export const BOOTSTRAP_FILES: ReadonlyArray<{ path: string; contents: string }> = [ + { path: ".gitignore", contents: DEFAULT_GITIGNORE }, + { path: "AGENTS.md", contents: DEFAULT_WIKI_SCHEMA }, + { path: "IDEA.md", contents: DEFAULT_IDEA }, + { path: "wiki/index.md", contents: DEFAULT_INDEX }, + { path: "wiki/log.md", contents: DEFAULT_LOG }, + { path: "raw/.gitkeep", contents: "" }, + { path: "wiki/sources/.gitkeep", contents: "" }, + { path: "wiki/projects/.gitkeep", contents: "" }, + { path: "wiki/entities/.gitkeep", contents: "" }, + { path: "wiki/concepts/.gitkeep", contents: "" }, + { path: "wiki/synthesis/.gitkeep", contents: "" }, +]; diff --git a/packages/plugins/plugin-llm-wiki/src/ui/app.tsx b/packages/plugins/plugin-llm-wiki/src/ui/app.tsx new file mode 100644 index 00000000..8110e827 --- /dev/null +++ b/packages/plugins/plugin-llm-wiki/src/ui/app.tsx @@ -0,0 +1,7120 @@ +import { + AssigneePicker, + FileTree, + IssuesList as PluginIssuesList, + ManagedRoutinesList as PluginManagedRoutinesList, + MarkdownBlock, + MarkdownEditor, + ProjectPicker, + usePluginAction, + usePluginData, + usePluginStream, + usePluginToast, + useHostLocation, + useHostNavigation, + type FileTreeNode, + type ManagedRoutinesListItem, + type PluginPageProps, + type PluginRouteSidebarProps, + type PluginSettingsPageProps, + type PluginSidebarProps, +} from "@paperclipai/plugin-sdk/ui"; +import { useCallback, useEffect, useMemo, useRef, useState, type AnchorHTMLAttributes, type CSSProperties, type ReactElement, type ReactNode } from "react"; +import { readIngestOperationIssueId, uploadIssueAttachmentFile } from "./issue-attachments.js"; + +// --------------------------------------------------------------------------- +// Shared design tokens — copied from the UX wireframe shared.css so the plugin +// looks identical inside the host whether or not host theme tokens are +// available at runtime. +// --------------------------------------------------------------------------- + +const tokens = { + border: "var(--border, oklch(0.269 0 0))", + card: "var(--card, oklch(0.205 0 0))", + bg: "var(--background, oklch(0.145 0 0))", + fg: "var(--foreground, oklch(0.985 0 0))", + muted: "var(--muted-foreground, oklch(0.708 0 0))", + accent: "var(--accent, oklch(0.269 0 0))", + primary: "var(--primary, oklch(0.985 0 0))", + primaryFg: "var(--primary-foreground, oklch(0.205 0 0))", + destructive: "var(--destructive, oklch(0.637 0.237 25.331))", + pluginBg: "oklch(0.3 0.06 70)", + pluginFg: "oklch(0.92 0.08 80)", + pluginBorder: "oklch(0.55 0.15 70)", + hiddenOpBg: "oklch(0.27 0.04 280)", + hiddenOpFg: "oklch(0.85 0.08 280)", + hiddenOpBorder: "oklch(0.45 0.1 280)", + callout: { bg: "oklch(0.2 0.04 250)", fg: "oklch(0.85 0.08 250)", border: "oklch(0.4 0.1 250)" }, + statusDone: "oklch(0.65 0.16 145)", + statusRunning: "oklch(0.7 0.13 200)", + statusBlocked: "oklch(0.6 0.21 25)", + statusInProgress: "oklch(0.58 0.18 280)", + statusTodo: "oklch(0.6 0.17 250)", + statusPaused: "oklch(0.72 0.15 70)", +}; + +type Tone = "todo" | "in_progress" | "in_review" | "done" | "blocked" | "running" | "paused" | "failed" | "queued" | "default"; + +const toneStyles: Record = { + default: { background: "var(--secondary, oklch(0.269 0 0))", color: tokens.fg, border: `1px solid ${tokens.border}` }, + todo: { background: "oklch(0.27 0.06 250)", color: "oklch(0.85 0.1 250)" }, + in_progress: { background: "oklch(0.27 0.06 280)", color: "oklch(0.85 0.1 280)" }, + in_review: { background: "oklch(0.27 0.07 305)", color: "oklch(0.85 0.1 305)" }, + done: { background: "oklch(0.27 0.06 145)", color: "oklch(0.85 0.1 145)" }, + blocked: { background: "oklch(0.27 0.08 25)", color: "oklch(0.82 0.13 25)" }, + running: { background: "oklch(0.27 0.06 200)", color: "oklch(0.83 0.11 200)" }, + paused: { background: "oklch(0.27 0.07 70)", color: "oklch(0.85 0.1 70)" }, + failed: { background: "oklch(0.27 0.08 25)", color: "oklch(0.82 0.13 25)" }, + queued: { background: "oklch(0.27 0.06 250)", color: "oklch(0.85 0.1 250)" }, +}; + +const fontStack = `ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif`; +const mobileMediaQuery = "(max-width: 767px)"; +const PLUGIN_ID = "paperclipai.plugin-llm-wiki"; +const WIKI_SIDEBAR_NAV_STATE_KEY = "paperclipWikiSidebarTreePath"; +const ROUTE_SIDEBAR_EXPANDED_STORAGE_PREFIX = `${PLUGIN_ID}:route-sidebar-expanded:v2`; +const WIKI_TOC_STICKY_TOP = 88; +const WIKI_SPACE_PREFETCH_LIMIT = 8; +const DEFAULT_ROUTE_SIDEBAR_EXPANDED_PATHS = [ + "wiki", + "wiki/sources", + "wiki/projects", + "wiki/entities", + "wiki/concepts", + "wiki/synthesis", +] as const; + +// --------------------------------------------------------------------------- +// Shared types coming back from the worker. +// --------------------------------------------------------------------------- + +type FolderStatus = { + configured: boolean; + path: string | null; + realPath: string | null; + access: "read" | "readWrite"; + readable: boolean; + writable: boolean; + requiredDirectories: string[]; + requiredFiles: string[]; + missingDirectories: string[]; + missingFiles: string[]; + healthy: boolean; + problems: { code: string; message: string; path?: string }[]; + checkedAt: string; +}; + +type ManagedAgent = { + status: string; + source?: "managed" | "selected"; + agentId?: string | null; + resourceKey?: string | null; + details?: { name?: string; status?: string; adapterType?: string | null; icon?: string | null; urlKey?: string | null } | null; + defaultDrift?: { entryFile: string; changedFiles: string[] } | null; +}; + +type ManagedProject = { + status: string; + source?: "managed" | "selected"; + projectId?: string | null; + resourceKey?: string | null; + details?: { name?: string; status?: string; color?: string | null } | null; +}; + +type ManagedRoutine = { + status: string; + routineId?: string | null; + resourceKey?: string | null; + missingRefs?: Array<{ pluginKey?: string; resourceKind: string; resourceKey: string }>; + defaultDrift?: { + changedFields: string[]; + defaultTitle?: string | null; + defaultDescription?: string | null; + } | null; + routine?: { + id?: string; + title?: string; + status?: string; + assigneeAgentId?: string | null; + projectId?: string | null; + lastTriggeredAt?: string | null; + lastEnqueuedAt?: string | null; + managedByPlugin?: { + pluginDisplayName?: string; + resourceKey?: string; + } | null; + } | null; + details?: { + title?: string; + status?: string; + cronExpression?: string | null; + enabled?: boolean; + nextRunAt?: string | null; + lastRunAt?: string | null; + assigneeAgentId?: string | null; + } | null; +}; + +type ManagedSkill = { + status: string; + skillId?: string | null; + resourceKey?: string | null; + defaultDrift?: { changedFiles: string[] } | null; + skill?: { + id?: string; + name?: string; + key?: string; + description?: string | null; + } | null; + details?: { + name?: string; + key?: string; + description?: string | null; + } | null; +}; + +type OverviewData = { + status: "ok"; + checkedAt: string; + wikiId: string; + folder: FolderStatus; + managedAgent: ManagedAgent; + managedProject: ManagedProject; + managedSkills: ManagedSkill[]; + operationCount: number; + eventIngestion: EventIngestionSettings; + capabilities: string[]; + prompts: { query: string; lint: string }; +}; + +type EventIngestionSettings = { + enabled: boolean; + sources: { + issues: boolean; + comments: boolean; + documents: boolean; + }; + wikiId: string; + maxCharacters: number; +}; + +type WikiEventIngestionSource = "issues" | "comments" | "documents"; + +type PaperclipIngestionSourceScope = + | { kind: "active_projects"; limit: number; statuses?: Array<"in_progress" | "todo" | "done"> } + | { kind: "selected_projects"; projectIds: string[] } + | { kind: "root_issues"; issueIds: string[] } + | { kind: "company_all"; requiresBoardConfirmation: true }; + +type PaperclipIngestionProfile = { + version: 1; + enabled: boolean; + sourceScopes: PaperclipIngestionSourceScope[]; + sourceKinds: { + issues: boolean; + comments: boolean; + documents: boolean; + attachments: "off" | "metadata_only"; + workProducts: "off" | "metadata_only"; + }; + cursor: { + maxWindowCharacters: number; + maxCharactersPerSource: number; + minSourceAgeMinutes: number; + maxWindowsPerRun: number; + staleAfterHours: number; + }; + backfill: { + defaultStartAt?: string | null; + defaultEndAt?: string | null; + requireManualQueue: boolean; + }; +}; + +type PaperclipIngestionProfileData = { + wikiId: string; + space: Pick; + profile: PaperclipIngestionProfile; + effectiveState: "enabled" | "disabled" | "policy_blocked" | "pending_approval" | "enabled_no_scopes"; + policyBlocks: string[]; + historicalPageCount: number; + overlapCount: number; +}; + +type SettingsData = { + folder: FolderStatus; + managedAgent: ManagedAgent; + managedProject: ManagedProject; + managedRoutine?: ManagedRoutine; + managedRoutines?: ManagedRoutine[]; + managedSkills?: ManagedSkill[]; + distillationPolicy?: { + autoApplyAllowed: boolean; + autoApplyRestriction: string | null; + deploymentMode: "local_trusted" | "authenticated" | null; + deploymentExposure: "private" | "public" | null; + }; + eventIngestion: EventIngestionSettings; + agentOptions: Array<{ id: string; name: string; status?: string | null; adapterType?: string | null; icon?: string | null; urlKey?: string | null }>; + projectOptions: Array<{ id: string; name: string; status?: string | null; color?: string | null }>; + capabilities: string[]; +}; + +type WikiSpace = { + id: string; + companyId: string; + wikiId: string; + slug: string; + displayName: string; + spaceType: string; + folderMode: string; + rootFolderKey: string; + pathPrefix: string | null; + configuredRootPath: string | null; + accessScope: string; + ownerUserId: string | null; + ownerAgentId: string | null; + teamKey: string | null; + settings: Record; + status: string; + createdAt: string | null; + updatedAt: string | null; +}; + +type WikiSpacesData = { + spaces: WikiSpace[]; +}; + +type WikiSpaceWithFolderStatus = WikiSpace & { + relativeRoot: string; + folder: FolderStatus; +}; + +const DEFAULT_SPACE_SLUG = "default"; + +type WikiPageRow = { + path: string; + title: string | null; + pageType: string | null; + backlinkCount: number; + sourceCount: number; + contentHash: string | null; + updatedAt: string; +}; + +type WikiSourceRow = { + rawPath: string; + title: string | null; + sourceType: string; + url: string | null; + status: string; + createdAt: string; +}; + +type PagesData = { + pages: WikiPageRow[]; + sources: WikiSourceRow[]; +}; + +type PageContentData = { + wikiId: string; + path: string; + contents: string; + title: string | null; + pageType: string | null; + backlinks: string[]; + sourceRefs: Array | string>; + updatedAt: string | null; + hash: string; +}; + +type WikiOperationRow = { + id: string; + operationType: string; + status: string; + hiddenIssueId: string | null; + hiddenIssueIdentifier: string | null; + hiddenIssueTitle: string | null; + hiddenIssueStatus: string | null; + projectId: string | null; + runIds: unknown[]; + costCents: number; + warnings: unknown[]; + affectedPages: unknown[]; + metadata?: Record; + createdAt: string; + updatedAt: string; +}; + +type OperationsData = { + operations: WikiOperationRow[]; +}; + +type TemplateData = { + path: string; + contents: string; + hash: string | null; + exists: boolean; +}; + +type WikiFrontmatterValue = string | string[]; + +type WikiFrontmatterProperty = { + key: string; + value: WikiFrontmatterValue; +}; + +type ParsedWikiMarkdown = { + body: string; + frontmatter: WikiFrontmatterProperty[]; +}; + +type WikiTocHeading = { + id: string; + text: string; + level: number; +}; + +// --------------------------------------------------------------------------- +// Small presentational primitives. +// --------------------------------------------------------------------------- + +function Badge({ children, tone = "default", style }: { children: ReactNode; tone?: Tone; style?: CSSProperties }) { + return ( + {children} + ); +} + +function HiddenOpBadge() { + return ( + 📖 wiki task + ); +} + +function StatusIcon({ status }: { status: string }) { + const map: Record = { + done: { color: tokens.statusDone, filled: true }, + in_progress: { color: tokens.statusInProgress }, + running: { color: tokens.statusRunning, pulse: true }, + queued: { color: tokens.statusTodo }, + todo: { color: tokens.statusTodo }, + blocked: { color: tokens.statusBlocked }, + failed: { color: tokens.statusBlocked }, + paused: { color: tokens.statusPaused }, + }; + const tone = map[status] ?? { color: tokens.muted }; + return ( + + ); +} + +function Card({ children, style }: { children: ReactNode; style?: CSSProperties }) { + return ( +
{children}
+ ); +} + +function CardHeader({ title, right, badges }: { title: ReactNode; right?: ReactNode; badges?: ReactNode }) { + return ( +
+

{title}

+ {badges} + {right ?
{right}
: null} +
+ ); +} + +function CardBody({ children, padding = 16 }: { children: ReactNode; padding?: number | string }) { + return
{children}
; +} + +const unfilledSurfaceStyle: CSSProperties = { + background: "transparent", +}; + +function PropRow({ label, value }: { label: ReactNode; value: ReactNode }) { + return ( +
+ {label} + {value} +
+ ); +} + +function Tiny({ children, style }: { children: ReactNode; style?: CSSProperties }) { + return
{children}
; +} + +function Mono({ children, style }: { children: ReactNode; style?: CSSProperties }) { + return {children}; +} + +type ButtonVariant = "primary" | "default" | "ghost" | "destructive"; +type ButtonSize = "sm" | "md"; + +function Button({ + variant = "default", + size = "md", + disabled, + loading, + onClick, + children, + type = "button", + style, + title, +}: { + variant?: ButtonVariant; + size?: ButtonSize; + disabled?: boolean; + loading?: boolean; + onClick?: () => void; + children: ReactNode; + type?: "button" | "submit"; + style?: CSSProperties; + title?: string; +}) { + const palette: Record = { + primary: { + background: tokens.primary, + color: tokens.primaryFg, + border: `1px solid transparent`, + }, + default: { + background: tokens.card, + color: tokens.fg, + border: `1px solid ${tokens.border}`, + }, + ghost: { + background: "transparent", + color: tokens.fg, + border: `1px solid transparent`, + }, + destructive: { + background: "transparent", + color: "oklch(0.7 0.2 25)", + border: `1px solid oklch(0.5 0.18 25)`, + }, + }; + return ( + + ); +} + +function TextInput(props: React.InputHTMLAttributes) { + return ( + + ); +} + +function TextArea(props: React.TextareaHTMLAttributes) { + return ( +