Make a plugin

Write a look or an importer for Ducter, check it, try it on your own computer and publish it from your own repository, with every manifest field and every check message explained.

On this page
  1. What you can make today
  2. A look in five minutes
  3. An importer
  4. Manifest reference
  5. Publish your plugin
  6. Versions and updates
  7. Troubleshooting
  8. Coming soon

This page is for people who write plugins. If you want to use one, start with Plugins.

A plugin is a folder with a ducter-plugin.json at its top. Ducter reads the folder, pins it to exact bytes, and shows it on the shelf in Settings › 插件 / Plugins.

What you can make today

Pages, connectors and to-do sources as plugins are coming soon. A manifest that names one of those kinds is refused with a message that says so.

A look in five minutes

1. Start from a look that already passes.

ducter plugin new theme ~/src/sea-glass

This writes two files: ducter-plugin.json (the manifest, its id taken from the folder’s name) and theme.json (Pebble’s own colours for both papers, so it passes every check before you change anything).

2. Change the tokens. Open theme.json and change the colours under tokens.light and tokens.dark. Each colour is #rrggbb. Give your look its own name in name, in ducter-plugin.json and in theme.json, and say who you are in author.name. The tokens are listed in The look’s tokens.

3. Check it.

ducter plugin check ~/src/sea-glass
ducter-plugin/2  sea-glass  0.1.0  theme
  manifest  ok  ducter-plugin/2 sea-glass 0.1.0 theme
  theme  ok  ducter-theme/1 light + dark, motion calm
  contrast  ok  24 pairs, both modes, all at or above their floor
0 things to fix

The check is the same gate an install runs: the manifest, the token file, and 24 pairs of text on its ground, 12 in each paper, each at a contrast of at least 4.5 to 1. It exits 0 when everything passes, 1 when the look needs a fix, and 2 when the folder or manifest can’t be read. Add --json for a result a script or your own agent can read; it also names every pair that fails.

4. Try it.

ducter plugin add ~/src/sea-glass

Open Settings › 插件 / Plugins. Your look is on the shelf, marked 你自己加的 / Added by you. 试试 / Try it wears it on the whole window for ten seconds; 换上 / Use it keeps it on. Ducter reads a look added from your folder where it is, so you can go on editing it; run ducter plugin check after each change. To take it off the shelf, open its card’s ⋯ and choose 删掉 / Remove.

5. Publish it. Put the folder in a git repository with an index.json, and anyone can add your repository in Settings. See Publish your plugin.

An importer

An importer brings another app’s past conversations into 做过的事 / Past tasks, read only. The official repository’s plugins/t3code is a complete one to start from: github.com/wey-gu/ducter-plugins.

Its manifest

An importer’s manifest uses the format ducter-plugin/1:

{
  "format": "ducter-plugin/1",
  "id": "acme-notes",
  "kind": "importer",
  "version": "0.1.0",
  "name": { "en": "Acme Notes", "zh": "Acme 笔记" },
  "app": { "name": "Acme Notes", "icon": "icon.png" },
  "author": { "name": "Your name" },
  "emits": "ducter-import/1",
  "run": ["bun", "main.ts"],
  "reads": ["~/Library/Application Support/AcmeNotes/**/*.sqlite*"],
  "uses": [],
  "detect": ["~/Library/Application Support/AcmeNotes/store.sqlite"],
  "ducter": "^0.1"
}

Every field is in The importer’s manifest. Ducter shows reads, every command in uses and its why, word for word, on the sheet the person reads before 装上 / Install.

What your reader gets, and what it prints

What it gets. Ducter starts the run command in your plugin’s folder, with no arguments of its own and nothing on standard input. bun in run is Ducter’s own Bun, and bun install never runs, so ship everything your reader needs inside the folder. HOME is the person’s home folder, TMPDIR is the one folder it may write, and PATH is the folders of the commands it declared in uses, then /usr/local/bin, /usr/bin and /bin.

What it prints. Lines of ducter-import/1 on standard output: one source record, then each thread and its msg records, optional skipped counts, and one end with the totals. The format, its limits and what each field becomes are in Bring past conversations in. Print only what a person saw: user and assistant words, no tool calls, thinking, system prompts or unfinished replies. Use the other app’s own ids, so a second run brings only what is new.

