@trading-boy/cli 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/README.md +8 -0
- package/dist/api-client.d.ts +20 -0
- package/dist/api-client.d.ts.map +1 -0
- package/dist/api-client.js +81 -0
- package/dist/api-client.js.map +1 -0
- package/dist/cli.d.ts +5 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +71 -0
- package/dist/cli.js.map +1 -0
- package/dist/commands/audit.d.ts +33 -0
- package/dist/commands/audit.d.ts.map +1 -0
- package/dist/commands/audit.js +135 -0
- package/dist/commands/audit.js.map +1 -0
- package/dist/commands/behavioral.d.ts +40 -0
- package/dist/commands/behavioral.d.ts.map +1 -0
- package/dist/commands/behavioral.js +369 -0
- package/dist/commands/behavioral.js.map +1 -0
- package/dist/commands/billing.d.ts +12 -0
- package/dist/commands/billing.d.ts.map +1 -0
- package/dist/commands/billing.js +111 -0
- package/dist/commands/billing.js.map +1 -0
- package/dist/commands/catalysts.d.ts +8 -0
- package/dist/commands/catalysts.d.ts.map +1 -0
- package/dist/commands/catalysts.js +192 -0
- package/dist/commands/catalysts.js.map +1 -0
- package/dist/commands/config-cmd.d.ts +30 -0
- package/dist/commands/config-cmd.d.ts.map +1 -0
- package/dist/commands/config-cmd.js +265 -0
- package/dist/commands/config-cmd.js.map +1 -0
- package/dist/commands/context.d.ts +40 -0
- package/dist/commands/context.d.ts.map +1 -0
- package/dist/commands/context.js +385 -0
- package/dist/commands/context.js.map +1 -0
- package/dist/commands/decisions.d.ts +21 -0
- package/dist/commands/decisions.d.ts.map +1 -0
- package/dist/commands/decisions.js +327 -0
- package/dist/commands/decisions.js.map +1 -0
- package/dist/commands/events.d.ts +3 -0
- package/dist/commands/events.d.ts.map +1 -0
- package/dist/commands/events.js +201 -0
- package/dist/commands/events.js.map +1 -0
- package/dist/commands/infra.d.ts +22 -0
- package/dist/commands/infra.d.ts.map +1 -0
- package/dist/commands/infra.js +228 -0
- package/dist/commands/infra.js.map +1 -0
- package/dist/commands/journal.d.ts +3 -0
- package/dist/commands/journal.d.ts.map +1 -0
- package/dist/commands/journal.js +616 -0
- package/dist/commands/journal.js.map +1 -0
- package/dist/commands/login.d.ts +18 -0
- package/dist/commands/login.d.ts.map +1 -0
- package/dist/commands/login.js +121 -0
- package/dist/commands/login.js.map +1 -0
- package/dist/commands/logout.d.ts +7 -0
- package/dist/commands/logout.d.ts.map +1 -0
- package/dist/commands/logout.js +39 -0
- package/dist/commands/logout.js.map +1 -0
- package/dist/commands/narratives.d.ts +3 -0
- package/dist/commands/narratives.d.ts.map +1 -0
- package/dist/commands/narratives.js +336 -0
- package/dist/commands/narratives.js.map +1 -0
- package/dist/commands/query.d.ts +39 -0
- package/dist/commands/query.d.ts.map +1 -0
- package/dist/commands/query.js +212 -0
- package/dist/commands/query.js.map +1 -0
- package/dist/commands/review.d.ts +3 -0
- package/dist/commands/review.d.ts.map +1 -0
- package/dist/commands/review.js +481 -0
- package/dist/commands/review.js.map +1 -0
- package/dist/commands/risk.d.ts +19 -0
- package/dist/commands/risk.d.ts.map +1 -0
- package/dist/commands/risk.js +190 -0
- package/dist/commands/risk.js.map +1 -0
- package/dist/commands/social.d.ts +9 -0
- package/dist/commands/social.d.ts.map +1 -0
- package/dist/commands/social.js +386 -0
- package/dist/commands/social.js.map +1 -0
- package/dist/commands/subscribe.d.ts +45 -0
- package/dist/commands/subscribe.d.ts.map +1 -0
- package/dist/commands/subscribe.js +259 -0
- package/dist/commands/subscribe.js.map +1 -0
- package/dist/commands/trader.d.ts +12 -0
- package/dist/commands/trader.d.ts.map +1 -0
- package/dist/commands/trader.js +265 -0
- package/dist/commands/trader.js.map +1 -0
- package/dist/commands/watch.d.ts +26 -0
- package/dist/commands/watch.d.ts.map +1 -0
- package/dist/commands/watch.js +121 -0
- package/dist/commands/watch.js.map +1 -0
- package/dist/commands/whoami.d.ts +14 -0
- package/dist/commands/whoami.d.ts.map +1 -0
- package/dist/commands/whoami.js +73 -0
- package/dist/commands/whoami.js.map +1 -0
- package/dist/credentials.d.ts +18 -0
- package/dist/credentials.d.ts.map +1 -0
- package/dist/credentials.js +164 -0
- package/dist/credentials.js.map +1 -0
- package/dist/index.d.ts +33 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +28 -0
- package/dist/index.js.map +1 -0
- package/dist/utils.d.ts +6 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +21 -0
- package/dist/utils.js.map +1 -0
- package/package.json +40 -0
package/README.md
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { redactApiKey } from './credentials.js';
|
|
2
|
+
export interface ApiResponse<T> {
|
|
3
|
+
data: T;
|
|
4
|
+
status: number;
|
|
5
|
+
}
|
|
6
|
+
export declare class ApiError extends Error {
|
|
7
|
+
readonly status: number;
|
|
8
|
+
readonly body?: unknown | undefined;
|
|
9
|
+
constructor(message: string, status: number, body?: unknown | undefined);
|
|
10
|
+
}
|
|
11
|
+
export declare function resolveApiKey(flagKey?: string): Promise<string>;
|
|
12
|
+
export declare function getApiBase(): string;
|
|
13
|
+
export declare function apiRequest<T>(path: string, options?: {
|
|
14
|
+
method?: string;
|
|
15
|
+
body?: unknown;
|
|
16
|
+
apiKey?: string;
|
|
17
|
+
headers?: Record<string, string>;
|
|
18
|
+
}): Promise<T>;
|
|
19
|
+
export { redactApiKey };
|
|
20
|
+
//# sourceMappingURL=api-client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api-client.d.ts","sourceRoot":"","sources":["../src/api-client.ts"],"names":[],"mappings":"AACA,OAAO,EAAmB,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAUjE,MAAM,WAAW,WAAW,CAAC,CAAC;IAC5B,IAAI,EAAE,CAAC,CAAC;IACR,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,qBAAa,QAAS,SAAQ,KAAK;aAGf,MAAM,EAAE,MAAM;aACd,IAAI,CAAC,EAAE,OAAO;gBAF9B,OAAO,EAAE,MAAM,EACC,MAAM,EAAE,MAAM,EACd,IAAI,CAAC,EAAE,OAAO,YAAA;CAKjC;AAID,wBAAsB,aAAa,CAAC,OAAO,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAoBrE;AAID,wBAAgB,UAAU,IAAI,MAAM,CAEnC;AAID,wBAAsB,UAAU,CAAC,CAAC,EAChC,IAAI,EAAE,MAAM,EACZ,OAAO,GAAE;IACP,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAC7B,GACL,OAAO,CAAC,CAAC,CAAC,CAyDZ;AAED,OAAO,EAAE,YAAY,EAAE,CAAC"}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { createLogger } from '@trading-boy/core';
|
|
2
|
+
import { loadCredentials, redactApiKey } from './credentials.js';
|
|
3
|
+
const logger = createLogger('cli-api-client');
|
|
4
|
+
// ─── Constants ───
|
|
5
|
+
const DEFAULT_API_BASE = 'http://localhost:3003';
|
|
6
|
+
export class ApiError extends Error {
|
|
7
|
+
status;
|
|
8
|
+
body;
|
|
9
|
+
constructor(message, status, body) {
|
|
10
|
+
super(message);
|
|
11
|
+
this.status = status;
|
|
12
|
+
this.body = body;
|
|
13
|
+
this.name = 'ApiError';
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
// ─── API Key Resolution ───
|
|
17
|
+
export async function resolveApiKey(flagKey) {
|
|
18
|
+
// Priority: env var > flag > stored key
|
|
19
|
+
const envKey = process.env.TRADING_BOY_API_KEY;
|
|
20
|
+
if (envKey) {
|
|
21
|
+
logger.debug('Using API key from TRADING_BOY_API_KEY env var');
|
|
22
|
+
return envKey;
|
|
23
|
+
}
|
|
24
|
+
if (flagKey) {
|
|
25
|
+
logger.debug('Using API key from --api-key flag');
|
|
26
|
+
return flagKey;
|
|
27
|
+
}
|
|
28
|
+
const stored = await loadCredentials();
|
|
29
|
+
if (stored?.apiKey) {
|
|
30
|
+
logger.debug('Using stored API key');
|
|
31
|
+
return stored.apiKey;
|
|
32
|
+
}
|
|
33
|
+
throw new Error('Not authenticated. Run `trading-boy login` to set up your API key.');
|
|
34
|
+
}
|
|
35
|
+
// ─── API Base URL ───
|
|
36
|
+
export function getApiBase() {
|
|
37
|
+
return process.env.TRADING_BOY_API_URL || DEFAULT_API_BASE;
|
|
38
|
+
}
|
|
39
|
+
// ─── API Request ───
|
|
40
|
+
export async function apiRequest(path, options = {}) {
|
|
41
|
+
const apiKey = options.apiKey ?? (await resolveApiKey());
|
|
42
|
+
const apiBase = getApiBase();
|
|
43
|
+
const url = `${apiBase}${path}`;
|
|
44
|
+
const headers = {
|
|
45
|
+
'X-API-Key': apiKey,
|
|
46
|
+
'Content-Type': 'application/json',
|
|
47
|
+
...options.headers,
|
|
48
|
+
};
|
|
49
|
+
const fetchOptions = {
|
|
50
|
+
method: options.method ?? 'GET',
|
|
51
|
+
headers,
|
|
52
|
+
};
|
|
53
|
+
if (options.body) {
|
|
54
|
+
fetchOptions.body = JSON.stringify(options.body);
|
|
55
|
+
}
|
|
56
|
+
logger.debug({ url, method: fetchOptions.method }, 'API request');
|
|
57
|
+
const response = await fetch(url, fetchOptions);
|
|
58
|
+
if (response.status === 401) {
|
|
59
|
+
throw new ApiError('API key invalid or expired. Run `trading-boy login` to re-authenticate.', 401);
|
|
60
|
+
}
|
|
61
|
+
if (response.status === 403) {
|
|
62
|
+
throw new ApiError('Subscription inactive. Run `trading-boy billing manage` to update your billing.', 403);
|
|
63
|
+
}
|
|
64
|
+
if (response.status === 429) {
|
|
65
|
+
const retryAfter = response.headers.get('Retry-After');
|
|
66
|
+
throw new ApiError(`Rate limited. Retry after ${retryAfter ?? '60'}s.`, 429);
|
|
67
|
+
}
|
|
68
|
+
if (!response.ok) {
|
|
69
|
+
let body;
|
|
70
|
+
try {
|
|
71
|
+
body = await response.json();
|
|
72
|
+
}
|
|
73
|
+
catch {
|
|
74
|
+
body = await response.text().catch(() => null);
|
|
75
|
+
}
|
|
76
|
+
throw new ApiError(`API error: ${response.status}`, response.status, body);
|
|
77
|
+
}
|
|
78
|
+
return (await response.json());
|
|
79
|
+
}
|
|
80
|
+
export { redactApiKey };
|
|
81
|
+
//# sourceMappingURL=api-client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api-client.js","sourceRoot":"","sources":["../src/api-client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAEjE,MAAM,MAAM,GAAG,YAAY,CAAC,gBAAgB,CAAC,CAAC;AAE9C,oBAAoB;AAEpB,MAAM,gBAAgB,GAAG,uBAAuB,CAAC;AASjD,MAAM,OAAO,QAAS,SAAQ,KAAK;IAGf;IACA;IAHlB,YACE,OAAe,EACC,MAAc,EACd,IAAc;QAE9B,KAAK,CAAC,OAAO,CAAC,CAAC;QAHC,WAAM,GAAN,MAAM,CAAQ;QACd,SAAI,GAAJ,IAAI,CAAU;QAG9B,IAAI,CAAC,IAAI,GAAG,UAAU,CAAC;IACzB,CAAC;CACF;AAED,6BAA6B;AAE7B,MAAM,CAAC,KAAK,UAAU,aAAa,CAAC,OAAgB;IAClD,wCAAwC;IACxC,MAAM,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,mBAAmB,CAAC;IAC/C,IAAI,MAAM,EAAE,CAAC;QACX,MAAM,CAAC,KAAK,CAAC,gDAAgD,CAAC,CAAC;QAC/D,OAAO,MAAM,CAAC;IAChB,CAAC;IAED,IAAI,OAAO,EAAE,CAAC;QACZ,MAAM,CAAC,KAAK,CAAC,mCAAmC,CAAC,CAAC;QAClD,OAAO,OAAO,CAAC;IACjB,CAAC;IAED,MAAM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li.js
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { Command } from 'commander';
|
|
3
|
+
import { registerQueryCommand } from './commands/query.js';
|
|
4
|
+
import { registerWatchCommand } from './commands/watch.js';
|
|
5
|
+
import { registerCatalystsCommand } from './commands/catalysts.js';
|
|
6
|
+
import { registerRiskCommand } from './commands/risk.js';
|
|
7
|
+
import { registerDecisionsCommand } from './commands/decisions.js';
|
|
8
|
+
import { registerTraderCommand } from './commands/trader.js';
|
|
9
|
+
import { registerBehavioralCommand } from './commands/behavioral.js';
|
|
10
|
+
import { registerSocialCommand } from './commands/social.js';
|
|
11
|
+
import { registerNarrativeCommand } from './commands/narratives.js';
|
|
12
|
+
import { registerEventsCommand } from './commands/events.js';
|
|
13
|
+
import { registerJournalCommand } from './commands/journal.js';
|
|
14
|
+
import { registerAuditCommand } from './commands/audit.js';
|
|
15
|
+
import { registerContextCommand } from './commands/context.js';
|
|
16
|
+
import { registerConfigCommand } from './commands/config-cmd.js';
|
|
17
|
+
import { registerInfraCommand } from './commands/infra.js';
|
|
18
|
+
import { registerLoginCommand } from './commands/login.js';
|
|
19
|
+
import { registerLogoutCommand } from './commands/logout.js';
|
|
20
|
+
import { registerWhoamiCommand } from './commands/whoami.js';
|
|
21
|
+
import { registerBillingCommand } from './commands/billing.js';
|
|
22
|
+
import { registerSubscribeCommand } from './commands/subscribe.js';
|
|
23
|
+
// ─── CLI Setup ───
|
|
24
|
+
export function createCli() {
|
|
25
|
+
const program = new Command();
|
|
26
|
+
program
|
|
27
|
+
.name('trading-boy')
|
|
28
|
+
.description('Trading Boy — Crypto context graph system for traders and agentic trading systems')
|
|
29
|
+
.version('0.1.0');
|
|
30
|
+
// ─── Register all commands ───
|
|
31
|
+
// Primary: context assembly
|
|
32
|
+
registerContextCommand(program);
|
|
33
|
+
// Data queries
|
|
34
|
+
registerQueryCommand(program);
|
|
35
|
+
registerWatchCommand(program);
|
|
36
|
+
registerCatalystsCommand(program);
|
|
37
|
+
registerRiskCommand(program);
|
|
38
|
+
registerSocialCommand(program);
|
|
39
|
+
registerNarrativeCommand(program);
|
|
40
|
+
// Trading journal & decisions
|
|
41
|
+
registerJournalCommand(program);
|
|
42
|
+
registerDecisionsCommand(program);
|
|
43
|
+
registerTraderCommand(program);
|
|
44
|
+
registerBehavioralCommand(program);
|
|
45
|
+
registerAuditCommand(program);
|
|
46
|
+
registerEventsCommand(program);
|
|
47
|
+
// Authentication & billing
|
|
48
|
+
registerLoginCommand(program);
|
|
49
|
+
registerLogoutCommand(program);
|
|
50
|
+
registerWhoamiCommand(program);
|
|
51
|
+
registerBillingCommand(program);
|
|
52
|
+
registerSubscribeCommand(program);
|
|
53
|
+
// System management
|
|
54
|
+
registerConfigCommand(program);
|
|
55
|
+
registerInfraCommand(program);
|
|
56
|
+
return program;
|
|
57
|
+
}
|
|
58
|
+
// ─── Main Entry Point ───
|
|
59
|
+
export async function main() {
|
|
60
|
+
const program = createCli();
|
|
61
|
+
await program.parseAsync(process.argv);
|
|
62
|
+
}
|
|
63
|
+
// Auto-execute when run directly (not during test imports)
|
|
64
|
+
const isDirectRun = process.argv[1]?.endsWith('cli.js') || process.argv[1]?.endsWith('cli.ts');
|
|
65
|
+
if (isDirectRun) {
|
|
66
|
+
main().catch((err) => {
|
|
67
|
+
console.error(err);
|
|
68
|
+
process.exit(1);
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
//# sourceMappingURL=cli.js.map
|
package/dist/cli.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAC3D,OAAO,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAC3D,OAAO,EAAE,wBAAwB,EAAE,MAAM,yBAA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AC,GAAG,EAAE,EAAE;QACnB,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QACnB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { Command } from 'commander';
|
|
2
|
+
import { type ChainVerificationResult, type VerifiableDecision } from '@trading-boy/core';
|
|
3
|
+
import { type DecisionEventRecord } from '@trading-boy/graph-db';
|
|
4
|
+
/**
|
|
5
|
+
* Convert a DecisionEventRecord (string eventTime) to a VerifiableDecision
|
|
6
|
+
* (Date eventTime) required by the core verifyChain function.
|
|
7
|
+
*/
|
|
8
|
+
export declare function toVerifiableDecision(record: DecisionEventRecord): VerifiableDecision;
|
|
9
|
+
export interface AuditVerifyResult {
|
|
10
|
+
valid: boolean;
|
|
11
|
+
chainLength: number;
|
|
12
|
+
verifiedCount: number;
|
|
13
|
+
breakPoint?: {
|
|
14
|
+
index: number;
|
|
15
|
+
decisionId: string;
|
|
16
|
+
decisionType: string;
|
|
17
|
+
eventTime: string;
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Build a human-readable audit result from chain verification output.
|
|
22
|
+
*
|
|
23
|
+
* @param verification - Core chain verification result
|
|
24
|
+
* @param decisions - The original decision records (for break point details)
|
|
25
|
+
* @returns Structured audit result
|
|
26
|
+
*/
|
|
27
|
+
export declare function buildAuditResult(verification: ChainVerificationResult, decisions: DecisionEventRecord[]): AuditVerifyResult;
|
|
28
|
+
/**
|
|
29
|
+
* Format audit verification output with chalk styling.
|
|
30
|
+
*/
|
|
31
|
+
export declare function formatAuditVerifyOutput(result: AuditVerifyResult, elapsedMs: number): string;
|
|
32
|
+
export declare function registerAuditCommand(program: Command): void;
|
|
33
|
+
//# sourceMappingURL=audit.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"audit.d.ts","sourceRoot":"","sources":["../../src/commands/audit.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEpC,OAAO,EAIL,KAAK,uBAAuB,EAC5B,KAAK,kBAAkB,EACxB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAGL,KAAK,mBAAmB,EACzB,MAAM,uBAAuB,CAAC;AAwB/B;;;GAGG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,mBAAmB,GAAG,kBAAkB,CAepF;AAID,MAAM,WAAW,iBAAiB;IAChC,KAAK,EAAE,OAAO,CAAC;IACf,WAAW,EAAE,MAAM,CAAC;IACpB,aAAa,EAAE,MAAM,CAAC;IACtB,UAAU,CAAC,EAAE;QACX,KAAK,EAAE,MAAM,CAAC;QACd,UAAU,EAAE,MAAM,CAAC;QACnB,YAAY,EAAE,MAAM,CAAC;QACrB,SAAS,EAAE,MAAM,CAAC;KACnB,CAAC;CACH;AAED;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAC9B,YAAY,EAAE,uBAAuB,EACrC,SAAS,EAAE,mBAAmB,EAAE,GAC/B,iBAAiB,CAuBnB;AAID;;GAEG;AACH,wBAAgB,uBAAuB,CAAC,MAAM,EAAE,iBAAiB,EAAE,SAAS,EAAE,MAAM,GAAG,MAAM,CAwB5F;AAID,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CA4C3D"}
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import chalk from 'chalk';
|
|
2
|
+
import { getConfig, createLogger, verifyChain, } from '@trading-boy/core';
|
|
3
|
+
import { Neo4jClient, getDecisionChain, } from '@trading-boy/graph-db';
|
|
4
|
+
import { formatConnectionError } from '../utils.js';
|
|
5
|
+
// ─── Logger ───
|
|
6
|
+
const logger = createLogger('cli-audit');
|
|
7
|
+
// ─── Default Trader ───
|
|
8
|
+
const DEFAULT_TRADER_ID = 'default';
|
|
9
|
+
// ─── Neo4j Client Factory ───
|
|
10
|
+
function createNeo4jClient() {
|
|
11
|
+
const config = getConfig();
|
|
12
|
+
return new Neo4jClient({
|
|
13
|
+
uri: config.NEO4J_URI,
|
|
14
|
+
username: config.NEO4J_USER,
|
|
15
|
+
password: config.NEO4J_PASSWORD,
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
// ─── Record → VerifiableDecision Conversion ───
|
|
19
|
+
/**
|
|
20
|
+
* Convert a DecisionEventRecord (string eventTime) to a VerifiableDecision
|
|
21
|
+
* (Date eventTime) required by the core verifyChain function.
|
|
22
|
+
*/
|
|
23
|
+
export function toVerifiableDecision(record) {
|
|
24
|
+
return {
|
|
25
|
+
decisionType: record.decisionType,
|
|
26
|
+
tokenSymbol: record.tokenSymbol,
|
|
27
|
+
eventTime: new Date(record.eventTime),
|
|
28
|
+
direction: record.direction,
|
|
29
|
+
entryPrice: record.entryPrice,
|
|
30
|
+
exitPrice: record.exitPrice,
|
|
31
|
+
size: record.size,
|
|
32
|
+
thesis: record.thesis,
|
|
33
|
+
confidence: record.confidence,
|
|
34
|
+
actor: record.actor,
|
|
35
|
+
hash: record.hash,
|
|
36
|
+
previousHash: record.previousHash,
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Build a human-readable audit result from chain verification output.
|
|
41
|
+
*
|
|
42
|
+
* @param verification - Core chain verification result
|
|
43
|
+
* @param decisions - The original decision records (for break point details)
|
|
44
|
+
* @returns Structured audit result
|
|
45
|
+
*/
|
|
46
|
+
export function buildAuditResult(verification, decisions) {
|
|
47
|
+
if (verification.valid) {
|
|
48
|
+
return {
|
|
49
|
+
valid: true,
|
|
50
|
+
chainLength: decisions.length,
|
|
51
|
+
verifiedCount: decisions.length,
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
const breakIndex = verification.brokenAt;
|
|
55
|
+
const broken = decisions[breakIndex];
|
|
56
|
+
return {
|
|
57
|
+
valid: false,
|
|
58
|
+
chainLength: decisions.length,
|
|
59
|
+
verifiedCount: breakIndex,
|
|
60
|
+
breakPoint: {
|
|
61
|
+
index: breakIndex,
|
|
62
|
+
decisionId: broken.id,
|
|
63
|
+
decisionType: broken.decisionType,
|
|
64
|
+
eventTime: broken.eventTime,
|
|
65
|
+
},
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
// ─── Formatter ───
|
|
69
|
+
/**
|
|
70
|
+
* Format audit verification output with chalk styling.
|
|
71
|
+
*/
|
|
72
|
+
export function formatAuditVerifyOutput(result, elapsedMs) {
|
|
73
|
+
const lines = [];
|
|
74
|
+
lines.push('');
|
|
75
|
+
lines.push(chalk.bold.cyan(' Audit Verification'));
|
|
76
|
+
lines.push(chalk.gray(' ' + '\u2500'.repeat(50)));
|
|
77
|
+
lines.push('');
|
|
78
|
+
if (result.valid) {
|
|
79
|
+
lines.push(` ${chalk.green('\u2713')} ${chalk.green('Chain integrity verified')}`);
|
|
80
|
+
lines.push(` ${chalk.gray('Decisions verified:')} ${chalk.white(String(result.verifiedCount))}`);
|
|
81
|
+
lines.push(` ${chalk.gray('Chain length:')} ${chalk.white(String(result.chainLength))}`);
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
lines.push(` ${chalk.red('\u2717')} ${chalk.red(`Chain integrity BROKEN at decision ${result.breakPoint.index}`)}`);
|
|
85
|
+
lines.push(` ${chalk.gray('Decision ID:')} ${chalk.white(result.breakPoint.decisionId)}`);
|
|
86
|
+
lines.push(` ${chalk.gray('Type:')} ${chalk.white(result.breakPoint.decisionType)}`);
|
|
87
|
+
lines.push(` ${chalk.gray('Event time:')} ${chalk.white(result.breakPoint.eventTime)}`);
|
|
88
|
+
lines.push(` ${chalk.gray('Verified:')} ${chalk.yellow(`${result.verifiedCount} of ${result.chainLength}`)} decisions`);
|
|
89
|
+
}
|
|
90
|
+
lines.push(` ${chalk.dim(`Elapsed: ${elapsedMs.toFixed(2)}ms`)}`);
|
|
91
|
+
lines.push('');
|
|
92
|
+
return lines.join('\n');
|
|
93
|
+
}
|
|
94
|
+
// ─── Command Registration ───
|
|
95
|
+
export function registerAuditCommand(program) {
|
|
96
|
+
const audit = program
|
|
97
|
+
.command('audit')
|
|
98
|
+
.description('Audit and integrity verification commands');
|
|
99
|
+
// ─── audit verify ───
|
|
100
|
+
audit
|
|
101
|
+
.command('verify')
|
|
102
|
+
.description('Verify the integrity of the decision hash chain')
|
|
103
|
+
.option('--trader <traderId>', 'Trader ID', DEFAULT_TRADER_ID)
|
|
104
|
+
.action(async (options) => {
|
|
105
|
+
const client = createNeo4jClient();
|
|
106
|
+
try {
|
|
107
|
+
await client.connect();
|
|
108
|
+
const decisions = await getDecisionChain(client, options.trader);
|
|
109
|
+
if (decisions.length === 0) {
|
|
110
|
+
console.log('No decisions found for trader.');
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
const startTime = performance.now();
|
|
114
|
+
const verifiable = decisions.map(toVerifiableDecision);
|
|
115
|
+
const verification = verifyChain(verifiable);
|
|
116
|
+
const elapsed = performance.now() - startTime;
|
|
117
|
+
const result = buildAuditResult(verification, decisions);
|
|
118
|
+
console.log(formatAuditVerifyOutput(result, elapsed));
|
|
119
|
+
logger.debug({ elapsed: elapsed.toFixed(2) + 'ms' }, 'Chain verification complete');
|
|
120
|
+
}
|
|
121
|
+
catch (error) {
|
|
122
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
123
|
+
logger.error({ error: message }, 'Failed to verify chain');
|
|
124
|
+
console.error(`Error: ${message}`);
|
|
125
|
+
const guidance = formatConnectionError(message);
|
|
126
|
+
if (guidance)
|
|
127
|
+
console.error(guidance);
|
|
128
|
+
process.exitCode = 1;
|
|
129
|
+
}
|
|
130
|
+
finally {
|
|
131
|
+
await client.disconnect();
|
|
132
|
+
}
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
//# sourceMappingURL=audit.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"audit.js","sourceRoot":"","sources":["../../src/commands/audit.ts"],"names":[],"mappings":"AACA,O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AC,EAAE,OAAO,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,IAAI,EAAE,EAAE,6BAA6B,CAAC,CAAC;QACtF,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,OAAO,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;YACvE,MAAM,CAAC,KAAK,CAAC,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE,wBAAwB,CAAC,CAAC;YAC3D,OAAO,CAAC,KAAK,CAAC,UAAU,OAAO,EAAE,CAAC,CAAC;YACnC,MAAM,QAAQ,GAAG,qBAAqB,CAAC,OAAO,CAAC,CAAC;YAChD,IAAI,QAAQ;gBAAE,OAAO,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;YACtC,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAC;QACvB,CAAC;gBAAS,CAAC;YACT,MAAM,MAAM,CAAC,UAAU,EAAE,CAAC;QAC5B,CAAC;IACH,CAAC,CAAC,CAAC;AACP,CAAC"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { Command } from 'commander';
|
|
2
|
+
import type { BehavioralProfile, PatternCostAnalysis } from '@trading-boy/context-engine';
|
|
3
|
+
/**
|
|
4
|
+
* Parse a period string like "30d", "7d", "90d" into days.
|
|
5
|
+
* Returns default 30 if the string cannot be parsed.
|
|
6
|
+
*/
|
|
7
|
+
export declare function parsePeriodDays(period: string): number;
|
|
8
|
+
/**
|
|
9
|
+
* Color-code a behavioral health score.
|
|
10
|
+
* 0-30: green (healthy), 31-60: yellow (watch), 61+: red (concerning)
|
|
11
|
+
*/
|
|
12
|
+
export declare function colorScore(score: number): string;
|
|
13
|
+
/**
|
|
14
|
+
* Format a commitment honor rate as a colored percentage.
|
|
15
|
+
*/
|
|
16
|
+
export declare function colorHonorRate(rate: number): string;
|
|
17
|
+
/**
|
|
18
|
+
* Return the label for a behavioral health score.
|
|
19
|
+
*/
|
|
20
|
+
export declare function scoreLabel(score: number): string;
|
|
21
|
+
/**
|
|
22
|
+
* Format a full behavioral profile as a human-readable string.
|
|
23
|
+
*/
|
|
24
|
+
export declare function formatBehavioralProfile(profile: BehavioralProfile): string;
|
|
25
|
+
/**
|
|
26
|
+
* Format a list of decisions with behavioral flags.
|
|
27
|
+
*/
|
|
28
|
+
export declare function formatBehavioralFlags(decisions: Array<{
|
|
29
|
+
id: string;
|
|
30
|
+
eventTime: string;
|
|
31
|
+
tokenSymbol: string;
|
|
32
|
+
decisionType: string;
|
|
33
|
+
behavioralFlags: string[];
|
|
34
|
+
}>): string;
|
|
35
|
+
/**
|
|
36
|
+
* Format a pattern cost analysis as a human-readable table.
|
|
37
|
+
*/
|
|
38
|
+
export declare function formatCostAnalysis(analysis: PatternCostAnalysis, period: string): string;
|
|
39
|
+
export declare function registerBehavioralCommand(program: Command): void;
|
|
40
|
+
//# sourceMappingURL=behavioral.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"behavioral.d.ts","sourceRoot":"","sources":["../../src/commands/behavioral.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAU,MAAM,WAAW,CAAC;AAW5C,OAAO,KAAK,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAC;AAwB1F;;;GAGG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAMtD;AAID;;;GAGG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAKhD;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAKnD;AAED;;GAEG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAIhD;AAED;;GAEG;AACH,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,iBAAiB,GAAG,MAAM,CAoD1E;AAED;;GAEG;AACH,wBAAgB,qBAAqB,CACnC,SAAS,EAAE,KAAK,CAAC;IACf,EAAE,EAAE,MAAM,CAAC;IACX,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE,MAAM,CAAC;IACrB,eAAe,EAAE,MAAM,EAAE,CAAC;CAC3B,CAAC,GACD,MAAM,CA0CR;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,mBAAmB,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CA6DxF;AA8CD,wBAAgB,yBAAyB,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CA+HhE"}
|