@jive-sh/jive 0.10.2 → 0.11.0-latest-darwin-x64
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/multi-call-binary +4 -0
- package/package.json +12 -40
- package/README.md +0 -367
- package/bin/jive +0 -34
- package/bin/jive-daemon +0 -34
- package/bin/jive-native-host +0 -34
- package/bin/jive-ssh +0 -34
- package/bin/jive-ssh-sign +0 -34
- package/bin/package.json +0 -1
- package/postinstall.cjs +0 -663
package/package.json
CHANGED
|
@@ -1,9 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jive-sh/jive",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"license": "MIT",
|
|
3
|
+
"version": "0.11.0-latest-darwin-x64",
|
|
5
4
|
"type": "module",
|
|
6
|
-
"
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"os": [
|
|
7
|
+
"darwin"
|
|
8
|
+
],
|
|
9
|
+
"cpu": [
|
|
10
|
+
"x64"
|
|
11
|
+
],
|
|
12
|
+
"files": [
|
|
13
|
+
"multi-call-binary"
|
|
14
|
+
],
|
|
15
|
+
"description": "The Jive CLI: signs you in to Jive, signs your git commits and GitHub pushes with your account's key on the Jive server, loads repos into a workspace, creates packages from abstracts' templates, and answers the Jive browser extension.",
|
|
7
16
|
"repository": {
|
|
8
17
|
"type": "git",
|
|
9
18
|
"url": "git+https://github.com/jive-sh/jive.git"
|
|
@@ -11,42 +20,5 @@
|
|
|
11
20
|
"publishConfig": {
|
|
12
21
|
"access": "public",
|
|
13
22
|
"provenance": true
|
|
14
|
-
},
|
|
15
|
-
"files": [
|
|
16
|
-
"README.md",
|
|
17
|
-
"bin",
|
|
18
|
-
"postinstall.cjs"
|
|
19
|
-
],
|
|
20
|
-
"scripts": {
|
|
21
|
-
"postinstall": "node ./postinstall.cjs"
|
|
22
|
-
},
|
|
23
|
-
"bin": {
|
|
24
|
-
"jive": "./bin/jive",
|
|
25
|
-
"jive-daemon": "./bin/jive-daemon",
|
|
26
|
-
"jive-native-host": "./bin/jive-native-host",
|
|
27
|
-
"jive-ssh": "./bin/jive-ssh",
|
|
28
|
-
"jive-ssh-sign": "./bin/jive-ssh-sign"
|
|
29
|
-
},
|
|
30
|
-
"optionalDependencies": {
|
|
31
|
-
"@jive-sh/jive-darwin-arm64": "npm:@jive-sh/jive@0.10.2-latest-darwin-arm64",
|
|
32
|
-
"@jive-sh/jive-darwin-x64": "npm:@jive-sh/jive@0.10.2-latest-darwin-x64",
|
|
33
|
-
"@jive-sh/jive-linux-arm64": "npm:@jive-sh/jive@0.10.2-latest-linux-arm64",
|
|
34
|
-
"@jive-sh/jive-linux-x64": "npm:@jive-sh/jive@0.10.2-latest-linux-x64",
|
|
35
|
-
"@jive-sh/jive-windows-x64": "npm:@jive-sh/jive@0.10.2-latest-windows-x64"
|
|
36
|
-
},
|
|
37
|
-
"jive": {
|
|
38
|
-
"daemons": [
|
|
39
|
-
"jive-daemon"
|
|
40
|
-
],
|
|
41
|
-
"completionCommands": [
|
|
42
|
-
"jive"
|
|
43
|
-
]
|
|
44
|
-
},
|
|
45
|
-
"dependencies": {
|
|
46
|
-
"@effect/platform-bun": "^4.0.0",
|
|
47
|
-
"@jive-sh/server-client": "0.12.0",
|
|
48
|
-
"convex": "^1.48.0",
|
|
49
|
-
"effect": "^4.0.0",
|
|
50
|
-
"effective-modules": "0.3.6"
|
|
51
23
|
}
|
|
52
24
|
}
|
package/README.md
DELETED
|
@@ -1,367 +0,0 @@
|
|
|
1
|
-
# Jive
|
|
2
|
-
|
|
3
|
-
Jive is a **developer platform** and an **agentic workforce platform**. It takes the manual steps out of building,
|
|
4
|
-
shipping and running software, and the infrastructure behind it. A few ideas run through all of it:
|
|
5
|
-
|
|
6
|
-
- **Agents in the cloud** (planned). Agentic workflows run on cloud compute with a session Jive gives them, not on a laptop that
|
|
7
|
-
has to stay on.
|
|
8
|
-
- **Composable agentic workflows** (planned). A workflow is a package built from steps, and a workforce is built from workflows.
|
|
9
|
-
- **Minimal configuration.** A package extends an abstract for its kind and gets its pipeline, its config schema and
|
|
10
|
-
its scaffold from it.
|
|
11
|
-
- **Composable software.** Packages declare the resources they need instead of sharing code, so independent
|
|
12
|
-
repositories work together without a monorepo.
|
|
13
|
-
|
|
14
|
-
- **Developer platform:** the `jive` CLI (this repository), the CI/CD pipeline every Jive package runs (its
|
|
15
|
-
[reusable workflow](.github/workflows/reusable-pipeline.yml), contract in [CICD_API.md](CICD_API.md)), and resource
|
|
16
|
-
provisioning, which makes sure every resource a package needs exists in its organization.
|
|
17
|
-
- **Agentic workforce platform:** workforces of agents and code that run an organization's work. A software factory
|
|
18
|
-
is one kind of workforce, binary decompilation another, a business and its operations another.
|
|
19
|
-
|
|
20
|
-
<picture>
|
|
21
|
-
<source media="(prefers-color-scheme: dark)" srcset="docs/jive-platforms-dark.svg">
|
|
22
|
-
<img alt="Agentic workforce, the outer circle, holding three separate circles: software factory, binary decompilation, and a business and its operations" src="docs/jive-platforms-light.svg" width="480">
|
|
23
|
-
</picture>
|
|
24
|
-
|
|
25
|
-
## Agentic workflows, not skills
|
|
26
|
-
|
|
27
|
-
A **skill** is instructions an agent reads: it may follow them, skip a step, or forget them after a long session, and
|
|
28
|
-
nothing records whether it did. An **agentic workflow** is a process defined in code: each step is deterministic code
|
|
29
|
-
or a call to an agent for one bounded task; triggers (a schedule, a commit, a message, a threshold) start it; its
|
|
30
|
-
state is saved at every step, so a failed or interrupted step is retried rather than the whole run; and every step
|
|
31
|
-
records its start, end, outcome and cost. What must happen is enforced by the workflow, not hoped for from the agent.
|
|
32
|
-
|
|
33
|
-
So a business process in Jive is "a running, inspectable, maintainable workflow instead of a fragile chain of manual
|
|
34
|
-
procedures" ([architecture §3.3](docs/jive_architecture_discussion.md#33-arbitrary-durable-workflows)), and agents
|
|
35
|
-
are called for bounded tasks rather than kept as long-running conversations
|
|
36
|
-
([§2.A](docs/jive_architecture_discussion.md#a-workflows-versus-long-lived-claude-channels)). A workforce is a set of
|
|
37
|
-
such workflows, the agents they call, and the connectors they act through
|
|
38
|
-
([§3.2](docs/jive_architecture_discussion.md#32-agentic-workforces)). *Planned:* agentic workflows as a package kind
|
|
39
|
-
(`jive-abstract-resource-agentic-workflow`) and workforces built from them.
|
|
40
|
-
|
|
41
|
-
## A marketplace of package kinds
|
|
42
|
-
|
|
43
|
-
Everything in Jive is an npm package, and **every kind of package is itself a package**: an *abstract*,
|
|
44
|
-
`jive-abstract-<kind>`, implements the six CI/CD hooks for that kind, owns its manifest schema, and scaffolds new
|
|
45
|
-
packages of the kind. Extending one gives a package a working pipeline with no CI configuration of its own. Kinds
|
|
46
|
-
built today: `jive-abstract-library` (npm libraries and CLIs, this one included), `jive-abstract-backend-convex`,
|
|
47
|
-
`jive-abstract-app-expo`, `jive-abstract-docker-image`, `jive-abstract-backend-spacetimedb`, and
|
|
48
|
-
`jive-abstract-abstraction`, which creates new abstracts. Anyone can publish an abstract, so the set of kinds grows
|
|
49
|
-
like a marketplace. *Planned:* `jive create <kind>` finds every `jive-abstract-*` package and offers them as a menu
|
|
50
|
-
(`jive create agentic workflow` resolves `jive-abstract-agentic-workflow`).
|
|
51
|
-
|
|
52
|
-
**Resources** are the same idea for what packages use. A resource kind is an abstract defining a contract
|
|
53
|
-
(`jive-abstract-resource-connector-package-registry`), and an implementation is a package on one system
|
|
54
|
-
(`jive-resource-connector-package-registry-npm`). An organization configures one implementation per kind, and callers
|
|
55
|
-
name only the kind: `jive provision connector-package-registry @scope/name` makes sure that package exists on
|
|
56
|
-
whichever registry the organization uses. Public *ecosystem* packages (abstracts, connectors) are shared; a *usage*
|
|
57
|
-
package is someone's own use of them.
|
|
58
|
-
|
|
59
|
-
## No monorepo needed
|
|
60
|
-
|
|
61
|
-
Jive began as a way to make independent repositories work like a monorepo
|
|
62
|
-
([§1](docs/jive_architecture_discussion.md#1-executive-framing)). Each package keeps its own repository, version and
|
|
63
|
-
pipeline, and Jive supplies what a monorepo would:
|
|
64
|
-
|
|
65
|
-
- **One checkout for local work:** `jive init` makes any monorepo a workspace and `jive load` adds repos to it as
|
|
66
|
-
submodules at `packages/<package name>` ([Workspace layout](#workspace-layout)), all signing and pushing the same
|
|
67
|
-
way, and the packages in it are linked to each other, so each one runs its workspace dependencies from their
|
|
68
|
-
checkouts while its own lockfile and CI stay as they are ([Workspace links](#workspace-links)).
|
|
69
|
-
- **One way to ship:** every repository runs the same reusable pipeline through its abstract.
|
|
70
|
-
- **Connectors instead of shared code:** a package declares the resources it needs and the organization's connectors
|
|
71
|
-
provide them, so nothing has to live in the same repository to work together. *Planned:* the code-repository
|
|
72
|
-
connector (`jive-abstract-resource-connector-code-repository`, GitHub for jive-sh), so a package's repository and
|
|
73
|
-
its URLs come from the organization rather than from paths or a hard-coded host.
|
|
74
|
-
|
|
75
|
-
## What Jive borrows from Brazil and Version Sets
|
|
76
|
-
|
|
77
|
-
Amazon builds its services with an internal system called **Brazil**, organised around many small repositories
|
|
78
|
-
rather than one. Public descriptions of it are second-hand: a former Amazon build-team engineer's account
|
|
79
|
-
([gist, 2017](https://gist.github.com/terabyte/15a2d3d407285b8b5a0a7964dd6283b0)) and
|
|
80
|
-
[ByteByteGo's guide](https://bytebytego.com/guides/how-does-amazon-build-system-work/). In them:
|
|
81
|
-
|
|
82
|
-
- code is broken into **packages**, each team owning its own repositories;
|
|
83
|
-
- a **version set** is "a list of package versions that are known to be consistent together", and every build runs
|
|
84
|
-
"in a version set";
|
|
85
|
-
- a default version set, **live**, is where anyone publishes, and each team keeps its own version set, so "no one team
|
|
86
|
-
is blocked on" another's builds;
|
|
87
|
-
- minor versions are non-breaking, and major versions are "picked up by request only".
|
|
88
|
-
|
|
89
|
-
Jive takes the same shape: independent packages in independent repositories and, *planned*, **version sets**: a
|
|
90
|
-
pinned set of package versions known to work together, built and tested as a whole before it is promoted, with
|
|
91
|
-
dependents updated when a dependency publishes and versions derived from API changes
|
|
92
|
-
([§15.2](docs/jive_architecture_discussion.md#152-versioning-and-version-sets)). Today each package pins the exact
|
|
93
|
-
versions it builds with.
|
|
94
|
-
|
|
95
|
-
## Install
|
|
96
|
-
|
|
97
|
-
```sh
|
|
98
|
-
bun add -g @jive-sh/jive
|
|
99
|
-
```
|
|
100
|
-
|
|
101
|
-
Installing registers `jive-daemon` to start at login (a LaunchAgent on macOS, a
|
|
102
|
-
`systemctl --user` unit on Linux, which starts at boot because the installer turns on `loginctl enable-linger` for
|
|
103
|
-
you, a scheduled task on Windows).
|
|
104
|
-
|
|
105
|
-
## Commands
|
|
106
|
-
|
|
107
|
-
| Command | What it does |
|
|
108
|
-
| --- | --- |
|
|
109
|
-
| `jive login` | Opens `https://jive.sh/login?request=…`, where you sign in with your jive.sh passkey, and waits; then prints the account you signed in as, saves its handle beside the session, and fetches your account's public key (`ssh:publicKey`) into `~/.jive/ssh/account.pub`. |
|
|
110
|
-
| `jive login --cicd` | In a GitHub Actions job with `id-token: write`: exchanges the job's ID token for a session of its pipeline. |
|
|
111
|
-
| `jive whoami` | Prints the handle of the Jive account this machine is signed in as, as `jive-daemon` reports it. When the server can't be reached it prints the handle saved at the last check, followed by `(not confirmed: can't reach Jive's server)`. |
|
|
112
|
-
| `jive init` | Marks the workspace root: the nearest directory, from the current one upward, whose `package.json` has `"jive": { "root": true }`; when there is none, the top of the outermost git repository you are in, or, in a folder in no repository, that folder, which it makes a new repository on branch `main` (`git init -b main`). The root's `package.json` gets the mark (created if missing; its other fields and indentation kept). Run below an existing workspace root, it warns that it configures that workspace and asks "Are you sure you want to continue? [y/N]": yes goes on, no (the default) exits changing nothing, and with no terminal to ask it exits 1 changing nothing. It takes the workspace's git identity from the root's own git config (`user.name`, `user.email`), saying which it used; when the root has none it asks for a name and an email in the terminal, and with no terminal it exits 1 changing nothing, saying to run it in one (see Git identity). Then, in that root, rewrites every .gitmodules at every depth to `https://github.com/<owner>/<repo>`, syncs them, checks out every submodule not yet checked out (one already checked out keeps its HEAD), and configures the root, every submodule and every untracked repository inside it: `user.name` and `user.email` (the workspace's git identity), `gpg.format=ssh`, `user.signingKey` (the account key's public half), `commit.gpgSign=true`, `gpg.ssh.program=jive-ssh-sign`, `core.sshCommand=jive-ssh`, `ssh.variant=ssh`, and `url."git@github.com:".insteadOf "https://github.com/"` so https URLs fetch and push over SSH. Then links the packages among those repositories with each other (see Workspace links). Nothing else, and no GitHub sign-in. Safe to run again: a submodule already checked out keeps its HEAD, and the links are made again. |
|
|
113
|
-
| `jive load <org> <repo>` | Adds a GitHub repo to the workspace as a submodule by its https URL at `packages/<its package.json name>` (see Workspace layout): clones it, or adopts a checkout of it already there (one whose remote names the repo), keeping its uncommitted work. Stages only its own `.gitmodules` entry and gitlink, so uncommitted edits to `.gitmodules` stay unstaged, and commits nothing. Run again on a loaded repo, it only does what follows. Fetches its submodules, configures it and them as `jive init` does (the root's git identity included; a root with none is refused with `jive init` as the fix), runs `bun install` in it, then links it with the workspace's packages: its workspace dependencies into it, and it into every workspace package that depends on it. |
|
|
114
|
-
| `jive unload <org> <repo>` | Removes every workspace link into the repo, running `bun install` in each package that had one so it gets its registry copy back, then removes the repo. |
|
|
115
|
-
| `jive on <org> <repo> -- <command…>` | Runs a command in a loaded repo's directory; its exit code is jive's. |
|
|
116
|
-
| `jive provision <kind> <name>` | Makes sure a resource instance exists, e.g. `jive provision connector-package-registry @scope/name`. The instance is `./package.json`'s `jive.resources.<kind>.<name>`, or `--instance '<json>'`. Needs a pipeline session. |
|
|
117
|
-
| `jive daemons` | Lists every Jive daemon registered on this machine, with its state, executable and log. First it deletes any broken registration record, and for one whose package is still installed it warns, naming that package, that it must be reinstalled to register its daemon again. |
|
|
118
|
-
| `jive upgrade` | Upgrades jive with the package manager that installed it. |
|
|
119
|
-
|
|
120
|
-
`--help`, `--version` and Tab completion (`jive --setup-completion`) work as for every command built with
|
|
121
|
-
`jive-abstract-library`'s `Cli`.
|
|
122
|
-
|
|
123
|
-
Two more commands are installed beside `jive`, for git and for you:
|
|
124
|
-
|
|
125
|
-
| Command | What it does |
|
|
126
|
-
| --- | --- |
|
|
127
|
-
| `jive-ssh <ssh arguments…>` | ssh with your Jive key and no other: runs `ssh -o IdentityAgent=~/.jive/signing-agent.sock -o IdentityFile=~/.jive/ssh/account.pub -o IdentitiesOnly=yes <ssh arguments…>`, after asking `jive-daemon` whether the key can sign (see How signing works). git runs it as `core.sshCommand`. ssh's exit code is its own; a refusal exits 255, as ssh does. |
|
|
128
|
-
| `jive-ssh-sign <ssh-keygen arguments…>` | git's `gpg.ssh.program`: stock ssh-keygen with every argument unchanged and `SSH_AUTH_SOCK` set to the agent's socket, so `-Y sign -f ~/.jive/ssh/account.pub` signs with your Jive key. Before `-Y sign` it makes the same check; git's other uses (`-Y verify`, `-Y find-principals`, `-Y check-novalidate`) and anything else run as plain ssh-keygen would. ssh-keygen's exit code is its own. |
|
|
129
|
-
|
|
130
|
-
A repository jive 0.7.0 configured names `jive-ssh-keygen` as git's `gpg.ssh.program`, which 0.9.1 no longer installs, so
|
|
131
|
-
its commits fail until `jive init` runs in it.
|
|
132
|
-
|
|
133
|
-
## Workspace layout
|
|
134
|
-
|
|
135
|
-
A workspace is a git monorepo whose root `package.json` has `"jive": { "root": true }`; `jive init` writes it, and
|
|
136
|
-
every other command finds the root by it. Each repo `jive load` adds is a submodule at `packages/<its package.json
|
|
137
|
-
name>`, the one layout tools built on jive rely on: `@jive-sh/jive` at `packages/@jive-sh/jive`,
|
|
138
|
-
`jive-abstract-library` at `packages/jive-abstract-library`. There is no option to put a repo elsewhere. A repo
|
|
139
|
-
without a package.json naming its package can't be loaded, and a checkout of the repo somewhere else under `packages/`
|
|
140
|
-
is refused with the `git mv` that puts it in place. `jive unload` and `jive on` find a loaded repo by the GitHub URL
|
|
141
|
-
in the root `.gitmodules`.
|
|
142
|
-
|
|
143
|
-
## Git identity
|
|
144
|
-
|
|
145
|
-
A workspace has one git identity, the name and email its commits carry: its root repository's own `user.name` and
|
|
146
|
-
`user.email` (`git config --local`), the only place it is kept. `jive init` asks for it the first time and writes it
|
|
147
|
-
into the root, and into every repository it configures; `jive load` copies it into the repo it adds. So a machine with
|
|
148
|
-
no global git identity commits as you in every repository of the workspace, and the machine's global one, if any, is
|
|
149
|
-
never read. Someone with several personas (work and personal) keeps one workspace per persona. To change a
|
|
150
|
-
workspace's identity, set it in the root (`git config user.name …`, `git config user.email …`) and run `jive init`
|
|
151
|
-
again.
|
|
152
|
-
|
|
153
|
-
## Workspace links
|
|
154
|
-
|
|
155
|
-
A workspace's packages are separate repositories, each with its own `package.json`, `bun.lock` and pipeline. Linking
|
|
156
|
-
makes them use each other the way a monorepo's members do, without changing what any of them installs in CI.
|
|
157
|
-
|
|
158
|
-
Every repository in the workspace whose `package.json` names a package is a member. Wherever one member depends on
|
|
159
|
-
another, `jive load` and `jive init` replace the dependent's `node_modules/<name>` with a relative
|
|
160
|
-
symlink to the dependency's checkout:
|
|
161
|
-
|
|
162
|
-
```
|
|
163
|
-
$ jive init
|
|
164
|
-
…
|
|
165
|
-
0 submodule URLs moved to https; 12 repositories sign with your Jive account key and fetch and push over SSH through jive's agent
|
|
166
|
-
Linked effective-modules into @jive-sh/jive: packages/effective-modules/dist/base (0.3.6)
|
|
167
|
-
Left jive-abstract-library into @jive-sh/jive: jive-abstract-library's build is 0.7.0-local and its checkout 0.13.1; run `bun run jive:cicd:build` in it, then `jive init`
|
|
168
|
-
1 workspace link in place; 1 left as installed
|
|
169
|
-
```
|
|
170
|
-
|
|
171
|
-
- **What a link points at.** A package whose source `package.json` names an entry point (`exports`, `main` or
|
|
172
|
-
`module`) is linked at its checkout. A package built by a Jive abstract names none, since its build writes
|
|
173
|
-
`exports`, so it is linked at the build in its `dist/base`, which must be of its checkout's version; after editing
|
|
174
|
-
it, rebuild it (`bun run jive:cicd:build`) and the link serves the new build.
|
|
175
|
-
- **The checkout wins over the pin.** A link is made whatever version the dependent pins, and the line says when the
|
|
176
|
-
checkout's version is outside the pin, since CI will install the pin.
|
|
177
|
-
- **Nothing in any repository changes.** No `package.json` or `bun.lock` is written, so each repository installs alone
|
|
178
|
-
from its own lockfile, locally and in CI, exactly as before.
|
|
179
|
-
- **Left as installed:** a dependency the dependent names locally itself (`link:`, `file:`, `workspace:`), one `bun
|
|
180
|
-
install` didn't install there (a peer dependency), one with no build or a build of another version, and a name two
|
|
181
|
-
members share.
|
|
182
|
-
- **A `bun install` or `bun add` in a dependent puts the registry copies back.** Run `jive init` again afterwards.
|
|
183
|
-
- **Shared peers.** A linked package resolves its own imports from its checkout, so a peer it shares with the
|
|
184
|
-
dependent (`effect`) is a second copy there. TypeScript needs `"preserveSymlinks": true` in the dependent's
|
|
185
|
-
tsconfig to type-check against one copy, as jive's has; at run time Bun has no such option, so two copies load.
|
|
186
|
-
|
|
187
|
-
Why not bun's own mechanisms: a root `workspaces` list links a member only when its version satisfies the dependent's
|
|
188
|
-
range (a pin of `0.3.6` against a checkout at `0.3.7` installs the registry copy), and a `bun install` run inside a
|
|
189
|
-
member then writes the root lockfile instead of the member's own. `bun link` registers each package in bun's global
|
|
190
|
-
folder, where it replaces any globally installed package of the same name (a checkout of jive would replace the jive
|
|
191
|
-
you run), and its links are undone by the same `bun install`.
|
|
192
|
-
|
|
193
|
-
## How signing works
|
|
194
|
-
|
|
195
|
-
Your SSH key lives with your Jive account on [`@jive-sh/server`](https://github.com/jive-sh/server); this machine keeps
|
|
196
|
-
only its public key (`~/.jive/ssh/account.pub`). A session comes only from your passkey (`jive login`) or, for a
|
|
197
|
-
pipeline, its GitHub OIDC token (`jive login --cicd`), and is kept in `~/.jive/session.json` (owner-only), with the
|
|
198
|
-
handle of its account as the server last confirmed it. A passkey session ends a day after its last use: each signature
|
|
199
|
-
moves its end a day on, on the server, so a machine that signs at least daily stays signed in; once the server refuses
|
|
200
|
-
the session, signing stops and says to run `jive login`. A pipeline's session lasts an hour.
|
|
201
|
-
`jive-daemon` serves the SSH agent protocol on `~/.jive/signing-agent.sock`: it lists the public key and sends
|
|
202
|
-
each request's bytes to the server's `ssh:sign`. It never signs you in: with no live session it refuses. That covers
|
|
203
|
-
git commit signatures and GitHub's SSH authentication alike: each repository `jive init` or `jive load` configures signs
|
|
204
|
-
through `jive-ssh-sign` and fetches and pushes over SSH through `jive-ssh`. jive holds no GitHub token and never signs
|
|
205
|
-
in to GitHub; GitHub must know the account key's public half as an SSH and signing key. Signing needs `ssh` and
|
|
206
|
-
`ssh-keygen` (OpenSSH) on PATH.
|
|
207
|
-
|
|
208
|
-
The SSH agent protocol refuses with one byte and no reason, which ssh reports as `agent refused operation` and then
|
|
209
|
-
`Permission denied (publickey)`. So before ssh or ssh-keygen runs, `jive-ssh` and `jive-ssh-sign` ask `jive-daemon` on
|
|
210
|
-
its own socket, `~/.jive/jive-daemon.sock`, who is signed in (`GetSession`, which checks with the server), and stop
|
|
211
|
-
with the reason when the key can't sign:
|
|
212
|
-
|
|
213
|
-
```text
|
|
214
|
-
jive-ssh: not signed in to Jive; run `jive login`
|
|
215
|
-
jive-ssh: your computer can't reach Jive's server (https://…) to sign as <you>; reconnect and run the command again
|
|
216
|
-
jive-ssh: jive's daemon is not running; run `jive daemons` to see why; `jive upgrade` registers and starts it again, and so does logging in again
|
|
217
|
-
```
|
|
218
|
-
|
|
219
|
-
`jive-ssh-sign` says the same, named `jive-ssh-sign:`. The server check gives up after 5 seconds, so a network that
|
|
220
|
-
swallows requests reads as unreachable.
|
|
221
|
-
|
|
222
|
-
jive never writes to `~/.ssh`: no key file and no `~/.ssh/config` block. Everything it sets up is per repository.
|
|
223
|
-
|
|
224
|
-
## Using your Jive key for other SSH
|
|
225
|
-
|
|
226
|
-
Your Jive key works for anything that takes an SSH key, not only git and GitHub. `jive-ssh` stands in for ssh and
|
|
227
|
-
`jive-ssh-sign` for ssh-keygen; signing with either needs `jive-daemon` running (`jive daemons`).
|
|
228
|
-
|
|
229
|
-
**Sign in to an SSH server.** Add the contents of `~/.jive/ssh/account.pub` to `~/.ssh/authorized_keys` on the server,
|
|
230
|
-
then:
|
|
231
|
-
|
|
232
|
-
```sh
|
|
233
|
-
jive-ssh user@host
|
|
234
|
-
```
|
|
235
|
-
|
|
236
|
-
Every argument goes to ssh after jive's three options. ssh keeps the first value of an option, so `jive-ssh` names on
|
|
237
|
-
stderr each option of yours that changes nothing or more than you may expect:
|
|
238
|
-
|
|
239
|
-
```text
|
|
240
|
-
$ jive-ssh -o IdentitiesOnly=no -o IdentityFile=~/.ssh/other -A user@host
|
|
241
|
-
jive-ssh: warning: -o IdentitiesOnly=no has no effect: jive-ssh passes IdentitiesOnly=yes first, and ssh keeps the first value
|
|
242
|
-
jive-ssh: warning: -o IdentityFile=~/.ssh/other adds a second key: ssh offers your Jive account key, ~/.jive/ssh/account.pub, first, then ~/.ssh/other
|
|
243
|
-
jive-ssh: warning: -A forwards jive's agent: while you are connected, the remote host can sign as <you> with your Jive key
|
|
244
|
-
```
|
|
245
|
-
|
|
246
|
-
`-i` is refused, even naming the Jive key: `jive-ssh` always logs in with your Jive key, so log in with another key
|
|
247
|
-
with plain `ssh -i <key>`. `-G`, which only prints ssh's configuration, runs without asking the daemon.
|
|
248
|
-
|
|
249
|
-
To use the key without jive, for example from a GUI client, add a block like this to your own `~/.ssh/config`. That
|
|
250
|
-
client talks to the agent directly, so a refusal there reads only `agent refused operation`; `jive whoami` says why.
|
|
251
|
-
|
|
252
|
-
```
|
|
253
|
-
Host myserver
|
|
254
|
-
HostName host
|
|
255
|
-
User user
|
|
256
|
-
IdentityAgent ~/.jive/signing-agent.sock
|
|
257
|
-
IdentityFile ~/.jive/ssh/account.pub
|
|
258
|
-
IdentitiesOnly yes
|
|
259
|
-
```
|
|
260
|
-
|
|
261
|
-
**Sign a file, or anything else.** Use `jive-ssh-sign -Y sign` with your own namespace (`-n`), and `ssh-keygen -Y
|
|
262
|
-
verify` with an `allowed_signers` file to check it:
|
|
263
|
-
|
|
264
|
-
```sh
|
|
265
|
-
jive-ssh-sign -Y sign -f ~/.jive/ssh/account.pub -n file release.tar
|
|
266
|
-
```
|
|
267
|
-
|
|
268
|
-
which runs `SSH_AUTH_SOCK=~/.jive/signing-agent.sock ssh-keygen -Y sign -f ~/.jive/ssh/account.pub -n file
|
|
269
|
-
release.tar` and writes `release.tar.sig`.
|
|
270
|
-
|
|
271
|
-
What is tested, in [`src/ssh.test.ts`](src/ssh.test.ts),
|
|
272
|
-
[`src/modules/signing-agent/signing-agent.test.ts`](src/modules/signing-agent/signing-agent.test.ts) and
|
|
273
|
-
[`src/workspace-cutover.test.ts`](src/workspace-cutover.test.ts), with a scratch home and a fake Jive server that
|
|
274
|
-
signs with a key the test makes and can be made unreachable:
|
|
275
|
-
- `jive-ssh` and `jive-ssh-sign` run as processes, as git runs them, against jive-daemon's two sockets. `jive-ssh` logs
|
|
276
|
-
in to an sshd on the same machine that accepts only the account key, passes git's `-o SendEnv=GIT_PROTOCOL` and
|
|
277
|
-
ssh's exit code on, and prints nothing of its own. `jive-ssh-sign -Y sign` signs through the agent, and
|
|
278
|
-
`-Y verify`, `-Y find-principals`, `-Y check-novalidate`, `-l` and key generation pass to ssh-keygen unchanged
|
|
279
|
-
without asking the daemon.
|
|
280
|
-
- Not signed in, the server unreachable and the daemon not running: each command prints exactly the line above, exits
|
|
281
|
-
255, and nothing signs or opens a sign-in. `-i` in each spelling is refused with its message; the ignored `-o`
|
|
282
|
-
options and `-A` warn with the lines above; `-G` prints exactly what plain ssh with jive's options prints.
|
|
283
|
-
- `jive whoami` prints the confirmed account, the saved one marked unconfirmed while offline, and the fix when signed
|
|
284
|
-
out or when no daemon runs.
|
|
285
|
-
- Upgrading from 0.7.0 ([`src/upgrade-from-0.7.0.test.ts`](src/upgrade-from-0.7.0.test.ts)): the built installer removes the
|
|
286
|
-
`jive-signing-agent` and `jive-extension-daemon` registrations and stops them, and `jive-daemon`, registered in their
|
|
287
|
-
place, waits for them to exit and serves both sockets. The service manager is a fake that, like launchd's `bootout`,
|
|
288
|
-
returns before a stopped daemon has exited; the test needs `bun run jive:cicd:build` first, and CI runs it.
|
|
289
|
-
- The agent refuses a sign request with no session, and one whose session the server has ended, without opening a
|
|
290
|
-
sign-in; an unreachable server fails a sign request without asking the server a second time.
|
|
291
|
-
- After `jive init`, a commit is signed through `jive-ssh-sign`, verifies, and is pushed through `jive-ssh` to the
|
|
292
|
-
sshd.
|
|
293
|
-
- With no global git identity, where a plain `git commit` fails for want of one, a fresh folder goes
|
|
294
|
-
through `jive init` (its questions answered by the test) and its first commit is made as that identity and signed.
|
|
295
|
-
|
|
296
|
-
Not tested: a remote server, the `~/.ssh/config` block (it sets the same options as `jive-ssh`), and Linux.
|
|
297
|
-
|
|
298
|
-
## The Jive browser extension
|
|
299
|
-
|
|
300
|
-
The Jive browser extension (`@jive-sh/extension`, a proof of concept) signs this machine in to Jive and collects
|
|
301
|
-
credentials from the person's own signed-in browser, such as an npm token. It never holds the session: it asks
|
|
302
|
-
`jive-daemon`, which uses the same session `jive login` keeps in `~/.jive/session.json`. The session goes
|
|
303
|
-
from Jive to the daemon and never passes through the browser or the extension.
|
|
304
|
-
|
|
305
|
-
- **Native host.** Chrome starts a program when the extension calls `chrome.runtime.connectNative("sh.jive.daemon")`.
|
|
306
|
-
Chrome can only start a host, never attach to a running process, so `jive-native-host` relays each message to the
|
|
307
|
-
daemon's socket, `~/.jive/jive-daemon.sock` (owner-only), without reading it.
|
|
308
|
-
- **Page script.** On `https://www.npmjs.com/*` and `https://npmjs.com/*`, `page.js` runs in the page's own world at
|
|
309
|
-
the start of the document and wraps `navigator.credentials.create` and `get` only when the call carries `publicKey`.
|
|
310
|
-
An isolated script relays that ask to the service worker, which is the only extension page that calls `connectNative`.
|
|
311
|
-
- **Registration with Chrome.** At each start the daemon writes the host manifest,
|
|
312
|
-
`~/Library/Application Support/{Google/Chrome,Chromium}/NativeMessagingHosts/sh.jive.daemon.json` on macOS and
|
|
313
|
-
`~/.config/{google-chrome,chromium}/NativeMessagingHosts/` on Linux, only where that browser is installed. It allows
|
|
314
|
-
only the Jive extension's id, which Chrome derives from the extension's public key. Windows (the registry) is not
|
|
315
|
-
done yet.
|
|
316
|
-
|
|
317
|
-
### The protocol
|
|
318
|
-
|
|
319
|
-
[`src/modules/extension-daemon/protocol.ts`](src/modules/extension-daemon/protocol.ts) is the one definition, and the
|
|
320
|
-
extension imports it from jive's source (jive exports no library yet). Every request carries `protocolVersion`, and a
|
|
321
|
-
mismatch is refused with which side to upgrade.
|
|
322
|
-
|
|
323
|
-
| Request | Response |
|
|
324
|
-
| --- | --- |
|
|
325
|
-
| `GetSession` | `SignedOut`, `SigningIn { loginUrl, expiresAt }`, `SignedIn { username, expiresAt, confirmedByServer, unreachableServerUrl }`, or `Failed { message }` when the server refused to check the session. `confirmedByServer` is false when the server could not be reached: `username` and `expiresAt` are then the ones saved at the last check, and `unreachableServerUrl` names the server. `jive-ssh`, `jive-ssh-sign` and `jive whoami` send it on the daemon socket directly. |
|
|
326
|
-
| `StartSignIn` | `SigningIn`, or `SignInFailed { reason }` when Jive can't be reached |
|
|
327
|
-
| `SignOut` | `SignedOut`. Forgets this machine's session, so `jive` signs in again too. |
|
|
328
|
-
| `GetNpmConnectionReadiness` | `Ready` or `NotReady { reason }`. The extension asks this before it changes anything on npm. |
|
|
329
|
-
| `PostNpmCredential { credential: { npmUser, token } }` | `Posted` or `Refused { reason }` |
|
|
330
|
-
| `PrepareSigningPasskey { repositoryOwner, repositoryName }` | `SigningPasskeyPrepared`. Stores that repository in `~/.jive/signing-passkey-repository.json` and uses it after a restart. Sent on the daemon socket by the program that opens npm's page, because the page does not name a repository. |
|
|
331
|
-
| `AnswerSecurityKey { kind, challenge, rpId, origin, crossOrigin }` | `SecurityKeyAnswer` or `SecurityKeyRefused { reason }`. `kind` is `create` or `get`. `challenge` is the page's challenge, base64url. The answer's byte strings are standard base64: `credentialId`, `clientDataJSON`, `authenticatorData`, `signature`, and `attestationObject` on `create` only. The daemon sends `authenticatorData` concatenated with the SHA-256 of `clientDataJSON` to `signingPasskey:sign`. The server returns raw ECDSA `r‖s` and does not interpret those bytes. |
|
|
332
|
-
|
|
333
|
-
No response carries the session token, the claim secret or a credential.
|
|
334
|
-
|
|
335
|
-
### How the extension signs in
|
|
336
|
-
|
|
337
|
-
1. The extension's Sign in button sends `StartSignIn`.
|
|
338
|
-
2. The daemon signs in the way `jive login` does: it opens a sign-in request on `@jive-sh/server` and answers with its
|
|
339
|
-
page, `https://jive.sh/login?request=…`.
|
|
340
|
-
3. The extension opens the page, and the person signs in there with their jive.sh passkey.
|
|
341
|
-
4. The daemon claims the request every 2 seconds. Once the person has approved it, the claim returns a session, which
|
|
342
|
-
the daemon stores in `~/.jive/session.json`. The extension sees `SignedIn` on its next `GetSession`.
|
|
343
|
-
|
|
344
|
-
A daemon restart drops a sign-in still waiting, because the claim secret is kept in memory only. A stored session
|
|
345
|
-
survives restarts until it expires.
|
|
346
|
-
|
|
347
|
-
**Not decided yet: who accepts the npm credential.** Either jive.sh or `@jive-sh/server`, which holds npm connections,
|
|
348
|
-
could. Posting is behind `INpmCredentialPoster` ([`src/modules/npm-credential-poster/interface.ts`](src/modules/npm-credential-poster/interface.ts)).
|
|
349
|
-
Until the decision, the daemon ships `NpmCredentialPosterNotDecidedImpl`, which answers `NotReady` with that reason,
|
|
350
|
-
so the extension stops before it touches npm.
|
|
351
|
-
|
|
352
|
-
## Developing
|
|
353
|
-
|
|
354
|
-
```sh
|
|
355
|
-
bun install
|
|
356
|
-
bun run jive:cicd:audit # type check and tests
|
|
357
|
-
bun run install:local # build with the jive-abstract-library checkout beside this one, install globally
|
|
358
|
-
```
|
|
359
|
-
|
|
360
|
-
Tests never reach jive.sh, the server or GitHub. The signing agent's tests run the real `ssh-keygen` and `ssh-add`
|
|
361
|
-
against a fake server; `src/workspace-cutover.test.ts` runs `jive init` on a scratch workspace with nested submodules,
|
|
362
|
-
signs a commit through the agent and pushes it over SSH to a local sshd. The extension daemon's tests
|
|
363
|
-
([`src/modules/extension-daemon/extension-daemon.test.ts`](src/modules/extension-daemon/extension-daemon.test.ts)) run the
|
|
364
|
-
daemon against a fake server and speak Chrome's framing to the native host started from the manifest the daemon
|
|
365
|
-
wrote: sign-in end to end into `~/.jive/session.json`, a session `jive login` stored, a restart, posting, sign-out,
|
|
366
|
-
protocol refusal, a second daemon standing down, and the native host reporting a stopped daemon. Not covered by tests:
|
|
367
|
-
registration with the OS service manager, the compiled binary under a real Chrome, Linux, and Windows.
|
package/bin/jive
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
"use strict";
|
|
3
|
-
/**
|
|
4
|
-
* Every command's file in a built package's bin/, the same for every command: it is the command its own file name says.
|
|
5
|
-
*
|
|
6
|
-
* On macOS and Linux it runs once. It has the package's postinstall.cjs replace it (and every other command's file)
|
|
7
|
-
* with a hard link to the real program, which the package manager skips when it does not run postinstall (Bun, for a
|
|
8
|
-
* package it does not trust), then runs the program with what was typed. On Windows a command starts through its .cmd
|
|
9
|
-
* shim, which always runs this file, so it runs the program every time and sets up again only when the commands are
|
|
10
|
-
* stale.
|
|
11
|
-
*
|
|
12
|
-
* CommonJS for the reason postinstall.cjs gives: bin/package.json makes this extensionless file CommonJS.
|
|
13
|
-
*/
|
|
14
|
-
const { spawnSync } = require("child_process");
|
|
15
|
-
const { realpathSync } = require("fs");
|
|
16
|
-
const { basename, dirname, join } = require("path");
|
|
17
|
-
|
|
18
|
-
// The real path: reached through a link in a bin directory, the package is wherever the link points.
|
|
19
|
-
const launcherPath = realpathSync(__filename);
|
|
20
|
-
const packageDir = dirname(dirname(launcherPath));
|
|
21
|
-
const postinstall = require(join(packageDir, "postinstall.cjs"));
|
|
22
|
-
|
|
23
|
-
if (process.platform !== "win32" || !postinstall.commandsAreCurrent({ packageDir })) {
|
|
24
|
-
// A shell's, a launcher's or the user's own call to the completion code is left to do its job alone.
|
|
25
|
-
const setUpCompletion = !postinstall.COMPLETION_FLAGS.includes(process.argv[2]);
|
|
26
|
-
postinstall.setUp({ packageDir, repairOnly: false, setUpCompletion });
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
const result = spawnSync(postinstall.commandTarget({ packageDir, command: basename(launcherPath) }), process.argv.slice(2), { stdio: "inherit" });
|
|
30
|
-
if (result.error) {
|
|
31
|
-
console.error(result.error.message);
|
|
32
|
-
process.exit(1);
|
|
33
|
-
}
|
|
34
|
-
process.exit(result.status === null ? 1 : result.status);
|
package/bin/jive-daemon
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
"use strict";
|
|
3
|
-
/**
|
|
4
|
-
* Every command's file in a built package's bin/, the same for every command: it is the command its own file name says.
|
|
5
|
-
*
|
|
6
|
-
* On macOS and Linux it runs once. It has the package's postinstall.cjs replace it (and every other command's file)
|
|
7
|
-
* with a hard link to the real program, which the package manager skips when it does not run postinstall (Bun, for a
|
|
8
|
-
* package it does not trust), then runs the program with what was typed. On Windows a command starts through its .cmd
|
|
9
|
-
* shim, which always runs this file, so it runs the program every time and sets up again only when the commands are
|
|
10
|
-
* stale.
|
|
11
|
-
*
|
|
12
|
-
* CommonJS for the reason postinstall.cjs gives: bin/package.json makes this extensionless file CommonJS.
|
|
13
|
-
*/
|
|
14
|
-
const { spawnSync } = require("child_process");
|
|
15
|
-
const { realpathSync } = require("fs");
|
|
16
|
-
const { basename, dirname, join } = require("path");
|
|
17
|
-
|
|
18
|
-
// The real path: reached through a link in a bin directory, the package is wherever the link points.
|
|
19
|
-
const launcherPath = realpathSync(__filename);
|
|
20
|
-
const packageDir = dirname(dirname(launcherPath));
|
|
21
|
-
const postinstall = require(join(packageDir, "postinstall.cjs"));
|
|
22
|
-
|
|
23
|
-
if (process.platform !== "win32" || !postinstall.commandsAreCurrent({ packageDir })) {
|
|
24
|
-
// A shell's, a launcher's or the user's own call to the completion code is left to do its job alone.
|
|
25
|
-
const setUpCompletion = !postinstall.COMPLETION_FLAGS.includes(process.argv[2]);
|
|
26
|
-
postinstall.setUp({ packageDir, repairOnly: false, setUpCompletion });
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
const result = spawnSync(postinstall.commandTarget({ packageDir, command: basename(launcherPath) }), process.argv.slice(2), { stdio: "inherit" });
|
|
30
|
-
if (result.error) {
|
|
31
|
-
console.error(result.error.message);
|
|
32
|
-
process.exit(1);
|
|
33
|
-
}
|
|
34
|
-
process.exit(result.status === null ? 1 : result.status);
|
package/bin/jive-native-host
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
"use strict";
|
|
3
|
-
/**
|
|
4
|
-
* Every command's file in a built package's bin/, the same for every command: it is the command its own file name says.
|
|
5
|
-
*
|
|
6
|
-
* On macOS and Linux it runs once. It has the package's postinstall.cjs replace it (and every other command's file)
|
|
7
|
-
* with a hard link to the real program, which the package manager skips when it does not run postinstall (Bun, for a
|
|
8
|
-
* package it does not trust), then runs the program with what was typed. On Windows a command starts through its .cmd
|
|
9
|
-
* shim, which always runs this file, so it runs the program every time and sets up again only when the commands are
|
|
10
|
-
* stale.
|
|
11
|
-
*
|
|
12
|
-
* CommonJS for the reason postinstall.cjs gives: bin/package.json makes this extensionless file CommonJS.
|
|
13
|
-
*/
|
|
14
|
-
const { spawnSync } = require("child_process");
|
|
15
|
-
const { realpathSync } = require("fs");
|
|
16
|
-
const { basename, dirname, join } = require("path");
|
|
17
|
-
|
|
18
|
-
// The real path: reached through a link in a bin directory, the package is wherever the link points.
|
|
19
|
-
const launcherPath = realpathSync(__filename);
|
|
20
|
-
const packageDir = dirname(dirname(launcherPath));
|
|
21
|
-
const postinstall = require(join(packageDir, "postinstall.cjs"));
|
|
22
|
-
|
|
23
|
-
if (process.platform !== "win32" || !postinstall.commandsAreCurrent({ packageDir })) {
|
|
24
|
-
// A shell's, a launcher's or the user's own call to the completion code is left to do its job alone.
|
|
25
|
-
const setUpCompletion = !postinstall.COMPLETION_FLAGS.includes(process.argv[2]);
|
|
26
|
-
postinstall.setUp({ packageDir, repairOnly: false, setUpCompletion });
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
const result = spawnSync(postinstall.commandTarget({ packageDir, command: basename(launcherPath) }), process.argv.slice(2), { stdio: "inherit" });
|
|
30
|
-
if (result.error) {
|
|
31
|
-
console.error(result.error.message);
|
|
32
|
-
process.exit(1);
|
|
33
|
-
}
|
|
34
|
-
process.exit(result.status === null ? 1 : result.status);
|
package/bin/jive-ssh
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
"use strict";
|
|
3
|
-
/**
|
|
4
|
-
* Every command's file in a built package's bin/, the same for every command: it is the command its own file name says.
|
|
5
|
-
*
|
|
6
|
-
* On macOS and Linux it runs once. It has the package's postinstall.cjs replace it (and every other command's file)
|
|
7
|
-
* with a hard link to the real program, which the package manager skips when it does not run postinstall (Bun, for a
|
|
8
|
-
* package it does not trust), then runs the program with what was typed. On Windows a command starts through its .cmd
|
|
9
|
-
* shim, which always runs this file, so it runs the program every time and sets up again only when the commands are
|
|
10
|
-
* stale.
|
|
11
|
-
*
|
|
12
|
-
* CommonJS for the reason postinstall.cjs gives: bin/package.json makes this extensionless file CommonJS.
|
|
13
|
-
*/
|
|
14
|
-
const { spawnSync } = require("child_process");
|
|
15
|
-
const { realpathSync } = require("fs");
|
|
16
|
-
const { basename, dirname, join } = require("path");
|
|
17
|
-
|
|
18
|
-
// The real path: reached through a link in a bin directory, the package is wherever the link points.
|
|
19
|
-
const launcherPath = realpathSync(__filename);
|
|
20
|
-
const packageDir = dirname(dirname(launcherPath));
|
|
21
|
-
const postinstall = require(join(packageDir, "postinstall.cjs"));
|
|
22
|
-
|
|
23
|
-
if (process.platform !== "win32" || !postinstall.commandsAreCurrent({ packageDir })) {
|
|
24
|
-
// A shell's, a launcher's or the user's own call to the completion code is left to do its job alone.
|
|
25
|
-
const setUpCompletion = !postinstall.COMPLETION_FLAGS.includes(process.argv[2]);
|
|
26
|
-
postinstall.setUp({ packageDir, repairOnly: false, setUpCompletion });
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
const result = spawnSync(postinstall.commandTarget({ packageDir, command: basename(launcherPath) }), process.argv.slice(2), { stdio: "inherit" });
|
|
30
|
-
if (result.error) {
|
|
31
|
-
console.error(result.error.message);
|
|
32
|
-
process.exit(1);
|
|
33
|
-
}
|
|
34
|
-
process.exit(result.status === null ? 1 : result.status);
|
package/bin/jive-ssh-sign
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
"use strict";
|
|
3
|
-
/**
|
|
4
|
-
* Every command's file in a built package's bin/, the same for every command: it is the command its own file name says.
|
|
5
|
-
*
|
|
6
|
-
* On macOS and Linux it runs once. It has the package's postinstall.cjs replace it (and every other command's file)
|
|
7
|
-
* with a hard link to the real program, which the package manager skips when it does not run postinstall (Bun, for a
|
|
8
|
-
* package it does not trust), then runs the program with what was typed. On Windows a command starts through its .cmd
|
|
9
|
-
* shim, which always runs this file, so it runs the program every time and sets up again only when the commands are
|
|
10
|
-
* stale.
|
|
11
|
-
*
|
|
12
|
-
* CommonJS for the reason postinstall.cjs gives: bin/package.json makes this extensionless file CommonJS.
|
|
13
|
-
*/
|
|
14
|
-
const { spawnSync } = require("child_process");
|
|
15
|
-
const { realpathSync } = require("fs");
|
|
16
|
-
const { basename, dirname, join } = require("path");
|
|
17
|
-
|
|
18
|
-
// The real path: reached through a link in a bin directory, the package is wherever the link points.
|
|
19
|
-
const launcherPath = realpathSync(__filename);
|
|
20
|
-
const packageDir = dirname(dirname(launcherPath));
|
|
21
|
-
const postinstall = require(join(packageDir, "postinstall.cjs"));
|
|
22
|
-
|
|
23
|
-
if (process.platform !== "win32" || !postinstall.commandsAreCurrent({ packageDir })) {
|
|
24
|
-
// A shell's, a launcher's or the user's own call to the completion code is left to do its job alone.
|
|
25
|
-
const setUpCompletion = !postinstall.COMPLETION_FLAGS.includes(process.argv[2]);
|
|
26
|
-
postinstall.setUp({ packageDir, repairOnly: false, setUpCompletion });
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
const result = spawnSync(postinstall.commandTarget({ packageDir, command: basename(launcherPath) }), process.argv.slice(2), { stdio: "inherit" });
|
|
30
|
-
if (result.error) {
|
|
31
|
-
console.error(result.error.message);
|
|
32
|
-
process.exit(1);
|
|
33
|
-
}
|
|
34
|
-
process.exit(result.status === null ? 1 : result.status);
|
package/bin/package.json
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"type":"commonjs"}
|
package/postinstall.cjs
DELETED
|
@@ -1,663 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// Its literals deliberately repeat the library's constants (src/internal/common/constants.ts and
|
|
3
|
-
// src/internal/public/cli/parse.ts), so this shipped file stays plain, readable JS with nothing generated into it. The
|
|
4
|
-
// test "the library's daemon listing finds the daemon postinstall.cjs registered, with its log where the library
|
|
5
|
-
// expects" (postinstall.test.ts) catches any disagreement.
|
|
6
|
-
/**
|
|
7
|
-
* The install step of every package built with jive-abstract-library that has commands or daemons. The builder copies
|
|
8
|
-
* this file unchanged to the root of each such package; the package's postinstall script runs it, and each command's
|
|
9
|
-
* launcher in bin/ requires it to do the same on its first run, because Bun skips postinstall for a package it does not
|
|
10
|
-
* trust.
|
|
11
|
-
*
|
|
12
|
-
* Nothing in it is filled in per package. It reads its own package's package.json at run time: "name", the commands in
|
|
13
|
-
* "bin", the platform packages in "optionalDependencies", and "jive", which the builder adds for what package.json has
|
|
14
|
-
* no field for (the daemons, and the commands that set up Tab completion).
|
|
15
|
-
*
|
|
16
|
-
* CommonJS, not an ES module: Node 14 and 16 refuse to load an extensionless ES module in a "type": "module" package
|
|
17
|
-
* (ERR_UNKNOWN_FILE_EXTENSION; Node 18.20 accepts it), and the launchers are extensionless. bin/package.json marks that
|
|
18
|
-
* directory "commonjs" and this file ends in .cjs, so both load the same way on every Node and on Bun.
|
|
19
|
-
*/
|
|
20
|
-
const { spawnSync } = require("child_process");
|
|
21
|
-
const {
|
|
22
|
-
chmodSync,
|
|
23
|
-
copyFileSync,
|
|
24
|
-
existsSync,
|
|
25
|
-
linkSync,
|
|
26
|
-
mkdirSync,
|
|
27
|
-
readdirSync,
|
|
28
|
-
readFileSync,
|
|
29
|
-
realpathSync,
|
|
30
|
-
renameSync,
|
|
31
|
-
rmSync,
|
|
32
|
-
writeFileSync,
|
|
33
|
-
} = require("fs");
|
|
34
|
-
const { createHash } = require("crypto");
|
|
35
|
-
const { homedir, userInfo } = require("os");
|
|
36
|
-
const { basename, delimiter, dirname, join } = require("path");
|
|
37
|
-
|
|
38
|
-
/** Where a built package keeps its commands: the launchers, and on macOS and Linux the hard links that replace them. */
|
|
39
|
-
const BIN_DIR = "bin";
|
|
40
|
-
/** The real program in each platform package, holding every command and daemon; it runs the one its own name says. */
|
|
41
|
-
const MULTI_CALL_BINARY = "multi-call-binary";
|
|
42
|
-
const WINDOWS_EXECUTABLE_SUFFIX = ".exe";
|
|
43
|
-
/** On Windows, beside the commands: the platform package version they were copied from. */
|
|
44
|
-
const INSTALLED_JSON = "installed.json";
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* Prefix every daemon registration carries, on every platform: the record file name, the launchd label, the systemd unit
|
|
48
|
-
* and the scheduled task are all this same one string.
|
|
49
|
-
*
|
|
50
|
-
* It exists so Jive's own registrations are identifiable without the registry, which is the recovery path for exactly
|
|
51
|
-
* the orphaned-unit problem the registry is there to prevent, and so a command that lists daemons and their statuses
|
|
52
|
-
* has one thing to look for rather than three per-platform conventions.
|
|
53
|
-
*/
|
|
54
|
-
const DAEMON_ID_PREFIX = "jive-daemon";
|
|
55
|
-
/** Directory under the user's home where every Jive daemon's registration record and log live. */
|
|
56
|
-
const DAEMON_HOME_DIR = ".jive";
|
|
57
|
-
const DAEMON_REGISTRY_SUBDIR = "daemons";
|
|
58
|
-
const DAEMON_LOG_SUBDIR = "logs";
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
* Tells this script to link the commands and stop, leaving daemons unregistered.
|
|
62
|
-
*
|
|
63
|
-
* An argument rather than an environment variable: this is one caller telling one callee about one invocation, and an
|
|
64
|
-
* ambient variable would be inherited by everything either of them spawns.
|
|
65
|
-
*/
|
|
66
|
-
const REPAIR_ONLY_FLAG = "--repair-only";
|
|
67
|
-
|
|
68
|
-
/*
|
|
69
|
-
* Hidden flags of a command built with the library's Cli, never offered by Tab or listed by --help: what shells,
|
|
70
|
-
* launchers and builds call a command with. Together they are the completion protocol (COMPLETION_PROTOCOL in
|
|
71
|
-
* public/cli/parse.ts). A launcher leaves Tab completion alone when the first argument is one of them.
|
|
72
|
-
*/
|
|
73
|
-
/** What a shell's Tab completion calls the command with, followed by the words typed so far. */
|
|
74
|
-
const COMPGEN_FLAG = "--compgen";
|
|
75
|
-
/** Followed by a shell's name: prints the script that registers Tab completion, which the startup line evaluates. */
|
|
76
|
-
const COMPLETION_SCRIPT_FLAG = "--completion";
|
|
77
|
-
/** Prints the completion protocol's version: how a build, or another copy of the command, learns this one speaks it. */
|
|
78
|
-
const COMPLETION_PROTOCOL_FLAG = "--completion-protocol";
|
|
79
|
-
const SET_UP_COMPLETION_FLAG = "--setup-completion";
|
|
80
|
-
const REMOVE_COMPLETION_FLAG = "--remove-completion";
|
|
81
|
-
/** What this script runs each completion command with after an install or upgrade: set up Tab completion if the user's shell lacks it. */
|
|
82
|
-
const SET_UP_MISSING_COMPLETION_FLAG = "--setup-completion-if-missing";
|
|
83
|
-
const COMPLETION_FLAGS = [
|
|
84
|
-
COMPGEN_FLAG,
|
|
85
|
-
COMPLETION_SCRIPT_FLAG,
|
|
86
|
-
COMPLETION_PROTOCOL_FLAG,
|
|
87
|
-
SET_UP_COMPLETION_FLAG,
|
|
88
|
-
REMOVE_COMPLETION_FLAG,
|
|
89
|
-
SET_UP_MISSING_COMPLETION_FLAG,
|
|
90
|
-
];
|
|
91
|
-
|
|
92
|
-
function fail(message) {
|
|
93
|
-
console.error(message);
|
|
94
|
-
process.exit(1);
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
/**
|
|
98
|
-
* The package at `packageDir`, from its package.json: its name, its commands in "bin" order, its platform packages, and
|
|
99
|
-
* the daemons and completion commands the builder put in its "jive" field.
|
|
100
|
-
*/
|
|
101
|
-
function readPackage(packageDir) {
|
|
102
|
-
const manifestPath = join(packageDir, "package.json");
|
|
103
|
-
let manifest;
|
|
104
|
-
try {
|
|
105
|
-
manifest = JSON.parse(readFileSync(manifestPath, "utf-8"));
|
|
106
|
-
} catch (error) {
|
|
107
|
-
fail(`Cannot read ${manifestPath}: ${error.message}`);
|
|
108
|
-
}
|
|
109
|
-
const jive = manifest.jive || {};
|
|
110
|
-
return {
|
|
111
|
-
packageDir,
|
|
112
|
-
name: manifest.name,
|
|
113
|
-
commands: Object.keys(manifest.bin || {}),
|
|
114
|
-
platformPackages: Object.keys(manifest.optionalDependencies || {}),
|
|
115
|
-
daemons: jive.daemons || [],
|
|
116
|
-
completionCommands: jive.completionCommands || [],
|
|
117
|
-
};
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
function installedPlatformPackage(pkg, platformPackage) {
|
|
121
|
-
try {
|
|
122
|
-
const manifestPath = require.resolve(`${platformPackage}/package.json`, { paths: [pkg.packageDir] });
|
|
123
|
-
const manifest = JSON.parse(readFileSync(manifestPath, "utf-8"));
|
|
124
|
-
if (!Array.isArray(manifest.os) || !Array.isArray(manifest.cpu)) return undefined;
|
|
125
|
-
const binaryFile = manifest.os.includes("win32") ? `${MULTI_CALL_BINARY}${WINDOWS_EXECUTABLE_SUFFIX}` : MULTI_CALL_BINARY;
|
|
126
|
-
return {
|
|
127
|
-
name: platformPackage,
|
|
128
|
-
os: manifest.os,
|
|
129
|
-
cpu: manifest.cpu,
|
|
130
|
-
binaryPath: join(dirname(manifestPath), binaryFile),
|
|
131
|
-
version: manifest.version,
|
|
132
|
-
};
|
|
133
|
-
} catch {
|
|
134
|
-
return undefined;
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
/**
|
|
139
|
-
* The base package has one optional dependency per platform, each holding that platform's build of every command. The
|
|
140
|
-
* package manager installs the one whose "os" and "cpu" match the machine, so this uses whichever is installed rather
|
|
141
|
-
* than deciding the platform again. Asking again can disagree with the package manager: on an Apple Silicon Mac, bun
|
|
142
|
-
* (native) installs darwin-arm64, while an Intel build of Node running under Rosetta reports process.arch "x64".
|
|
143
|
-
* @returns the path to the platform binary and the exact version of the platform package.
|
|
144
|
-
*/
|
|
145
|
-
function currentPlatformPackage(pkg) {
|
|
146
|
-
const installed = pkg.platformPackages.map((name) => installedPlatformPackage(pkg, name)).filter(Boolean);
|
|
147
|
-
if (installed.length === 1) return installed[0];
|
|
148
|
-
|
|
149
|
-
// More than one is installed only when the package manager was told to (npm's --cpu and --os flags).
|
|
150
|
-
const matching = installed.find((platformPackage) =>
|
|
151
|
-
platformPackage.os.includes(process.platform) && platformPackage.cpu.includes(process.arch));
|
|
152
|
-
if (matching) return matching;
|
|
153
|
-
|
|
154
|
-
fail(installed.length === 0
|
|
155
|
-
? `None of ${pkg.name}'s platform packages is installed (${pkg.platformPackages.join(", ")}). Reinstall ${pkg.name}.`
|
|
156
|
-
: `Several of ${pkg.name}'s platform packages are installed (${installed.map((p) => p.name).join(", ")}) and none matches ${process.platform}-${process.arch}. Reinstall ${pkg.name}.`);
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
/** The real program a command runs: on macOS and Linux its own file in bin/, once linked; on Windows the .exe beside it. */
|
|
160
|
-
function commandTarget(input) {
|
|
161
|
-
const suffix = process.platform === "win32" ? WINDOWS_EXECUTABLE_SUFFIX : "";
|
|
162
|
-
return join(input.packageDir, BIN_DIR, `${input.command}${suffix}`);
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
function installedJsonPath(packageDir) {
|
|
166
|
-
return join(packageDir, BIN_DIR, INSTALLED_JSON);
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
/**
|
|
170
|
-
* Whether the Windows commands are copies of the installed platform package's version. A launcher on Windows runs every
|
|
171
|
-
* time, since Windows runs a command through its .cmd shim rather than the file in bin/, so it sets up again only when
|
|
172
|
-
* this says the commands are stale: after an install or upgrade the package manager skipped this script for.
|
|
173
|
-
*/
|
|
174
|
-
function commandsAreCurrent(input) {
|
|
175
|
-
if (process.platform !== "win32") return false;
|
|
176
|
-
const pkg = readPackage(input.packageDir);
|
|
177
|
-
const platformPackage = currentPlatformPackage(pkg);
|
|
178
|
-
if (!pkg.commands.every((command) => existsSync(commandTarget({ packageDir: pkg.packageDir, command })))) return false;
|
|
179
|
-
|
|
180
|
-
try {
|
|
181
|
-
const installed = JSON.parse(readFileSync(installedJsonPath(pkg.packageDir), "utf-8"));
|
|
182
|
-
return installed.version === platformPackage.version;
|
|
183
|
-
} catch {
|
|
184
|
-
return false;
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
function temporaryPath(targetPath) {
|
|
189
|
-
return `${targetPath}.${process.pid}.${Date.now()}.tmp${process.platform === "win32" ? WINDOWS_EXECUTABLE_SUFFIX : ""}`;
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
function linkOrCopyFirstExecutable(sourcePath, targetPath) {
|
|
193
|
-
mkdirSync(dirname(targetPath), { recursive: true });
|
|
194
|
-
const tempPath = temporaryPath(targetPath);
|
|
195
|
-
rmSync(tempPath, { force: true });
|
|
196
|
-
|
|
197
|
-
try {
|
|
198
|
-
try {
|
|
199
|
-
linkSync(sourcePath, tempPath);
|
|
200
|
-
} catch {
|
|
201
|
-
copyFileSync(sourcePath, tempPath);
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
chmodSync(tempPath, 0o755);
|
|
205
|
-
rmSync(targetPath, { force: true });
|
|
206
|
-
renameSync(tempPath, targetPath);
|
|
207
|
-
} finally {
|
|
208
|
-
rmSync(tempPath, { force: true });
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
function hardLinkCommandTarget(sourcePath, targetPath) {
|
|
213
|
-
if (sourcePath === targetPath) return;
|
|
214
|
-
|
|
215
|
-
const tempPath = temporaryPath(targetPath);
|
|
216
|
-
rmSync(tempPath, { force: true });
|
|
217
|
-
|
|
218
|
-
try {
|
|
219
|
-
linkSync(sourcePath, tempPath);
|
|
220
|
-
chmodSync(tempPath, 0o755);
|
|
221
|
-
rmSync(targetPath, { force: true });
|
|
222
|
-
renameSync(tempPath, targetPath);
|
|
223
|
-
} finally {
|
|
224
|
-
rmSync(tempPath, { force: true });
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
/**
|
|
229
|
-
* Points every command at the installed platform package's program: on macOS and Linux each launcher in bin/ is
|
|
230
|
-
* replaced by a hard link to it, so later runs start the program directly; on Windows a .exe beside each launcher, with
|
|
231
|
-
* installed.json recording the version, unless the commands are already that version's.
|
|
232
|
-
*/
|
|
233
|
-
function linkCommands(pkg) {
|
|
234
|
-
const platformPackage = currentPlatformPackage(pkg);
|
|
235
|
-
if (commandsAreCurrent({ packageDir: pkg.packageDir })) return;
|
|
236
|
-
|
|
237
|
-
const firstTargetPath = commandTarget({ packageDir: pkg.packageDir, command: pkg.commands[0] });
|
|
238
|
-
linkOrCopyFirstExecutable(platformPackage.binaryPath, firstTargetPath);
|
|
239
|
-
|
|
240
|
-
for (const command of pkg.commands.slice(1)) {
|
|
241
|
-
hardLinkCommandTarget(firstTargetPath, commandTarget({ packageDir: pkg.packageDir, command }));
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
if (process.platform === "win32") {
|
|
245
|
-
writeFileSync(installedJsonPath(pkg.packageDir), `${JSON.stringify({ version: platformPackage.version }, null, 2)}\n`);
|
|
246
|
-
}
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
/* ------------------------------------------------------------------ Tab completion ---------- */
|
|
250
|
-
|
|
251
|
-
/**
|
|
252
|
-
* Asks each command built with Cli to set up Tab completion if the user's shell lacks it. The command decides everything
|
|
253
|
-
* (which shell, which file, whether this copy is the one the user's PATH runs, whether it was turned off) and says on
|
|
254
|
-
* stderr what it set up; its stdout is dropped, since the caller of the command the user typed may be reading this
|
|
255
|
-
* process's stdout.
|
|
256
|
-
*/
|
|
257
|
-
function setUpMissingCompletion(pkg) {
|
|
258
|
-
for (const command of pkg.completionCommands) {
|
|
259
|
-
const result = spawnSync(commandTarget({ packageDir: pkg.packageDir, command }), [SET_UP_MISSING_COMPLETION_FLAG], { stdio: ["ignore", "ignore", "inherit"] });
|
|
260
|
-
if (result.error) console.error(`Could not check Tab completion for ${command}: ${result.error.message}`);
|
|
261
|
-
}
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
/* ------------------------------------------------------------------ daemon registration ---------- */
|
|
265
|
-
|
|
266
|
-
/**
|
|
267
|
-
* Registering a package's daemons with the operating system so they start at login.
|
|
268
|
-
*
|
|
269
|
-
* As the user, not system-wide: a daemon here acts for one user, with access to that user's keychain, SSH agent and home
|
|
270
|
-
* directory, and a system-wide service would have none of those. On macOS and Windows it starts at login; on Linux at
|
|
271
|
-
* boot, because the user is made to linger (registerSystemd). On Windows that is a scheduled task rather than a service
|
|
272
|
-
* for the same reason: a service runs in session 0, isolated from the desktop the user is actually logged into.
|
|
273
|
-
*
|
|
274
|
-
* This runs here, in plain JavaScript, because it has to run on a machine that has only just received the package. The
|
|
275
|
-
* daemon binary cannot register itself: nothing has started it yet.
|
|
276
|
-
*/
|
|
277
|
-
|
|
278
|
-
function jiveHome() {
|
|
279
|
-
return join(homedir(), DAEMON_HOME_DIR);
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
function registryDir() {
|
|
283
|
-
return join(jiveHome(), DAEMON_REGISTRY_SUBDIR);
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
function logDir() {
|
|
287
|
-
return join(jiveHome(), DAEMON_LOG_SUBDIR);
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
function recordPath(id) {
|
|
291
|
-
return join(registryDir(), `${id}.json`);
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
/**
|
|
295
|
-
* The tree this copy of the package was installed into, which is where its daemons should work.
|
|
296
|
-
*
|
|
297
|
-
* Derived from the path rather than from INIT_CWD, which npm sets and Bun does not, and which answers the wrong question
|
|
298
|
-
* anyway: where the install was *typed*, not what it installed into. Walking out of the enclosing node_modules answers
|
|
299
|
-
* it for a project install and a global one alike, and a package with no node_modules above it (one built and installed
|
|
300
|
-
* in place) is its own root.
|
|
301
|
-
*/
|
|
302
|
-
function installRoot(pkg) {
|
|
303
|
-
let dir = pkg.packageDir;
|
|
304
|
-
while (true) {
|
|
305
|
-
if (basename(dir) === "node_modules") return dirname(dir);
|
|
306
|
-
const parent = dirname(dir);
|
|
307
|
-
if (parent === dir) return pkg.packageDir;
|
|
308
|
-
dir = parent;
|
|
309
|
-
}
|
|
310
|
-
}
|
|
311
|
-
|
|
312
|
-
/** One id segment: dots separate segments, so a dot inside a name cannot be left as one. */
|
|
313
|
-
function idSegment(value) {
|
|
314
|
-
return value.replace(/[^A-Za-z0-9-]+/g, "-");
|
|
315
|
-
}
|
|
316
|
-
|
|
317
|
-
/**
|
|
318
|
-
* Scope and name get a segment each, and an unscoped package gets "_" where its scope would be.
|
|
319
|
-
*
|
|
320
|
-
* Joining them with a dash instead would not be reversible: `@ozyman42/ozy-cli` and a package actually named
|
|
321
|
-
* `ozyman42-ozy-cli` would produce the same text. "_" is safe as the marker because npm forbids a scope or name from
|
|
322
|
-
* starting with it, so no real scope can collide with it.
|
|
323
|
-
*/
|
|
324
|
-
function packageSegments(packageName) {
|
|
325
|
-
if (!packageName.startsWith("@")) return ["_", idSegment(packageName)];
|
|
326
|
-
const separator = packageName.indexOf("/");
|
|
327
|
-
return [
|
|
328
|
-
idSegment(packageName.slice(1, separator)),
|
|
329
|
-
idSegment(packageName.slice(separator + 1)),
|
|
330
|
-
];
|
|
331
|
-
}
|
|
332
|
-
|
|
333
|
-
/**
|
|
334
|
-
* The id a registration is replaced at: the package's name, the daemon's name, and a digest of the directory this copy
|
|
335
|
-
* of the package was installed into.
|
|
336
|
-
*
|
|
337
|
-
* **Where the package is installed is what decides how many of its daemons exist.** Reinstalling or upgrading the same
|
|
338
|
-
* copy keeps the id, so the registration is replaced; a second copy installed somewhere else gets its own id, so each
|
|
339
|
-
* project that installs its own copy gets its own daemon and a globally installed copy gets exactly one.
|
|
340
|
-
*
|
|
341
|
-
* An earlier version had each daemon declare `local` or `global` in the manifest instead. That was a second source of
|
|
342
|
-
* truth that contradicted the real one: a `global` daemon installed into two projects registered once, pointing at
|
|
343
|
-
* whichever installed last, so uninstalling the second took the first project's daemon away, the very failure `local`
|
|
344
|
-
* existed to prevent.
|
|
345
|
-
*/
|
|
346
|
-
function daemonId(pkg, name) {
|
|
347
|
-
const [scope, packageName] = packageSegments(pkg.name);
|
|
348
|
-
const installDigest = createHash("sha256").update(pkg.packageDir).digest("hex").slice(0, 10);
|
|
349
|
-
return `${DAEMON_ID_PREFIX}.${scope}.${packageName}.${idSegment(name)}.${installDigest}`;
|
|
350
|
-
}
|
|
351
|
-
|
|
352
|
-
function run(argv, allowFailure) {
|
|
353
|
-
const result = spawnSync(argv[0], argv.slice(1), { stdio: ["ignore", "ignore", "pipe"] });
|
|
354
|
-
if (result.error || result.status !== 0) {
|
|
355
|
-
if (!allowFailure) {
|
|
356
|
-
const detail = result.error ? result.error.message : String(result.stderr || "").trim();
|
|
357
|
-
console.error(` ${argv.join(" ")} failed: ${detail}`);
|
|
358
|
-
}
|
|
359
|
-
return false;
|
|
360
|
-
}
|
|
361
|
-
return true;
|
|
362
|
-
}
|
|
363
|
-
|
|
364
|
-
function xmlEscape(value) {
|
|
365
|
-
return String(value)
|
|
366
|
-
.split("&").join("&")
|
|
367
|
-
.split("<").join("<")
|
|
368
|
-
.split(">").join(">");
|
|
369
|
-
}
|
|
370
|
-
|
|
371
|
-
/**
|
|
372
|
-
* launchd. KeepAlive on SuccessfulExit=false restarts a daemon that crashes but respects one that exits zero, which is
|
|
373
|
-
* how a daemon that has removed its own registration stays stopped.
|
|
374
|
-
*/
|
|
375
|
-
function registerLaunchd(input) {
|
|
376
|
-
const { id, executable, workingDirectory, logPath } = input;
|
|
377
|
-
// The id verbatim, rather than a reverse-DNS label: one string names this daemon on every platform.
|
|
378
|
-
const label = id;
|
|
379
|
-
const agentsDir = join(homedir(), "Library", "LaunchAgents");
|
|
380
|
-
const plistPath = join(agentsDir, `${label}.plist`);
|
|
381
|
-
const domain = `gui/${process.getuid()}`;
|
|
382
|
-
const unregister = ["launchctl", "bootout", `${domain}/${label}`];
|
|
383
|
-
|
|
384
|
-
mkdirSync(agentsDir, { recursive: true });
|
|
385
|
-
writeFileSync(plistPath, [
|
|
386
|
-
'<?xml version="1.0" encoding="UTF-8"?>',
|
|
387
|
-
'<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">',
|
|
388
|
-
'<plist version="1.0">',
|
|
389
|
-
"<dict>",
|
|
390
|
-
` <key>Label</key><string>${xmlEscape(label)}</string>`,
|
|
391
|
-
` <key>ProgramArguments</key><array><string>${xmlEscape(executable)}</string></array>`,
|
|
392
|
-
` <key>WorkingDirectory</key><string>${xmlEscape(workingDirectory)}</string>`,
|
|
393
|
-
" <key>RunAtLoad</key><true/>",
|
|
394
|
-
" <key>KeepAlive</key><dict><key>SuccessfulExit</key><false/></dict>",
|
|
395
|
-
` <key>StandardOutPath</key><string>${xmlEscape(logPath)}</string>`,
|
|
396
|
-
` <key>StandardErrorPath</key><string>${xmlEscape(logPath)}</string>`,
|
|
397
|
-
" <key>ProcessType</key><string>Background</string>",
|
|
398
|
-
"</dict>",
|
|
399
|
-
"</plist>",
|
|
400
|
-
"",
|
|
401
|
-
].join("\n"));
|
|
402
|
-
|
|
403
|
-
const start = () => {
|
|
404
|
-
// Booting out first: bootstrap refuses a label that is already loaded, and a reinstall is the common case. bootout
|
|
405
|
-
// returns before launchd has finished stopping a daemon that is running, and bootstrap is refused until it has
|
|
406
|
-
// ("Bootstrap failed: 5"), so a reinstall over a live daemon left it stopped until the next login. Retry for a few
|
|
407
|
-
// seconds; only the last failure is reported.
|
|
408
|
-
run(unregister, true);
|
|
409
|
-
const attempts = 20;
|
|
410
|
-
let started = false;
|
|
411
|
-
for (let attempt = 1; attempt <= attempts && !started; attempt++) {
|
|
412
|
-
if (attempt > 1) Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, 250);
|
|
413
|
-
started = run(["launchctl", "bootstrap", domain, plistPath], attempt < attempts);
|
|
414
|
-
}
|
|
415
|
-
return started;
|
|
416
|
-
};
|
|
417
|
-
return { kind: "launchd", unit: label, files: [plistPath], unregister, start };
|
|
418
|
-
}
|
|
419
|
-
|
|
420
|
-
/**
|
|
421
|
-
* systemd user units. `--user` rather than system units, for the same reason launchd gets a LaunchAgent.
|
|
422
|
-
*
|
|
423
|
-
* A user's systemd manager, and every unit in it, stops when their last session ends and starts again at their next
|
|
424
|
-
* login, unless the user lingers. On a server nobody stays logged in to, the daemons would be down most of the time, so
|
|
425
|
-
* the user is made to linger, which starts their manager at boot. systemd lets every user set their own (polkit's
|
|
426
|
-
* org.freedesktop.login1.set-self-linger), with no password. Removing a registration leaves lingering on: something
|
|
427
|
-
* else of the user's may rely on it, and it costs only their manager running.
|
|
428
|
-
*/
|
|
429
|
-
function registerSystemd(input) {
|
|
430
|
-
const { id, name, packageName, executable, workingDirectory, logPath } = input;
|
|
431
|
-
const unit = `${id}.service`;
|
|
432
|
-
const unitDir = join(process.env.XDG_CONFIG_HOME || join(homedir(), ".config"), "systemd", "user");
|
|
433
|
-
const unitPath = join(unitDir, unit);
|
|
434
|
-
const unregister = ["systemctl", "--user", "disable", "--now", unit];
|
|
435
|
-
|
|
436
|
-
mkdirSync(unitDir, { recursive: true });
|
|
437
|
-
writeFileSync(unitPath, [
|
|
438
|
-
"[Unit]",
|
|
439
|
-
`Description=Jive daemon ${name} for ${packageName}`,
|
|
440
|
-
"",
|
|
441
|
-
"[Service]",
|
|
442
|
-
"Type=simple",
|
|
443
|
-
`ExecStart=${executable}`,
|
|
444
|
-
`WorkingDirectory=${workingDirectory}`,
|
|
445
|
-
"Restart=on-failure",
|
|
446
|
-
"RestartSec=5",
|
|
447
|
-
`StandardOutput=append:${logPath}`,
|
|
448
|
-
`StandardError=append:${logPath}`,
|
|
449
|
-
"",
|
|
450
|
-
"[Install]",
|
|
451
|
-
"WantedBy=default.target",
|
|
452
|
-
"",
|
|
453
|
-
].join("\n"));
|
|
454
|
-
|
|
455
|
-
const start = () => {
|
|
456
|
-
if (!run(["loginctl", "enable-linger", "--no-ask-password"], false)) {
|
|
457
|
-
console.error(` ${unit} stops whenever you have no session open; \`sudo loginctl enable-linger ${userInfo().username}\` keeps it running`);
|
|
458
|
-
}
|
|
459
|
-
run(["systemctl", "--user", "daemon-reload"], true);
|
|
460
|
-
// Restart rather than `enable --now`, which leaves a running daemon on the executable it started from: after an
|
|
461
|
-
// upgrade that is the old version, held open after its file was replaced.
|
|
462
|
-
return run(["systemctl", "--user", "enable", unit], false)
|
|
463
|
-
&& run(["systemctl", "--user", "restart", unit], false);
|
|
464
|
-
};
|
|
465
|
-
return { kind: "systemd", unit, files: [unitPath], unregister, start };
|
|
466
|
-
}
|
|
467
|
-
|
|
468
|
-
/**
|
|
469
|
-
* Windows Task Scheduler, through a .cmd shim.
|
|
470
|
-
*
|
|
471
|
-
* The shim exists because schtasks can set neither a working directory nor environment variables, and it also supplies
|
|
472
|
-
* the restart-on-crash behaviour the other two platforms get from their service manager: an ONLOGON task starts its
|
|
473
|
-
* program once and does not watch it. The loop mirrors launchd's KeepAlive, so a daemon that exits zero after removing
|
|
474
|
-
* itself is not restarted.
|
|
475
|
-
*/
|
|
476
|
-
function registerScheduledTask(input) {
|
|
477
|
-
const { id, executable, workingDirectory, logPath } = input;
|
|
478
|
-
const taskName = id;
|
|
479
|
-
const shimPath = join(registryDir(), `${id}.cmd`);
|
|
480
|
-
const unregister = ["schtasks", "/Delete", "/F", "/TN", taskName];
|
|
481
|
-
|
|
482
|
-
writeFileSync(shimPath, [
|
|
483
|
-
"@echo off",
|
|
484
|
-
`cd /d "${workingDirectory}"`,
|
|
485
|
-
":jive_loop",
|
|
486
|
-
`"${executable}" >> "${logPath}" 2>&1`,
|
|
487
|
-
"if %ERRORLEVEL% EQU 0 goto :eof",
|
|
488
|
-
"timeout /t 5 /nobreak > nul",
|
|
489
|
-
"goto jive_loop",
|
|
490
|
-
"",
|
|
491
|
-
].join("\r\n"));
|
|
492
|
-
|
|
493
|
-
// An ONLOGON task waits for the next login, so it is also run now, as launchd and systemd start theirs.
|
|
494
|
-
const start = () => run([
|
|
495
|
-
"schtasks", "/Create", "/F",
|
|
496
|
-
"/SC", "ONLOGON",
|
|
497
|
-
"/TN", taskName,
|
|
498
|
-
"/TR", `"${shimPath}"`,
|
|
499
|
-
"/RL", "LIMITED",
|
|
500
|
-
], false) && run(["schtasks", "/Run", "/TN", taskName], false);
|
|
501
|
-
return { kind: "scheduled-task", unit: taskName, files: [shimPath], unregister, start };
|
|
502
|
-
}
|
|
503
|
-
|
|
504
|
-
const DAEMON_REGISTRARS = {
|
|
505
|
-
darwin: registerLaunchd,
|
|
506
|
-
linux: registerSystemd,
|
|
507
|
-
win32: registerScheduledTask,
|
|
508
|
-
};
|
|
509
|
-
|
|
510
|
-
function readRecord(path) {
|
|
511
|
-
try {
|
|
512
|
-
return JSON.parse(readFileSync(path, "utf-8"));
|
|
513
|
-
} catch {
|
|
514
|
-
return undefined;
|
|
515
|
-
}
|
|
516
|
-
}
|
|
517
|
-
|
|
518
|
-
function removeRegistration(record, reason) {
|
|
519
|
-
console.log(`Removing daemon ${record.id} (${reason})`);
|
|
520
|
-
if (Array.isArray(record.unregister) && record.unregister.length > 0) {
|
|
521
|
-
run(record.unregister, true);
|
|
522
|
-
}
|
|
523
|
-
for (const file of record.files || []) {
|
|
524
|
-
rmSync(file, { force: true });
|
|
525
|
-
}
|
|
526
|
-
}
|
|
527
|
-
|
|
528
|
-
/**
|
|
529
|
-
* Drops this package's registrations that should no longer exist.
|
|
530
|
-
*
|
|
531
|
-
* Three cases, all of which would otherwise leave the operating system starting a missing or unwanted executable at
|
|
532
|
-
* every login: a daemon this version of the package no longer has, a copy of the package whose directory is gone, and a
|
|
533
|
-
* registration of this very copy under an id we no longer use, which is what makes a change to the id scheme replace
|
|
534
|
-
* its registrations instead of doubling them.
|
|
535
|
-
*
|
|
536
|
-
* Only this package's own registrations are considered, by name, so another package's daemon is never touched; and only
|
|
537
|
-
* this copy's, except where the copy itself has been deleted.
|
|
538
|
-
*/
|
|
539
|
-
function pruneRemovedDaemons(pkg, currentIds) {
|
|
540
|
-
let entries;
|
|
541
|
-
try {
|
|
542
|
-
entries = readdirSync(registryDir());
|
|
543
|
-
} catch {
|
|
544
|
-
return;
|
|
545
|
-
}
|
|
546
|
-
|
|
547
|
-
for (const entry of entries) {
|
|
548
|
-
if (!entry.endsWith(".json")) continue;
|
|
549
|
-
const path = join(registryDir(), entry);
|
|
550
|
-
const record = readRecord(path);
|
|
551
|
-
if (!record || record.packageName !== pkg.name) continue;
|
|
552
|
-
|
|
553
|
-
const reason =
|
|
554
|
-
!pkg.daemons.includes(record.name) ? `no longer part of ${pkg.name}`
|
|
555
|
-
: !existsSync(record.packageDir) ? `${record.packageDir} is gone`
|
|
556
|
-
: record.packageDir === pkg.packageDir && !currentIds.includes(record.id) ? "superseded by a new id"
|
|
557
|
-
: undefined;
|
|
558
|
-
if (reason === undefined) continue;
|
|
559
|
-
|
|
560
|
-
removeRegistration(record, reason);
|
|
561
|
-
rmSync(path, { force: true });
|
|
562
|
-
}
|
|
563
|
-
}
|
|
564
|
-
|
|
565
|
-
function registerDaemons(pkg, repairOnly) {
|
|
566
|
-
// Two reasons not to register. The caller asked for repair alone: the local deploy does, because its install exists so
|
|
567
|
-
// the launcher can resolve a platform package, not because anyone chose to install that copy. Or this is a build
|
|
568
|
-
// agent, which installs a package to run one command and is then discarded: registering something to start at a login
|
|
569
|
-
// that will never happen is pure noise, and in a container it fails outright.
|
|
570
|
-
const skip = repairOnly ? `${REPAIR_ONLY_FLAG} was passed`
|
|
571
|
-
: process.env.CI ? "CI is set"
|
|
572
|
-
: undefined;
|
|
573
|
-
const names = skip === undefined ? pkg.daemons : [];
|
|
574
|
-
|
|
575
|
-
// Pruning first, and with no current ids when skipping: declining to run daemons here has to also take away any this
|
|
576
|
-
// copy registered earlier, or one such install would leave them starting at every login forever. Before the early
|
|
577
|
-
// return below, too: a version that drops its last daemon still has to take the previous version's registration away,
|
|
578
|
-
// and the record carries everything undoing it needs.
|
|
579
|
-
pruneRemovedDaemons(pkg, names.map((name) => daemonId(pkg, name)));
|
|
580
|
-
if (skip !== undefined) {
|
|
581
|
-
if (pkg.daemons.length > 0) console.log(`${skip}: not registering ${pkg.daemons.join(", ")}`);
|
|
582
|
-
return;
|
|
583
|
-
}
|
|
584
|
-
if (names.length === 0) return;
|
|
585
|
-
|
|
586
|
-
const registrar = DAEMON_REGISTRARS[process.platform];
|
|
587
|
-
if (!registrar) {
|
|
588
|
-
console.log(`No daemon support for ${process.platform}: ${names.join(", ")} will not start automatically`);
|
|
589
|
-
return;
|
|
590
|
-
}
|
|
591
|
-
|
|
592
|
-
mkdirSync(registryDir(), { recursive: true });
|
|
593
|
-
mkdirSync(logDir(), { recursive: true });
|
|
594
|
-
|
|
595
|
-
for (const name of names) {
|
|
596
|
-
const id = daemonId(pkg, name);
|
|
597
|
-
const path = recordPath(id);
|
|
598
|
-
const previous = readRecord(path);
|
|
599
|
-
const workingDirectory = installRoot(pkg);
|
|
600
|
-
const executable = commandTarget({ packageDir: pkg.packageDir, command: name });
|
|
601
|
-
const logPath = join(logDir(), `${id}.log`);
|
|
602
|
-
|
|
603
|
-
console.log(
|
|
604
|
-
`${previous ? "Replacing existing" : "Creating"} daemon ${id}`
|
|
605
|
-
+ ` (${name} from ${pkg.name}) in ${workingDirectory}`,
|
|
606
|
-
);
|
|
607
|
-
|
|
608
|
-
// The registrar writes its unit file and says how it will be loaded; the record goes down, whole, before the unit is
|
|
609
|
-
// loaded, because loading it starts the daemon, and the first thing the daemon does is read this file to find out
|
|
610
|
-
// how it was registered. Whole, so an install stopped at any point leaves either the previous record or this one,
|
|
611
|
-
// never one missing the kind and unit a listing command asks the platform about.
|
|
612
|
-
const registration = registrar({ id, name, packageName: pkg.name, executable, workingDirectory, logPath });
|
|
613
|
-
writeFileSync(path, `${JSON.stringify({
|
|
614
|
-
id,
|
|
615
|
-
name,
|
|
616
|
-
packageName: pkg.name,
|
|
617
|
-
packageDir: pkg.packageDir,
|
|
618
|
-
workingDirectory,
|
|
619
|
-
executable,
|
|
620
|
-
registeredAt: new Date().toISOString(),
|
|
621
|
-
searchPath: [...new Set((process.env.PATH || "").split(delimiter).filter(Boolean))].join(delimiter),
|
|
622
|
-
kind: registration.kind,
|
|
623
|
-
unit: registration.unit,
|
|
624
|
-
logPath,
|
|
625
|
-
files: [...registration.files, path],
|
|
626
|
-
unregister: registration.unregister,
|
|
627
|
-
}, null, 2)}\n`);
|
|
628
|
-
|
|
629
|
-
if (!registration.start()) {
|
|
630
|
-
console.error(` ${id} is registered but could not be started; it will start at your next login`);
|
|
631
|
-
}
|
|
632
|
-
}
|
|
633
|
-
}
|
|
634
|
-
|
|
635
|
-
/**
|
|
636
|
-
* Sets up the package at `packageDir`: links its commands to the installed platform package's program, registers its
|
|
637
|
-
* daemons (or, with `repairOnly`, removes this copy's registrations), and with `setUpCompletion` asks its completion
|
|
638
|
-
* commands to set up Tab completion.
|
|
639
|
-
*
|
|
640
|
-
* Every step replaces what an earlier run did rather than assuming it is the first: package.json's postinstall names
|
|
641
|
-
* this file, and a package manager may run it again at any later install (bun reruns a trusted folder dependency's on
|
|
642
|
-
* later global installs).
|
|
643
|
-
*/
|
|
644
|
-
function setUp(input) {
|
|
645
|
-
const pkg = readPackage(input.packageDir);
|
|
646
|
-
linkCommands(pkg);
|
|
647
|
-
registerDaemons(pkg, input.repairOnly);
|
|
648
|
-
if (input.setUpCompletion) setUpMissingCompletion(pkg);
|
|
649
|
-
}
|
|
650
|
-
|
|
651
|
-
// What a command's launcher in bin/ uses.
|
|
652
|
-
module.exports = {
|
|
653
|
-
COMPLETION_FLAGS,
|
|
654
|
-
commandTarget,
|
|
655
|
-
commandsAreCurrent,
|
|
656
|
-
setUp,
|
|
657
|
-
};
|
|
658
|
-
|
|
659
|
-
// Run as package.json's postinstall (`node ./postinstall.cjs`); a launcher only uses the exports above.
|
|
660
|
-
if (require.main === module) {
|
|
661
|
-
const repairOnly = process.argv.includes(REPAIR_ONLY_FLAG);
|
|
662
|
-
setUp({ packageDir: realpathSync(__dirname), repairOnly, setUpCompletion: !repairOnly });
|
|
663
|
-
}
|