What it may say besides. Anything on standard error is kept as diagnostics, never as conversations; the first 2,000 characters show when a run fails. A reader that exits with an error and prints nothing has failed; whatever whole conversations it printed before stopping are kept.

Ducter checks every line before anything is stored, so a mistake in your reader can stop an import but can’t damage what the person already has.

The sandbox

Ducter never runs a reader unconfined. On a Mac it runs inside macOS’s own sandbox; on Linux, inside bubblewrap, which must be installed. Where neither is available, for example on Windows, the reader doesn’t run, and the shelf says it can’t run here.

Test it

  1. Build a small fake store in a temporary folder and run your reader against it with bun test. Never read your own real store in a test.

  2. Check what your reader prints, writing nothing:

    bun main.ts | ducter import --check

    It says how many conversations and messages the stream holds, and where and why it stopped if it did. Run it until it is clean.

  3. Install it from your folder and run it the way a person will, in the sandbox:

    ducter plugin add ~/src/acme-notes

    Open Settings › 插件 / Plugins and tap 带进来 / Bring them in on its row. The sheet shows exactly what you declared, and the run happens in the sandbox. After you change the reader, ducter plugin update acme-notes takes the folder’s new files; if it now reads more, the person is asked again.

ducter plugin check checks looks only today. A first importer from ducter plugin new importer is coming soon, and so is ducter plugin check for an importer, with --stream <file> to check a sample of what it prints.

Manifest reference

These are every field Ducter reads, and the rules it checks. A look’s manifest refuses any field not listed; an importer’s manifest ignores one.

The look’s manifest

ducter-plugin.json, format ducter-plugin/2:

Field Needed What it is
format yes "ducter-plugin/2"
id yes 2 to 64 characters: lower-case letters, digits and -, starting with a letter or digit. Unique on the shelf.
kind yes "theme"
version yes Your look’s own version, like 0.1.0 (1.2.3, optionally with -beta.1).
name yes { "en": "…", "zh": "…" }. en is needed; zh is optional.
author yes { "name": "…", "url": "…" }. name is needed.
ducter yes The Ducter versions it works with: ^0.1 (any 0.1 from 0.1.0), >=0.1.20, an exact version, or *.
theme yes { "file": "theme.json" }. Keep the token file’s name theme.json: that is the file Ducter reads.
permissions no {} or left out. A look may not read files, run programs or go online.
summary no One line, { "en": "…", "zh": "…" }, each at most 140 characters.
icon no A path inside the folder.
license no For example "Apache-2.0".
repo no Where its source lives.

The look’s tokens

theme.json, format ducter-theme/1:

Field Needed What it is
format yes "ducter-theme/1"
name yes { "en": "…", "zh": "…" }; en is needed.
tokens yes { "light": {…}, "dark": {…} }. Every look has both papers, even a dark-first one.
motion no personality (bouncy, snappy, calm or stepped), press (40 to 140 ms) and enter (120 to 320 ms).
shape no All of radiusSm, radiusMd, radiusLg, radiusXl and pill, each a number above 0 and at most 999.
depth no press, offset, hairline or glow.
density no comfortable or compact.

Today a look puts on its colours. motion, shape, depth and density are checked and kept; putting them on is coming soon.

Each paper fills these colours, each #rrggbb:

Token Where it shows
bg The page’s ground.
surface Cards and the composer.
surfaceRaised A raised surface: a knob, a raised row.
ink Text.
inkMuted Quieter text.
accent Your messages, the send button, what is chosen.
onAccent Text on the accent.
line Hairlines.
userBubble, onUserBubble Your messages and their text.
partnerBubble, onPartnerBubble Your partner’s messages and their text.
decide, progress, wait, ok, fail Needs you, working, waiting, done and failed. Each is { "dot", "surface", "ink" }: the mark, the tinted ground and the text on it.

A token you leave out, or one that isn’t #rrggbb, takes Pebble’s value, so a half-written look is still a whole one. The shelf calls your look 暖色 / Warm, 冷色 / Cool, 素色 / Plain or 深色 / Dark from its own light bg and accent, not from its name.

The 12 pairs check holds to 4.5 to 1 in each paper are ink and inkMuted on bg and on surface, onAccent on accent, onUserBubble on userBubble, onPartnerBubble on partnerBubble, and each state’s ink on its own surface.

