@fapost/jig-ui 0.0.0-stage → 0.1.0-next.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 +21 -0
- package/dist/args.js +32 -0
- package/dist/cli.js +18 -0
- package/dist/http/app.js +45 -0
- package/dist/main.js +47 -0
- package/dist/node-version.js +14 -0
- package/package.json +35 -4
- package/README.md +0 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Alexander Zinchenko
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/dist/args.js
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { parseArgs } from 'node:util';
|
|
2
|
+
export const DEFAULT_PORT = 4870;
|
|
3
|
+
/** Parses the command line (without the node and script entries). Pure: it never exits or prints. */
|
|
4
|
+
export function parseCliArgs(argv) {
|
|
5
|
+
let values;
|
|
6
|
+
try {
|
|
7
|
+
({ values } = parseArgs({
|
|
8
|
+
args: argv,
|
|
9
|
+
strict: true,
|
|
10
|
+
allowPositionals: false,
|
|
11
|
+
options: {
|
|
12
|
+
port: { type: 'string' },
|
|
13
|
+
help: { type: 'boolean', short: 'h' },
|
|
14
|
+
version: { type: 'boolean', short: 'v' },
|
|
15
|
+
},
|
|
16
|
+
}));
|
|
17
|
+
}
|
|
18
|
+
catch (error) {
|
|
19
|
+
return { kind: 'error', message: error instanceof Error ? error.message : String(error) };
|
|
20
|
+
}
|
|
21
|
+
if (values.help)
|
|
22
|
+
return { kind: 'help' };
|
|
23
|
+
if (values.version)
|
|
24
|
+
return { kind: 'version' };
|
|
25
|
+
if (values.port === undefined)
|
|
26
|
+
return { kind: 'run', port: DEFAULT_PORT };
|
|
27
|
+
const port = /^\d+$/.test(values.port) ? Number(values.port) : Number.NaN;
|
|
28
|
+
if (!Number.isInteger(port) || port < 1 || port > 65535) {
|
|
29
|
+
return { kind: 'error', message: `Invalid --port value: ${values.port}. Use a number from 1 to 65535.` };
|
|
30
|
+
}
|
|
31
|
+
return { kind: 'run', port };
|
|
32
|
+
}
|
package/dist/cli.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// Entry point. It must parse and run on any Node.js, so that an old one gets a clear message
|
|
3
|
+
// instead of a syntax error: no dependencies are imported here, and the real program is loaded
|
|
4
|
+
// only after the version check.
|
|
5
|
+
import { checkNodeVersion } from './node-version.js';
|
|
6
|
+
const nodeCheck = checkNodeVersion(process.versions.node);
|
|
7
|
+
if (!nodeCheck.ok) {
|
|
8
|
+
console.error(nodeCheck.message);
|
|
9
|
+
process.exit(1);
|
|
10
|
+
}
|
|
11
|
+
else {
|
|
12
|
+
import('./main.js')
|
|
13
|
+
.then((m) => m.main())
|
|
14
|
+
.catch((error) => {
|
|
15
|
+
console.error(error instanceof Error ? error.message : String(error));
|
|
16
|
+
process.exit(1);
|
|
17
|
+
});
|
|
18
|
+
}
|
package/dist/http/app.js
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { readFileSync } from 'node:fs';
|
|
2
|
+
import { Hono } from 'hono';
|
|
3
|
+
/**
|
|
4
|
+
* Reads the version from the package's own package.json. The relative path is the same from
|
|
5
|
+
* `server/http/` (tests) and `dist/http/` (published), as both sit two levels below the root.
|
|
6
|
+
*/
|
|
7
|
+
export function readPackageVersion() {
|
|
8
|
+
const url = new URL('../../package.json', import.meta.url);
|
|
9
|
+
const pkg = JSON.parse(readFileSync(url, 'utf8'));
|
|
10
|
+
return pkg.version;
|
|
11
|
+
}
|
|
12
|
+
/** Refuses requests whose `Host` or `Origin` is not this server's own loopback address. */
|
|
13
|
+
export function localOnly(port) {
|
|
14
|
+
const hosts = new Set([`127.0.0.1:${port}`, `localhost:${port}`]);
|
|
15
|
+
const origins = new Set([`http://127.0.0.1:${port}`, `http://localhost:${port}`]);
|
|
16
|
+
return async (c, next) => {
|
|
17
|
+
const host = c.req.header('host');
|
|
18
|
+
const origin = c.req.header('origin');
|
|
19
|
+
if (host === undefined || !hosts.has(host.toLowerCase())) {
|
|
20
|
+
return c.text('Forbidden', 403);
|
|
21
|
+
}
|
|
22
|
+
if (origin !== undefined && !origins.has(origin.toLowerCase())) {
|
|
23
|
+
return c.text('Forbidden', 403);
|
|
24
|
+
}
|
|
25
|
+
await next();
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
export function createApp({ port, version = readPackageVersion() }) {
|
|
29
|
+
const app = new Hono();
|
|
30
|
+
app.use(localOnly(port));
|
|
31
|
+
app.get('/', (c) => c.html(`<!doctype html>
|
|
32
|
+
<html lang="en">
|
|
33
|
+
<head>
|
|
34
|
+
<meta charset="utf-8" />
|
|
35
|
+
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
36
|
+
<title>Jig UI</title>
|
|
37
|
+
</head>
|
|
38
|
+
<body>
|
|
39
|
+
<h1>Jig UI — not built yet</h1>
|
|
40
|
+
<p>Version ${version}</p>
|
|
41
|
+
</body>
|
|
42
|
+
</html>
|
|
43
|
+
`));
|
|
44
|
+
return app;
|
|
45
|
+
}
|
package/dist/main.js
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { serve } from '@hono/node-server';
|
|
2
|
+
import { parseCliArgs } from './args.js';
|
|
3
|
+
import { createApp, readPackageVersion } from './http/app.js';
|
|
4
|
+
const HOST = '127.0.0.1';
|
|
5
|
+
const HELP = `Usage: jig-ui [options]
|
|
6
|
+
|
|
7
|
+
Options:
|
|
8
|
+
--port <n> Port to listen on (default 4870)
|
|
9
|
+
-v, --version Print the version and exit
|
|
10
|
+
-h, --help Print this help and exit
|
|
11
|
+
`;
|
|
12
|
+
function fail(message) {
|
|
13
|
+
console.error(message);
|
|
14
|
+
process.exit(1);
|
|
15
|
+
}
|
|
16
|
+
export function main() {
|
|
17
|
+
const command = parseCliArgs(process.argv.slice(2));
|
|
18
|
+
if (command.kind === 'error')
|
|
19
|
+
fail(command.message);
|
|
20
|
+
if (command.kind === 'help') {
|
|
21
|
+
process.stdout.write(HELP);
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
if (command.kind === 'version') {
|
|
25
|
+
console.log(readPackageVersion());
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
const { port } = command;
|
|
29
|
+
const version = readPackageVersion();
|
|
30
|
+
const server = serve({ fetch: createApp({ port, version }).fetch, hostname: HOST, port }, () => {
|
|
31
|
+
console.log(`Jig UI ${version} is running at http://${HOST}:${port}/`);
|
|
32
|
+
console.log('Press Ctrl+C to stop.');
|
|
33
|
+
});
|
|
34
|
+
server.on('error', (error) => {
|
|
35
|
+
if (error.code === 'EADDRINUSE') {
|
|
36
|
+
fail(`Port ${port} is already in use. Stop the other process or choose another port with --port.`);
|
|
37
|
+
}
|
|
38
|
+
fail(`Could not start the server: ${error.message}`);
|
|
39
|
+
});
|
|
40
|
+
const shutdown = () => {
|
|
41
|
+
server.close(() => process.exit(0));
|
|
42
|
+
if ('closeAllConnections' in server)
|
|
43
|
+
server.closeAllConnections();
|
|
44
|
+
};
|
|
45
|
+
process.on('SIGINT', shutdown);
|
|
46
|
+
process.on('SIGTERM', shutdown);
|
|
47
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// This module is imported by the CLI entry before anything else, so it must parse on old Node.js.
|
|
2
|
+
export const MINIMUM_NODE_MAJOR = 24;
|
|
3
|
+
/** Checks a Node.js version string such as `v24.1.0` or `24.1.0` against the supported minimum. */
|
|
4
|
+
export function checkNodeVersion(version) {
|
|
5
|
+
const major = Number.parseInt(version.replace(/^v/, '').split('.')[0] || '', 10);
|
|
6
|
+
if (Number.isInteger(major) && major >= MINIMUM_NODE_MAJOR) {
|
|
7
|
+
return { ok: true };
|
|
8
|
+
}
|
|
9
|
+
return {
|
|
10
|
+
ok: false,
|
|
11
|
+
message: 'Jig UI needs Node.js ' + MINIMUM_NODE_MAJOR + ' or later, but this is ' + version +
|
|
12
|
+
'. Install a newer Node.js and run it again.',
|
|
13
|
+
};
|
|
14
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,37 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fapost/jig-ui",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0-next.1",
|
|
4
|
+
"description": "A local web interface for Jig, the agent SDLC framework.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"bin": {
|
|
8
|
+
"jig-ui": "dist/cli.js"
|
|
9
|
+
},
|
|
10
|
+
"files": [
|
|
11
|
+
"dist"
|
|
12
|
+
],
|
|
13
|
+
"engines": {
|
|
14
|
+
"node": ">=24"
|
|
15
|
+
},
|
|
16
|
+
"publishConfig": {
|
|
17
|
+
"access": "public"
|
|
18
|
+
},
|
|
19
|
+
"repository": {
|
|
20
|
+
"type": "git",
|
|
21
|
+
"url": "git+https://github.com/fapost-lab/jig-ui.git"
|
|
22
|
+
},
|
|
23
|
+
"scripts": {
|
|
24
|
+
"build": "tsc -p tsconfig.build.json",
|
|
25
|
+
"typecheck": "tsc --noEmit",
|
|
26
|
+
"test": "vitest run"
|
|
27
|
+
},
|
|
28
|
+
"dependencies": {
|
|
29
|
+
"@hono/node-server": "^2.1.5",
|
|
30
|
+
"hono": "^4.13.13"
|
|
31
|
+
},
|
|
32
|
+
"devDependencies": {
|
|
33
|
+
"@types/node": "^24.19.2",
|
|
34
|
+
"typescript": "^7.0.2",
|
|
35
|
+
"vitest": "^5.0.4"
|
|
36
|
+
}
|
|
37
|
+
}
|
package/README.md
DELETED