@fml-inc/fml 0.7.0 → 0.8.0-rc.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/.claude-plugin/plugin.json +2 -4
- package/README.md +312 -79
- package/agent-assets/fml/SKILL.md +180 -0
- package/bin/fml +4 -18
- package/bin/hook-handler +7 -0
- package/bin/mcp-server +4 -18
- package/bin/observer +6 -0
- package/dist/chunk-7DR5X7XI.js +1522 -0
- package/dist/chunk-CK5MEL5J.js +140 -0
- package/dist/chunk-DEMVOVVY.js +4442 -0
- package/dist/chunk-F66IBM3Z.js +1037 -0
- package/dist/chunk-HUR2HCUG.js +953 -0
- package/dist/chunk-I4GZPTBM.js +109 -0
- package/dist/chunk-JXSSPQ5B.js +3331 -0
- package/dist/{chunk-PZ5AY32C.js → chunk-MLKGABMK.js} +0 -1
- package/dist/{chunk-PTUZMKSN.js → chunk-P3QLARXE.js} +34 -23
- package/dist/chunk-T5YVLSUC.js +138 -0
- package/dist/cli.js +7523 -1005
- package/dist/{esm-2EUDFZWP.js → esm-4YKLKFRX.js} +546 -741
- package/dist/hook-handler.js +190 -0
- package/dist/mcp/server.js +112 -98
- package/dist/observer-server.js +1566 -0
- package/dist/sync-cycle.js +31 -0
- package/dist/{token-store-3IQSLOTQ.js → token-store-R7WXEPLI.js} +10 -3
- package/hooks/hooks.json +290 -0
- package/package.json +24 -27
- package/dist/chunk-PTUZMKSN.js.map +0 -1
- package/dist/chunk-PZ5AY32C.js.map +0 -1
- package/dist/chunk-S4TJNLEN.js +0 -61
- package/dist/chunk-S4TJNLEN.js.map +0 -1
- package/dist/chunk-VV4JHH4H.js +0 -437
- package/dist/chunk-VV4JHH4H.js.map +0 -1
- package/dist/chunk-YH5ROR7G.js +0 -69
- package/dist/chunk-YH5ROR7G.js.map +0 -1
- package/dist/cli.js.map +0 -1
- package/dist/daemon-MSLDHLMH.js +0 -21
- package/dist/daemon-MSLDHLMH.js.map +0 -1
- package/dist/daemon-utils-OODBIYB7.js +0 -10
- package/dist/daemon-utils-OODBIYB7.js.map +0 -1
- package/dist/esm-2EUDFZWP.js.map +0 -1
- package/dist/mcp/server.js.map +0 -1
- package/dist/postinstall.js +0 -16
- package/dist/postinstall.js.map +0 -1
- package/dist/token-store-3IQSLOTQ.js.map +0 -1
- package/scripts/postinstall.cjs +0 -25
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import {
|
|
2
|
+
resolvePackageRoot,
|
|
3
|
+
runRawSyncOnce
|
|
4
|
+
} from "./chunk-JXSSPQ5B.js";
|
|
5
|
+
|
|
6
|
+
// src/observer/sync-cycle.ts
|
|
7
|
+
import { fork } from "child_process";
|
|
8
|
+
import path from "path";
|
|
9
|
+
var ObserverSyncCycleAbortedError = class extends Error {
|
|
10
|
+
constructor() {
|
|
11
|
+
super("observer sync cycle aborted");
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
function abortableFetch(signal) {
|
|
15
|
+
return (input, init) => {
|
|
16
|
+
const requestSignal = init?.signal;
|
|
17
|
+
return fetch(input, {
|
|
18
|
+
...init,
|
|
19
|
+
signal: requestSignal ? AbortSignal.any([signal, requestSignal]) : signal
|
|
20
|
+
});
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
async function runObserverSyncCycle(signal) {
|
|
24
|
+
const attempt = await runRawSyncOnce({
|
|
25
|
+
continuous: true,
|
|
26
|
+
...signal ? { fetch: abortableFetch(signal) } : {}
|
|
27
|
+
});
|
|
28
|
+
if (attempt.kind === "disabled") return { kind: "disabled" };
|
|
29
|
+
if (attempt.kind === "unauthenticated") {
|
|
30
|
+
return {
|
|
31
|
+
kind: "unauthenticated",
|
|
32
|
+
environment: attempt.environment
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
return {
|
|
36
|
+
kind: "completed",
|
|
37
|
+
environment: attempt.environment,
|
|
38
|
+
outcome: attempt.result.outcome,
|
|
39
|
+
uploadedBytes: attempt.result.upload.uploadedBytes,
|
|
40
|
+
failed: attempt.result.upload.failed,
|
|
41
|
+
exhausted: attempt.result.upload.exhausted,
|
|
42
|
+
retryAtMs: attempt.result.upload.retryAtMs,
|
|
43
|
+
nextRetryAtMs: attempt.result.upload.nextRetryAtMs
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
function isSyncOutcome(value) {
|
|
47
|
+
return value === "drained" || value === "pending" || value === "backing_off" || value === "busy" || value === "throttled" || value === "failed" || value === "exhausted";
|
|
48
|
+
}
|
|
49
|
+
function parseObserverSyncCycleResult(value) {
|
|
50
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return null;
|
|
51
|
+
const record = value;
|
|
52
|
+
if (record.kind === "disabled") return { kind: "disabled" };
|
|
53
|
+
if (record.kind === "unauthenticated" && typeof record.environment === "string") {
|
|
54
|
+
return { kind: "unauthenticated", environment: record.environment };
|
|
55
|
+
}
|
|
56
|
+
if (record.kind !== "completed" || typeof record.environment !== "string" || !isSyncOutcome(record.outcome) || typeof record.uploadedBytes !== "number" || typeof record.failed !== "number" || typeof record.exhausted !== "number" || record.retryAtMs !== void 0 && typeof record.retryAtMs !== "number" || record.nextRetryAtMs !== void 0 && typeof record.nextRetryAtMs !== "number") {
|
|
57
|
+
return null;
|
|
58
|
+
}
|
|
59
|
+
return {
|
|
60
|
+
kind: "completed",
|
|
61
|
+
environment: record.environment,
|
|
62
|
+
outcome: record.outcome,
|
|
63
|
+
uploadedBytes: record.uploadedBytes,
|
|
64
|
+
failed: record.failed,
|
|
65
|
+
exhausted: record.exhausted,
|
|
66
|
+
...typeof record.retryAtMs === "number" ? { retryAtMs: record.retryAtMs } : {},
|
|
67
|
+
...typeof record.nextRetryAtMs === "number" ? { nextRetryAtMs: record.nextRetryAtMs } : {}
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
function runObserverSyncCycleSubprocess(opts = {}) {
|
|
71
|
+
if (opts.signal?.aborted) {
|
|
72
|
+
return Promise.reject(new ObserverSyncCycleAbortedError());
|
|
73
|
+
}
|
|
74
|
+
const scriptPath = opts.scriptPath ?? path.join(resolvePackageRoot(), "dist", "sync-cycle.js");
|
|
75
|
+
return new Promise((resolve, reject) => {
|
|
76
|
+
const child = fork(scriptPath, [], {
|
|
77
|
+
detached: false,
|
|
78
|
+
env: process.env,
|
|
79
|
+
execPath: process.execPath,
|
|
80
|
+
silent: false,
|
|
81
|
+
stdio: ["ignore", "inherit", "inherit", "ipc"]
|
|
82
|
+
});
|
|
83
|
+
let result = null;
|
|
84
|
+
let settled = false;
|
|
85
|
+
let forceKillTimer = null;
|
|
86
|
+
const cleanup = () => {
|
|
87
|
+
opts.signal?.removeEventListener("abort", abort);
|
|
88
|
+
if (forceKillTimer) clearTimeout(forceKillTimer);
|
|
89
|
+
};
|
|
90
|
+
const finishReject = (error) => {
|
|
91
|
+
if (settled) return;
|
|
92
|
+
settled = true;
|
|
93
|
+
cleanup();
|
|
94
|
+
reject(error);
|
|
95
|
+
};
|
|
96
|
+
const abort = () => {
|
|
97
|
+
try {
|
|
98
|
+
child.kill("SIGTERM");
|
|
99
|
+
forceKillTimer = setTimeout(() => {
|
|
100
|
+
try {
|
|
101
|
+
child.kill("SIGKILL");
|
|
102
|
+
} catch {
|
|
103
|
+
}
|
|
104
|
+
}, 2e3);
|
|
105
|
+
forceKillTimer.unref();
|
|
106
|
+
} catch {
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
opts.signal?.addEventListener("abort", abort, { once: true });
|
|
110
|
+
child.once("error", finishReject);
|
|
111
|
+
child.on("message", (message) => {
|
|
112
|
+
const parsed = parseObserverSyncCycleResult(message);
|
|
113
|
+
if (parsed) result = parsed;
|
|
114
|
+
});
|
|
115
|
+
child.once("exit", (code, signal) => {
|
|
116
|
+
if (settled) return;
|
|
117
|
+
settled = true;
|
|
118
|
+
cleanup();
|
|
119
|
+
if (opts.signal?.aborted) {
|
|
120
|
+
reject(new ObserverSyncCycleAbortedError());
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
if (code !== 0 || !result) {
|
|
124
|
+
reject(
|
|
125
|
+
new Error(
|
|
126
|
+
`observer sync cycle exited code=${code ?? "null"} signal=${signal ?? "null"}`
|
|
127
|
+
)
|
|
128
|
+
);
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
resolve(result);
|
|
132
|
+
});
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
export {
|
|
137
|
+
ObserverSyncCycleAbortedError,
|
|
138
|
+
runObserverSyncCycle,
|
|
139
|
+
runObserverSyncCycleSubprocess
|
|
140
|
+
};
|