@magland/mochi 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/README.md +108 -0
- package/dist/ansi.js +174 -0
- package/dist/api/admin.js +416 -0
- package/dist/api/auth.js +166 -0
- package/dist/api/backup.js +598 -0
- package/dist/api/ci.js +336 -0
- package/dist/api/contents.js +339 -0
- package/dist/api/issues.js +165 -0
- package/dist/api/pulls.js +244 -0
- package/dist/api/releases.js +83 -0
- package/dist/api/repos.js +156 -0
- package/dist/api/write.js +518 -0
- package/dist/api.js +326 -0
- package/dist/assets.js +29 -0
- package/dist/atom.js +32 -0
- package/dist/atomic.js +171 -0
- package/dist/avatar.js +81 -0
- package/dist/browse.js +630 -0
- package/dist/build-info.json +4 -0
- package/dist/ci/actionref.js +86 -0
- package/dist/ci/api.js +829 -0
- package/dist/ci/artifacts.js +201 -0
- package/dist/ci/dispatch.js +30 -0
- package/dist/ci/engine.js +1321 -0
- package/dist/ci/expr.js +526 -0
- package/dist/ci/manual.js +199 -0
- package/dist/ci/present.js +82 -0
- package/dist/ci/protocol.js +6 -0
- package/dist/ci/runners.js +256 -0
- package/dist/ci/runs.js +208 -0
- package/dist/ci/trigger.js +28 -0
- package/dist/ci/views.js +441 -0
- package/dist/ci/wake.js +194 -0
- package/dist/ci/web.js +617 -0
- package/dist/ci/workflow.js +436 -0
- package/dist/cli/admin-cmd.js +324 -0
- package/dist/cli/api-cmd.js +128 -0
- package/dist/cli/backup-cmd.js +1500 -0
- package/dist/cli/exit.js +69 -0
- package/dist/cli/input.js +64 -0
- package/dist/cli/issue-cmd.js +243 -0
- package/dist/cli/output.js +93 -0
- package/dist/cli/parse.js +317 -0
- package/dist/cli/pr-cmd.js +289 -0
- package/dist/cli/release-cmd.js +171 -0
- package/dist/cli/repo-cmd.js +763 -0
- package/dist/cli/repo.js +101 -0
- package/dist/cli/run-cmd.js +438 -0
- package/dist/cli/target.js +54 -0
- package/dist/cli-api.js +84 -0
- package/dist/compare.js +111 -0
- package/dist/config.js +212 -0
- package/dist/credentials.js +235 -0
- package/dist/deploy-cli.js +859 -0
- package/dist/deploy-runner-cli.js +592 -0
- package/dist/diff.js +171 -0
- package/dist/discussion.js +253 -0
- package/dist/egress.js +559 -0
- package/dist/filecache.js +68 -0
- package/dist/find.js +162 -0
- package/dist/forms.js +737 -0
- package/dist/git.js +547 -0
- package/dist/githttp.js +428 -0
- package/dist/html.js +87 -0
- package/dist/icons.js +101 -0
- package/dist/import-cli.js +316 -0
- package/dist/index.js +752 -0
- package/dist/issues.js +308 -0
- package/dist/issueweb.js +447 -0
- package/dist/job-cli.js +197 -0
- package/dist/jobtoken.js +96 -0
- package/dist/languages.js +383 -0
- package/dist/layout.js +100 -0
- package/dist/lfs.js +438 -0
- package/dist/lfsstore.js +425 -0
- package/dist/limit.js +259 -0
- package/dist/logo.js +61 -0
- package/dist/markdown.js +382 -0
- package/dist/migrate.js +334 -0
- package/dist/multipart.js +90 -0
- package/dist/ops.js +869 -0
- package/dist/pagescript.js +465 -0
- package/dist/perms.js +370 -0
- package/dist/pointer.js +55 -0
- package/dist/profile.js +106 -0
- package/dist/pulls.js +320 -0
- package/dist/pullweb.js +461 -0
- package/dist/redirects.js +455 -0
- package/dist/releases.js +435 -0
- package/dist/render.js +233 -0
- package/dist/runner/actions.js +448 -0
- package/dist/runner/client.js +428 -0
- package/dist/runner/context.js +247 -0
- package/dist/runner/docker.js +197 -0
- package/dist/runner/externals.js +175 -0
- package/dist/runner/job.js +290 -0
- package/dist/runner/manual-run.js +272 -0
- package/dist/runner/overrides.js +554 -0
- package/dist/runner/steps.js +571 -0
- package/dist/runner/wake.js +84 -0
- package/dist/runner-cli.js +405 -0
- package/dist/scan.js +231 -0
- package/dist/server.js +424 -0
- package/dist/session.js +267 -0
- package/dist/site.js +259 -0
- package/dist/siteshost.js +94 -0
- package/dist/source.js +90 -0
- package/dist/style.js +1295 -0
- package/dist/themes.js +369 -0
- package/dist/vault.js +442 -0
- package/dist/version.js +88 -0
- package/dist/views.js +1007 -0
- package/dist/web.js +182 -0
- package/dist/webops.js +1402 -0
- package/package.json +71 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2026 Jeremy Magland
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
# Mochi Forge
|
|
2
|
+
|
|
3
|
+
A self-hosted git forge, GitHub-shaped: repository browsing, in-browser editing, issues, pull requests, releases, Actions-style workflows, static sites, and Git LFS. One Node process, no database, nothing installed beside it but git.
|
|
4
|
+
|
|
5
|
+
Mochi Forge is usually shortened to *mochi*, which is how the command, the npm package, and the vault's own files are spelled.
|
|
6
|
+
|
|
7
|
+
Reading is anonymous, unless a repository is made private, in which case it is visible only to its collaborators, its collection's owners, and site admins. Every write is authorized by a token, and users are created by an administrator rather than registering themselves. Permissions are GitHub-shaped: a user owns the collection named after them, repositories take collaborators with read, write, or admin roles, and one site-admin bit runs the vault.
|
|
8
|
+
|
|
9
|
+
## Try it locally
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
mkdir myvault
|
|
13
|
+
npx @magland/mochi serve myvault
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
The server initializes the vault and prints an owner token once (only its hash is stored). Open http://127.0.0.1:3000, sign in at `/login` as `owner`, then push a repository in - the push creates it:
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
cd ~/some/project
|
|
20
|
+
git push http://127.0.0.1:3000/alice/myproject main # user 'owner', password the token
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Put it on the internet
|
|
24
|
+
|
|
25
|
+
With a [Fly.io](https://fly.io) account and flyctl installed, one command creates the app, the volume, and the machine:
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
npm install -g @magland/mochi
|
|
29
|
+
mochi deploy fly my-vault-name # -> https://my-vault-name.fly.dev
|
|
30
|
+
mochi login https://my-vault-name.fly.dev
|
|
31
|
+
mochi user add alice
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
The same command deploys updates. See [Deploying a vault](docs/deploying.md) for Docker, self-hosting, costs, and giving the vault a domain of your own.
|
|
35
|
+
|
|
36
|
+
## What it does
|
|
37
|
+
|
|
38
|
+
- **Browsing:** files at any ref, syntax highlighting, markdown with KaTeX, history, diffs, blame, compare, search, contributors, archives. Anonymous, apart from private repositories. A collection introduces itself with a profile README, from a `.mochi` repository in it.
|
|
39
|
+
- **Editing in the browser:** files, uploads, branches, tags, repositories, collections, forks, users. Controls a token cannot use are not shown.
|
|
40
|
+
- **Issues and pull requests,** stored as markdown in the vault. Merge or squash, refused on conflicts.
|
|
41
|
+
- **Releases** tied to a tag, with Atom feeds.
|
|
42
|
+
- **Workflows:** GitHub Actions workflows, planned by the server and run by a Docker runner you start elsewhere, including one deployed to Fly.io with a command, which stops when idle and is woken by the vault when a job is queued. A job marked `runs-on: manual` instead waits for a command you paste on a machine of your choosing, which shows the steps and asks before executing them.
|
|
43
|
+
- **Sites:** a static site per repository, sandboxed by default, optionally on its own hostname.
|
|
44
|
+
- **Git:** anonymous clone over smart HTTP for public repositories and authenticated clone for private ones, token-authenticated push including push-to-create, and LFS to S3 or to the vault.
|
|
45
|
+
- **CLI and JSON API** covering everything the web UI does, plus a generic `mochi api`. Built for scripts: `--json` everywhere, distinct exit codes, no prompts.
|
|
46
|
+
|
|
47
|
+
The frontend has no build step and no client framework: plain server-rendered HTML with a little vanilla JavaScript.
|
|
48
|
+
|
|
49
|
+
## The vault
|
|
50
|
+
|
|
51
|
+
A vault is one directory. Repositories are grouped into *collections*; a vault holds any number of them and knows nothing of any other vault.
|
|
52
|
+
|
|
53
|
+
```
|
|
54
|
+
<vault>/
|
|
55
|
+
vault.json users and hashed tokens
|
|
56
|
+
config.json vault settings
|
|
57
|
+
collections/
|
|
58
|
+
alice/
|
|
59
|
+
repos/
|
|
60
|
+
webapp.git/ bare repository
|
|
61
|
+
webapp.site/ its static site
|
|
62
|
+
webapp.issues/ .pulls/ .releases/ .runs/ .lfs/
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
No database, no state outside the directory. Backup is `cp -a`, migration is `rsync`, and `mochi backup <dir>` pulls the same copy over HTTP where you have no shell. The server reads disk on every request, so a running vault can be read and grepped with ordinary tools.
|
|
66
|
+
|
|
67
|
+
## Documentation
|
|
68
|
+
|
|
69
|
+
- [Getting started](docs/getting-started.md) - a local vault, a public one, and a domain of your own
|
|
70
|
+
- [The command line](docs/cli.md) - the `mochi` command and its subcommands
|
|
71
|
+
- [The vault](docs/vault.md) - the on-disk layout, tokens, and sessions
|
|
72
|
+
- [Deploying a vault](docs/deploying.md) | [Backing up a vault](docs/backup.md)
|
|
73
|
+
- [Workflows](docs/workflows.md) | [Sites](docs/sites.md) | [Git LFS](docs/lfs.md) | [Themes](docs/themes.md) | [Issues and pull requests](docs/issues-and-pull-requests.md)
|
|
74
|
+
- [The JSON API](docs/api.md) - every route, body, and response
|
|
75
|
+
- [Mochi Forge for an agent](docs/agents.md) - short enough to paste into a context window
|
|
76
|
+
|
|
77
|
+
## Using a vault from Claude Code
|
|
78
|
+
|
|
79
|
+
[mochi-skill](https://github.com/magland/mochi-skill) teaches an agent this CLI the way it already knows `gh`.
|
|
80
|
+
|
|
81
|
+
```
|
|
82
|
+
/plugin marketplace add magland/mochi-skill
|
|
83
|
+
/plugin install mochi@mochi-skill
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
The agent needs `mochi` on its PATH and either `MOCHI_HOST`/`MOCHI_TOKEN` or a completed `mochi login`.
|
|
87
|
+
|
|
88
|
+
## Development
|
|
89
|
+
|
|
90
|
+
```bash
|
|
91
|
+
npm install
|
|
92
|
+
npm run example # creates example-root/ with sample data and a dev user
|
|
93
|
+
npm run dev # serves example-root/ at http://127.0.0.1:3000
|
|
94
|
+
npm run test:unit # the pure modules, in milliseconds
|
|
95
|
+
npm run smoke # end to end; npm run smoke:slow adds containerized workflow jobs
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
The example vault has site admin `dev` with token `mochi_example_dev_token` (example vault only) and plain user `reader` with `mochi_example_reader_token`.
|
|
99
|
+
|
|
100
|
+
## Roadmap
|
|
101
|
+
|
|
102
|
+
- Secrets, and widening the per-job token (today it grants read for the clone, private repositories included) so a workflow can push to its own repository and call the API
|
|
103
|
+
- `actions/cache`
|
|
104
|
+
- Docker actions, `container:` jobs, and service containers
|
|
105
|
+
|
|
106
|
+
## License
|
|
107
|
+
|
|
108
|
+
Apache License 2.0. See [LICENSE](LICENSE).
|
package/dist/ansi.js
ADDED
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.stripAnsi = stripAnsi;
|
|
4
|
+
exports.ansiLineHtml = ansiLineHtml;
|
|
5
|
+
const render_1 = require("./render");
|
|
6
|
+
const DEFAULT = { bold: false, dim: false, italic: false, underline: false, fgClass: null, fgColor: null };
|
|
7
|
+
// Each class resolves to an --ansi-* token the active theme defines (see
|
|
8
|
+
// themes.ts), so a dark theme brightens the palette and a light one darkens
|
|
9
|
+
// it, like every other colour in the interface.
|
|
10
|
+
const FG_CLASS = {
|
|
11
|
+
30: 'a-blk', 31: 'a-red', 32: 'a-grn', 33: 'a-yel',
|
|
12
|
+
34: 'a-blu', 35: 'a-mag', 36: 'a-cyn', 37: 'a-wht',
|
|
13
|
+
90: 'a-bblk', 91: 'a-bred', 92: 'a-bgrn', 93: 'a-byel',
|
|
14
|
+
94: 'a-bblu', 95: 'a-bmag', 96: 'a-bcyn', 97: 'a-bwht',
|
|
15
|
+
};
|
|
16
|
+
/** The 6x6x6 cube's channel values, per xterm. */
|
|
17
|
+
const CUBE = [0, 95, 135, 175, 215, 255];
|
|
18
|
+
/**
|
|
19
|
+
* A 256-colour or truecolour foreground as inline CSS, pulled towards the
|
|
20
|
+
* middle when it sits at either extreme: near-white is invisible on a light
|
|
21
|
+
* theme and near-black on a dark one, and a log has to be readable on both.
|
|
22
|
+
*/
|
|
23
|
+
function inlineColor(r, g, b) {
|
|
24
|
+
const l = (0.299 * r + 0.587 * g + 0.114 * b) / 255;
|
|
25
|
+
if (l > 0.82 || l < 0.18)
|
|
26
|
+
return 'var(--fg-muted, #6e7781)';
|
|
27
|
+
return `rgb(${r},${g},${b})`;
|
|
28
|
+
}
|
|
29
|
+
function color256(n) {
|
|
30
|
+
if (n < 0 || n > 255)
|
|
31
|
+
return null;
|
|
32
|
+
if (n < 8)
|
|
33
|
+
return null; // caller maps to the classed palette
|
|
34
|
+
if (n < 16)
|
|
35
|
+
return null;
|
|
36
|
+
if (n < 232) {
|
|
37
|
+
const c = n - 16;
|
|
38
|
+
return inlineColor(CUBE[Math.floor(c / 36)], CUBE[Math.floor(c / 6) % 6], CUBE[c % 6]);
|
|
39
|
+
}
|
|
40
|
+
const v = 8 + (n - 232) * 10;
|
|
41
|
+
return inlineColor(v, v, v);
|
|
42
|
+
}
|
|
43
|
+
/** Apply one SGR parameter list to a style, consuming extended-colour params. */
|
|
44
|
+
function applySgr(params, style) {
|
|
45
|
+
const s = { ...style };
|
|
46
|
+
for (let i = 0; i < params.length; i++) {
|
|
47
|
+
const p = params[i];
|
|
48
|
+
if (p === 0)
|
|
49
|
+
Object.assign(s, DEFAULT);
|
|
50
|
+
else if (p === 1)
|
|
51
|
+
s.bold = true;
|
|
52
|
+
else if (p === 2)
|
|
53
|
+
s.dim = true;
|
|
54
|
+
else if (p === 3)
|
|
55
|
+
s.italic = true;
|
|
56
|
+
else if (p === 4)
|
|
57
|
+
s.underline = true;
|
|
58
|
+
else if (p === 22) {
|
|
59
|
+
s.bold = false;
|
|
60
|
+
s.dim = false;
|
|
61
|
+
}
|
|
62
|
+
else if (p === 23)
|
|
63
|
+
s.italic = false;
|
|
64
|
+
else if (p === 24)
|
|
65
|
+
s.underline = false;
|
|
66
|
+
else if (p === 39) {
|
|
67
|
+
s.fgClass = null;
|
|
68
|
+
s.fgColor = null;
|
|
69
|
+
}
|
|
70
|
+
else if (FG_CLASS[p]) {
|
|
71
|
+
s.fgClass = FG_CLASS[p];
|
|
72
|
+
s.fgColor = null;
|
|
73
|
+
}
|
|
74
|
+
else if (p === 38 || p === 48) {
|
|
75
|
+
// Extended colour; 48 (background) consumes its params and is dropped.
|
|
76
|
+
const mode = params[i + 1];
|
|
77
|
+
if (mode === 5) {
|
|
78
|
+
const n = params[i + 2] ?? -1;
|
|
79
|
+
if (p === 38) {
|
|
80
|
+
if (n >= 0 && n < 8) {
|
|
81
|
+
s.fgClass = FG_CLASS[30 + n];
|
|
82
|
+
s.fgColor = null;
|
|
83
|
+
}
|
|
84
|
+
else if (n >= 8 && n < 16) {
|
|
85
|
+
s.fgClass = FG_CLASS[90 + (n - 8)];
|
|
86
|
+
s.fgColor = null;
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
const c = color256(n);
|
|
90
|
+
if (c) {
|
|
91
|
+
s.fgColor = c;
|
|
92
|
+
s.fgClass = null;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
i += 2;
|
|
97
|
+
}
|
|
98
|
+
else if (mode === 2) {
|
|
99
|
+
if (p === 38) {
|
|
100
|
+
s.fgColor = inlineColor(params[i + 2] ?? 0, params[i + 3] ?? 0, params[i + 4] ?? 0);
|
|
101
|
+
s.fgClass = null;
|
|
102
|
+
}
|
|
103
|
+
i += 4;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
// 40-47, 100-107 backgrounds and everything else: dropped.
|
|
107
|
+
}
|
|
108
|
+
return s;
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* A terminal shows a line with carriage returns in it as whatever was written
|
|
112
|
+
* after the last one, so that is what the reader gets: `50%\r100%` is `100%`,
|
|
113
|
+
* and a line that ends mid-rewrite falls back to its last non-empty state.
|
|
114
|
+
*/
|
|
115
|
+
function resolveCr(line) {
|
|
116
|
+
if (!line.includes('\r'))
|
|
117
|
+
return line;
|
|
118
|
+
const parts = line.split('\r');
|
|
119
|
+
for (let i = parts.length - 1; i >= 0; i--) {
|
|
120
|
+
if (parts[i] !== '')
|
|
121
|
+
return parts[i];
|
|
122
|
+
}
|
|
123
|
+
return '';
|
|
124
|
+
}
|
|
125
|
+
// SGR is captured; every other escape -- cursor movement, OSC titles, stray
|
|
126
|
+
// escapes -- matches an uncaptured alternative and is dropped.
|
|
127
|
+
const TOKEN = /\x1b\[([0-9;]*)m|\x1b\][^\x07\x1b]*(?:\x07|\x1b\\)?|\x1b\[[0-9;?]*[A-Za-z]|\x1b./g;
|
|
128
|
+
/** The line with every escape sequence removed and carriage returns resolved: what a live tail appends as text. */
|
|
129
|
+
function stripAnsi(line) {
|
|
130
|
+
return resolveCr(line).replace(TOKEN, '');
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* The line as HTML: text escaped, SGR styling as spans. The classes and the
|
|
134
|
+
* clamped inline colours are the only markup that can come out of it, whatever
|
|
135
|
+
* bytes a job wrote.
|
|
136
|
+
*/
|
|
137
|
+
function ansiLineHtml(line) {
|
|
138
|
+
const resolved = resolveCr(line);
|
|
139
|
+
if (!resolved.includes('\x1b'))
|
|
140
|
+
return (0, render_1.esc)(resolved);
|
|
141
|
+
let out = '';
|
|
142
|
+
let style = { ...DEFAULT };
|
|
143
|
+
let last = 0;
|
|
144
|
+
const emit = (text) => {
|
|
145
|
+
if (text === '')
|
|
146
|
+
return;
|
|
147
|
+
const classes = [
|
|
148
|
+
style.fgClass,
|
|
149
|
+
style.bold ? 'a-b' : null,
|
|
150
|
+
style.dim ? 'a-d' : null,
|
|
151
|
+
style.italic ? 'a-i' : null,
|
|
152
|
+
style.underline ? 'a-u' : null,
|
|
153
|
+
].filter((c) => c !== null);
|
|
154
|
+
const styled = classes.length > 0 || style.fgColor !== null;
|
|
155
|
+
if (!styled) {
|
|
156
|
+
out += (0, render_1.esc)(text);
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
const cls = classes.length ? ` class="${classes.join(' ')}"` : '';
|
|
160
|
+
const inline = style.fgColor ? ` style="color:${style.fgColor}"` : '';
|
|
161
|
+
out += `<span${cls}${inline}>${(0, render_1.esc)(text)}</span>`;
|
|
162
|
+
};
|
|
163
|
+
TOKEN.lastIndex = 0;
|
|
164
|
+
for (let m = TOKEN.exec(resolved); m !== null; m = TOKEN.exec(resolved)) {
|
|
165
|
+
emit(resolved.slice(last, m.index));
|
|
166
|
+
last = m.index + m[0].length;
|
|
167
|
+
if (m[1] !== undefined) {
|
|
168
|
+
const params = m[1] === '' ? [0] : m[1].split(';').map((x) => (x === '' ? 0 : parseInt(x, 10)));
|
|
169
|
+
style = applySgr(params, style);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
emit(resolved.slice(last));
|
|
173
|
+
return out;
|
|
174
|
+
}
|