The importer’s manifest

ducter-plugin.json, format ducter-plugin/1:

Field Needed What it is
format yes "ducter-plugin/1"
id yes 2 to 64 characters: lower-case letters, digits and -, starting with a letter or digit.
kind yes "importer"
version yes Your reader’s own version, like 0.1.0.
name yes { "en": "…", "zh": "…" }; en is needed.
app yes { "name": "…", "icon": "…" }. name is the app whose conversations it reads; only one installed importer may read each app. icon is a PNG or SVG inside the folder, at most 256 KB; without one, the app’s initial shows.
author yes { "name": "…", "url": "…" }; name is needed and shown on the sheet.
emits yes "ducter-import/1"
run yes The command and its arguments, 1 to 16 items. bun means Ducter’s own Bun; any other command is found on the person’s PATH.
reads yes 1 to 64 paths it opens, literally. See The sandbox.
uses no Up to 8 commands the reader starts, each { "command", "online", "why" }. why is { "en", "zh" }, the sentence the sheet shows; en is needed. online: true is the only way a run may go online.
starts no Extra programs with no network. New importers should use uses.
detect no Paths whose existence means the app is on this computer, so its row comes first. Checked by existence only; never read.
network no Kept for older manifests: false, or true only with an online use.
ducter yes The Ducter versions it works with, as for a look.

An importer written as ducter-plugin/2 is refused at install for now: write ducter-plugin/1. One manifest format for both kinds is coming soon.

Publish your plugin

Your own repository

A plugin repository is any git repository with an index.json at its top:

{
  "format": "ducter-plugins/1",
  "plugins": [
    {
      "id": "acme-notes",
      "path": "plugins/acme-notes",
      "version": "0.1.0",
      "commit": "e92a6d857c85901e9e7d17f89239caa29c2b39ad",
      "hash": "1993e19e6ba7150da369a4270cec35dea165ec87a33991eb7139e58db3e8f891",
      "app": "Acme Notes",
      "icon": "icon.png"
    },
    {
      "id": "sea-glass",
      "path": "plugins/sea-glass",
      "version": "0.1.0",
      "commit": "babf12ec59fc408f2ce6c31196713a9d450f7d0b",
      "hash": "b822502be848d09905319750d9b28122fa0f077ed65628920a225939ec832ea2",
      "kind": "theme"
    }
  ]
}

The official repository’s scripts/index.ts computes every hash and commit and writes index.json; copy it into your repository. Commit your plugin’s files first, then run it and commit index.json.

Before you push, you can try the whole index from your own folder: ducter plugin source add ~/src/my-plugins reads index.json where it is and checks each hash when you install.

Adding it in Settings

People add your repository in Settings › 插件 / Plugins › 插件仓库 / Plugin repositories › 加一个插件仓库 / Add a plugin repository, or from a terminal:

ducter plugin source add https://github.com/you/my-plugins

Its plugins join the shelf marked 你加的仓库 / From your repository. To hand someone a single plugin instead, ducter plugin add <git-url> installs one from its own repository, and <git-url>#<branch, tag or commit> installs it at that point.

Pinned by commit and hash

Ducter installs a plugin from a repository by checking out the index’s commit, hashing the plugin’s folder, and refusing it if the hash differs from the index. The hash is checked again before every run of an importer, and when a look is put on. Files changed after the pin lock the card: nothing installs or runs, and a look already on is set aside for Pebble. So a published version is a promise about exact bytes: to change anything, publish a new version.

What “Reviewed” means

Ducter 查过 / Reviewed means Ducter’s official repository, https://github.com/wey-gu/ducter-plugins, lists this plugin at this exact version and content hash. It is about one version, not a person or a repository: your plugin can be reviewed while it lives in your own repository, if the official index lists the same id, version and hash. Any other version is installed as unreviewed, and an unreviewed importer that goes online asks for one more tick. To be listed, open a pull request on the official repository.

Versions and updates

Going back to the version before an update (ducter plugin rollback <id>) is coming soon.

Troubleshooting

What ducter plugin check says

check stops at the first thing it can’t read. manifest problems exit 2, theme and contrast problems exit 1.

