log-llm-config 1.2.2 → 1.2.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.
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  // Barrel — all public exports. Sub-modules live in this folder.
3
3
  export { BATCH_CHUNK_SIZE } from './sender/batch_sender.js';
4
- export { sendConfigFile, sendConfigFilesBatch } from './sender/batch_sender.js';
4
+ export { sendConfigFile, sendConfigFilesBatch, sendIngestSessionStart, sendIngestSessionFinish } from './sender/batch_sender.js';
5
5
  export { createSignature, canonicalizePayload } from './sender/signing.js';
6
6
  export { readVSCDBState } from './readers/vscdb_reader.js';
7
7
  export { readJSONFile, readMarkdownFile } from './readers/file_readers.js';
@@ -12,7 +12,7 @@ import { readJSONFile, readMarkdownFile } from '../readers/file_readers.js';
12
12
  import { isVscdbVirtualPath, tryReadVscdbVirtualFile } from '../readers/vscdb_config_builder.js';
13
13
  import { collectConfigFilesFromPatterns, collectMcpToolFiles, collectConfigFilesFromInstalledPlugins, determineFileTypeFromPath } from '../collection/config_collector.js';
14
14
  import { normalizePathSkipPrefixes } from '../paths/pattern_resolver.js';
15
- import { sendConfigFile, sendConfigFilesBatch, sendHookRequestCreate, sendHookRequestUpdateManifest, BATCH_CHUNK_SIZE } from '../sender/batch_sender.js';
15
+ import { sendConfigFile, sendConfigFilesBatch, sendHookRequestCreate, sendHookRequestUpdateManifest, sendIngestSessionStart, sendIngestSessionFinish, BATCH_CHUNK_SIZE } from '../sender/batch_sender.js';
16
16
  import { createSignature, canonicalizePayload } from '../sender/signing.js';
17
17
  const PROJECT_ROOT = process.cwd();
