cannwork-rehearsal 0.0.0-stage → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/README.md +113 -2
  2. package/bin/cannwork.js +126 -0
  3. package/package.json +21 -4
package/README.md CHANGED
@@ -1,3 +1,114 @@
1
- # Temporary Holding Version
1
+ # cannwork-cli
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ A terminal launcher for AI coding agents (starting with [opencode](https://opencode.ai)), built with [OpenTUI](https://github.com/msmps/opentui) and React, running on [Bun](https://bun.sh/).
4
+
5
+ ## Requirements
6
+
7
+ - [Bun](https://bun.sh/) **1.3.0** or later — to run from source and to build
8
+ - Node.js 18+ — only to launch the tiny `cannwork` shim when installed from npm; the packaged executable embeds its own runtime and does not need Bun
9
+
10
+ ## Install
11
+
12
+ Trial-period name (currently available — the official scoped name is not published yet):
13
+
14
+ ```bash
15
+ npm install -g cannwork-rehearsal
16
+ # or run without installing
17
+ npx cannwork-rehearsal
18
+ ```
19
+
20
+ Official name (to be published later): `@zhoufangchaojs/cannwork`, same usage once available.
21
+
22
+ The npm package ships standalone executables per platform. Supported platforms:
23
+
24
+ | Platform | Suffix |
25
+ | --- | --- |
26
+ | Windows x64 | `win32-x64` |
27
+ | Linux x64 (glibc) | `linux-x64` |
28
+ | Linux arm64 (glibc) | `linux-arm64` |
29
+ | macOS x64 | `darwin-x64` |
30
+ | macOS arm64 | `darwin-arm64` |
31
+
32
+ The installed platform package is `<package-name>-<suffix>` (currently `cannwork-rehearsal-<suffix>`, later `@zhoufangchaojs/cannwork-<suffix>`).
33
+
34
+ Notes:
35
+
36
+ - Do not install with `--omit=optional`: the matching platform package is an optional dependency.
37
+ - Linux binaries link glibc; Alpine/musl is not covered yet — `OPENTUI_LIBC`/musl builds are not published.
38
+ - The macOS binaries are not codesigned/notarized. If Gatekeeper blocks the binary, clear the quarantine flag:
39
+ ```bash
40
+ xattr -d com.apple.quarantine "$(npm root -g)/cannwork-rehearsal-darwin-arm64/bin/cannwork"
41
+ ```
42
+ - `cannwork-rehearsal` is the **trial-period release name**: it is published and installable on purpose so real users can try it while the official `@zhoufangchaojs/cannwork` name is not released yet. It will be retired (unpublished/deprecated) once the official name is published.
43
+
44
+ ## Getting Started (from source)
45
+
46
+ Install dependencies:
47
+
48
+ ```bash
49
+ bun install
50
+ ```
51
+
52
+ Start the app in watch mode:
53
+
54
+ ```bash
55
+ bun dev
56
+ ```
57
+
58
+ ## Scripts
59
+
60
+ | Script | Description |
61
+ | --- | --- |
62
+ | `bun dev` | Run the app with auto-reload on file changes |
63
+ | `bun run typecheck` | Type-check the source with `tsc --noEmit` |
64
+ | `bun run test` | Run the test suite |
65
+ | `bun run build` | Build a JS bundle (requires Bun on the target machine) |
66
+ | `bun run build:exe` | Build a standalone executable for the current platform |
67
+ | `bun run build:publish` | Cross-compile all 5 platforms and assemble `dist/publish/<pkg>/` |
68
+ | `bun run release` | Check → build → publish all packages (sub-packages first) |
69
+
70
+ Build artifacts are written to `dist/`.
71
+
72
+ `build:publish` prepares any missing target-platform native packages (`@opentui/core-*`) automatically by fetching them from npm into `node_modules`, so the build machine needs network access on first run. Pass `--manifests-only` to assemble manifests without compiling.
73
+
74
+ ## Maintainer release runbook
75
+
76
+ Releases are published manually to <https://registry.npmjs.org/> in two phases: an unscoped **trial release** that is kept live for real users, then (later) the official scoped release, after which the trial name is retired.
77
+
78
+ ### Phase 1 — unscoped trial release (kept live)
79
+
80
+ 1. Set `name` to `cannwork-rehearsal` and `version` to `0.1.0` in the root `package.json` (single source of truth).
81
+ 2. `npm login` (any account with publish rights).
82
+ 3. `bun run release` — runs typecheck + tests, cross-compiles, then publishes the 5 platform packages followed by the main package. Add `--dry-run` to pack and verify without uploading.
83
+ 4. Check each package on the registry (`npm view <pkg> version`). A `0.0.0-stage` value means npm staged the version for review; wait for it to go live (or approve it on npmjs.com) before smoke-testing.
84
+ 5. Smoke-test in a clean directory: `npx cannwork-rehearsal`. On success the script writes `dist/.rehearsal-ok`, which unlocks phase 2.
85
+ 6. **Keep it live**: do not unpublish. During the trial, ship updates by repeating steps 3–5 with a bumped version.
86
+
87
+ ### Phase 2 — official scoped release (deferred), then retire the trial name
88
+
89
+ 7. Set `name` to `@zhoufangchaojs/cannwork`, then `bun run release`. The script refuses to publish a scoped name until the trial-release marker exists.
90
+ 8. Verify: `npm view @zhoufangchaojs/cannwork version`, smoke-test `npx @zhoufangchaojs/cannwork`, then tag the release:
91
+ ```bash
92
+ git tag <version>
93
+ ```
94
+ 9. Retire the trial packages: `npm unpublish` all 6 (`cannwork-rehearsal` and `cannwork-rehearsal-*`) within the 72-hour window, otherwise `npm deprecate` them as trial packages. If the active credential is a `Granular access token` that bypasses 2FA, unpublish is rejected with 403 — delete the packages on npmjs.com instead, or run `npm login --auth-type=web` first.
95
+
96
+ Rollback: `npm unpublish` the affected version within the allowed window; afterwards `npm deprecate` and publish a fixed version.
97
+
98
+ ## Project Structure
99
+
100
+ ```
101
+ ├── bin/
102
+ │ └── cannwork.js # Node-compatible launcher shipped in the npm main package
103
+ ├── scripts/ # cross-platform build and publish tooling
104
+ ├── src/
105
+ │ └── index.tsx # App entry, renders the TUI with @opentui/react
106
+ ├── openspec/ # OpenSpec change management workspace
107
+ ├── dist/ # Build output
108
+ ├── package.json
109
+ └── tsconfig.json
110
+ ```
111
+
112
+ ## Notes
113
+
114
+ This project was created using `bun create tui`. [create-tui](https://github.com/msmps/create-tui) is the easiest way to get started with OpenTUI.
@@ -0,0 +1,126 @@
1
+ #!/usr/bin/env node
2
+ import { createRequire } from "node:module";
3
+ import { spawn } from "node:child_process";
4
+ import { accessSync, chmodSync, constants } from "node:fs";
5
+ import { resolve } from "node:path";
6
+ import { fileURLToPath } from "node:url";
7
+
8
+ export const SUPPORTED_TARGETS = Object.freeze([
9
+ "win32-x64",
10
+ "linux-x64",
11
+ "linux-arm64",
12
+ "darwin-x64",
13
+ "darwin-arm64",
14
+ ]);
15
+
16
+ export function subPackageName(mainName, os, arch) {
17
+ if (typeof mainName !== "string" || mainName.length === 0) return null;
18
+ if (!SUPPORTED_TARGETS.includes(`${os}-${arch}`)) return null;
19
+ const suffix = `-${os}-${arch}`;
20
+ if (mainName.startsWith("@")) {
21
+ const slash = mainName.indexOf("/");
22
+ if (slash <= 1 || slash === mainName.length - 1) return null;
23
+ return `${mainName}${suffix}`;
24
+ }
25
+ return `${mainName}${suffix}`;
26
+ }
27
+
28
+ export function binarySubpath(os) {
29
+ return os === "win32" ? "bin/cannwork.exe" : "bin/cannwork";
30
+ }
31
+
32
+ export function missingPackageMessage(mainName, os, arch) {
33
+ const pkg = subPackageName(mainName, os, arch) ?? `${mainName}-${os}-${arch}`;
34
+ return [
35
+ `${mainName}: 缺少当前平台 (${os}-${arch}) 的运行时包 ${pkg}。`,
36
+ "",
37
+ " 可能原因:安装时使用了 --omit=optional,或该平台尚未提供预编译产物。",
38
+ ` 受支持平台:${SUPPORTED_TARGETS.join(", ")}`,
39
+ "",
40
+ " 修复:重新完整安装(保留可选依赖),例如",
41
+ ` npm install -g ${mainName}`,
42
+ "",
43
+ ].join("\n");
44
+ }
45
+
46
+ export function resolveBinaryPath(mainName, os, arch, requireFn) {
47
+ const subPackage = subPackageName(mainName, os, arch);
48
+ if (subPackage === null) return null;
49
+ try {
50
+ return requireFn.resolve(`${subPackage}/${binarySubpath(os)}`);
51
+ } catch {
52
+ return null;
53
+ }
54
+ }
55
+
56
+ function ensureExecutable(binaryPath, os) {
57
+ if (os === "win32") return;
58
+ try {
59
+ accessSync(binaryPath, constants.X_OK);
60
+ } catch {
61
+ try {
62
+ chmodSync(binaryPath, 0o755);
63
+ } catch {
64
+ return;
65
+ }
66
+ }
67
+ }
68
+
69
+ export function spawnBinary(binaryPath, args) {
70
+ return new Promise((resolveCode) => {
71
+ let child;
72
+ try {
73
+ child = spawn(binaryPath, args, { stdio: "inherit", windowsHide: false });
74
+ } catch {
75
+ resolveCode(1);
76
+ return;
77
+ }
78
+ child.on("error", () => resolveCode(1));
79
+ child.on("exit", (code) => {
80
+ resolveCode(typeof code === "number" ? code : 1);
81
+ });
82
+ });
83
+ }
84
+
85
+ export async function run(argv = process.argv.slice(2)) {
86
+ const { platform: os, arch } = process;
87
+
88
+ const requireFromHere = createRequire(import.meta.url);
89
+ let manifest;
90
+ try {
91
+ manifest = requireFromHere("../package.json");
92
+ } catch {
93
+ process.stderr.write("cannwork: 无法读取自身包清单,安装可能已损坏。\n");
94
+ return 1;
95
+ }
96
+ const mainName = manifest.name;
97
+
98
+ if (argv.includes("-v") || argv.includes("--version")) {
99
+ process.stdout.write(`${manifest.version}\n`);
100
+ return 0;
101
+ }
102
+
103
+ const binaryPath = resolveBinaryPath(mainName, os, arch, requireFromHere);
104
+ if (binaryPath === null) {
105
+ process.stderr.write(missingPackageMessage(mainName, os, arch));
106
+ return 1;
107
+ }
108
+
109
+ ensureExecutable(binaryPath, os);
110
+ return await spawnBinary(binaryPath, argv);
111
+ }
112
+
113
+ export function isEntrypoint(metaUrl, argv1) {
114
+ if (typeof argv1 !== "string" || argv1.length === 0) return false;
115
+ try {
116
+ return fileURLToPath(metaUrl) === resolve(argv1);
117
+ } catch {
118
+ return false;
119
+ }
120
+ }
121
+
122
+ if (isEntrypoint(import.meta.url, process.argv[1])) {
123
+ run().then((code) => {
124
+ process.exit(code);
125
+ });
126
+ }
package/package.json CHANGED
@@ -1,6 +1,23 @@
1
1
  {
2
2
  "name": "cannwork-rehearsal",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.2.0",
4
+ "type": "module",
5
+ "bin": {
6
+ "cannwork": "bin/cannwork.js"
7
+ },
8
+ "files": [
9
+ "bin",
10
+ "README.md"
11
+ ],
12
+ "optionalDependencies": {
13
+ "cannwork-rehearsal-win32-x64": "0.2.0",
14
+ "cannwork-rehearsal-linux-x64": "0.2.0",
15
+ "cannwork-rehearsal-linux-arm64": "0.2.0",
16
+ "cannwork-rehearsal-darwin-x64": "0.2.0",
17
+ "cannwork-rehearsal-darwin-arm64": "0.2.0"
18
+ },
19
+ "publishConfig": {
20
+ "registry": "https://registry.npmjs.org/",
21
+ "access": "public"
22
+ }
23
+ }