@dna113p/machines 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 (50) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +186 -0
  3. package/dist/codex/machines/ui/machines.html +286 -0
  4. package/dist/examples/agent.d.ts +1 -0
  5. package/dist/examples/agent.js +19 -0
  6. package/dist/examples/choices.d.ts +1 -0
  7. package/dist/examples/choices.js +17 -0
  8. package/dist/examples/host.d.ts +3 -0
  9. package/dist/examples/host.js +32 -0
  10. package/dist/examples/human.d.ts +1 -0
  11. package/dist/examples/human.js +17 -0
  12. package/dist/examples/named-agents.d.ts +1 -0
  13. package/dist/examples/named-agents.js +38 -0
  14. package/dist/examples/operation.d.ts +1 -0
  15. package/dist/examples/operation.js +10 -0
  16. package/dist/examples/pi.d.ts +1 -0
  17. package/dist/examples/pi.js +29 -0
  18. package/dist/mcp/server.d.ts +17 -0
  19. package/dist/mcp/server.js +313 -0
  20. package/dist/pi-extension/index.d.ts +52 -0
  21. package/dist/pi-extension/index.js +390 -0
  22. package/dist/src/acp.d.ts +7 -0
  23. package/dist/src/acp.js +184 -0
  24. package/dist/src/agent-bindings.d.ts +15 -0
  25. package/dist/src/agent-bindings.js +113 -0
  26. package/dist/src/catalog.d.ts +31 -0
  27. package/dist/src/catalog.js +68 -0
  28. package/dist/src/cli.d.ts +2 -0
  29. package/dist/src/cli.js +392 -0
  30. package/dist/src/discovery-worker.d.ts +3 -0
  31. package/dist/src/discovery-worker.js +52 -0
  32. package/dist/src/discovery.d.ts +8 -0
  33. package/dist/src/discovery.js +94 -0
  34. package/dist/src/host.d.ts +25 -0
  35. package/dist/src/host.js +357 -0
  36. package/dist/src/index.d.ts +210 -0
  37. package/dist/src/index.js +204 -0
  38. package/dist/src/launcher.d.ts +19 -0
  39. package/dist/src/launcher.js +98 -0
  40. package/dist/src/machine-module.d.ts +3 -0
  41. package/dist/src/machine-module.js +55 -0
  42. package/dist/src/session.d.ts +40 -0
  43. package/dist/src/session.js +165 -0
  44. package/dist/src/terminal-human.d.ts +2 -0
  45. package/dist/src/terminal-human.js +100 -0
  46. package/docs/architecture.md +111 -0
  47. package/docs/authoring.md +193 -0
  48. package/docs/integrations.md +142 -0
  49. package/package.json +58 -0
  50. package/skills/machine-builder/SKILL.md +34 -0