18
18
  async function collectAllConfigFiles(endpointBase) {
@@ -74,9 +74,11 @@ async function sendAllConfigFiles(configFiles, hardwareUuid, authKey) {
74
74
  const manifest = configFiles.map((c) => c.file_path);
75
75
  const hookRequestId = await sendHookRequestCreate(hardwareUuid, authKey, hookType, workspaceRepo);
76
76
  hookRunLog(`hook-request id=${hookRequestId ?? 'none'}`);
77
+ const ingestSessionId = await sendIngestSessionStart(hardwareUuid, authKey);
78
+ hookRunLog(`ingest-session id=${ingestSessionId ?? 'none'}`);
77
79
  const estimatedRequests = Math.ceil(configFiles.length / BATCH_CHUNK_SIZE);
78
- hookRunLog(`config send: batch ${configFiles.length} file(s) in ~${estimatedRequests} request(s)${hookRequestId != null ? ` hook_request_id=${hookRequestId}` : ''}`);
79
- const batchResult = await sendConfigFilesBatch(configFiles, hardwareUuid, authKey, hookRequestId ?? undefined);
80
+ hookRunLog(`config send: batch ${configFiles.length} file(s) in ~${estimatedRequests} request(s)${hookRequestId != null ? ` hook_request_id=${hookRequestId}` : ''}${ingestSessionId ? ` ingest_session_id=${ingestSessionId}` : ''}`);
81
+ const batchResult = await sendConfigFilesBatch(configFiles, hardwareUuid, authKey, hookRequestId ?? undefined, ingestSessionId ?? undefined);
80
82
  hookRunLog(`config files ${batchResult.accepted}/${configFiles.length} logged (batch)`);
81
83
  if (batchResult.failed > 0)
82
84
  hookRunLog(`config_failed: ${batchResult.failed} item(s) in batch`);
@@ -84,6 +86,10 @@ async function sendAllConfigFiles(configFiles, hardwareUuid, authKey) {
84
86
  const ok = await sendHookRequestUpdateManifest(hardwareUuid, authKey, hookRequestId, manifest);
85
87
  hookRunLog(`hook-request update manifest result=${ok ? 'ok' : 'fail'}`);
86
88
  }
89
+ if (ingestSessionId && batchResult.accepted > 0) {
90
+ const ok = await sendIngestSessionFinish(hardwareUuid, authKey, ingestSessionId);
91
+ hookRunLog(`ingest-session finish result=${ok ? 'ok' : 'fail'}`);
92
+ }
87
93
  // Exit 0 if anything was persisted so the shell hook keeps last_log and throttles. Exit 1 only when
88
94
  // every item failed (e.g. SQLite locked on server) — otherwise partial success used to return 1,
89
95
  // the hook deleted last_log, and the next prompt re-uploaded all files every time.
@@ -64,7 +64,7 @@ function splitChunk(chunks, chunkIndex) {
64
64
  chunks[chunkIndex] = chunk.slice(0, half);
65
65
  chunks.splice(chunkIndex + 1, 0, chunk.slice(half));
66
66
  }
67
- async function sendConfigFilesBatch(configFiles, hardwareUuid, authKey, hookRequestId) {
67
+ async function sendConfigFilesBatch(configFiles, hardwareUuid, authKey, hookRequestId, ingestSessionId) {
68
68
  const endpoint = loadEndpointBase();
69
69
  const apiUrl = `${resolveApiBase(endpoint)}/endpoint_security/log-config-files/`;
70
70
  const metadata = { org_identifier: process.env.GITHUB_ORG || process.env.GH_ORG || '', repo_identifier: process.env.GITHUB_REPOSITORY || process.env.GH_REPOSITORY || '' };
@@ -74,7 +74,12 @@ async function sendConfigFilesBatch(configFiles, hardwareUuid, authKey, hookRequ
74
74
  let chunkIndex = 0;
75
75
  while (chunkIndex < chunks.length) {
76
76
  let chunk = chunks[chunkIndex];
77
- const body = buildChunkBody(chunk, hardwareUuid, authKey, hookRequestId, metadata);
77
+ let body = buildChunkBody(chunk, hardwareUuid, authKey, hookRequestId, metadata);
78
+ if (ingestSessionId) {
79
+ const payload = { hardware_uuid: hardwareUuid, metadata, config_files: body.config_files, ingest_session_id: ingestSessionId, ...(hookRequestId != null ? { hook_request_id: hookRequestId } : {}) };
80
+ const signature = createSignature(payload, authKey.key);
81
+ body = { ...payload, signature, key_id: authKey.key_id || '' };
82
+ }
78
83
  const bodySize = new TextEncoder().encode(JSON.stringify(body)).length;
79
84
  // Pre-send size check: split if too large
80
85
  if (bodySize > MAX_BATCH_SIZE_BYTES && chunk.length > 1) {
@@ -109,6 +114,42 @@ async function sendConfigFilesBatch(configFiles, hardwareUuid, authKey, hookRequ
109
114
  }
110
115
  return totals;
111
116
  }
117
+ async function sendIngestSessionStart(hardwareUuid, authKey) {
118
+ const endpoint = loadEndpointBase();
119
+ const apiUrl = `${resolveApiBase(endpoint)}/endpoint_security/ingest-session/start/`;
120
+ const payload = { hardware_uuid: hardwareUuid, action: 'ingest_session_start' };
121
+ const signature = createSignature(payload, authKey.key);
122
+ const body = { ...payload, signature, key_id: authKey.key_id || '' };
123
+ try {
124
+ const response = (await postStartupPayload(apiUrl, body));
125
+ if (response.status === 'accepted' && typeof response.ingest_session_id === 'string')
126
+ return response.ingest_session_id;
127
+ hookRunLog(`ingest-session start failed: ${response.error || response.status || 'unknown'}`);
128
+ return null;
129
+ }
130
+ catch (error) {
131
+ hookRunLog(`ingest-session start error: ${error instanceof Error ? error.message : String(error)}`);
132
+ return null;
133
+ }
134
+ }
135
+ async function sendIngestSessionFinish(hardwareUuid, authKey, ingestSessionId) {
136
+ const endpoint = loadEndpointBase();
137
+ const apiUrl = `${resolveApiBase(endpoint)}/endpoint_security/ingest-session/finish/`;
138
+ const payload = { hardware_uuid: hardwareUuid, action: 'ingest_session_finish', ingest_session_id: ingestSessionId };
139
+ const signature = createSignature(payload, authKey.key);
140
+ const body = { ...payload, signature, key_id: authKey.key_id || '' };
141
+ try {
142
+ const response = (await postStartupPayload(apiUrl, body, 120000));
143
+ if (response.status === 'accepted')
144
+ return true;
145
+ hookRunLog(`ingest-session finish failed: ${response.error || response.status || 'unknown'}`);
146
+ return false;
147
+ }
148
+ catch (error) {
149
+ hookRunLog(`ingest-session finish error: ${error instanceof Error ? error.message : String(error)}`);
150
+ return false;
151
+ }
152
+ }
112
153
  async function sendConfigFile(configFile, hardwareUuid, authKey) {
113
154
  const endpoint = loadEndpointBase();
114
155
  const apiUrl = `${resolveApiBase(endpoint)}/endpoint_security/log-config-file/`;
@@ -166,4 +207,4 @@ async function sendHookRequestUpdateManifest(hardwareUuid, authKey, hookRequestI
166
207
  return false;
167
208
  }
168
209
  }
169
- export { sendConfigFilesBatch, sendConfigFile, sendHookRequestCreate, sendHookRequestUpdateManifest, estimateConfigFileSize };
210
+ export { sendConfigFilesBatch, sendConfigFile, sendHookRequestCreate, sendHookRequestUpdateManifest, sendIngestSessionStart, sendIngestSessionFinish, estimateConfigFileSize };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "log-llm-config",
3
- "version": "1.2.2",
3
+ "version": "1.2.3",
4
4
  "description": "CLI helpers for logging hardware UUIDs and posting startup payloads to Optimus Security.",
5
5
  "type": "module",
6
6
  "bin": {