@factory/cli 0.1.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 +172 -0
  2. package/bundle/factory.js +762 -0
  3. package/package.json +93 -0
package/README.md ADDED
@@ -0,0 +1,172 @@
1
+ # Factory CLI - Demo Edit
2
+
3
+ A hybrid command-line interface that runs **either**:
4
+
5
+ 1. **Interactive TUI** – a full-screen React/Ink terminal app
6
+ 2. **Headless commands** – traditional `factory headless <command>` sub-commands powered by Commander
7
+
8
+ The entry-point (`src/index.ts`) detects how it was invoked and chooses the right mode automatically.
9
+
10
+ ---
11
+
12
+ ## 1. Overview of the Hybrid Architecture
13
+
14
+ ```
15
+ src/
16
+ ├── index.ts # Hybrid entry – mode detection
17
+
18
+ ├── app.tsx # React/Ink TUI (interactive mode)
19
+
20
+ └── commands/ # Commander commands (headless mode)
21
+ ├── droid.ts
22
+ └── login.ts
23
+ ```
24
+
25
+ • **No positional args** ➜ Interactive TUI
26
+ • **`headless` subcommand** ➜ Headless mode
27
+
28
+ ---
29
+
30
+ ## 2 · Local Development
31
+
32
+ All dev tasks are exposed as **npm scripts** – never run compiled `.js` files directly.
33
+
34
+ | Purpose | Command |
35
+ | ------------------------- | ------------------- |
36
+ | Start CLI (auto mode) | `npm start` |
37
+ | Start with Node inspector | `npm run debug` |
38
+ | Lint source | `npm run lint` |
39
+ | Type-check | `npm run typecheck` |
40
+ | Run tests | `npm test` |
41
+ | Build JS into `dist/` | `npm run build` |
42
+ | Produce executable bundle | `npm run bundle` |
43
+ | Clean build artifacts | `npm run clean` |
44
+
45
+ The `start`/`debug` scripts use **tsx** so you can edit TypeScript and restart instantly.
46
+
47
+ ---
48
+
49
+ ## 3 · Testing Both Modes Locally
50
+
51
+ ### Interactive TUI
52
+
53
+ ```
54
+ # Launch interactive UI
55
+ npm start
56
+ ```
57
+
58
+ You’ll see a colourful Ink interface; quit with `Ctrl-C`.
59
+
60
+ ### Headless Commands
61
+
62
+ ```
63
+ # Show global help
64
+ npm start -- --help
65
+
66
+ # Show headless subcommands
67
+ npm start -- headless --help
68
+
69
+ # Run login interactively (headless)
70
+ npm start -- headless login
71
+
72
+ # Send message to a droid
73
+ npm start -- headless droid "Hello, Droid!" --session-id <sessionId>
74
+ ```
75
+
76
+ The extra `--` after `npm start` passes subsequent flags to the CLI.
77
+
78
+ ---
79
+
80
+ ## 4 · Development vs Production
81
+
82
+ | Phase | Command(s) | Result |
83
+ | ----------- | ------------------------------------ | ------------------------------------------------ |
84
+ | **Dev** | `npm start` / `npm run debug` | Runs from TS sources with tsx, fast reload. |
85
+ | **Build** | `npm run build` | Compiles TS → `dist/`. |
86
+ | **Bundle** | `npm run bundle` (calls `build`) | Generates single executable `bundle/factory.js`. |
87
+ | **Publish** | `npm publish` (bundled in `prepare`) | Users install `factory` binary from npm. |
88
+
89
+ During CI the `prepare` script produces the bundle automatically.
90
+
91
+ ---
92
+
93
+ ## 5 · Examples
94
+
95
+ ### Headless examples
96
+
97
+ ```bash
98
+ # Show authentication status
99
+ factory headless status
100
+
101
+ # Authenticate (opens browser)
102
+ factory headless login
103
+
104
+ # Talk to Droid
105
+ factory headless droid "Hello" --session-id dOLpXUI8ux6YdZrg3kCs
106
+ ```
107
+
108
+ ### Interactive example
109
+
110
+ ```bash
111
+ # Simply run with no args
112
+ factory
113
+ ```
114
+
115
+ ---
116
+
117
+ ## 6 · Testing the Production **`factory`** Command
118
+
119
+ Sometimes you need to test the **exact binary** users will get from `npm
120
+ install -g factory-cli`.
121
+ Follow this workflow:
122
+
123
+ ```bash
124
+ # 1. Build optimised bundle (also compiles TS → JS)
125
+ npm run bundle
126
+
127
+ # 2. Link globally so `factory` is on your PATH
128
+ npm link
129
+
130
+ # 3. Use it anywhere
131
+ factory --help
132
+ factory headless status
133
+ factory headless droid "Hello" --session-id <sessionId>
134
+
135
+ # 4. (Optional) Un-link when finished
136
+ npm unlink -g factory-cli
137
+ ```
138
+
139
+ | Situation | Command to use |
140
+ | --------------------------- | ----------------------------------------------------------- |
141
+ | Fast iteration / TypeScript | `npm start -- <args>` |
142
+ | Debug with inspector | `npm run debug -- <args>` |
143
+ | Validate production bundle | `npm run bundle && npm link` then `factory headless <args>` |
144
+
145
+ ℹ️ _Tip:_ The extra `--` after `npm start` or `npm run debug` passes the
146
+ remaining flags **directly to the CLI**.
147
+
148
+ ---
149
+
150
+ ## 7 · ESM & Imports
151
+
152
+ The package is `"type": "module"`; all runtime imports use `.js` extensions even though the source is TypeScript. The build pipeline rewrites them automatically.
153
+
154
+ ---
155
+
156
+ ## 8 · Troubleshooting
157
+
158
+ | Problem | Fix |
159
+ | --------------------------------------- | ------------------------------------------------------------------------------------------------------------ |
160
+ | `EACCES` when running `factory` | Ensure the bundle is executable (`chmod +x bundle/factory.js`). `npm run bundle` handles this automatically. |
161
+ | `module not found` after rename | Run `npm run clean && npm run bundle` to rebuild from scratch. |
162
+ | Global command still points to old code | Run `npm unlink -g factory-cli && npm link` to refresh the symlink. |
163
+
164
+ ---
165
+
166
+ ## 9 · Contributing
167
+
168
+ 1. `pnpm install` (or `npm install`) at repo root
169
+ 2. `cd apps/factory-cli`
170
+ 3. Implement feature / fix
171
+ 4. Ensure `npm run lint && npm run typecheck && npm test` pass
172
+ 5. Commit & open PR 🚀