It says What to do
not a folder Point check at the plugin’s folder.
no ducter-plugin.json Put the manifest at the top of the folder, with that name.
no readable ducter-plugin.json The manifest isn’t valid JSON. Find the stray comma or quote.
the manifest must be a JSON object The file holds a list or a value; it must be one { … }.
format must be ducter-plugin/1 or ducter-plugin/2 A look uses "format": "ducter-plugin/2".
a v1 manifest is an importer, not a theme check reads looks only today. Test an importer as in Test it.
kind "importer" is not a theme The same, for an importer written in the newer format.
kind names what the plugin is Add "kind": "theme".
kind "ui" is reserved … (or connector, source) Those kinds are coming soon; only looks and importers install today.
kind must be importer or theme (others are reserved) Use "theme" for a look.
unknown manifest key "…" A typo, or a field Ducter doesn’t read. Check the name against The look’s manifest.
unknown theme key "…" theme holds only file.
unknown permissions key "…" permissions holds only files, exec and network; a look leaves it {}.
id must be lower-case letters, digits and - 2 to 64 characters, like sea-glass.
version must be a version Use three numbers, like 0.1.0.
ducter is the Ducter range it needs Add "ducter": "^0.1".
name.en is needed (or summary.en is needed) Give an English name or summary; Chinese is optional.
summary.en is longer than 140 (or summary.zh) Shorten the summary to one line.
author.name says who made it Add "author": { "name": "…" }.
icon must be inside the folder (or theme.file …) Use a path inside the plugin’s folder, without .. or a leading /.
a theme plugin has a theme object Add "theme": { "file": "theme.json" }.
a theme plugin may not carry a importer object A manifest carries only the object for its own kind.
a theme may not read files, run programs or go online Leave permissions as {}.
no readable theme.json Put theme.json beside the manifest, as valid JSON.
format must be ducter-theme/1 Add "format": "ducter-theme/1" to theme.json.
tokens has a light and a dark paper Add tokens with light and dark.
motion must be an object, motion.personality is …, motion.press and motion.enter are milliseconds Give motion all three fields, as in The look’s tokens.
motion.press stays within 40–140 ms (or motion.enter … 120–320 ms) Bring the number inside the range.
shape must be an object, shape.radiusSm is a positive number (or another radius) Give all five radii, each above 0 and at most 999, or leave shape out.
depth is press, offset, hairline or glow Use one of those, or leave depth out.
density is comfortable or compact Use one of those, or leave density out.
N pair(s) under their floor Some text is too faint on its ground. Run check --json: failures names each pair, like light: inkMuted / bg, with both colours. Darken the text or lighten the ground (or the reverse on the dark paper) until each reaches 4.5 to 1.

A colour that doesn’t change when you edit it isn’t #rrggbb: Ducter quietly uses Pebble’s value for it.

When an install or a run refuses

It says What to do
already_installed That id is installed. For an importer, ducter plugin update <id> takes your new files; for a look, remove it from its card’s ⋯ first.
app_taken Another installed importer already reads that app.
contrast The look fails its contrast check. Run ducter plugin check.
hash_mismatch The files at the index’s commit don’t hash to the index’s hash. Run your index script again and commit index.json.
symlink A plugin may not contain a symbolic link. Copy the file in.
git_failed The address can’t be cloned, or the commit isn’t in it. Push the commit the index names.
reserved_kind An importer written as ducter-plugin/2. Write it as ducter-plugin/1.
A bad_manifest message The same rules as the tables above; for an importer, see The importer’s manifest.
Needs a newer Ducter The person’s Ducter is outside your ducter range.
Can’t run here (sandbox_unavailable) On Linux, install bubblewrap (bwrap). Importers don’t run on Windows.
the … command isn't on this computer A command in uses isn’t on the person’s PATH. Say in your README what to install.
The run fails (plugin_failed) Your reader exited with an error and printed nothing. The first 2,000 characters of its standard error show with it. Most often it tried to read a path it didn’t declare.

If your plugin doesn’t show on the shelf at all, check its index entry: an id that isn’t lower-case, a repeated id, a path with .., a commit that isn’t 7 to 64 hexadecimal characters, a hash that isn’t 64, an importer without app, or a version that differs from its manifest each leave that entry out.

Coming soon