@cogcoin/client 0.5.15 → 1.0.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/README.md +80 -25
- package/dist/app-paths.d.ts +5 -6
- package/dist/app-paths.js +8 -16
- package/dist/art/balance.txt +10 -0
- package/dist/art/welcome.txt +16 -0
- package/dist/bitcoind/bootstrap/controller.d.ts +1 -0
- package/dist/bitcoind/bootstrap/controller.js +53 -1
- package/dist/bitcoind/client/follow-block-times.d.ts +1 -0
- package/dist/bitcoind/client/follow-block-times.js +1 -1
- package/dist/bitcoind/client/internal-types.d.ts +7 -3
- package/dist/bitcoind/client/managed-client.d.ts +4 -2
- package/dist/bitcoind/client/managed-client.js +14 -0
- package/dist/bitcoind/client/sync-engine.js +72 -11
- package/dist/bitcoind/hash-order.d.ts +4 -0
- package/dist/bitcoind/hash-order.js +13 -0
- package/dist/bitcoind/indexer-daemon-main.js +11 -3
- package/dist/bitcoind/normalize.js +3 -2
- package/dist/bitcoind/processing-start-height.d.ts +5 -0
- package/dist/bitcoind/processing-start-height.js +7 -0
- package/dist/bitcoind/progress/constants.d.ts +4 -0
- package/dist/bitcoind/progress/constants.js +4 -0
- package/dist/bitcoind/progress/controller.d.ts +2 -1
- package/dist/bitcoind/progress/controller.js +3 -3
- package/dist/bitcoind/progress/follow-scene.d.ts +6 -2
- package/dist/bitcoind/progress/follow-scene.js +29 -6
- package/dist/bitcoind/progress/formatting.d.ts +1 -0
- package/dist/bitcoind/progress/formatting.js +6 -0
- package/dist/bitcoind/progress/train-scene.js +37 -18
- package/dist/bitcoind/progress/tty-renderer.d.ts +6 -1
- package/dist/bitcoind/progress/tty-renderer.js +8 -4
- package/dist/bitcoind/rpc.d.ts +2 -1
- package/dist/bitcoind/rpc.js +3 -0
- package/dist/bitcoind/types.d.ts +6 -0
- package/dist/bytes.d.ts +1 -0
- package/dist/bytes.js +3 -0
- package/dist/cli/art.d.ts +2 -0
- package/dist/cli/art.js +37 -0
- package/dist/cli/commands/client-admin.d.ts +2 -0
- package/dist/cli/commands/client-admin.js +91 -0
- package/dist/cli/commands/follow.js +0 -2
- package/dist/cli/commands/mining-admin.js +6 -47
- package/dist/cli/commands/mining-read.js +11 -50
- package/dist/cli/commands/mining-runtime.js +142 -5
- package/dist/cli/commands/service-runtime.js +0 -2
- package/dist/cli/commands/status.js +8 -2
- package/dist/cli/commands/sync.js +49 -92
- package/dist/cli/commands/wallet-admin.js +142 -136
- package/dist/cli/commands/wallet-mutation.js +91 -79
- package/dist/cli/commands/wallet-read.js +15 -18
- package/dist/cli/context.js +5 -14
- package/dist/cli/mining-format.d.ts +0 -1
- package/dist/cli/mining-format.js +5 -37
- package/dist/cli/mining-json.d.ts +0 -18
- package/dist/cli/mining-json.js +0 -35
- package/dist/cli/mutation-command-groups.d.ts +1 -2
- package/dist/cli/mutation-command-groups.js +0 -5
- package/dist/cli/mutation-json.d.ts +24 -145
- package/dist/cli/mutation-json.js +30 -136
- package/dist/cli/mutation-resolved-json.d.ts +0 -7
- package/dist/cli/mutation-resolved-json.js +4 -10
- package/dist/cli/mutation-success.d.ts +2 -0
- package/dist/cli/mutation-success.js +11 -1
- package/dist/cli/mutation-text-format.js +1 -3
- package/dist/cli/output.d.ts +1 -1
- package/dist/cli/output.js +254 -231
- package/dist/cli/parse.d.ts +1 -1
- package/dist/cli/parse.js +93 -122
- package/dist/cli/preview-json.d.ts +17 -120
- package/dist/cli/preview-json.js +14 -97
- package/dist/cli/prompt.js +8 -13
- package/dist/cli/read-json.d.ts +15 -37
- package/dist/cli/read-json.js +44 -140
- package/dist/cli/runner.js +10 -13
- package/dist/cli/sync-progress.d.ts +6 -0
- package/dist/cli/sync-progress.js +91 -0
- package/dist/cli/types.d.ts +9 -17
- package/dist/cli/types.js +0 -2
- package/dist/cli/wallet-format.d.ts +1 -0
- package/dist/cli/wallet-format.js +208 -144
- package/dist/cli/workflow-hints.d.ts +3 -3
- package/dist/cli/workflow-hints.js +11 -8
- package/dist/client/default-client.d.ts +3 -1
- package/dist/client/default-client.js +45 -2
- package/dist/client/factory.js +1 -1
- package/dist/client/initialization.js +23 -0
- package/dist/client/persistence.js +5 -5
- package/dist/client/store-adapter.js +1 -0
- package/dist/sqlite/checkpoints.d.ts +1 -0
- package/dist/sqlite/checkpoints.js +7 -0
- package/dist/sqlite/store.js +14 -1
- package/dist/types.d.ts +1 -0
- package/dist/wallet/coin-control.d.ts +41 -12
- package/dist/wallet/coin-control.js +100 -428
- package/dist/wallet/descriptor-normalization.d.ts +1 -3
- package/dist/wallet/descriptor-normalization.js +0 -16
- package/dist/wallet/lifecycle.d.ts +7 -99
- package/dist/wallet/lifecycle.js +513 -968
- package/dist/wallet/managed-core-wallet.d.ts +13 -0
- package/dist/wallet/managed-core-wallet.js +20 -0
- package/dist/wallet/mining/constants.d.ts +5 -12
- package/dist/wallet/mining/constants.js +5 -12
- package/dist/wallet/mining/control.d.ts +1 -13
- package/dist/wallet/mining/control.js +45 -349
- package/dist/wallet/mining/index.d.ts +4 -5
- package/dist/wallet/mining/index.js +2 -3
- package/dist/wallet/mining/runner.d.ts +123 -13
- package/dist/wallet/mining/runner.js +899 -511
- package/dist/wallet/mining/runtime-artifacts.js +23 -3
- package/dist/wallet/mining/sentence-protocol.d.ts +44 -0
- package/dist/wallet/mining/sentence-protocol.js +123 -0
- package/dist/wallet/mining/sentences.d.ts +4 -8
- package/dist/wallet/mining/sentences.js +3 -52
- package/dist/wallet/mining/state.d.ts +11 -6
- package/dist/wallet/mining/state.js +7 -6
- package/dist/wallet/mining/types.d.ts +2 -30
- package/dist/wallet/mining/visualizer.d.ts +31 -3
- package/dist/wallet/mining/visualizer.js +135 -13
- package/dist/wallet/read/context.d.ts +0 -2
- package/dist/wallet/read/context.js +119 -140
- package/dist/wallet/read/filter.js +2 -11
- package/dist/wallet/read/index.d.ts +1 -1
- package/dist/wallet/read/project.js +24 -77
- package/dist/wallet/read/types.d.ts +10 -25
- package/dist/wallet/reset.d.ts +0 -1
- package/dist/wallet/reset.js +60 -138
- package/dist/wallet/root-resolution.d.ts +1 -5
- package/dist/wallet/root-resolution.js +0 -18
- package/dist/wallet/runtime.d.ts +0 -6
- package/dist/wallet/runtime.js +0 -8
- package/dist/wallet/state/client-password-agent.js +208 -0
- package/dist/wallet/state/client-password.d.ts +65 -0
- package/dist/wallet/state/client-password.js +952 -0
- package/dist/wallet/state/crypto.d.ts +1 -20
- package/dist/wallet/state/crypto.js +0 -63
- package/dist/wallet/state/provider.d.ts +23 -11
- package/dist/wallet/state/provider.js +248 -290
- package/dist/wallet/state/storage.d.ts +2 -2
- package/dist/wallet/state/storage.js +48 -16
- package/dist/wallet/tx/anchor.d.ts +3 -28
- package/dist/wallet/tx/anchor.js +349 -1250
- package/dist/wallet/tx/bitcoin-transfer.d.ts +35 -0
- package/dist/wallet/tx/bitcoin-transfer.js +200 -0
- package/dist/wallet/tx/cog.d.ts +5 -1
- package/dist/wallet/tx/cog.js +149 -185
- package/dist/wallet/tx/common.d.ts +61 -8
- package/dist/wallet/tx/common.js +266 -146
- package/dist/wallet/tx/domain-admin.d.ts +3 -1
- package/dist/wallet/tx/domain-admin.js +61 -99
- package/dist/wallet/tx/domain-market.d.ts +5 -1
- package/dist/wallet/tx/domain-market.js +221 -228
- package/dist/wallet/tx/field.d.ts +4 -10
- package/dist/wallet/tx/field.js +83 -924
- package/dist/wallet/tx/identity-selector.d.ts +9 -3
- package/dist/wallet/tx/identity-selector.js +17 -35
- package/dist/wallet/tx/index.d.ts +3 -1
- package/dist/wallet/tx/index.js +2 -1
- package/dist/wallet/tx/register.d.ts +3 -1
- package/dist/wallet/tx/register.js +62 -220
- package/dist/wallet/tx/reputation.d.ts +3 -1
- package/dist/wallet/tx/reputation.js +58 -95
- package/dist/wallet/types.d.ts +8 -122
- package/package.json +5 -5
- package/dist/wallet/archive.d.ts +0 -4
- package/dist/wallet/archive.js +0 -41
- package/dist/wallet/mining/hook-protocol.d.ts +0 -47
- package/dist/wallet/mining/hook-protocol.js +0 -161
- package/dist/wallet/mining/hook-runner.js +0 -52
- package/dist/wallet/mining/hooks.d.ts +0 -38
- package/dist/wallet/mining/hooks.js +0 -520
- package/dist/wallet/state/explicit-lock.d.ts +0 -4
- package/dist/wallet/state/explicit-lock.js +0 -19
- package/dist/wallet/state/session.d.ts +0 -12
- package/dist/wallet/state/session.js +0 -23
- /package/dist/wallet/{mining/hook-runner.d.ts → state/client-password-agent.d.ts} +0 -0
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import { MINING_HOOK_SCHEMA_VERSION } from "./constants.js";
|
|
2
|
-
export interface GenerateSentencesHookRequestV1 {
|
|
3
|
-
schemaVersion: typeof MINING_HOOK_SCHEMA_VERSION;
|
|
4
|
-
requestId: string;
|
|
5
|
-
targetBlockHeight: number;
|
|
6
|
-
referencedBlockHashDisplay: string;
|
|
7
|
-
generatedAtUnixMs: number;
|
|
8
|
-
extraPrompt: string | null;
|
|
9
|
-
limits: {
|
|
10
|
-
maxCandidatesPerRootDomain: number;
|
|
11
|
-
maxCandidatesTotal: number;
|
|
12
|
-
timeoutMs: number;
|
|
13
|
-
maxCandidateSentenceUtf8Bytes: number;
|
|
14
|
-
};
|
|
15
|
-
rootDomains: Array<{
|
|
16
|
-
domainId: number;
|
|
17
|
-
domainName: string;
|
|
18
|
-
requiredWords: [string, string, string, string, string];
|
|
19
|
-
}>;
|
|
20
|
-
}
|
|
21
|
-
export interface GenerateSentencesHookCandidateV1 {
|
|
22
|
-
domainId: number;
|
|
23
|
-
sentence: string;
|
|
24
|
-
attribution?: {
|
|
25
|
-
hook?: string;
|
|
26
|
-
provider?: string;
|
|
27
|
-
model?: string;
|
|
28
|
-
promptLabel?: string;
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
-
export interface GenerateSentencesHookResponseV1 {
|
|
32
|
-
schemaVersion: typeof MINING_HOOK_SCHEMA_VERSION;
|
|
33
|
-
requestId: string;
|
|
34
|
-
candidates: GenerateSentencesHookCandidateV1[];
|
|
35
|
-
}
|
|
36
|
-
export type MiningHookOperatorValidationState = "never" | "current" | "stale" | "failed";
|
|
37
|
-
export declare const MINING_HOOK_VALIDATION_FIXTURES: GenerateSentencesHookRequestV1[];
|
|
38
|
-
export declare function createGenerateSentencesHookLimits(): GenerateSentencesHookRequestV1["limits"];
|
|
39
|
-
export declare function parseStrictJsonValue(raw: string, invalidMessage: string): unknown;
|
|
40
|
-
export declare function stripMarkdownCodeFence(raw: string): string;
|
|
41
|
-
export declare function normalizeHookResponse(options: {
|
|
42
|
-
request: GenerateSentencesHookRequestV1;
|
|
43
|
-
response: unknown;
|
|
44
|
-
}): {
|
|
45
|
-
response: GenerateSentencesHookResponseV1;
|
|
46
|
-
candidates: GenerateSentencesHookCandidateV1[];
|
|
47
|
-
};
|
|
@@ -1,161 +0,0 @@
|
|
|
1
|
-
import { MINING_HOOK_MAX_CANDIDATES_PER_ROOT_DOMAIN, MINING_HOOK_MAX_CANDIDATES_TOTAL, MINING_HOOK_MAX_CANDIDATE_SENTENCE_UTF8_BYTES, MINING_HOOK_SCHEMA_VERSION, MINING_HOOK_TIMEOUT_MS, } from "./constants.js";
|
|
2
|
-
export const MINING_HOOK_VALIDATION_FIXTURES = [
|
|
3
|
-
{
|
|
4
|
-
schemaVersion: MINING_HOOK_SCHEMA_VERSION,
|
|
5
|
-
requestId: "validation-empty-mining-v1",
|
|
6
|
-
targetBlockHeight: 840_000,
|
|
7
|
-
referencedBlockHashDisplay: "0000000000000000000000000000000000000000000000000000000000000042",
|
|
8
|
-
generatedAtUnixMs: 0,
|
|
9
|
-
extraPrompt: "",
|
|
10
|
-
limits: {
|
|
11
|
-
maxCandidateSentenceUtf8Bytes: MINING_HOOK_MAX_CANDIDATE_SENTENCE_UTF8_BYTES,
|
|
12
|
-
maxCandidatesPerRootDomain: MINING_HOOK_MAX_CANDIDATES_PER_ROOT_DOMAIN,
|
|
13
|
-
maxCandidatesTotal: MINING_HOOK_MAX_CANDIDATES_TOTAL,
|
|
14
|
-
timeoutMs: MINING_HOOK_TIMEOUT_MS,
|
|
15
|
-
},
|
|
16
|
-
rootDomains: [],
|
|
17
|
-
},
|
|
18
|
-
{
|
|
19
|
-
schemaVersion: MINING_HOOK_SCHEMA_VERSION,
|
|
20
|
-
requestId: "validation-fixture-mining-v1",
|
|
21
|
-
targetBlockHeight: 840_000,
|
|
22
|
-
referencedBlockHashDisplay: "0000000000000000000000000000000000000000000000000000000000000042",
|
|
23
|
-
generatedAtUnixMs: 0,
|
|
24
|
-
extraPrompt: "",
|
|
25
|
-
limits: {
|
|
26
|
-
maxCandidateSentenceUtf8Bytes: MINING_HOOK_MAX_CANDIDATE_SENTENCE_UTF8_BYTES,
|
|
27
|
-
maxCandidatesPerRootDomain: MINING_HOOK_MAX_CANDIDATES_PER_ROOT_DOMAIN,
|
|
28
|
-
maxCandidatesTotal: MINING_HOOK_MAX_CANDIDATES_TOTAL,
|
|
29
|
-
timeoutMs: MINING_HOOK_TIMEOUT_MS,
|
|
30
|
-
},
|
|
31
|
-
rootDomains: [
|
|
32
|
-
{
|
|
33
|
-
domainId: 424_242,
|
|
34
|
-
domainName: "fixture",
|
|
35
|
-
requiredWords: ["abandon", "ability", "able", "about", "above"],
|
|
36
|
-
},
|
|
37
|
-
],
|
|
38
|
-
},
|
|
39
|
-
];
|
|
40
|
-
export function createGenerateSentencesHookLimits() {
|
|
41
|
-
return {
|
|
42
|
-
maxCandidateSentenceUtf8Bytes: MINING_HOOK_MAX_CANDIDATE_SENTENCE_UTF8_BYTES,
|
|
43
|
-
maxCandidatesPerRootDomain: MINING_HOOK_MAX_CANDIDATES_PER_ROOT_DOMAIN,
|
|
44
|
-
maxCandidatesTotal: MINING_HOOK_MAX_CANDIDATES_TOTAL,
|
|
45
|
-
timeoutMs: MINING_HOOK_TIMEOUT_MS,
|
|
46
|
-
};
|
|
47
|
-
}
|
|
48
|
-
function normalizeAttribution(raw) {
|
|
49
|
-
if (raw === null || typeof raw !== "object") {
|
|
50
|
-
return undefined;
|
|
51
|
-
}
|
|
52
|
-
const attribution = raw;
|
|
53
|
-
const normalized = {};
|
|
54
|
-
for (const key of ["hook", "provider", "model", "promptLabel"]) {
|
|
55
|
-
const value = attribution[key];
|
|
56
|
-
if (typeof value === "string" && value.length > 0) {
|
|
57
|
-
normalized[key] = value;
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
return Object.keys(normalized).length === 0
|
|
61
|
-
? undefined
|
|
62
|
-
: normalized;
|
|
63
|
-
}
|
|
64
|
-
export function parseStrictJsonValue(raw, invalidMessage) {
|
|
65
|
-
const trimmed = raw.trim();
|
|
66
|
-
if (trimmed.length === 0) {
|
|
67
|
-
throw new Error(invalidMessage);
|
|
68
|
-
}
|
|
69
|
-
try {
|
|
70
|
-
return JSON.parse(trimmed);
|
|
71
|
-
}
|
|
72
|
-
catch {
|
|
73
|
-
throw new Error(invalidMessage);
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
export function stripMarkdownCodeFence(raw) {
|
|
77
|
-
const trimmed = raw.trim();
|
|
78
|
-
if (!trimmed.startsWith("```")) {
|
|
79
|
-
return raw;
|
|
80
|
-
}
|
|
81
|
-
const lines = trimmed.split(/\r?\n/);
|
|
82
|
-
if (lines.length < 3) {
|
|
83
|
-
return raw;
|
|
84
|
-
}
|
|
85
|
-
const first = lines[0].trim();
|
|
86
|
-
const last = lines.at(-1)?.trim();
|
|
87
|
-
if (!first.startsWith("```") || last !== "```") {
|
|
88
|
-
return raw;
|
|
89
|
-
}
|
|
90
|
-
return lines.slice(1, -1).join("\n");
|
|
91
|
-
}
|
|
92
|
-
export function normalizeHookResponse(options) {
|
|
93
|
-
const raw = options.response;
|
|
94
|
-
if (raw === null || typeof raw !== "object") {
|
|
95
|
-
throw new Error("Custom mining hook returned an invalid JSON response.");
|
|
96
|
-
}
|
|
97
|
-
const response = raw;
|
|
98
|
-
if (response.schemaVersion !== MINING_HOOK_SCHEMA_VERSION) {
|
|
99
|
-
throw new Error("Custom mining hook returned an unsupported schema version.");
|
|
100
|
-
}
|
|
101
|
-
if (response.requestId !== options.request.requestId) {
|
|
102
|
-
throw new Error("Custom mining hook returned a mismatched requestId.");
|
|
103
|
-
}
|
|
104
|
-
if (!Array.isArray(response.candidates)) {
|
|
105
|
-
throw new Error("Custom mining hook response must include a candidates array.");
|
|
106
|
-
}
|
|
107
|
-
if (response.candidates.length > options.request.limits.maxCandidatesTotal) {
|
|
108
|
-
throw new Error("Custom mining hook returned too many total candidates.");
|
|
109
|
-
}
|
|
110
|
-
const allowedDomainIds = new Set(options.request.rootDomains.map((domain) => domain.domainId));
|
|
111
|
-
const perDomainCounts = new Map();
|
|
112
|
-
const dedupe = new Set();
|
|
113
|
-
const candidates = [];
|
|
114
|
-
for (const rawCandidate of response.candidates) {
|
|
115
|
-
if (rawCandidate === null || typeof rawCandidate !== "object") {
|
|
116
|
-
throw new Error("Custom mining hook returned an invalid candidate entry.");
|
|
117
|
-
}
|
|
118
|
-
const candidate = rawCandidate;
|
|
119
|
-
const domainId = candidate.domainId;
|
|
120
|
-
const sentence = candidate.sentence;
|
|
121
|
-
if (!Number.isInteger(domainId)) {
|
|
122
|
-
throw new Error("Custom mining hook candidate is missing a valid domainId.");
|
|
123
|
-
}
|
|
124
|
-
if (!allowedDomainIds.has(domainId)) {
|
|
125
|
-
throw new Error("Custom mining hook candidate referenced an unknown domainId.");
|
|
126
|
-
}
|
|
127
|
-
if (typeof sentence !== "string") {
|
|
128
|
-
throw new Error("Custom mining hook candidate is missing a valid sentence.");
|
|
129
|
-
}
|
|
130
|
-
const trimmedSentence = sentence.trim();
|
|
131
|
-
if (trimmedSentence.length === 0) {
|
|
132
|
-
throw new Error("Custom mining hook candidate sentence was empty after trimming.");
|
|
133
|
-
}
|
|
134
|
-
if (Buffer.byteLength(trimmedSentence, "utf8") > options.request.limits.maxCandidateSentenceUtf8Bytes) {
|
|
135
|
-
throw new Error("Custom mining hook candidate sentence exceeded the UTF-8 byte limit.");
|
|
136
|
-
}
|
|
137
|
-
const nextCount = (perDomainCounts.get(domainId) ?? 0) + 1;
|
|
138
|
-
perDomainCounts.set(domainId, nextCount);
|
|
139
|
-
if (nextCount > options.request.limits.maxCandidatesPerRootDomain) {
|
|
140
|
-
throw new Error("Custom mining hook returned too many candidates for one domain.");
|
|
141
|
-
}
|
|
142
|
-
const dedupeKey = `${domainId}:${trimmedSentence}`;
|
|
143
|
-
if (dedupe.has(dedupeKey)) {
|
|
144
|
-
continue;
|
|
145
|
-
}
|
|
146
|
-
dedupe.add(dedupeKey);
|
|
147
|
-
candidates.push({
|
|
148
|
-
domainId: domainId,
|
|
149
|
-
sentence: trimmedSentence,
|
|
150
|
-
attribution: normalizeAttribution(candidate.attribution),
|
|
151
|
-
});
|
|
152
|
-
}
|
|
153
|
-
return {
|
|
154
|
-
response: {
|
|
155
|
-
schemaVersion: MINING_HOOK_SCHEMA_VERSION,
|
|
156
|
-
requestId: options.request.requestId,
|
|
157
|
-
candidates,
|
|
158
|
-
},
|
|
159
|
-
candidates,
|
|
160
|
-
};
|
|
161
|
-
}
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import { readFile } from "node:fs/promises";
|
|
2
|
-
import { pathToFileURL } from "node:url";
|
|
3
|
-
async function readStdin() {
|
|
4
|
-
const chunks = [];
|
|
5
|
-
for await (const chunk of process.stdin) {
|
|
6
|
-
chunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk));
|
|
7
|
-
}
|
|
8
|
-
return Buffer.concat(chunks).toString("utf8");
|
|
9
|
-
}
|
|
10
|
-
async function run() {
|
|
11
|
-
const entrypointPath = process.argv[2];
|
|
12
|
-
if (typeof entrypointPath !== "string" || entrypointPath.length === 0) {
|
|
13
|
-
throw new Error("Missing custom mining hook entrypoint path.");
|
|
14
|
-
}
|
|
15
|
-
const moduleUrl = pathToFileURL(entrypointPath).href;
|
|
16
|
-
const requestText = await readStdin();
|
|
17
|
-
let request;
|
|
18
|
-
try {
|
|
19
|
-
request = JSON.parse(requestText);
|
|
20
|
-
}
|
|
21
|
-
catch {
|
|
22
|
-
throw new Error("Custom mining hook runner received invalid JSON on stdin.");
|
|
23
|
-
}
|
|
24
|
-
const loaded = await import(moduleUrl);
|
|
25
|
-
const generateSentences = loaded.generateSentences;
|
|
26
|
-
if (typeof generateSentences !== "function") {
|
|
27
|
-
throw new Error("Custom mining hooks must export generateSentences(request).");
|
|
28
|
-
}
|
|
29
|
-
const response = await generateSentences(request);
|
|
30
|
-
process.stdout.write(`${JSON.stringify(response)}\n`, "utf8");
|
|
31
|
-
}
|
|
32
|
-
if (process.argv[1] !== undefined) {
|
|
33
|
-
const mainUrl = pathToFileURL(process.argv[1]).href;
|
|
34
|
-
if (import.meta.url === mainUrl) {
|
|
35
|
-
await run().catch(async (error) => {
|
|
36
|
-
if (error instanceof Error && error.message.includes("Cannot find module")) {
|
|
37
|
-
try {
|
|
38
|
-
const entrypointPath = process.argv[2];
|
|
39
|
-
if (typeof entrypointPath === "string") {
|
|
40
|
-
await readFile(entrypointPath, "utf8");
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
catch {
|
|
44
|
-
// Ignore; the original import error is still the best diagnostic.
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
const message = error instanceof Error ? (error.stack ?? error.message) : String(error);
|
|
48
|
-
process.stderr.write(`${message.trim()}\n`, "utf8");
|
|
49
|
-
process.exitCode = 1;
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
}
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import type { HookClientStateRecord } from "../types.js";
|
|
2
|
-
import { type GenerateSentencesHookCandidateV1, type GenerateSentencesHookRequestV1, type GenerateSentencesHookResponseV1 } from "./hook-protocol.js";
|
|
3
|
-
import type { MiningHookInspection } from "./types.js";
|
|
4
|
-
export declare function runGenerateSentencesHookRequest(options: {
|
|
5
|
-
hookRootPath: string;
|
|
6
|
-
entrypointPath: string;
|
|
7
|
-
request: GenerateSentencesHookRequestV1;
|
|
8
|
-
signal?: AbortSignal;
|
|
9
|
-
timeoutMs?: number;
|
|
10
|
-
}): Promise<{
|
|
11
|
-
response: GenerateSentencesHookResponseV1;
|
|
12
|
-
candidates: GenerateSentencesHookCandidateV1[];
|
|
13
|
-
}>;
|
|
14
|
-
export declare function ensureMiningHookTemplate(options: {
|
|
15
|
-
hookRootPath: string;
|
|
16
|
-
entrypointPath: string;
|
|
17
|
-
packagePath: string;
|
|
18
|
-
}): Promise<boolean>;
|
|
19
|
-
export declare function validateCustomMiningHook(options: {
|
|
20
|
-
hookRootPath: string;
|
|
21
|
-
entrypointPath: string;
|
|
22
|
-
packagePath: string;
|
|
23
|
-
}): Promise<{
|
|
24
|
-
launchFingerprint: string;
|
|
25
|
-
fullFingerprint: string;
|
|
26
|
-
}>;
|
|
27
|
-
export declare function inspectMiningHookState(options: {
|
|
28
|
-
hookRootPath: string;
|
|
29
|
-
entrypointPath: string;
|
|
30
|
-
packagePath: string;
|
|
31
|
-
localState: HookClientStateRecord | null;
|
|
32
|
-
verify: boolean;
|
|
33
|
-
nowUnixMs?: number;
|
|
34
|
-
}): Promise<MiningHookInspection>;
|
|
35
|
-
export declare function shouldEnterHookCooldown(options: {
|
|
36
|
-
consecutiveFailureCount: number;
|
|
37
|
-
nowUnixMs: number;
|
|
38
|
-
}): number | null;
|