@@ -0,0 +1,142 @@
1
+ # Integrations
2
+
3
+ ## Codex through direct MCP
4
+
5
+ From an arbitrary checkout, build and register the server:
6
+
7
+ ```bash
8
+ npm ci
9
+ npm run build
10
+ codex mcp add machines -- node "$PWD/dist/mcp/server.js"
11
+ ```
12
+
13
+ This command records the current checkout's absolute built entry point. Keep that
14
+ checkout available, or register again after moving it. It requires no marketplace
15
+ or helper skill. Start a new Codex thread and ask “Show me the Machines available
16
+ here.” The [official MCP guide](https://developers.openai.com/codex/mcp) describes
17
+ stdio server registration and configuration.
18
+
19
+ The five tools are:
20
+
21
+ | Tool | Inputs and result |
22
+ | --- | --- |
23
+ | `machine_list` | Absolute `cwd`; definitions, descriptions, missing Agents, per-file errors |
24
+ | `machine_agents` | Absolute `cwd`; configured Agent preset names and metadata |
25
+ | `machine_start` | Absolute `cwd`, Machine name, optional input/preset overrides; immediate run snapshot |
26
+ | `machine_status` | Optional exact `runId`; authoritative current-session snapshots |
27
+ | `machine_respond` | Exact `runId`, current `human.requestId`, and response; submits one waiting request |
28
+
29
+ Preserve the IDs returned by the tools. A stale request or repeated submission is
30
+ rejected. When explicit choices are present, send one of those exact strings.
31
+
32
+ Codex CLI can use text and structured tool results. Clients supporting MCP Apps
33
+ can also render the attached live card, which polls status and submits Human input.
34
+ Client support for the card varies; the same tools work without it.
35
+
36
+ ## Portable Codex plugin
37
+
38
+ Build the self-contained plugin from the checkout:
39
+
40
+ ```bash
41
+ npm ci
42
+ npm run build:plugin
43
+ npm run smoke:plugin
44
+ ```
45
+
46
+ The result is `build/codex/machines/`, containing the manifest, compiled server,
47
+ production dependencies, widget assets, and machine-builder skill. Copy the entire
48
+ directory when distributing it. Node 24 or later must be on the receiving system's
49
+ PATH; the original checkout is unnecessary after copying. Build does not modify
50
+ your Codex installation or global configuration.
51
+
52
+ The plugin MCP configuration uses `command: "node"`, a relative server argument,
53
+ and `cwd: "."`. Codex resolves the plugin's relative working directory against
54
+ the installed plugin root, so no checkout-specific path or shell expansion is
55
+ needed. The source `codex/machines/` directory is an input to this build, not the
56
+ complete installable bundle.
57
+ This path behavior is implemented by the
58
+ [Codex 0.153.2 plugin parser](https://github.com/openai/codex/blob/rust-v0.153.2/codex-rs/codex-mcp/src/plugin_config.rs#L281-L288).
59
+
60
+ Install the resulting directory through your chosen local/repository marketplace
61
+ using the [official plugin packaging guide](https://developers.openai.com/plugins/build/plugins#install-a-local-plugin-manually).
62
+ For example, copy the complete bundle to a marketplace repository's
63
+ `plugins/machines/`, and add this entry to its `.agents/plugins/marketplace.json`:
64
+
65
+ ```json
66
+ {
67
+ "name": "machines-local",
68
+ "interface": { "displayName": "Machines local" },
69
+ "plugins": [{
70
+ "name": "machines",
71
+ "source": { "source": "local", "path": "./plugins/machines" },
72
+ "policy": { "installation": "AVAILABLE", "authentication": "ON_INSTALL" },
73
+ "category": "Productivity"
74
+ }]
75
+ }
76
+ ```
77
+
78
+ From that marketplace root, the current Codex CLI accepts:
79
+
80
+ ```bash
81
+ codex plugin marketplace add "$PWD"
82
+ codex plugin add machines@machines-local
83
+ ```
84
+
85
+ Existing marketplaces can add the plugin entry to their current list instead of
86
+ replacing their catalog. Use the direct MCP route when a marketplace is unnecessary.
87
+ Choose one installation route per Codex environment to avoid duplicate tools.
88
+
89
+ After updating the build, replace the complete bundle in the marketplace and
90
+ refresh the installation using the host's plugin management controls. Start a new
91
+ thread after installing or updating. The plugin version comes from its checked-in
92
+ manifest; release changes should bump it along with the package version.
93
+
94
+ The bundled configuration pre-approves the launcher tools. Discovery imports
95
+ trusted code, and start/respond can continue work that modifies files or contacts
96
+ external services. Tool annotations describe those capabilities. Configure your
97
+ preferred tool-approval policy in Codex if you need different behavior; workflow
98
+ Human states remain defined by each Machine.
99
+
100
+ ## Pi extension
101
+
102
+ For a checkout on POSIX systems:
103
+
104
+ ```bash
105
+ mkdir -p ~/.pi/agent/extensions
106
+ ln -s "$PWD/pi-extension/index.ts" ~/.pi/agent/extensions/machines.ts
107
+ ```
108
+
109
+ Run this from the Machines checkout after `npm ci`. Choose an unused destination;
110
+ the command does not replace an existing extension. Pi discovers it on startup;
111
+ use `/reload` after a source update. Keep the checkout available while using the
112
+ symlink. A locally installed npm package also includes the built extension at
113
+ `node_modules/@dna113p/machines/dist/pi-extension/index.js`.
114
+
115
+ Pi exposes the same five tools using the conversation's current directory, with
116
+ a status widget and native Human dialogs. Canceling a dialog leaves its Machine
117
+ waiting; answer later through `machine_respond` with the current request ID.
118
+ Pi exit, session replacement, and reload terminate its session-owned runs.
119
+
120
+ ## Troubleshooting
121
+
122
+ For an isolated global catalog, set `MACHINES_USER_HOME` to an absolute directory;
123
+ Machines reads global definitions and presets from that directory's `.machines/`.
124
+ Explicit programmatic `home` options take precedence. This is useful for tests or
125
+ separate workflow collections without changing the operating-system home directory.
126
+
127
+ - **Node cannot load TypeScript from a dependency:** install the built tarball;
128
+ source exports are for checkout development. Keep workflow definitions outside
129
+ `node_modules` and use Node 24 or later.
130
+ - **A definition has an error or missing Agent:** inspect `machine list` and
131
+ `machine agents`, correct metadata or presets, and list again. Imports refresh
132
+ on the next discovery call. Run preflight remains strict.
133
+ - **The Agent fails on a permission request:** ACP permission interaction is not
134
+ implemented. Use a harness configured for the intended task; Human states
135
+ handle workflow decisions, not ACP permission prompts.
136
+ - **A run disappeared after reload:** runs are session-scoped and have no durable
137
+ resume mechanism. Inspect effects already produced before starting another run.
138
+ - **The Codex card is absent:** use `machine_status` and `machine_respond`; visual
139
+ resource rendering depends on the MCP client.
140
+ - **Agent output is too noisy:** ACP callers can select `output: "capture"`;
141
+ the launcher already captures final text. The CLI's `o` hotkey toggles normalized
142
+ activity while an Agent runs and is suspended during Human input.
package/package.json ADDED
@@ -0,0 +1,58 @@
1
+ {
2
+ "name": "@dna113p/machines",
3
+ "version": "0.1.0",
4
+ "description": "Reusable workflows coordinating agents, local operations, and human decisions.",
5
+ "license": "MIT",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/dna113p/machines.git"
9
+ },
10
+ "publishConfig": {
11
+ "access": "public",
12
+ "registry": "https://registry.npmjs.org/"
13
+ },
14
+ "type": "module",
15
+ "engines": {
16
+ "node": ">=24"
17
+ },
18
+ "bin": {
19
+ "machine": "./dist/src/cli.js"
20
+ },
21
+ "types": "./dist/src/index.d.ts",
22
+ "exports": {
23
+ ".": { "types": "./dist/src/index.d.ts", "import": "./dist/src/index.js" },
24
+ "./acp": { "types": "./dist/src/acp.d.ts", "import": "./dist/src/acp.js" },
25
+ "./launcher": { "types": "./dist/src/launcher.d.ts", "import": "./dist/src/launcher.js" },
26
+ "./mcp": { "types": "./dist/mcp/server.d.ts", "import": "./dist/mcp/server.js" },
27
+ "./pi-extension": { "types": "./dist/pi-extension/index.d.ts", "import": "./dist/pi-extension/index.js" }
28
+ },
29
+ "files": ["dist", "docs/architecture.md", "docs/authoring.md", "docs/integrations.md", "skills", "LICENSE", "README.md"],
30
+ "scripts": {
31
+ "build": "node scripts/build.mjs",
32
+ "build:plugin": "npm run build && node scripts/build-plugin.mjs",
33
+ "check": "npm run typecheck && npm test",
34
+ "example": "node examples/operation.ts",
35
+ "example:agents": "node examples/named-agents.ts",
36
+ "example:host": "node examples/host.ts",
37
+ "example:pi": "node examples/pi.ts",
38
+ "mcp": "node mcp/server.ts",
39
+ "prepack": "npm run build",
40
+ "smoke:package": "node scripts/smoke-package.mjs",
41
+ "smoke:plugin": "node scripts/smoke-plugin.mjs",
42
+ "test": "node --test tests/*.test.ts",
43
+ "typecheck": "tsc --noEmit"
44
+ },
45
+ "dependencies": {
46
+ "@agentclientprotocol/sdk": "^1.4.0",
47
+ "@modelcontextprotocol/sdk": "^1.30.0",
48
+ "typebox": "^1.3.7",
49
+ "valibot": "^1.4.2",
50
+ "xstate": "^5.32.6",
51
+ "yocto-spinner": "^1.2.2",
52
+ "yoctocolors": "^2.2.0"
53
+ },
54
+ "devDependencies": {
55
+ "@types/node": "^24.0.0",
56
+ "typescript": "^7.0.2"
57
+ }
58
+ }
@@ -0,0 +1,34 @@
1
+ ---
2
+ name: machine-builder
3
+ description: Create or edit TypeScript workflow definitions for the Machines runtime, including discovery metadata, Agent roles, Operations, Human decisions, and transitions. Use for reusable Machines workflows, not unrelated XState applications or runtime internals.
4
+ ---
5
+
6
+ # Machine builder
7
+
8
+ Use [Authoring Machines](../../docs/authoring.md) for the definition contract and
9
+ examples. Before choosing a workflow, inspect available Machines and Agent presets
10
+ with `machine list` and `machine agents`, or the connected `machine_list` and
11
+ `machine_agents` tools. Adapt a matching workflow when it fits the user's scope.
12
+
13
+ For a new definition, capture the intended states, returned events, and completion
14
+ condition. Put the definition in the requested location; project `.machines/` is
15
+ the default for project-specific work. Global installation is a separate choice.
16
+
17
+ Export a non-empty one-line `description` explaining when to use the Machine and
18
+ a default factory accepting the supplied primitives and input string. Declare
19
+ semantic `agentRoles` for named Agents, then use those exact roles in states.
20
+ Select harnesses and models through presets, keeping environment details out of
21
+ workflow policy. The [bundled examples](../../dist/examples/) show runtime usage
22
+ after the package is built; authoring examples in the guide also work before a build.
23
+
24
+ Keep module initialization side-effect free: discovery imports definitions and
25
+ their helpers. Put external work inside Operations or Agent requests so preflight
26
+ can finish before effects occur. Let XState choose the next state from the event
27
+ returned by a primitive. Use Human `suggestions` when free-form feedback is useful
28
+ and `choices` when only the declared responses are valid.
29
+
30
+ Verify discovery and bindings, then exercise the intended branches with fake
31
+ Agent runners or injected Human input where possible. A successful run reaches
32
+ the intended final state and produces the requested artifact or effect. Run real
33
+ external work only within the user's authorized scope. Report what was verified
34
+ and any branch that still requires a configured harness or human interaction.