wyrm-mcp 7.3.2 → 7.3.3
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/README.md +8 -14
- package/dist/activation.js +59 -1
- package/dist/agent-daemon.js +281 -4
- package/dist/agent-loop.js +332 -7
- package/dist/analytics.js +236 -13
- package/dist/attribution.js +49 -1
- package/dist/audit.js +457 -2
- package/dist/auto-capture.js +138 -3
- package/dist/auto-orchestrator.js +325 -1
- package/dist/autoconfig.d.ts +50 -0
- package/dist/autoconfig.d.ts.map +1 -1
- package/dist/autoconfig.js +1115 -39
- package/dist/autoconfig.js.map +1 -1
- package/dist/buddy-runner.js +109 -1
- package/dist/buddy.js +564 -14
- package/dist/build-flags.js +15 -1
- package/dist/capabilities.js +183 -3
- package/dist/capture.js +56 -1
- package/dist/causality.js +148 -8
- package/dist/cli.js +281 -20
- package/dist/cloud/cli.js +541 -5
- package/dist/cloud/client.js +221 -1
- package/dist/cloud/crypto.js +85 -1
- package/dist/cloud/machine-id.js +113 -2
- package/dist/cloud/recovery.js +60 -1
- package/dist/cloud/sync-engine.js +543 -7
- package/dist/cloud-backup.js +579 -5
- package/dist/cloud-profile.js +138 -1
- package/dist/cloud-sync-entrypoint.js +47 -1
- package/dist/cloud-sync.js +309 -2
- package/dist/connectors/bridge-source.d.ts +46 -0
- package/dist/connectors/bridge-source.d.ts.map +1 -0
- package/dist/connectors/bridge-source.js +77 -0
- package/dist/connectors/bridge-source.js.map +1 -0
- package/dist/connectors/index.d.ts +24 -0
- package/dist/connectors/index.d.ts.map +1 -0
- package/dist/connectors/index.js +69 -0
- package/dist/connectors/index.js.map +1 -0
- package/dist/connectors/ingest.d.ts +16 -0
- package/dist/connectors/ingest.d.ts.map +1 -0
- package/dist/connectors/ingest.js +116 -0
- package/dist/connectors/ingest.js.map +1 -0
- package/dist/connectors/types.d.ts +99 -0
- package/dist/connectors/types.d.ts.map +1 -0
- package/dist/connectors/types.js +17 -0
- package/dist/connectors/types.js.map +1 -0
- package/dist/constellation.js +168 -12
- package/dist/content-signature.js +45 -1
- package/dist/context-build-budgeted.js +144 -4
- package/dist/context-ranking.js +69 -1
- package/dist/crypto.js +179 -1
- package/dist/daemon-write-endpoint.js +290 -1
- package/dist/daemon-writer.js +406 -2
- package/dist/database.js +1278 -53
- package/dist/deprecations.js +162 -2
- package/dist/design.js +141 -13
- package/dist/event-replication.js +112 -1
- package/dist/events-sse.js +43 -7
- package/dist/events.js +238 -6
- package/dist/failure-patterns.d.ts +107 -0
- package/dist/failure-patterns.d.ts.map +1 -1
- package/dist/failure-patterns.js +924 -43
- package/dist/failure-patterns.js.map +1 -1
- package/dist/federation.js +236 -12
- package/dist/goals.js +101 -13
- package/dist/golden.js +355 -3
- package/dist/handlers/agent.js +165 -4
- package/dist/handlers/alias-adapters.js +129 -1
- package/dist/handlers/aliases.js +171 -1
- package/dist/handlers/audit.js +87 -1
- package/dist/handlers/boundary.js +221 -1
- package/dist/handlers/capture.js +1114 -73
- package/dist/handlers/causality.js +119 -9
- package/dist/handlers/cloud.js +382 -85
- package/dist/handlers/companion.js +459 -28
- package/dist/handlers/datalake.js +187 -7
- package/dist/handlers/dispatch-context.js +22 -0
- package/dist/handlers/entity.js +256 -25
- package/dist/handlers/events.js +335 -16
- package/dist/handlers/failure.d.ts.map +1 -1
- package/dist/handlers/failure.js +408 -13
- package/dist/handlers/failure.js.map +1 -1
- package/dist/handlers/goals.js +296 -4
- package/dist/handlers/intelligence.js +681 -126
- package/dist/handlers/invoicing.js +70 -1
- package/dist/handlers/mcpclient.js +137 -6
- package/dist/handlers/orchestration.js +125 -40
- package/dist/handlers/output-schemas.js +24 -1
- package/dist/handlers/presence.js +99 -3
- package/dist/handlers/project.js +182 -28
- package/dist/handlers/prompts.js +157 -6
- package/dist/handlers/quest.js +224 -4
- package/dist/handlers/recall.js +237 -13
- package/dist/handlers/registry.js +167 -1
- package/dist/handlers/resources.js +288 -1
- package/dist/handlers/review.js +74 -11
- package/dist/handlers/run.js +498 -16
- package/dist/handlers/search.js +338 -15
- package/dist/handlers/session.js +643 -31
- package/dist/handlers/share.js +184 -8
- package/dist/handlers/shims.js +464 -1
- package/dist/handlers/skill.js +449 -67
- package/dist/handlers/survivors.js +120 -1
- package/dist/handlers/symbols.js +109 -8
- package/dist/handlers/syncops.js +302 -4
- package/dist/handlers/types.js +27 -1
- package/dist/harvest.js +191 -5
- package/dist/hours.js +156 -7
- package/dist/http-auth.js +321 -3
- package/dist/http-fast.js +1302 -22
- package/dist/icons.js +47 -1
- package/dist/importers.js +268 -1
- package/dist/index.js +840 -2
- package/dist/indexer.js +145 -4
- package/dist/intelligence.js +261 -31
- package/dist/internal-dispatch.js +212 -3
- package/dist/keyset.js +110 -1
- package/dist/knowledge-graph.js +176 -12
- package/dist/license.js +441 -2
- package/dist/logger.js +199 -2
- package/dist/maintenance.js +148 -2
- package/dist/mcp-client.js +262 -6
- package/dist/memory-artifacts.js +596 -32
- package/dist/migrate-prompt.js +124 -2
- package/dist/migrations.d.ts.map +1 -1
- package/dist/migrations.js +799 -42
- package/dist/migrations.js.map +1 -1
- package/dist/performance.js +228 -1
- package/dist/presence.js +140 -11
- package/dist/priority-embed.js +164 -5
- package/dist/providers/embedding-provider.js +196 -1
- package/dist/readonly-gate.js +29 -1
- package/dist/receipt.js +43 -1
- package/dist/rehydration.js +157 -9
- package/dist/reindex.js +88 -1
- package/dist/render-target.js +544 -21
- package/dist/render.js +280 -4
- package/dist/repl-guard.js +173 -1
- package/dist/replication-daemon-entrypoint.js +31 -1
- package/dist/replication-daemon.js +262 -2
- package/dist/rerank.js +142 -1
- package/dist/resilience.js +591 -1
- package/dist/reverse-bridge.js +360 -5
- package/dist/security.js +244 -1
- package/dist/session-seen.js +51 -3
- package/dist/setup.js +260 -1
- package/dist/skill-author.js +168 -5
- package/dist/spec-kit.js +191 -1
- package/dist/sqlite-busy.js +154 -1
- package/dist/statusline.js +315 -11
- package/dist/sub-agent.js +262 -13
- package/dist/summarizer.js +139 -13
- package/dist/symbols.js +283 -7
- package/dist/sync.js +359 -5
- package/dist/tasks-dispatch.js +84 -1
- package/dist/tasks.js +282 -1
- package/dist/token-budget.js +143 -1
- package/dist/tool-analytics.js +129 -7
- package/dist/tool-annotations.js +365 -1
- package/dist/tool-manifest-v2.json +1 -1
- package/dist/tool-manifest.json +1 -1
- package/dist/tool-profiles.js +75 -1
- package/dist/trace-harvest.js +244 -6
- package/dist/types.js +30 -1
- package/dist/ui-dashboard.js +50 -41
- package/dist/ulid.js +81 -1
- package/dist/usage-tracker.js +66 -1
- package/dist/validate.js +129 -1
- package/dist/vault.js +534 -1
- package/dist/vector-init.js +67 -1
- package/dist/vectors.js +184 -3
- package/dist/version-check.js +136 -4
- package/dist/visibility.js +155 -19
- package/dist/wyrm-cli.js +2845 -101
- package/dist/wyrm-cli.js.map +1 -1
- package/dist/wyrm-guard.d.ts.map +1 -1
- package/dist/wyrm-guard.js +475 -14
- package/dist/wyrm-guard.js.map +1 -1
- package/dist/wyrm-loop.js +150 -3
- package/dist/wyrm-manifest.json +1 -1
- package/dist/wyrm-statusline-daemon.js +11 -1
- package/dist/wyrm-statusline.js +56 -4
- package/dist/wyrm-ui.js +77 -9
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -3,14 +3,14 @@
|
|
|
3
3
|
> Persistent memory is table stakes. The real problem is what agents *do* with it — Wyrm blocks the repeat, keeps decisions true, and learns as a fleet. Memory is the substrate; the judgment is the moat.
|
|
4
4
|
|
|
5
5
|
[](https://www.npmjs.com/package/wyrm-mcp)
|
|
6
|
-
[](LICENSE)
|
|
7
7
|
[](https://github.com/Ghosts-Protocol-Pvt-Ltd/Wyrm)
|
|
8
8
|
[](https://www.typescriptlang.org/)
|
|
9
9
|
[](https://modelcontextprotocol.io)
|
|
10
10
|
|
|
11
11
|
**[wyrm.ghosts.lk](https://wyrm.ghosts.lk)** · **[npm](https://www.npmjs.com/package/wyrm-mcp)** · **[GitHub](https://github.com/Ghosts-Protocol-Pvt-Ltd/Wyrm)** · **[Ghost Protocol](https://ghosts.lk)** · `npm i -g wyrm-mcp`
|
|
12
12
|
|
|
13
|
-
Local-first persistent memory for AI agents over MCP — by [Ghost Protocol](https://ghosts.lk). Runs fully offline on your machine: no cloud, no
|
|
13
|
+
Local-first persistent memory for AI agents over MCP — by [Ghost Protocol](https://ghosts.lk). Runs fully offline on your machine: no cloud, no LLM required. The official build activates with a one-time free `wyrm login`; your memory stays local either way. The managed cloud tier lives at **[wyrm.ghosts.lk](https://wyrm.ghosts.lk)**.
|
|
14
14
|
|
|
15
15
|
---
|
|
16
16
|
|
|
@@ -263,7 +263,7 @@ Once connected, your AI has access to all Wyrm tools. Try:
|
|
|
263
263
|
|
|
264
264
|
## MCP Tools Reference
|
|
265
265
|
|
|
266
|
-
Wyrm exposes
|
|
266
|
+
Wyrm exposes a frozen 32-verb typed surface (137 tools callable) via the Model Context Protocol:
|
|
267
267
|
|
|
268
268
|
### Projects
|
|
269
269
|
|
|
@@ -485,15 +485,9 @@ Wyrm/
|
|
|
485
485
|
|
|
486
486
|
## Contributing
|
|
487
487
|
|
|
488
|
-
|
|
488
|
+
Wyrm is a **proprietary repository** — free to use, but not open to external contributions. We do **not** accept forks or external pull requests.
|
|
489
489
|
|
|
490
|
-
|
|
491
|
-
2. **Create** a feature branch (`git checkout -b feat/amazing-feature`)
|
|
492
|
-
3. **Commit** your changes (`git commit -m 'feat: add amazing feature'`)
|
|
493
|
-
4. **Push** to the branch (`git push origin feat/amazing-feature`)
|
|
494
|
-
5. **Open** a Pull Request
|
|
495
|
-
|
|
496
|
-
Please ensure tests pass (`npm test`) and the project builds (`npm run build`) before submitting.
|
|
490
|
+
Issues and bug reports are welcome: please open an issue or email ryan@ghosts.lk.
|
|
497
491
|
|
|
498
492
|
---
|
|
499
493
|
|
|
@@ -504,7 +498,7 @@ Please ensure tests pass (`npm test`) and the project builds (`npm run build`) b
|
|
|
504
498
|
- **Optional encryption** — AES-256-GCM for sensitive context data.
|
|
505
499
|
- **Audited** — Security audits documented in [SECURITY_AUDIT.md](SECURITY_AUDIT.md) and [SECURITY_AUDIT_V2.md](SECURITY_AUDIT_V2.md).
|
|
506
500
|
|
|
507
|
-
Found a vulnerability? Please open an issue or email
|
|
501
|
+
Found a vulnerability? Please open an issue or email ryan@ghosts.lk.
|
|
508
502
|
|
|
509
503
|
---
|
|
510
504
|
|
|
@@ -513,9 +507,9 @@ Found a vulnerability? Please open an issue or email security@ghosts.lk.
|
|
|
513
507
|
**Open standard + protected implementation:**
|
|
514
508
|
|
|
515
509
|
- **The Wyrm Memory Protocol** ([`PROTOCOL.md`](../../PROTOCOL.md)) is an **open spec, freely implementable** by anyone (CC-BY-4.0) — build a WMP-compatible memory without touching Wyrm's code.
|
|
516
|
-
- **This implementation** (`wyrm-mcp`) is **[
|
|
510
|
+
- **This implementation** (`wyrm-mcp`) is **[Proprietary Freeware](LICENSE)** — free to use, all rights reserved. Copyright © 2024-2026 [Ghost Protocol (Pvt) Ltd](https://ghosts.lk).
|
|
517
511
|
|
|
518
|
-
For a **commercial license** (embedding Wyrm in a closed product, or running it as a managed service
|
|
512
|
+
For a **commercial license** (embedding Wyrm in a closed product, or running it as a managed service), contact [ryan@ghosts.lk](mailto:ryan@ghosts.lk).
|
|
519
513
|
|
|
520
514
|
---
|
|
521
515
|
|
package/dist/activation.js
CHANGED
|
@@ -1 +1,59 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Activation gate for account-required builds.
|
|
3
|
+
*
|
|
4
|
+
* OFF by default in source — the test suite and local dev builds are unaffected.
|
|
5
|
+
* The OFFICIAL distribution bakes `WYRM_REQUIRE_ACTIVATION=1`, so the free tier
|
|
6
|
+
* needs a (free) account: `wyrm login` fetches a short-lived, account-bound signed
|
|
7
|
+
* license that's validated locally by license.ts. A suspended account can't
|
|
8
|
+
* refresh, so access lapses at expiry. Memory is local either way — login only
|
|
9
|
+
* ties usage to a revocable identity. (Wyrm is proprietary; see LICENSE.)
|
|
10
|
+
*
|
|
11
|
+
* @copyright 2026 Ghost Protocol (Pvt) Ltd.
|
|
12
|
+
* @license Proprietary — (c) 2026 Ghost Protocol (Pvt) Ltd. All rights reserved. See LICENSE.
|
|
13
|
+
*/
|
|
14
|
+
import { getLicenseInfo, selfTestVerifier } from './license.js';
|
|
15
|
+
import { OFFICIAL_BUILD } from './build-flags.js';
|
|
16
|
+
/**
|
|
17
|
+
* Whether the account-required gate is enabled on this build. ON when this is the
|
|
18
|
+
* official published artifact (OFFICIAL_BUILD baked true at release), OR when the
|
|
19
|
+
* operator opts in via WYRM_REQUIRE_ACTIVATION. OFF in source + tests.
|
|
20
|
+
*/
|
|
21
|
+
export const REQUIRE_ACTIVATION = OFFICIAL_BUILD || /^(1|true|yes|on)$/i.test(process.env.WYRM_REQUIRE_ACTIVATION ?? '');
|
|
22
|
+
/**
|
|
23
|
+
* Tamper-evidence: on the official build, verify at load that the license verifier
|
|
24
|
+
* still rejects a forged signature. If it doesn't, someone stubbed the verifier to
|
|
25
|
+
* bypass the gate — so we keep the gate CLOSED regardless of what getLicenseInfo()
|
|
26
|
+
* now claims. A determined forker can remove this too (patching the closed, minified dist) — a
|
|
27
|
+
* deterrent, not a guarantee.
|
|
28
|
+
*/
|
|
29
|
+
const TAMPERED = OFFICIAL_BUILD ? !selfTestVerifier().ok : false;
|
|
30
|
+
if (TAMPERED) {
|
|
31
|
+
try {
|
|
32
|
+
console.error('Wyrm: integrity self-test FAILED — license verifier tampered; activation gate locked.');
|
|
33
|
+
}
|
|
34
|
+
catch { /* noop */ }
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* True when tool execution is permitted. Always true unless the build requires
|
|
38
|
+
* activation AND no valid (free or paid) account-bound license is loaded.
|
|
39
|
+
* Re-checked live so a mid-session `wyrm login` takes effect without a restart.
|
|
40
|
+
*/
|
|
41
|
+
export function activationSatisfied() {
|
|
42
|
+
if (TAMPERED)
|
|
43
|
+
return false; // verifier subverted → never satisfy the gate
|
|
44
|
+
return !REQUIRE_ACTIVATION || getLicenseInfo().valid;
|
|
45
|
+
}
|
|
46
|
+
/** The MCP error result returned for any tool call while activation is unmet. */
|
|
47
|
+
export function activationGateResult() {
|
|
48
|
+
return {
|
|
49
|
+
content: [{
|
|
50
|
+
type: 'text',
|
|
51
|
+
text: '🔒 Wyrm requires a free account on this build.\n\n'
|
|
52
|
+
+ 'Run `wyrm login` in your terminal to sign in and activate (free). '
|
|
53
|
+
+ 'Your memory stays local — login just ties usage to an account so it can be managed.\n\n'
|
|
54
|
+
+ 'Already logged in? Your activation may have expired — run `wyrm login` again to refresh.',
|
|
55
|
+
}],
|
|
56
|
+
isError: true,
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
//# sourceMappingURL=activation.js.map
|
package/dist/agent-daemon.js
CHANGED
|
@@ -1,6 +1,283 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Agent daemon process manager.
|
|
3
|
+
*
|
|
4
|
+
* Lets an AI client (Claude / Codex / Cursor / etc.) bootstrap, monitor,
|
|
5
|
+
* and tear down the `wyrm-loop` autonomous scheduler without the
|
|
6
|
+
* operator running shell commands. The MCP server can spawn the daemon
|
|
7
|
+
* as a detached background process, write a PID + log file under
|
|
8
|
+
* `~/.wyrm/`, and check liveness on demand.
|
|
9
|
+
*
|
|
10
|
+
* Files (all under `~/.wyrm/`):
|
|
11
|
+
* wyrm-loop.pid PID of the running daemon (single-line)
|
|
12
|
+
* wyrm-loop.log Stdout/stderr of the daemon (rotated at 1MB)
|
|
13
|
+
*
|
|
14
|
+
* Single-instance guarantee — if a PID file exists and the process is
|
|
15
|
+
* alive, `start()` refuses (no fork-bomb). `restart()` is provided as
|
|
16
|
+
* an explicit operation.
|
|
17
|
+
*
|
|
18
|
+
* @copyright 2026 Ghost Protocol (Pvt) Ltd.
|
|
19
|
+
* @license Proprietary — (c) 2026 Ghost Protocol (Pvt) Ltd. All rights reserved. See LICENSE.
|
|
20
|
+
*/
|
|
21
|
+
import { spawn } from 'child_process';
|
|
22
|
+
import { existsSync, readFileSync, writeFileSync, statSync, openSync, closeSync, renameSync, unlinkSync, mkdirSync } from 'fs';
|
|
23
|
+
import { homedir } from 'os';
|
|
24
|
+
import { join, dirname, resolve } from 'path';
|
|
25
|
+
import { fileURLToPath } from 'url';
|
|
26
|
+
const WYRM_DIR = join(homedir(), '.wyrm');
|
|
27
|
+
const PID_FILE = join(WYRM_DIR, 'wyrm-loop.pid');
|
|
28
|
+
const LOG_FILE = join(WYRM_DIR, 'wyrm-loop.log');
|
|
29
|
+
const LOG_FILE_OLD = join(WYRM_DIR, 'wyrm-loop.log.1');
|
|
30
|
+
const MAX_LOG_BYTES = 1_000_000;
|
|
31
|
+
function ensureWyrmDir() {
|
|
32
|
+
if (!existsSync(WYRM_DIR))
|
|
33
|
+
mkdirSync(WYRM_DIR, { recursive: true });
|
|
34
|
+
}
|
|
35
|
+
function rotateLogIfLarge() {
|
|
36
|
+
try {
|
|
37
|
+
if (existsSync(LOG_FILE) && statSync(LOG_FILE).size > MAX_LOG_BYTES) {
|
|
38
|
+
if (existsSync(LOG_FILE_OLD))
|
|
39
|
+
unlinkSync(LOG_FILE_OLD);
|
|
40
|
+
renameSync(LOG_FILE, LOG_FILE_OLD);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
catch { /* best-effort */ }
|
|
44
|
+
}
|
|
45
|
+
function readPid() {
|
|
46
|
+
try {
|
|
47
|
+
const raw = readFileSync(PID_FILE, 'utf-8').trim();
|
|
48
|
+
const pid = parseInt(raw, 10);
|
|
49
|
+
return Number.isFinite(pid) && pid > 0 ? pid : null;
|
|
50
|
+
}
|
|
51
|
+
catch {
|
|
52
|
+
return null;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
function isProcessAlive(pid) {
|
|
56
|
+
try {
|
|
57
|
+
// signal 0 doesn't kill; just checks existence + permission
|
|
58
|
+
process.kill(pid, 0);
|
|
59
|
+
return true;
|
|
60
|
+
}
|
|
61
|
+
catch {
|
|
62
|
+
return false;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
/** Find the bundled `wyrm-loop` script path. Resolves relative to this
|
|
66
|
+
* module so it works whether installed via npm, run from source, or
|
|
67
|
+
* invoked from a global symlink. */
|
|
68
|
+
function locateLoopBinary() {
|
|
69
|
+
// 1. import.meta.url → packages/mcp-server/dist/agent-daemon.js
|
|
70
|
+
try {
|
|
71
|
+
const here = fileURLToPath(import.meta.url);
|
|
72
|
+
const candidates = [
|
|
73
|
+
// installed alongside (dist/wyrm-loop.js)
|
|
74
|
+
resolve(dirname(here), 'wyrm-loop.js'),
|
|
75
|
+
// source layout
|
|
76
|
+
resolve(dirname(here), '..', 'dist', 'wyrm-loop.js'),
|
|
77
|
+
];
|
|
78
|
+
for (const p of candidates) {
|
|
79
|
+
if (existsSync(p))
|
|
80
|
+
return p;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
catch { /* fall through */ }
|
|
84
|
+
// 2. Look in PATH for the `wyrm-loop` binary (set up by `npm install -g`)
|
|
85
|
+
const pathDirs = (process.env.PATH ?? '').split(':');
|
|
86
|
+
for (const dir of pathDirs) {
|
|
87
|
+
const cand = join(dir, 'wyrm-loop');
|
|
88
|
+
if (existsSync(cand))
|
|
89
|
+
return cand;
|
|
90
|
+
}
|
|
91
|
+
return null;
|
|
92
|
+
}
|
|
93
|
+
export class AgentDaemon {
|
|
94
|
+
db;
|
|
95
|
+
constructor(db) {
|
|
96
|
+
this.db = db;
|
|
97
|
+
}
|
|
98
|
+
/** Current daemon status. Always safe to call. */
|
|
99
|
+
status() {
|
|
100
|
+
const pid = readPid();
|
|
101
|
+
const running = pid != null && isProcessAlive(pid);
|
|
102
|
+
let started_at;
|
|
103
|
+
let uptime_seconds;
|
|
104
|
+
try {
|
|
105
|
+
if (existsSync(PID_FILE)) {
|
|
106
|
+
const st = statSync(PID_FILE);
|
|
107
|
+
started_at = st.mtime.toISOString();
|
|
108
|
+
uptime_seconds = Math.round((Date.now() - st.mtime.getTime()) / 1000);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
catch { /* best-effort */ }
|
|
112
|
+
// Read latest agent_actions row for "last action" summary
|
|
113
|
+
let last_action;
|
|
114
|
+
try {
|
|
115
|
+
const row = this.db.prepare(`
|
|
2
116
|
SELECT actor, goal_id, action_kind, summary, result_status, ran_at
|
|
3
117
|
FROM agent_actions ORDER BY id DESC LIMIT 1
|
|
4
|
-
`).get();
|
|
5
|
-
|
|
6
|
-
|
|
118
|
+
`).get();
|
|
119
|
+
if (row)
|
|
120
|
+
last_action = {
|
|
121
|
+
ran_at: row.ran_at, actor: row.actor, goal_id: row.goal_id,
|
|
122
|
+
summary: `${row.action_kind}: ${row.summary}`.slice(0, 200),
|
|
123
|
+
result_status: row.result_status,
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
catch { /* table may not exist on pre-v5 DBs */ }
|
|
127
|
+
let active_goals = 0;
|
|
128
|
+
let total_iterations = 0;
|
|
129
|
+
try {
|
|
130
|
+
active_goals = this.db.prepare(`SELECT COUNT(*) as c FROM goals WHERE status = 'active'`).get().c;
|
|
131
|
+
total_iterations = this.db.prepare(`SELECT COALESCE(SUM(iterations_count), 0) as c FROM goals`).get().c;
|
|
132
|
+
}
|
|
133
|
+
catch { /* pre-v5 DB */ }
|
|
134
|
+
return {
|
|
135
|
+
running,
|
|
136
|
+
pid: running ? pid : null,
|
|
137
|
+
pid_file: PID_FILE,
|
|
138
|
+
log_file: LOG_FILE,
|
|
139
|
+
started_at: running ? started_at : undefined,
|
|
140
|
+
uptime_seconds: running ? uptime_seconds : undefined,
|
|
141
|
+
last_action,
|
|
142
|
+
active_goals,
|
|
143
|
+
total_iterations,
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
/** Start the daemon. No-op if already running. */
|
|
147
|
+
start(opts = {}) {
|
|
148
|
+
ensureWyrmDir();
|
|
149
|
+
rotateLogIfLarge();
|
|
150
|
+
const cur = this.status();
|
|
151
|
+
if (cur.running) {
|
|
152
|
+
return { ok: true, pid: cur.pid ?? undefined, status: cur };
|
|
153
|
+
}
|
|
154
|
+
// Clear stale PID file from a crashed prior run
|
|
155
|
+
if (existsSync(PID_FILE)) {
|
|
156
|
+
try {
|
|
157
|
+
unlinkSync(PID_FILE);
|
|
158
|
+
}
|
|
159
|
+
catch { /* ignore */ }
|
|
160
|
+
}
|
|
161
|
+
const binary = locateLoopBinary();
|
|
162
|
+
if (!binary) {
|
|
163
|
+
return { ok: false, error: 'Could not locate wyrm-loop binary. Run `npm install -g wyrm-mcp` or `npm run build` in packages/mcp-server.' };
|
|
164
|
+
}
|
|
165
|
+
const args = ['--interval', String(opts.interval_seconds ?? 600)];
|
|
166
|
+
if (opts.max_steps)
|
|
167
|
+
args.push('--max-steps', String(opts.max_steps));
|
|
168
|
+
if (opts.project_path)
|
|
169
|
+
args.push('--project', opts.project_path);
|
|
170
|
+
if (opts.verbose)
|
|
171
|
+
args.push('--verbose');
|
|
172
|
+
// Open the log file once, share fd with the child
|
|
173
|
+
let logFd;
|
|
174
|
+
try {
|
|
175
|
+
logFd = openSync(LOG_FILE, 'a');
|
|
176
|
+
}
|
|
177
|
+
catch (err) {
|
|
178
|
+
return { ok: false, error: `Could not open log file ${LOG_FILE}: ${err.message}` };
|
|
179
|
+
}
|
|
180
|
+
let child;
|
|
181
|
+
try {
|
|
182
|
+
child = spawn('node', [binary, ...args], {
|
|
183
|
+
detached: true,
|
|
184
|
+
stdio: ['ignore', logFd, logFd],
|
|
185
|
+
env: { ...process.env, WYRM_LOOP_LOG: opts.verbose ? '1' : '0' },
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
catch (err) {
|
|
189
|
+
return { ok: false, error: `spawn failed: ${err.message}` };
|
|
190
|
+
}
|
|
191
|
+
if (!child.pid) {
|
|
192
|
+
try {
|
|
193
|
+
closeSync(logFd);
|
|
194
|
+
}
|
|
195
|
+
catch { /* ignore */ }
|
|
196
|
+
return { ok: false, error: 'spawn returned no PID' };
|
|
197
|
+
}
|
|
198
|
+
try {
|
|
199
|
+
writeFileSync(PID_FILE, String(child.pid), 'utf-8');
|
|
200
|
+
}
|
|
201
|
+
catch (err) {
|
|
202
|
+
// Process is up but we can't track it — kill to keep state consistent
|
|
203
|
+
try {
|
|
204
|
+
process.kill(child.pid, 'SIGTERM');
|
|
205
|
+
}
|
|
206
|
+
catch { /* ignore */ }
|
|
207
|
+
try {
|
|
208
|
+
closeSync(logFd);
|
|
209
|
+
}
|
|
210
|
+
catch { /* ignore */ }
|
|
211
|
+
return { ok: false, error: `Could not write PID file: ${err.message}` };
|
|
212
|
+
}
|
|
213
|
+
// Close the parent's copy of the log fd — the child inherits its own
|
|
214
|
+
// dup via stdio. Without this, every successful spawn leaks one fd in
|
|
215
|
+
// the parent (the MCP server).
|
|
216
|
+
try {
|
|
217
|
+
closeSync(logFd);
|
|
218
|
+
}
|
|
219
|
+
catch { /* ignore */ }
|
|
220
|
+
// unref so this process doesn't wait on the child
|
|
221
|
+
child.unref();
|
|
222
|
+
// Brief settle delay so status() reflects the new state
|
|
223
|
+
return { ok: true, pid: child.pid, status: this.status() };
|
|
224
|
+
}
|
|
225
|
+
/** Stop the daemon. Sends SIGTERM, then SIGKILL after a grace period. */
|
|
226
|
+
async stop(opts = {}) {
|
|
227
|
+
const pid = readPid();
|
|
228
|
+
if (pid == null) {
|
|
229
|
+
return { ok: true, was_running: false };
|
|
230
|
+
}
|
|
231
|
+
if (!isProcessAlive(pid)) {
|
|
232
|
+
// Stale PID file
|
|
233
|
+
try {
|
|
234
|
+
unlinkSync(PID_FILE);
|
|
235
|
+
}
|
|
236
|
+
catch { /* ignore */ }
|
|
237
|
+
return { ok: true, was_running: false, pid };
|
|
238
|
+
}
|
|
239
|
+
try {
|
|
240
|
+
process.kill(pid, 'SIGTERM');
|
|
241
|
+
}
|
|
242
|
+
catch (err) {
|
|
243
|
+
return { ok: false, was_running: true, pid, error: `SIGTERM failed: ${err.message}` };
|
|
244
|
+
}
|
|
245
|
+
const grace = Math.max(100, Math.min(opts.grace_ms ?? 3000, 30_000));
|
|
246
|
+
const start = Date.now();
|
|
247
|
+
while (Date.now() - start < grace) {
|
|
248
|
+
if (!isProcessAlive(pid))
|
|
249
|
+
break;
|
|
250
|
+
await new Promise(r => { setTimeout(r, 100); });
|
|
251
|
+
}
|
|
252
|
+
if (isProcessAlive(pid)) {
|
|
253
|
+
try {
|
|
254
|
+
process.kill(pid, 'SIGKILL');
|
|
255
|
+
}
|
|
256
|
+
catch { /* may already be dead */ }
|
|
257
|
+
}
|
|
258
|
+
try {
|
|
259
|
+
unlinkSync(PID_FILE);
|
|
260
|
+
}
|
|
261
|
+
catch { /* ignore */ }
|
|
262
|
+
return { ok: true, was_running: true, pid };
|
|
263
|
+
}
|
|
264
|
+
/** Stop + Start in sequence. */
|
|
265
|
+
async restart(opts = {}) {
|
|
266
|
+
await this.stop({ grace_ms: 3000 });
|
|
267
|
+
return this.start(opts);
|
|
268
|
+
}
|
|
269
|
+
/** Read the last N lines of the daemon log. */
|
|
270
|
+
recentLog(lines = 40) {
|
|
271
|
+
try {
|
|
272
|
+
if (!existsSync(LOG_FILE))
|
|
273
|
+
return '(log file does not exist)';
|
|
274
|
+
const raw = readFileSync(LOG_FILE, 'utf-8');
|
|
275
|
+
const all = raw.split('\n');
|
|
276
|
+
return all.slice(-Math.max(1, Math.min(lines, 1000))).join('\n');
|
|
277
|
+
}
|
|
278
|
+
catch (err) {
|
|
279
|
+
return `(could not read log: ${err.message})`;
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
//# sourceMappingURL=agent-daemon.js.map
|