angine 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +17 -0
- package/LICENSE +21 -0
- package/README.md +138 -2
- package/dist/bin/angine.d.ts +2 -0
- package/dist/bin/angine.js +85 -0
- package/dist/bin/angine.js.map +1 -0
- package/dist/src/config.d.ts +1 -0
- package/dist/src/config.js +24 -0
- package/dist/src/config.js.map +1 -0
- package/dist/src/daemon.d.ts +1 -0
- package/dist/src/daemon.js +227 -0
- package/dist/src/daemon.js.map +1 -0
- package/dist/src/dashboard.d.ts +4 -0
- package/dist/src/dashboard.js +61 -0
- package/dist/src/dashboard.js.map +1 -0
- package/dist/src/health.d.ts +13 -0
- package/dist/src/health.js +66 -0
- package/dist/src/health.js.map +1 -0
- package/dist/src/hierarchy.d.ts +7 -0
- package/dist/src/hierarchy.js +41 -0
- package/dist/src/hierarchy.js.map +1 -0
- package/dist/src/identity.d.ts +3 -0
- package/dist/src/identity.js +12 -0
- package/dist/src/identity.js.map +1 -0
- package/dist/src/ipc.d.ts +5 -0
- package/dist/src/ipc.js +101 -0
- package/dist/src/ipc.js.map +1 -0
- package/dist/src/mcp.d.ts +1 -0
- package/dist/src/mcp.js +85 -0
- package/dist/src/mcp.js.map +1 -0
- package/dist/src/model.d.ts +13 -0
- package/dist/src/model.js +76 -0
- package/dist/src/model.js.map +1 -0
- package/dist/src/paths.d.ts +7 -0
- package/dist/src/paths.js +12 -0
- package/dist/src/paths.js.map +1 -0
- package/dist/src/reporting.d.ts +21 -0
- package/dist/src/reporting.js +51 -0
- package/dist/src/reporting.js.map +1 -0
- package/dist/src/setup.d.ts +15 -0
- package/dist/src/setup.js +220 -0
- package/dist/src/setup.js.map +1 -0
- package/dist/src/store.d.ts +24 -0
- package/dist/src/store.js +384 -0
- package/dist/src/store.js.map +1 -0
- package/dist/src/types.d.ts +204 -0
- package/dist/src/types.js +2 -0
- package/dist/src/types.js.map +1 -0
- package/dist/src/workflow.d.ts +4 -0
- package/dist/src/workflow.js +21 -0
- package/dist/src/workflow.js.map +1 -0
- package/docs/protocol.md +142 -0
- package/docs/releases/v0.1.0.md +15 -0
- package/docs/releasing.md +58 -0
- package/package.json +59 -4
- package/ui/dist/assets/index-CKFeQsCF.js +1 -0
- package/ui/dist/assets/index-ClFH-l-k.css +1 -0
- package/ui/dist/favicon.svg +4 -0
- package/ui/dist/index.html +4 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# Release notes
|
|
2
|
+
|
|
3
|
+
## 0.1.0 — Initial local MVP
|
|
4
|
+
|
|
5
|
+
- Project → Missions → Tasks, with workspace grouping, mission pages and filters, and automatic migration preserving IDs/history.
|
|
6
|
+
- Agent-reported mission plans and task updates over MCP, CLI, and local HTTP.
|
|
7
|
+
- Setup integration for Codex and Claude Code, with automatic server startup on reporting.
|
|
8
|
+
- Project and task pages, status lists, progress, and independently scrolling board columns.
|
|
9
|
+
- Agent/profile/project filtering, saved filters, stale indicators, and configurable browser alerts.
|
|
10
|
+
- Profiles, reported sessions and child-agent IDs, shared projects, related tasks, and blocker details.
|
|
11
|
+
- Archive/restore controls that preserve local history.
|
|
12
|
+
- Metadata persistence, input validation, token-protected HTTP reporting, and same-origin dashboard edits.
|
|
13
|
+
- A restart command for loading server updates, with proactive UI/server compatibility notices.
|
|
14
|
+
- MCP reporter heartbeat, connection check, accepted/rejected report diagnostics, and a compact needs-attention summary.
|
|
15
|
+
- Expandable connection instructions and secondary filters to keep the main views concise.
|
|
16
|
+
|
|
17
|
+
This version depends on agents reporting their work. Shared team hosting, Wi-Fi/mobile access, independent observation, and alerts with no open dashboard tab are future work.
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Angine contributors
|
|
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/README.md
CHANGED
|
@@ -1,3 +1,139 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Angine
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
**Follow your agents’ work.**
|
|
4
|
+
|
|
5
|
+
Angine is a local dashboard for **agent-reported work**. Connected agents send project missions, task updates, progress, and blockers while they work. You follow their work in one place instead of manually maintaining a status board.
|
|
6
|
+
|
|
7
|
+
**v0.1.0 is an early local MVP.** Angine relies on reports from connected agents; it does not independently observe their tool calls, file changes, or transcripts.
|
|
8
|
+
|
|
9
|
+
## Quick start
|
|
10
|
+
|
|
11
|
+
Requires Node.js 20 or later and a supported agent CLI installed locally.
|
|
12
|
+
|
|
13
|
+
Once the package is published to npm:
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
npm install -g angine
|
|
17
|
+
angine setup
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
To try the source checkout before publication:
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
npm install
|
|
24
|
+
npm install -g .
|
|
25
|
+
angine setup
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
`angine setup` configures detected Codex and Claude Code CLIs, starts the Angine server, and opens the dashboard. Restart your agent sessions after setup so they load the integration. You can configure just one with `angine setup codex` or `angine setup claude`.
|
|
29
|
+
|
|
30
|
+
Installing the package alone does not start Angine or configure an agent. After setup, agent reports start the server automatically when needed. Run `angine` anytime to reopen the dashboard.
|
|
31
|
+
|
|
32
|
+
## How it works
|
|
33
|
+
|
|
34
|
+
1. Setup registers a local MCP reporter and adds instructions telling the agent when to report.
|
|
35
|
+
2. The agent registers a mission with `sync_project`, using stable project, mission, and task keys.
|
|
36
|
+
3. It sends meaningful status changes with `update_tasks`.
|
|
37
|
+
4. The dashboard receives updates and shows the reported work live.
|
|
38
|
+
|
|
39
|
+
Angine collects short metadata: titles, statuses, progress, notes, timestamps, and optional reporter identity. Reports must not contain prompts, reasoning, source code, diffs, commands, terminal output, credentials, or environment variables. Angine does not read those sources itself. Reporting quality depends on the agent following the reporting instructions.
|
|
40
|
+
|
|
41
|
+
## Included in the MVP
|
|
42
|
+
|
|
43
|
+
- **Projects:** one container per local workspace, showing mission counts, running work, agents, and attention needed.
|
|
44
|
+
- **Missions:** goals within a project, grouped by status, with task completion percentages and separately scrolling sections.
|
|
45
|
+
- **Tasks:** status groups, reported progress, project and mission filters, and dedicated detail pages.
|
|
46
|
+
- **Board:** status columns with independent vertical scrolling.
|
|
47
|
+
- **Filters:** search, agent, profile, project, mission, status, and stale activity; saved separately for each view in your browser.
|
|
48
|
+
- **Connection health:** automatic MCP reporter heartbeats, accepted/rejected report counts, a connection check tool, and explicit server update notices.
|
|
49
|
+
- **Needs attention:** a compact summary of blocked, failed, stale, and tracked disconnected work; detailed diagnostics stay expandable.
|
|
50
|
+
- **Agents and sessions:** editable profiles, reporter sessions, supplied native session IDs, and parent/child links when IDs are reported.
|
|
51
|
+
- **Related work:** agents can share a project and mission, and link related tasks within that mission.
|
|
52
|
+
- **Blockers:** reason, next action, and optional owner.
|
|
53
|
+
- **Archive:** hide projects or individual missions and restore them without deleting their tasks or history.
|
|
54
|
+
- **Stale indicators:** flag active work with no recent report; threshold is configurable and does not change task status.
|
|
55
|
+
- **Notifications:** optional desktop alerts for existing tasks that finish or become blocked. A Angine browser tab must remain open, and browser/OS permission must be allowed.
|
|
56
|
+
|
|
57
|
+
Task progress is reported explicitly. Unknown active progress displays “Not reported”; completed tasks show 100% and to-do tasks show 0%. Mission progress is the share of non-cancelled tasks completed, not an estimate of effort. Projects stay active as long-lived containers; completing their current missions does not close them.
|
|
58
|
+
|
|
59
|
+
## Connecting a profile
|
|
60
|
+
|
|
61
|
+
A profile labels a reporter's work and can hold a context, owner name/email, and account nickname. Those details are user supplied; Angine does not retrieve or verify the agent's login account. Initial profiles use a neutral Other context.
|
|
62
|
+
|
|
63
|
+
Create or edit profiles in **Agents**. A profile connects in either of two ways:
|
|
64
|
+
|
|
65
|
+
- Set it as the default for its agent type. Reports without a profile key use it.
|
|
66
|
+
- Configure that agent's Angine MCP connection with the profile's stable key:
|
|
67
|
+
|
|
68
|
+
```text
|
|
69
|
+
command: angine
|
|
70
|
+
args: mcp --agent claude --profile claude-default
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
Replace the agent name and profile key with your own. Creating a profile does not install, connect, or start the agent. Additional agents can report through MCP, CLI, or HTTP; the Grok profile is not an automatic Grok integration.
|
|
74
|
+
|
|
75
|
+
Projects group work by canonical local workspace path. Two agents share a mission by reporting that workspace and the same stable mission key. Use distinct task keys within each mission; the same task key may appear in other missions. Parent/child agent relationships require supplied identifiers; Angine does not invent them. Codex native session IDs are populated when its runtime makes them available to the reporter; other identity fields are optional.
|
|
76
|
+
|
|
77
|
+
In Agents, expand **Connect this profile** to copy its MCP configuration. The connections panel shows whether the reporter is reachable and when work was last reported. Heartbeats run every 25 seconds; after 75 seconds without one, the connection is marked disconnected. They do not refresh task timestamps or change task statuses. Connection diagnostics are in memory and counters reset when the Angine server restarts. Last known report times are restored when an exact reporter ID matches saved session history. Older reporters and CLI/HTTP-only reports have unknown connection status until an updated MCP reporter connects.
|
|
78
|
+
|
|
79
|
+
See the [reporting protocol](docs/protocol.md) for payloads and integration examples.
|
|
80
|
+
|
|
81
|
+
## Commands
|
|
82
|
+
|
|
83
|
+
| Command | Purpose |
|
|
84
|
+
| --- | --- |
|
|
85
|
+
| `angine` or `angine open` | Start the server if needed and open the dashboard |
|
|
86
|
+
| `angine setup [codex\|claude]` | Configure detected supported agents and open Angine |
|
|
87
|
+
| `angine status` | Show server status, dashboard URL, and project counts |
|
|
88
|
+
| `angine restart` | Restart the server to load updated code; preserve history |
|
|
89
|
+
| `angine doctor` | Check agent integrations |
|
|
90
|
+
| `angine uninstall` | Remove managed integrations; preserve local history |
|
|
91
|
+
| `angine mcp --agent <name> [--profile <key>]` | Run an MCP reporter |
|
|
92
|
+
| `angine report <operation> --agent <name>` | Read a report as JSON from standard input |
|
|
93
|
+
| `angine token` | Show the local HTTP reporting token; keep it private |
|
|
94
|
+
|
|
95
|
+
For Codex, setup installs a removable approval policy for Angine's two reporting tools. Uninstall removes the managed instruction blocks, integrations, and policy.
|
|
96
|
+
|
|
97
|
+
## Local storage and access
|
|
98
|
+
|
|
99
|
+
The hierarchy is **Project → Missions → Tasks**. For example, a product contains a mission to improve reporting, which contains tasks to add connection checks and verify updates.
|
|
100
|
+
|
|
101
|
+
Angine stores history and configuration in `~/.angine`. The dashboard binds to `127.0.0.1`, starting at port 4317; use `angine status` for the active URL. MCP and CLI updates use a local Unix socket or Windows named pipe. HTTP reporting requires a local write token; dashboard edits require a same-origin browser session.
|
|
102
|
+
|
|
103
|
+
Angine makes no outbound network requests during normal operation. Saved filters and notification preferences live in browser storage. Agent reports and optional owner details are visible in the local dashboard; avoid putting sensitive content in metadata.
|
|
104
|
+
|
|
105
|
+
This MVP is for one computer. Mobile access over Wi-Fi, a shared company server, team authentication, independent agent observation, and notifications with all browser tabs closed are not implemented.
|
|
106
|
+
|
|
107
|
+
## Upgrading and troubleshooting
|
|
108
|
+
|
|
109
|
+
Existing plans automatically become missions grouped under their workspace project. IDs and history are preserved; old plan links still open their mission. Legacy snapshots are backed up before conversion.
|
|
110
|
+
|
|
111
|
+
After installing an update:
|
|
112
|
+
|
|
113
|
+
```bash
|
|
114
|
+
angine restart
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
Refresh the dashboard and restart agent sessions to load changed reporter tools. A new UI can load while an older server is still running; if saving a profile shows a restart message, restart Angine, refresh, and save again. On Windows, upgrading from a server without process identity support may require closing that old server manually first.
|
|
118
|
+
|
|
119
|
+
If work does not appear, inspect **Agents → Connections**, ask the agent to use `check_connection`, run `angine doctor`, confirm the agent loaded its MCP connection, and check agent/project/profile filters. A stale label means no recent report, not confirmed failure.
|
|
120
|
+
|
|
121
|
+
## Development and release
|
|
122
|
+
|
|
123
|
+
```bash
|
|
124
|
+
npm install
|
|
125
|
+
npm test
|
|
126
|
+
npx tsc --noEmit -p ui/tsconfig.json
|
|
127
|
+
npm run build
|
|
128
|
+
node dist/bin/angine.js open
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
The UI build uses Vite 7; development requires a compatible Node release (20.19+ or 22.12+). Published packages include compiled server code and dashboard assets; users do not need TypeScript or Vite.
|
|
132
|
+
|
|
133
|
+
Use `ANGINE_HOME` for isolated storage, `ANGINE_PORT` for a dashboard port, and `CODEX_HOME` for isolated Codex configuration tests.
|
|
134
|
+
|
|
135
|
+
See [release notes](CHANGELOG.md) and the [release checklist](docs/releasing.md).
|
|
136
|
+
|
|
137
|
+
## License
|
|
138
|
+
|
|
139
|
+
MIT — see [LICENSE](LICENSE).
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { spawn } from 'node:child_process';
|
|
3
|
+
import { ensureDaemon, request, restartDaemon } from '../src/ipc.js';
|
|
4
|
+
import { serverVersion } from '../src/reporting.js';
|
|
5
|
+
const command = process.argv[2] || 'open';
|
|
6
|
+
async function openDashboard() {
|
|
7
|
+
const status = await ensureDaemon();
|
|
8
|
+
const opener = process.platform === 'darwin' ? 'open' : process.platform === 'win32' ? 'cmd' : 'xdg-open';
|
|
9
|
+
const args = process.platform === 'win32' ? ['/c', 'start', '', status.url] : [status.url];
|
|
10
|
+
const child = spawn(opener, args, { stdio: 'ignore', detached: true });
|
|
11
|
+
child.on('error', () => { });
|
|
12
|
+
child.unref();
|
|
13
|
+
console.log(status.url);
|
|
14
|
+
}
|
|
15
|
+
try {
|
|
16
|
+
if (command === '--version' || command === 'version' || command === '-v')
|
|
17
|
+
console.log(`Angine ${serverVersion}`);
|
|
18
|
+
else if (command === 'mcp')
|
|
19
|
+
await import('../src/mcp.js');
|
|
20
|
+
else if (command === 'daemon')
|
|
21
|
+
await (await import('../src/daemon.js')).startDaemon();
|
|
22
|
+
else if (command === 'restart') {
|
|
23
|
+
await restartDaemon();
|
|
24
|
+
console.log('Angine restarted. Project history was kept.');
|
|
25
|
+
await openDashboard();
|
|
26
|
+
}
|
|
27
|
+
else if (command === 'setup') {
|
|
28
|
+
const { setup } = await import('../src/setup.js');
|
|
29
|
+
const result = setup(process.argv[3] || 'all');
|
|
30
|
+
console.log(`Angine ready. Configured: ${result.installed.join(', ')}.${result.skipped.length ? ` Not installed: ${result.skipped.join(', ')}.` : ''}\nRestart your agents to begin reporting. Opening the dashboard…`);
|
|
31
|
+
await openDashboard();
|
|
32
|
+
}
|
|
33
|
+
else if (command === 'uninstall') {
|
|
34
|
+
const { uninstall } = await import('../src/setup.js');
|
|
35
|
+
const result = uninstall();
|
|
36
|
+
console.log(result.removed.length ? `Removed ${result.removed.join(', ')} integration. Local project history was kept.` : 'No Angine integration found.');
|
|
37
|
+
}
|
|
38
|
+
else if (command === 'token') {
|
|
39
|
+
const { httpWriteToken } = await import('../src/config.js');
|
|
40
|
+
console.log(httpWriteToken());
|
|
41
|
+
}
|
|
42
|
+
else if (command === 'report') {
|
|
43
|
+
const method = process.argv[3];
|
|
44
|
+
if (!['sync_project', 'update_tasks'].includes(method))
|
|
45
|
+
throw new Error('Use: angine report sync_project|update_tasks --agent <name> < input.json');
|
|
46
|
+
const index = process.argv.indexOf('--agent');
|
|
47
|
+
const { agentName } = await import('../src/model.js');
|
|
48
|
+
const agent = agentName(index >= 0 ? process.argv[index + 1] : 'external');
|
|
49
|
+
let body = '';
|
|
50
|
+
for await (const chunk of process.stdin) {
|
|
51
|
+
body += chunk.toString();
|
|
52
|
+
if (body.length > 1_000_000)
|
|
53
|
+
throw new Error('Report exceeds 1 MB');
|
|
54
|
+
}
|
|
55
|
+
const input = JSON.parse(body);
|
|
56
|
+
const profileIndex = process.argv.indexOf('--profile');
|
|
57
|
+
const { nativeReporterIdentity } = await import('../src/identity.js');
|
|
58
|
+
await ensureDaemon();
|
|
59
|
+
console.log(JSON.stringify(await request(method, { ...nativeReporterIdentity(agent), ...input, ...(profileIndex >= 0 ? { profileKey: process.argv[profileIndex + 1] } : {}), agent })));
|
|
60
|
+
}
|
|
61
|
+
else if (command === 'doctor') {
|
|
62
|
+
const { doctor } = await import('../src/setup.js');
|
|
63
|
+
const checks = doctor();
|
|
64
|
+
for (const check of checks)
|
|
65
|
+
console.log(`${check.ok ? '✓' : '✗'} ${check.name}: ${check.detail}`);
|
|
66
|
+
if (checks.some(c => !c.ok))
|
|
67
|
+
process.exitCode = 1;
|
|
68
|
+
}
|
|
69
|
+
else if (command === 'status') {
|
|
70
|
+
const status = await request('status');
|
|
71
|
+
console.log(`Daemon: ${status.daemon}\nDashboard: ${status.url}\nProjects: ${status.projects}${status.missions !== undefined ? `\nMissions: ${status.missions}` : ''}\nRunning missions: ${status.running}`);
|
|
72
|
+
}
|
|
73
|
+
else if (command === 'open') {
|
|
74
|
+
await openDashboard();
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
console.error('Usage: angine [setup [codex|claude]|open|restart|status|doctor|uninstall|token|report|mcp]');
|
|
78
|
+
process.exitCode = 1;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
catch (error) {
|
|
82
|
+
console.error(`Angine: ${error.message}`);
|
|
83
|
+
process.exitCode = 1;
|
|
84
|
+
}
|
|
85
|
+
//# sourceMappingURL=angine.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"angine.js","sourceRoot":"","sources":["../../bin/angine.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC3C,OAAO,EAAE,YAAY,EAAE,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAErE,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEpD,MAAM,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,MAAM,CAAC;AAC1C,KAAK,UAAU,aAAa;IAC1B,MAAM,MAAM,GAAG,MAAM,YAAY,EAAE,CAAC;IACpC,MAAM,MAAM,GAAG,OAAO,CAAC,QAAQ,KAAK,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,QAAQ,KAAK,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,UAAU,CAAC;IAC1G,MAAM,IAAI,GAAG,OAAO,CAAC,QAAQ,KAAK,OAAO,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,OAAO,EAAE,EAAE,EAAE,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;IAC3F,MAAM,KAAK,GAAG,KAAK,CAAC,MAAM,EAAE,IAAI,EAAE,EAAE,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC;IACvE,KAAK,CAAC,EAAE,CAAC,OAAO,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,MAAM,OAAO,CAAe,QAAQ,CAAC,CAAC;QACrD,OAAO,CAAC,GAAG,CAAC,WAAW,MAAM,CAAC,MAAM,gBAAgB,MAAM,CAAC,GAAG,eAAe,MAAM,CAAC,QAAQ,GAAG,MAAM,CAAC,QAAQ,KAAK,SAAS,CAAC,CAAC,CAAC,eAAe,MAAM,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,EAAE,uBAAuB,MAAM,CAAC,OAAO,EAAE,CAAC,CAAC;IAC/M,CAAC;SAAM,IAAI,OAAO,KAAK,MAAM,EAAE,CAAC;QAC9B,MAAM,aAAa,EAAE,CAAC;IACxB,CAAC;SAAM,CAAC;QAAC,OAAO,CAAC,KAAK,CAAC,4FAA4F,CAAC,CAAC;QAAC,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAC;IAAC,CAAC;AAC/I,CAAC;AAAC,OAAO,KAAK,EAAE,CAAC;IAAC,OAAO,CAAC,KAAK,CAAC,WAAY,KAAe,CAAC,OAAO,EAAE,CAAC,CAAC;IAAC,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAC;AAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function httpWriteToken(): string;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import crypto from 'node:crypto';
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import { dataDir } from './paths.js';
|
|
5
|
+
const file = () => path.join(dataDir(), 'config.json');
|
|
6
|
+
export function httpWriteToken() {
|
|
7
|
+
fs.mkdirSync(dataDir(), { recursive: true, mode: 0o700 });
|
|
8
|
+
let config = {};
|
|
9
|
+
try {
|
|
10
|
+
config = JSON.parse(fs.readFileSync(file(), 'utf8'));
|
|
11
|
+
}
|
|
12
|
+
catch (error) {
|
|
13
|
+
if (error.code !== 'ENOENT')
|
|
14
|
+
throw error;
|
|
15
|
+
}
|
|
16
|
+
if (typeof config.httpWriteToken === 'string' && config.httpWriteToken.length >= 32)
|
|
17
|
+
return config.httpWriteToken;
|
|
18
|
+
config.httpWriteToken = crypto.randomBytes(32).toString('hex');
|
|
19
|
+
const temp = `${file()}.${process.pid}.tmp`;
|
|
20
|
+
fs.writeFileSync(temp, JSON.stringify(config, null, 2) + '\n', { mode: 0o600 });
|
|
21
|
+
fs.renameSync(temp, file());
|
|
22
|
+
return config.httpWriteToken;
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,aAAa,CAAC;AACjC,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAErC,MAAM,IAAI,GAAG,GAAG,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,EAAE,aAAa,CAAC,CAAC;AACvD,MAAM,UAAU,cAAc;IAC5B,EAAE,CAAC,SAAS,CAAC,OAAO,EAAE,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC;IAC1D,IAAI,MAAM,GAA4B,EAAE,CAAC;IACzC,IAAI,CAAC;QAAC,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,YAAY,CAAC,IAAI,EAAE,EAAE,MAAM,CAAC,CAA4B,CAAC;IAAC,CAAC;IACxF,OAAO,KAAK,EAAE,CAAC;QAAC,IAAK,KAA+B,CAAC,IAAI,KAAK,QAAQ;YAAE,MAAM,KAAK,CAAC;IAAC,CAAC;IACtF,IAAI,OAAO,MAAM,CAAC,cAAc,KAAK,QAAQ,IAAI,MAAM,CAAC,cAAc,CAAC,MAAM,IAAI,EAAE;QAAE,OAAO,MAAM,CAAC,cAAc,CAAC;IAClH,MAAM,CAAC,cAAc,GAAG,MAAM,CAAC,WAAW,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;IAC/D,MAAM,IAAI,GAAG,GAAG,IAAI,EAAE,IAAI,OAAO,CAAC,GAAG,MAAM,CAAC;IAC5C,EAAE,CAAC,aAAa,CAAC,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,GAAG,IAAI,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC;IAChF,EAAE,CAAC,UAAU,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC;IAC5B,OAAO,MAAM,CAAC,cAAwB,CAAC;AACzC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function startDaemon(): Promise<void>;
|
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import net from 'node:net';
|
|
4
|
+
import http from 'node:http';
|
|
5
|
+
import { fileURLToPath } from 'node:url';
|
|
6
|
+
import { Store } from './store.js';
|
|
7
|
+
import { ReporterRegistry, protocolVersion, serverVersion } from './health.js';
|
|
8
|
+
import { createDashboardRouter, equalSecret } from './dashboard.js';
|
|
9
|
+
import { dataDir, runtimePath, socketPath } from './paths.js';
|
|
10
|
+
import { httpWriteToken } from './config.js';
|
|
11
|
+
const uiDir = path.resolve(fileURLToPath(new URL('../../ui/dist/', import.meta.url)));
|
|
12
|
+
const mime = { '.html': 'text/html; charset=utf-8', '.js': 'text/javascript; charset=utf-8', '.css': 'text/css; charset=utf-8', '.svg': 'image/svg+xml' };
|
|
13
|
+
const securityHeaders = {
|
|
14
|
+
'Content-Security-Policy': "default-src 'self'; script-src 'self'; style-src 'self'; connect-src 'self'; img-src 'self' data:; object-src 'none'; base-uri 'none'; frame-ancestors 'none'",
|
|
15
|
+
'X-Content-Type-Options': 'nosniff',
|
|
16
|
+
'Referrer-Policy': 'no-referrer',
|
|
17
|
+
'Cache-Control': 'no-store'
|
|
18
|
+
};
|
|
19
|
+
const json = (res, value, status = 200) => { res.writeHead(status, { ...securityHeaders, 'Content-Type': 'application/json; charset=utf-8' }); res.end(JSON.stringify(value)); };
|
|
20
|
+
export async function startDaemon() {
|
|
21
|
+
fs.mkdirSync(path.join(dataDir(), 'runtime'), { recursive: true, mode: 0o700 });
|
|
22
|
+
const store = new Store();
|
|
23
|
+
store.load();
|
|
24
|
+
const reporters = new ReporterRegistry(() => store.state.profiles, () => Date.now(), reporterId => Object.values(store.state.sessions).filter(s => s.reporterId === reporterId).map(s => s.lastSeenAt).sort().at(-1));
|
|
25
|
+
const writeToken = httpWriteToken();
|
|
26
|
+
const dashboard = createDashboardRouter(store);
|
|
27
|
+
let port = Number(process.env.ANGINE_PORT || 4317);
|
|
28
|
+
if (!Number.isInteger(port) || port < 1 || port > 65535)
|
|
29
|
+
throw new Error('Invalid ANGINE_PORT');
|
|
30
|
+
const clients = new Set();
|
|
31
|
+
const httpServer = http.createServer((req, res) => {
|
|
32
|
+
const host = req.headers.host || '';
|
|
33
|
+
if (!/^((127\.0\.0\.1)|(localhost))(:(\d{1,5}))?$/.test(host))
|
|
34
|
+
return json(res, { error: 'Invalid host' }, 403);
|
|
35
|
+
const origin = req.headers.origin;
|
|
36
|
+
if (origin && origin !== `http://${host}`)
|
|
37
|
+
return json(res, { error: 'Invalid origin' }, 403);
|
|
38
|
+
let url;
|
|
39
|
+
try {
|
|
40
|
+
url = new URL(req.url || '/', `http://${host}`);
|
|
41
|
+
}
|
|
42
|
+
catch {
|
|
43
|
+
return json(res, { error: 'Invalid URL' }, 400);
|
|
44
|
+
}
|
|
45
|
+
if (dashboard(req, res, url))
|
|
46
|
+
return;
|
|
47
|
+
if (req.method === 'POST' && (url.pathname === '/api/ingest/sync_project' || url.pathname === '/api/ingest/update_tasks')) {
|
|
48
|
+
const header = req.headers.authorization || '';
|
|
49
|
+
const supplied = header.startsWith('Bearer ') ? header.slice(7) : '';
|
|
50
|
+
const valid = equalSecret(supplied, writeToken);
|
|
51
|
+
if (!valid)
|
|
52
|
+
return json(res, { error: 'Unauthorized' }, 401);
|
|
53
|
+
if (!String(req.headers['content-type'] || '').startsWith('application/json'))
|
|
54
|
+
return json(res, { error: 'JSON required' }, 415);
|
|
55
|
+
let body = '', exceeded = false;
|
|
56
|
+
req.on('data', (chunk) => {
|
|
57
|
+
body += chunk;
|
|
58
|
+
if (body.length > 1_000_000) {
|
|
59
|
+
exceeded = true;
|
|
60
|
+
req.destroy();
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
req.on('end', () => {
|
|
64
|
+
if (exceeded)
|
|
65
|
+
return;
|
|
66
|
+
try {
|
|
67
|
+
const input = JSON.parse(body);
|
|
68
|
+
const value = url.pathname.endsWith('sync_project') ? store.syncProject(input) : store.updateTasks(input);
|
|
69
|
+
json(res, value);
|
|
70
|
+
}
|
|
71
|
+
catch (error) {
|
|
72
|
+
json(res, { error: error.message }, 400);
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
if (req.method !== 'GET')
|
|
78
|
+
return json(res, { error: 'Method not allowed' }, 405);
|
|
79
|
+
if (url.pathname === '/api/health')
|
|
80
|
+
return json(res, reporters.view());
|
|
81
|
+
if (url.pathname === '/api/state')
|
|
82
|
+
return json(res, store.view());
|
|
83
|
+
if (url.pathname.startsWith('/api/missions/') && url.pathname.endsWith('/events')) {
|
|
84
|
+
const missionId = url.pathname.split('/')[3];
|
|
85
|
+
if (!store.state.missions[missionId])
|
|
86
|
+
return json(res, { error: 'Mission not found' }, 404);
|
|
87
|
+
return json(res, store.missionEvents(missionId));
|
|
88
|
+
}
|
|
89
|
+
if (url.pathname.startsWith('/api/projects/') && url.pathname.endsWith('/events')) {
|
|
90
|
+
const projectId = url.pathname.split('/')[3];
|
|
91
|
+
if (!store.state.projects[projectId] && !store.state.missions[projectId])
|
|
92
|
+
return json(res, { error: 'Project not found' }, 404);
|
|
93
|
+
return json(res, store.projectEvents(projectId));
|
|
94
|
+
}
|
|
95
|
+
if (url.pathname === '/api/events') {
|
|
96
|
+
res.writeHead(200, { ...securityHeaders, 'Content-Type': 'text/event-stream', Connection: 'keep-alive' });
|
|
97
|
+
res.write(`event: state\ndata: ${JSON.stringify(store.view())}\n\n`);
|
|
98
|
+
res.write(`event: health\ndata: ${JSON.stringify(reporters.view())}\n\n`);
|
|
99
|
+
clients.add(res);
|
|
100
|
+
req.on('close', () => clients.delete(res));
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
const relative = url.pathname === '/' ? 'index.html' : decodeURIComponent(url.pathname.slice(1));
|
|
104
|
+
const full = path.resolve(uiDir, relative);
|
|
105
|
+
if (!full.startsWith(uiDir + path.sep) && full !== path.join(uiDir, 'index.html'))
|
|
106
|
+
return json(res, { error: 'Not found' }, 404);
|
|
107
|
+
let content;
|
|
108
|
+
try {
|
|
109
|
+
content = fs.readFileSync(full);
|
|
110
|
+
}
|
|
111
|
+
catch {
|
|
112
|
+
return json(res, { error: 'Dashboard not built. Run npm run build.' }, 404);
|
|
113
|
+
}
|
|
114
|
+
res.writeHead(200, { ...securityHeaders, 'Content-Type': mime[path.extname(full)] || 'application/octet-stream' });
|
|
115
|
+
res.end(content);
|
|
116
|
+
});
|
|
117
|
+
store.listeners.add((_events, state) => {
|
|
118
|
+
const message = `event: state\ndata: ${JSON.stringify(state)}\n\n`;
|
|
119
|
+
for (const client of clients)
|
|
120
|
+
client.write(message);
|
|
121
|
+
});
|
|
122
|
+
const healthUpdate = () => { for (const client of clients)
|
|
123
|
+
client.write(`event: health\ndata: ${JSON.stringify(reporters.view())}\n\n`); };
|
|
124
|
+
const keepalive = setInterval(healthUpdate, 25000);
|
|
125
|
+
const desired = port;
|
|
126
|
+
while (true) {
|
|
127
|
+
try {
|
|
128
|
+
await new Promise((resolve, reject) => {
|
|
129
|
+
httpServer.once('error', reject);
|
|
130
|
+
httpServer.listen(port, '127.0.0.1', () => { httpServer.off('error', reject); resolve(); });
|
|
131
|
+
});
|
|
132
|
+
break;
|
|
133
|
+
}
|
|
134
|
+
catch (error) {
|
|
135
|
+
if (error.code !== 'EADDRINUSE' || port >= desired + 20)
|
|
136
|
+
throw error;
|
|
137
|
+
port++;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
const sock = socketPath();
|
|
141
|
+
if (process.platform !== 'win32' && fs.existsSync(sock)) {
|
|
142
|
+
try {
|
|
143
|
+
await new Promise((resolve, reject) => { const probe = net.createConnection(sock); probe.once('connect', () => { probe.destroy(); reject(new Error('Daemon already running')); }); probe.once('error', () => resolve()); });
|
|
144
|
+
}
|
|
145
|
+
catch (error) {
|
|
146
|
+
httpServer.close();
|
|
147
|
+
throw error;
|
|
148
|
+
}
|
|
149
|
+
fs.unlinkSync(sock);
|
|
150
|
+
}
|
|
151
|
+
const ipc = net.createServer(socket => {
|
|
152
|
+
let buffer = '';
|
|
153
|
+
socket.on('data', (chunk) => {
|
|
154
|
+
buffer += chunk;
|
|
155
|
+
if (buffer.length > 1_000_000)
|
|
156
|
+
return socket.destroy();
|
|
157
|
+
const end = buffer.indexOf('\n');
|
|
158
|
+
if (end < 0)
|
|
159
|
+
return;
|
|
160
|
+
try {
|
|
161
|
+
const { method, params } = JSON.parse(buffer.slice(0, end));
|
|
162
|
+
let value;
|
|
163
|
+
if (method === 'status')
|
|
164
|
+
value = { serverVersion, protocolVersion, pid: process.pid, daemon: 'running', url: `http://127.0.0.1:${port}`, projects: Object.keys(store.state.projects).length, missions: Object.keys(store.state.missions).length, running: Object.values(store.state.missions).filter(p => p.status === 'running' && !p.archivedAt && !store.state.projects[p.projectId]?.archivedAt).length };
|
|
165
|
+
else if (method === 'reporter_ping') {
|
|
166
|
+
value = reporters.ping(params);
|
|
167
|
+
healthUpdate();
|
|
168
|
+
}
|
|
169
|
+
else if (method === 'reporter_close') {
|
|
170
|
+
reporters.close(params?.reporterId);
|
|
171
|
+
value = { closed: true };
|
|
172
|
+
healthUpdate();
|
|
173
|
+
}
|
|
174
|
+
else if (method === 'reporter_health')
|
|
175
|
+
value = reporters.view();
|
|
176
|
+
else if (method === 'sync_project') {
|
|
177
|
+
try {
|
|
178
|
+
value = store.syncProject(params);
|
|
179
|
+
reporters.report(params?.reporterId, true);
|
|
180
|
+
}
|
|
181
|
+
catch (error) {
|
|
182
|
+
reporters.report(params?.reporterId, false);
|
|
183
|
+
throw error;
|
|
184
|
+
}
|
|
185
|
+
finally {
|
|
186
|
+
healthUpdate();
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
else if (method === 'update_tasks') {
|
|
190
|
+
try {
|
|
191
|
+
value = store.updateTasks(params);
|
|
192
|
+
reporters.report(params?.reporterId, true);
|
|
193
|
+
}
|
|
194
|
+
catch (error) {
|
|
195
|
+
reporters.report(params?.reporterId, false);
|
|
196
|
+
throw error;
|
|
197
|
+
}
|
|
198
|
+
finally {
|
|
199
|
+
healthUpdate();
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
else
|
|
203
|
+
throw new Error('Unknown method');
|
|
204
|
+
socket.end(JSON.stringify({ ok: true, value }) + '\n');
|
|
205
|
+
}
|
|
206
|
+
catch (error) {
|
|
207
|
+
socket.end(JSON.stringify({ ok: false, error: error.message }) + '\n');
|
|
208
|
+
}
|
|
209
|
+
});
|
|
210
|
+
});
|
|
211
|
+
await new Promise((resolve, reject) => { ipc.once('error', reject); ipc.listen(sock, () => { ipc.off('error', reject); resolve(); }); });
|
|
212
|
+
if (process.platform !== 'win32')
|
|
213
|
+
fs.chmodSync(sock, 0o600);
|
|
214
|
+
fs.writeFileSync(runtimePath(), JSON.stringify({ pid: process.pid, port, startedAt: new Date().toISOString() }), { mode: 0o600 });
|
|
215
|
+
const stop = () => { clearInterval(keepalive); store.snapshot(); for (const client of clients)
|
|
216
|
+
client.end(); clients.clear(); ipc.close(); httpServer.close(); if (process.platform !== 'win32')
|
|
217
|
+
try {
|
|
218
|
+
fs.unlinkSync(sock);
|
|
219
|
+
}
|
|
220
|
+
catch { } try {
|
|
221
|
+
fs.unlinkSync(runtimePath());
|
|
222
|
+
}
|
|
223
|
+
catch { } };
|
|
224
|
+
process.once('SIGTERM', stop);
|
|
225
|
+
process.once('SIGINT', stop);
|
|
226
|
+
}
|
|
227
|
+
//# sourceMappingURL=daemon.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"daemon.js","sourceRoot":"","sources":["../../src/daemon.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,GAAG,MAAM,UAAU,CAAC;AAC3B,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,gBAAgB,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC/E,OAAO,EAAE,qBAAqB,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AACpE,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAC9D,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAG7C,MAAM,KAAK,GAAG,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,IAAI,GAAG,CAAC,gBAAgB,EAAE,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;AACtF,MAAM,IAAI,GAA2B,EAAE,OAAO,EAAE,0BAA0B,EAAE,KAAK,EAAE,gCAAgC,EAAE,MAAM,EAAE,yBAAyB,EAAE,MAAM,EAAE,eAAe,EAAE,CAAC;AAClL,MAAM,eAAe,GAAG;IACtB,yBAAyB,EAAE,+JAA+J;IAC1L,wBAAwB,EAAE,SAAS;IACnC,iBAAiB,EAAE,aAAa;IAChC,eAAe,EAAE,UAAU;CA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AE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,EAAE,CAAC,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC;IAClI,MAAM,IAAI,GAAG,GAAG,EAAE,GAAG,aAAa,CAAC,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC,CAAC,KAAI,MAAM,MAAM,IAAI,OAAO;QAAE,MAAM,CAAC,GAAG,EAAE,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC,CAAC,GAAG,CAAC,KAAK,EAAE,CAAC,CAAC,UAAU,CAAC,KAAK,EAAE,CAAC,CAAC,IAAI,OAAO,CAAC,QAAQ,KAAK,OAAO;QAAE,IAAI,CAAC;YAAC,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;QAAC,CAAC;QAAC,MAAM,CAAC,CAAA,CAAC,CAAC,IAAI,CAAC;QAAC,EAAE,CAAC,UAAU,CAAC,WAAW,EAAE,CAAC,CAAC;IAAC,CAAC;IAAC,MAAM,CAAC,CAAA,CAAC,CAAC,CAAC,CAAC;IACvR,OAAO,CAAC,IAAI,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC;IAC9B,OAAO,CAAC,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;AAC/B,CAAC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type http from 'node:http';
|
|
2
|
+
import type { Store } from './store.js';
|
|
3
|
+
export declare function equalSecret(supplied: string, expected: string): boolean;
|
|
4
|
+
export declare function createDashboardRouter(store: Store): (req: http.IncomingMessage, res: http.ServerResponse, url: URL) => boolean;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import crypto from 'node:crypto';
|
|
2
|
+
export function equalSecret(supplied, expected) {
|
|
3
|
+
const left = Buffer.from(supplied), right = Buffer.from(expected);
|
|
4
|
+
return left.length === right.length && crypto.timingSafeEqual(left, right);
|
|
5
|
+
}
|
|
6
|
+
export function createDashboardRouter(store) {
|
|
7
|
+
const session = crypto.randomBytes(32).toString('hex');
|
|
8
|
+
const respond = (res, body, status = 200) => {
|
|
9
|
+
res.writeHead(status, { 'Content-Type': 'application/json; charset=utf-8', 'Cache-Control': 'no-store', 'X-Content-Type-Options': 'nosniff' });
|
|
10
|
+
res.end(JSON.stringify(body));
|
|
11
|
+
};
|
|
12
|
+
return (req, res, url) => {
|
|
13
|
+
if (url.pathname === '/api/dashboard/session' && req.method === 'GET') {
|
|
14
|
+
if (req.headers['sec-fetch-site'] && req.headers['sec-fetch-site'] !== 'same-origin') {
|
|
15
|
+
respond(res, { error: 'Same-origin request required' }, 403);
|
|
16
|
+
return true;
|
|
17
|
+
}
|
|
18
|
+
res.setHeader('Set-Cookie', `angine_dashboard=${session}; HttpOnly; SameSite=Strict; Path=/api/dashboard`);
|
|
19
|
+
respond(res, { ready: true });
|
|
20
|
+
return true;
|
|
21
|
+
}
|
|
22
|
+
if (req.method !== 'POST' || !['/api/dashboard/archive', '/api/dashboard/profiles', '/api/dashboard/task-details'].includes(url.pathname))
|
|
23
|
+
return false;
|
|
24
|
+
const cookie = (req.headers.cookie || '').split(';').map(item => item.trim()).find(item => item.startsWith('angine_dashboard='))?.slice('angine_dashboard='.length) || '';
|
|
25
|
+
if (req.headers.origin !== url.origin || req.headers['x-angine-ui'] !== '1' || !equalSecret(cookie, session)) {
|
|
26
|
+
respond(res, { error: 'Dashboard session required. Reload Angine and try again.' }, 403);
|
|
27
|
+
return true;
|
|
28
|
+
}
|
|
29
|
+
if (!String(req.headers['content-type'] || '').startsWith('application/json')) {
|
|
30
|
+
respond(res, { error: 'JSON required' }, 415);
|
|
31
|
+
return true;
|
|
32
|
+
}
|
|
33
|
+
let body = '', exceeded = false;
|
|
34
|
+
req.on('data', (chunk) => { if (exceeded)
|
|
35
|
+
return; body += chunk; if (Buffer.byteLength(body) > 65536) {
|
|
36
|
+
exceeded = true;
|
|
37
|
+
respond(res, { error: 'Request too large' }, 413);
|
|
38
|
+
} });
|
|
39
|
+
req.on('end', () => {
|
|
40
|
+
if (exceeded)
|
|
41
|
+
return;
|
|
42
|
+
try {
|
|
43
|
+
const input = JSON.parse(body);
|
|
44
|
+
if (!input || typeof input !== 'object' || Array.isArray(input))
|
|
45
|
+
throw new Error('Invalid dashboard request');
|
|
46
|
+
if (url.pathname.endsWith('/archive'))
|
|
47
|
+
store.archiveProject(input.projectId, input.archived);
|
|
48
|
+
if (url.pathname.endsWith('/profiles'))
|
|
49
|
+
store.saveProfile(input);
|
|
50
|
+
if (url.pathname.endsWith('/task-details'))
|
|
51
|
+
store.editTaskDetails(input.taskId, input);
|
|
52
|
+
respond(res, { state: store.view() });
|
|
53
|
+
}
|
|
54
|
+
catch (error) {
|
|
55
|
+
respond(res, { error: error.message }, 400);
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
return true;
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
//# sourceMappingURL=dashboard.js.map
|