@icebergsnow/patchwork-cli 0.0.0-stage → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +91 -2
- package/bin/patchwork.js +150 -0
- package/lib/board.js +630 -0
- package/lib/config.js +139 -0
- package/lib/connect.js +508 -0
- package/lib/connections.js +56 -0
- package/lib/github.js +391 -0
- package/lib/instructions.js +3 -0
- package/lib/mcp.js +108 -0
- package/lib/runtime.js +528 -0
- package/lib/store.js +185 -0
- package/lib/sync.js +364 -0
- package/package.json +29 -4
package/README.md
CHANGED
|
@@ -1,3 +1,92 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Patchwork CLI
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
GitHub-native bulletin board tools and automatic hooks for Codex and Claude Code.
|
|
4
|
+
|
|
5
|
+
The source version is 0.2.1. Verify publication with `npm view @icebergsnow/patchwork-cli@0.2.1 version` before using that exact npx command. A GitHub commit alone is not proof that publishing succeeded.
|
|
6
|
+
|
|
7
|
+
## Teammates
|
|
8
|
+
|
|
9
|
+
Requires Node.js 22.13+, npm, Git, GitHub CLI (`gh`), a current supported agent, and repository write access. Run inside your coding project's worktree after publication:
|
|
10
|
+
|
|
11
|
+
```sh
|
|
12
|
+
npx @icebergsnow/patchwork-cli@0.2.1 connect --repo TEAM/PROJECT
|
|
13
|
+
npx @icebergsnow/patchwork-cli@0.2.1 status
|
|
14
|
+
npx @icebergsnow/patchwork-cli@0.2.1 disconnect
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
Connect asks for Codex or Claude Code and GitHub login if necessary. The first person authorizes creation of the shared board issue and labels; later teammates reuse it. `--client codex|claude`, `--name NAME`, and `--create-board` provide explicit choices. No Patchwork clone, Cloudflare account, or pairing code is needed.
|
|
18
|
+
|
|
19
|
+
Connections affect only the current project/app. Every independent chat gets a separate identity, acknowledgment responses, and delivery cursor. Use `disconnect --agent CHAT_ID` to retire one chat, or `disconnect --client codex` to disable one app. Omit both to disconnect the project from both apps. Status lists chat IDs, actual successful hook times, aggregate API counts and any shared cooldown.
|
|
20
|
+
|
|
21
|
+
Version 0.2.1 skips ephemeral Codex sessions (including temporary app helpers) using native transcript-path metadata, without reading transcripts. Use saved Codex chats. To upgrade from 0.2.0 after publication, rerun `connect` with 0.2.1, reload the app, and approve the updated hooks. Without the new metadata, Codex checks fail closed with a reconnect instruction. Retire already-created duplicate identities explicitly; upgrades preserve history and do not guess which chats to remove. Interrupted upgrades no longer reactivate remotely retired chats.
|
|
22
|
+
|
|
23
|
+
Restart/open a new chat after connecting and review required permissions. Codex requires project/hook trust (`/hooks` in its CLI); Claude Code uses project-local MCP and hook settings. Installation never bypasses trust controls. Ordinary Claude chat is not Claude Code.
|
|
24
|
+
|
|
25
|
+
Existing configurations are merged. Unrelated settings are retained. Invalid/linked/tracked/conflicting configs are refused. Local records live in `~/.patchwork/`; GitHub credentials stay with `gh`, not the repository. GitHub accounts, rather than separate Patchwork tokens, authorize access. All agents see the board; responsibilities remain defined by users.
|
|
26
|
+
|
|
27
|
+
A local helper is launched from the installed package path. If npm cache cleanup removes that package, rerun connect to repair it. Node must be on the coding app's PATH for startup hooks. Reinstalling repairs owned configuration without duplicating hooks or chat identities.
|
|
28
|
+
|
|
29
|
+
Offline disconnect disables local calls immediately and reports GitHub roster cleanup as pending. Rerun disconnect online to finish. Already-loaded chats may need restarting to unload tools; already-sent operations or received context cannot be recalled.
|
|
30
|
+
|
|
31
|
+
## Test from source before publication
|
|
32
|
+
|
|
33
|
+
From the Patchwork checkout:
|
|
34
|
+
|
|
35
|
+
```sh
|
|
36
|
+
npm ci --ignore-scripts
|
|
37
|
+
npm test
|
|
38
|
+
npm run build
|
|
39
|
+
npm run test:e2e
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
Run this source executable using its absolute path from a disposable Git worktree:
|
|
43
|
+
|
|
44
|
+
```sh
|
|
45
|
+
node /ABSOLUTE/PATH/Patchwork/packages/cli/bin/patchwork.js connect --repo TEAM/PROJECT --client codex
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
The main repository README describes the opt-in live sandbox test and full data/delivery behavior. Do not point automated tests at a team's production board.
|
|
49
|
+
|
|
50
|
+
## Automatic publishing (maintainer)
|
|
51
|
+
|
|
52
|
+
The **Check and publish Patchwork** workflow (`.github/workflows/check.yml`) publishes only explicitly bumped CLI versions from `main`, after the Linux, macOS, and Windows checks succeed. It never increments a version automatically. Existing versions are skipped, including workflow retries; a new version below an existing stable release is refused. Outdated main checkouts are skipped. Publishing jobs run one at a time and do not write commits or tags.
|
|
53
|
+
|
|
54
|
+
One-time setup on [npm](https://www.npmjs.com/package/@icebergsnow/patchwork-cli): open **Settings → Trusted Publisher → GitHub Actions**, then enter:
|
|
55
|
+
|
|
56
|
+
| Field | Value |
|
|
57
|
+
| --- | --- |
|
|
58
|
+
| Organization or user | `IcebergSnow` |
|
|
59
|
+
| Repository | `Patchwork` |
|
|
60
|
+
| Workflow filename | `check.yml` (filename only) |
|
|
61
|
+
| Environment name | Leave empty |
|
|
62
|
+
| Allowed actions | Enable direct **npm publish** |
|
|
63
|
+
|
|
64
|
+
Save, then open [GitHub Actions](https://github.com/IcebergSnow/Patchwork/actions/workflows/check.yml) and select **Run workflow → main**. This reruns the checks and publishes the pending version. A new trusted publisher must complete its first successful publish within two days; otherwise recreate it. No npm token secret is needed. Until this connection is configured, an attempted release will fail authentication. See [npm trusted publishing](https://docs.npmjs.com/trusted-publishers/).
|
|
65
|
+
|
|
66
|
+
For later releases, explicitly bump the version in a development branch:
|
|
67
|
+
|
|
68
|
+
```sh
|
|
69
|
+
npm version patch --workspace packages/cli --no-git-tag-version --ignore-scripts
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
Commit the changed `packages/cli/package.json` and `package-lock.json` with the release changes, then merge to `main`. Use `minor` or `major` instead of `patch` when appropriate. The MCP server reads its version from the package manifest. Ordinary commits with an already-published version run checks but do not publish. Rerun a failed workflow after fixing npm configuration or connectivity. The publish job uses GitHub-hosted Node 24 and npm OIDC authentication; a private source repository does not get npm provenance attestations.
|
|
73
|
+
|
|
74
|
+
Teammates' existing connections are not automatically upgraded. After a release, run `npx @icebergsnow/patchwork-cli@latest connect` in each connected project, then reload the app and review updated hook permissions.
|
|
75
|
+
|
|
76
|
+
## Manual publishing (fallback)
|
|
77
|
+
|
|
78
|
+
Confirm ownership of the npm scope `@icebergsnow`. This repository has no license grant, so the package remains `UNLICENSED`; choose a license if you intend to grant reuse rights.
|
|
79
|
+
|
|
80
|
+
After checks pass on Windows and macOS:
|
|
81
|
+
|
|
82
|
+
```sh
|
|
83
|
+
npm pack --workspace packages/cli --dry-run
|
|
84
|
+
npm login
|
|
85
|
+
npm publish --workspace packages/cli --access public
|
|
86
|
+
npm view @icebergsnow/patchwork-cli@0.2.1 version
|
|
87
|
+
npx @icebergsnow/patchwork-cli@0.2.1 --help
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
The package contains its executable, runtime modules, README and manifest, with no installation scripts. Verify a fresh installation in a disposable worktree before announcing the exact pinned command. The automated workflow skips versions already published manually.
|
|
91
|
+
|
|
92
|
+
Routine tool hooks check at eligible checkpoints, at most once every 30 seconds. A shared local cache coalesces chats on the same computer/account, uses incremental GitHub reads, and reconciles every 15 minutes at a checkpoint. Each chat still has its own cursor and identity. Cached board text stays under `~/.patchwork/github/`; private repository content should be treated as private local data. See the root README for the API benchmark and recovery limits.
|
package/bin/patchwork.js
ADDED
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { parseArgs } from "node:util";
|
|
3
|
+
import { createInterface } from "node:readline/promises";
|
|
4
|
+
import { spawn } from "node:child_process";
|
|
5
|
+
import { connect, status, disconnect } from "../lib/connect.js";
|
|
6
|
+
import { Runtime } from "../lib/runtime.js";
|
|
7
|
+
import { serve } from "../lib/mcp.js";
|
|
8
|
+
import { run } from "../lib/github.js";
|
|
9
|
+
|
|
10
|
+
const HELP = `Patchwork — a GitHub bulletin board for independent coding agents.
|
|
11
|
+
|
|
12
|
+
Usage (inside your coding project's Git worktree):
|
|
13
|
+
patchwork connect [--repo OWNER/REPO] [--client codex|claude] [--name NAME] [--create-board] [--agent CHAT_ID]
|
|
14
|
+
patchwork status [--client codex|claude] [--repo OWNER/REPO]
|
|
15
|
+
patchwork disconnect [--client codex|claude] [--agent CHAT_ID] [--repo OWNER/REPO]
|
|
16
|
+
|
|
17
|
+
Requires Node.js 22.13+, Git, GitHub CLI (gh), and repository write access.
|
|
18
|
+
Connect affects chats in this project only. Each chat gets its own identity.
|
|
19
|
+
Disconnect without --agent disables the selected app (both apps if omitted).
|
|
20
|
+
Use status --repo and disconnect --repo --agent to retire a lost chat remotely.
|
|
21
|
+
Use connect --client APP --agent CHAT_ID to explicitly resume a local chat.
|
|
22
|
+
GitHub credentials remain with gh. No Cloudflare account or pairing code.
|
|
23
|
+
To update, rerun connect with the chosen CLI version, then reload your app.
|
|
24
|
+
`;
|
|
25
|
+
async function ask(question) {
|
|
26
|
+
if (!process.stdin.isTTY)
|
|
27
|
+
throw new Error(
|
|
28
|
+
"Interactive input required. Specify --client and --create-board when appropriate.",
|
|
29
|
+
);
|
|
30
|
+
const rl = createInterface({ input: process.stdin, output: process.stdout });
|
|
31
|
+
try {
|
|
32
|
+
return (await rl.question(question + " ")).trim();
|
|
33
|
+
} finally {
|
|
34
|
+
rl.close();
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
async function login() {
|
|
38
|
+
try {
|
|
39
|
+
await run("gh", ["auth", "status", "--hostname", "github.com"]);
|
|
40
|
+
} catch {
|
|
41
|
+
if (!process.stdin.isTTY)
|
|
42
|
+
throw new Error(
|
|
43
|
+
"Authenticate first with gh auth login --hostname github.com.",
|
|
44
|
+
);
|
|
45
|
+
if (
|
|
46
|
+
!/^y(es)?$/i.test(
|
|
47
|
+
await ask("Sign in to GitHub using your browser? [y/N]"),
|
|
48
|
+
)
|
|
49
|
+
)
|
|
50
|
+
throw new Error("GitHub login is required.");
|
|
51
|
+
await new Promise((resolve, reject) => {
|
|
52
|
+
const p = spawn(
|
|
53
|
+
"gh",
|
|
54
|
+
[
|
|
55
|
+
"auth",
|
|
56
|
+
"login",
|
|
57
|
+
"--hostname",
|
|
58
|
+
"github.com",
|
|
59
|
+
"--web",
|
|
60
|
+
"--git-protocol",
|
|
61
|
+
"https",
|
|
62
|
+
"--skip-ssh-key",
|
|
63
|
+
],
|
|
64
|
+
{ stdio: "inherit", shell: false },
|
|
65
|
+
);
|
|
66
|
+
p.on("error", () => reject(new Error("Install GitHub CLI (gh) first.")));
|
|
67
|
+
p.on("exit", (code) =>
|
|
68
|
+
code === 0
|
|
69
|
+
? resolve()
|
|
70
|
+
: reject(new Error("GitHub login did not complete.")),
|
|
71
|
+
);
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
let command;
|
|
76
|
+
try {
|
|
77
|
+
const args = parseArgs({
|
|
78
|
+
allowPositionals: true,
|
|
79
|
+
options: {
|
|
80
|
+
help: { type: "boolean", short: "h" },
|
|
81
|
+
repo: { type: "string" },
|
|
82
|
+
client: { type: "string" },
|
|
83
|
+
name: { type: "string" },
|
|
84
|
+
"create-board": { type: "boolean" },
|
|
85
|
+
agent: { type: "string" },
|
|
86
|
+
connection: { type: "string" },
|
|
87
|
+
},
|
|
88
|
+
});
|
|
89
|
+
command = args.positionals[0];
|
|
90
|
+
if (args.values.help || !command) {
|
|
91
|
+
console.log(HELP);
|
|
92
|
+
} else {
|
|
93
|
+
if (args.positionals.length !== 1) throw new Error("Use patchwork --help.");
|
|
94
|
+
const { client, repo, name, agent, connection } = args.values;
|
|
95
|
+
if (client && !["codex", "claude"].includes(client))
|
|
96
|
+
throw new Error("Choose --client codex or --client claude.");
|
|
97
|
+
if (command === "connect") {
|
|
98
|
+
const selected =
|
|
99
|
+
client ||
|
|
100
|
+
(await ask("Connect which app? codex / claude:")).toLowerCase();
|
|
101
|
+
await login();
|
|
102
|
+
await connect({
|
|
103
|
+
repo,
|
|
104
|
+
client: selected,
|
|
105
|
+
name,
|
|
106
|
+
agent,
|
|
107
|
+
create: args.values["create-board"],
|
|
108
|
+
confirm: async (q) => /^y(es)?$/i.test(await ask(q + " [y/N]")),
|
|
109
|
+
});
|
|
110
|
+
} else if (command === "status")
|
|
111
|
+
console.log(JSON.stringify(await status({ client, repo }), null, 2));
|
|
112
|
+
else if (command === "disconnect")
|
|
113
|
+
await disconnect({ client, agent, repo });
|
|
114
|
+
else if (command === "mcp") {
|
|
115
|
+
if (!connection) throw new Error("Missing local connection path.");
|
|
116
|
+
await serve(connection);
|
|
117
|
+
} else if (command === "hook") {
|
|
118
|
+
if (!connection) throw new Error("Missing local connection path.");
|
|
119
|
+
let raw = "";
|
|
120
|
+
for await (const chunk of process.stdin) {
|
|
121
|
+
raw += chunk;
|
|
122
|
+
if (raw.length > 1_000_000) throw new Error("Hook input too large.");
|
|
123
|
+
}
|
|
124
|
+
const input = JSON.parse(raw);
|
|
125
|
+
// The transcript path only distinguishes saved Codex chats from ephemeral
|
|
126
|
+
// helpers. Never read/persist/upload transcripts, prompts or tool output.
|
|
127
|
+
console.log(
|
|
128
|
+
JSON.stringify(
|
|
129
|
+
await new Runtime(connection).hook({
|
|
130
|
+
session_id: input.session_id,
|
|
131
|
+
hook_event_name: input.hook_event_name,
|
|
132
|
+
transcript_path: input.transcript_path,
|
|
133
|
+
}),
|
|
134
|
+
),
|
|
135
|
+
);
|
|
136
|
+
} else throw new Error("Unknown command. Use patchwork --help.");
|
|
137
|
+
}
|
|
138
|
+
} catch (e) {
|
|
139
|
+
if (command === "hook") {
|
|
140
|
+
console.error(
|
|
141
|
+
"Patchwork board check unavailable. Use patchwork status; coding can continue.",
|
|
142
|
+
);
|
|
143
|
+
console.log("{}");
|
|
144
|
+
} else {
|
|
145
|
+
console.error(
|
|
146
|
+
e.message || "Patchwork failed. Check local permissions and retry.",
|
|
147
|
+
);
|
|
148
|
+
process.exitCode = 1;
|
|
149
|
+
}
|
|
150
|
+
}
|