log-llm-config-staging 1.3.89 → 1.3.92

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.
@@ -6,10 +6,10 @@ import { OPT_AI_SEC_MANAGEMENT_REL } from '../../bootstrap_constants.js';
6
6
  import { hookRunLog } from '../runtime/hook_logger.js';
7
7
  const AUTH_KEY_RELATIVE_PATH = path.join(OPT_AI_SEC_MANAGEMENT_REL, 'auth_key.txt');
8
8
  /** Ensure authentication — verify stored key or request new one via handshake. */
9
- async function ensureAuthentication(hardwareUuid) {
9
+ async function ensureAuthentication(hardwareUuid, endpointBase) {
10
10
  const key = await ensureTofuAuthentication({
11
11
  hardwareUuid,
12
- endpointBase: loadEndpointBase(),
12
+ endpointBase: endpointBase ?? loadEndpointBase(),
13
13
  authRelativePath: AUTH_KEY_RELATIVE_PATH,
14
14
  postJson: (endpointUrl, body) => postStartupPayload(endpointUrl, body),
15
15
  onLog: (message) => {
@@ -39,6 +39,8 @@ export function normalizeAgentToken(raw) {
39
39
  return 'claude';
40
40
  if (s === 'cursor')
41
41
  return 'cursor';
42
+ if (s === 'copilot')
43
+ return 'copilot';
42
44
  return '';
43
45
  }
44
46
  function currentAgentFromEnv() {
@@ -46,9 +48,13 @@ function currentAgentFromEnv() {
46
48
  const override = normalizeAgentToken(process.env.OPTIMUS_AGENT);
47
49
  if (override)
48
50
  return override;
49
- // Backwards-compatible: hook wrappers set OPTIMUS_HOOK_TYPE to cursor|claude.
51
+ // Backwards-compatible: hook wrappers set OPTIMUS_HOOK_TYPE to cursor|claude|copilot.
50
52
  const hookType = normalizeAgentToken(process.env.OPTIMUS_HOOK_TYPE);
51
- return hookType === 'cursor' ? 'cursor' : 'claude';
53
+ if (hookType === 'cursor')
54
+ return 'cursor';
55
+ if (hookType === 'copilot')
56
+ return 'copilot';
57
+ return 'claude';
52
58
  }
53
59
  function targetsCurrentAgent(entry, agent) {
54
60
  // Prefer top-level manifest field; fall back to embedded fix payload for older local files.
@@ -91,7 +91,7 @@ async function addSensitivePathsAudit(endpointBase, configFiles) {
91
91
  }
92
92
  async function sendAllConfigFiles(configFiles, worktreeReport, hardwareUuid, authKey) {
93
93
  const hookTypeRaw = (process.env.OPTIMUS_HOOK_TYPE || 'claude').toLowerCase();
94
- const hookType = hookTypeRaw === 'cursor' ? 'cursor' : 'claude';
94
+ const hookType = hookTypeRaw === 'cursor' ? 'cursor' : hookTypeRaw === 'copilot' ? 'copilot' : 'claude';
95
95
  const manifest = configFiles.map((c) => canonicalCursorUserStateVscdbPath(c.file_path));
96
96
  const workspaceRepo = ensureWorkspaceRepoEnv(manifest);
97
97
  const hookRequestId = await sendHookRequestCreate(hardwareUuid, authKey, hookType, workspaceRepo);
@@ -132,7 +132,8 @@ async function main() {
132
132
  const endpointBase = loadEndpointBase();
133
133
  hookRunLog(`start endpoint=${endpointBase} hardware_uuid=${hardwareUuid}`);
134
134
  hookRunLog(`endpoint_source=${getEndpointSource()} cwd=${process.cwd()}`);
135
- hookRunLog(`env: OPTIMUS_HOOK_TYPE=${process.env.OPTIMUS_HOOK_TYPE ? 'set' : 'unset'} OPTIMUS_PROJECT_DIR=${process.env.OPTIMUS_PROJECT_DIR ? 'set' : 'unset'} OPTIMUS_WORKSPACE_REPO=${process.env.OPTIMUS_WORKSPACE_REPO ? 'set' : 'unset'} OPTIMUS_ENDPOINT=${process.env.OPTIMUS_ENDPOINT ? 'set' : 'unset'}`);
135
+ const envForLog = (v) => (v && v.trim() ? v.trim() : 'unset');
136
+ hookRunLog(`env: OPTIMUS_HOOK_TYPE=${envForLog(process.env.OPTIMUS_HOOK_TYPE)} OPTIMUS_PROJECT_DIR=${envForLog(process.env.OPTIMUS_PROJECT_DIR)} OPTIMUS_WORKSPACE_REPO=${envForLog(process.env.OPTIMUS_WORKSPACE_REPO)} OPTIMUS_ENDPOINT=${envForLog(process.env.OPTIMUS_ENDPOINT)}`);
136
137
  let authKey;
137
138
  try {
138
139
  authKey = await ensureAuthentication(hardwareUuid);
@@ -158,12 +158,9 @@ function transferQuarantineForRetiredUuids(removed, added, retiredInstructions,
158
158
  if (changed)
159
159
  writeRemediationApplyTrackingFile(file);
160
160
  }
161
- async function ensureAuthKeyForMachine(machineUuid) {
162
- const stored = readStoredAuthKey();
163
- if (stored?.key)
164
- return stored;
161
+ async function ensureAuthKeyForMachine(endpointBase, machineUuid) {
165
162
  try {
166
- return await ensureAuthentication(machineUuid);
163
+ return await ensureAuthentication(machineUuid, endpointBase);
167
164
  }
168
165
  catch (err) {
169
166
  hookRunLog(`remediation_sync: ensureAuthentication failed: ${err instanceof Error ? err.message : String(err)}`);
@@ -178,7 +175,7 @@ function buildSignedMachinePostBody(machineUuid, fields, authKey) {
178
175
  }
179
176
  export async function fetchSync(endpointBase, machineUuid, activeUuids, timeoutMs = 8000) {
180
177
  const sortedUuids = [...new Set(activeUuids.map((u) => u.trim()).filter(Boolean))].sort();
181
- const authKey = await ensureAuthKeyForMachine(machineUuid);
178
+ const authKey = await ensureAuthKeyForMachine(endpointBase, machineUuid);
182
179
  if (!authKey) {
183
180
  hookRunLog('remediation_sync_post: no auth key, skipping');
184
181
  complianceRunnerDiag('remediation_sync_post: no auth key');
@@ -200,7 +197,10 @@ export async function fetchSync(endpointBase, machineUuid, activeUuids, timeoutM
200
197
  return null;
201
198
  }
202
199
  if (statusCode !== 200 || !responseBody) {
203
- const line = `remediation_sync_post: url=${url} status=${statusCode} bytes=${responseBody?.length ?? 0}`;
200
+ const bodyHint = responseBody && responseBody.length < 500
201
+ ? ` body=${responseBody.replace(/\s+/g, ' ').trim()}`
202
+ : '';
203
+ const line = `remediation_sync_post: url=${url} status=${statusCode} bytes=${responseBody?.length ?? 0}${bodyHint}`;
204
204
  hookRunLog(line);
205
205
  complianceRunnerDiag(line);
206
206
  return null;
@@ -216,7 +216,7 @@ export async function fetchSync(endpointBase, machineUuid, activeUuids, timeoutM
216
216
  }
217
217
  async function fetchManifest(endpointBase, machineUuid, uuids, timeoutMs = 8000) {
218
218
  const sortedUuids = [...new Set(uuids.map((u) => u.trim()).filter(Boolean))].sort();
219
- const authKey = await ensureAuthKeyForMachine(machineUuid);
219
+ const authKey = await ensureAuthKeyForMachine(endpointBase, machineUuid);
220
220
  if (!authKey) {
221
221
  hookRunLog('remediation_manifest_post: no auth key, skipping');
222
222
  complianceRunnerDiag('remediation_manifest_post: no auth key');
@@ -32,10 +32,16 @@ function currentAgentFromEnv() {
32
32
  const override = normalizeAgentToken(process.env.OPTIMUS_AGENT);
33
33
  if (override === 'cursor')
34
34
  return 'cursor';
35
+ if (override === 'copilot')
36
+ return 'copilot';
35
37
  if (override === 'claude' || override === 'claude_desktop')
36
38
  return 'claude';
37
39
  const hookType = normalizeAgentToken(process.env.OPTIMUS_HOOK_TYPE);
38
- return hookType === 'cursor' ? 'cursor' : 'claude';
40
+ if (hookType === 'cursor')
41
+ return 'cursor';
42
+ if (hookType === 'copilot')
43
+ return 'copilot';
44
+ return 'claude';
39
45
  }
40
46
  /** Spawn each trusted command detached (same pattern as former compliance_prompt_gate fireRestartCommands). */
41
47
  export function executeTrustedRestartCommands(commands) {
@@ -1,9 +1,9 @@
1
1
  import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
2
2
  import path from 'node:path';
3
3
  import { OPT_AI_SEC_MANAGEMENT_REL } from '../bootstrap_constants.js';
4
+ import { loadEndpointBase } from '../log_config_files/sender/endpoint_config.js';
5
+ import { buildStartupEndpointUrl, normalizeBaseUrl } from '../tofu.js';
4
6
  const AUTH_KEY_RELATIVE_PATH = path.join(OPT_AI_SEC_MANAGEMENT_REL, 'auth_key.txt');
5
- const OPTIMUS_ENV_FILENAME = 'optimus_dev.env';
6
- const STARTUP_ENDPOINT_SUFFIX = '/endpoint_security/startup/';
7
7
  const getAuthKeyPath = () => {
8
8
  const homeDir = process.env.HOME || process.env.USERPROFILE;
9
9
  if (!homeDir)
@@ -34,38 +34,4 @@ const readStoredAuthKey = () => {
34
34
  }
35
35
  return null;
36
36
  };
37
- const loadEndpointBase = () => {
38
- const DEFAULT_ENDPOINT = 'https://demo.optimuslabs.io/';
39
- const fromEnv = process.env.OPTIMUS_ENDPOINT?.trim();
40
- if (fromEnv)
41
- return fromEnv;
42
- const envPath = path.join(process.cwd(), OPTIMUS_ENV_FILENAME);
43
- try {
44
- if (!existsSync(envPath))
45
- return DEFAULT_ENDPOINT;
46
- const envContent = readFileSync(envPath, 'utf8');
47
- for (const line of envContent.split(/\r?\n/)) {
48
- const trimmed = line.trim();
49
- if (!trimmed || trimmed.startsWith('#'))
50
- continue;
51
- const [key, ...rest] = trimmed.split('=');
52
- if (key === 'OPTIMUS_ENDPOINT') {
53
- const value = rest.join('=').trim();
54
- if (value)
55
- return value;
56
- }
57
- }
58
- }
59
- catch { /* fall back to default */ }
60
- return DEFAULT_ENDPOINT;
61
- };
62
- const normalizeBaseUrl = (rawUrl) => {
63
- let base = rawUrl.trim();
64
- if (!base)
65
- throw new Error('OPTIMUS_ENDPOINT is empty');
66
- base = base.replace(/\/+$/, '');
67
- base = base.replace(/\/(optimus_security|endpoint_security)$/i, '');
68
- return base;
69
- };
70
- const buildStartupEndpointUrl = (baseUrl) => `${normalizeBaseUrl(baseUrl)}${STARTUP_ENDPOINT_SUFFIX}`;
71
- export { getAuthKeyPath, writeAuthKey, readStoredAuthKey, loadEndpointBase, normalizeBaseUrl, buildStartupEndpointUrl };
37
+ export { getAuthKeyPath, writeAuthKey, readStoredAuthKey, loadEndpointBase, normalizeBaseUrl, buildStartupEndpointUrl, };
package/dist/tofu.js CHANGED
@@ -19,4 +19,4 @@ const useLocalTofu = shouldUseLocalTofuDist(localTofuPath);
19
19
  const tofu = (useLocalTofu
20
20
  ? await import(localTofuPath)
21
21
  : await import("optimus-tofu-staging"));
22
- export const { loadEndpointBase, buildStartupEndpointUrl, createSignature, persistAuthKey, readStoredAuthKey, ensureAuthentication, getEndpointSource, canonicalizePayload, getAuthKeyPath, } = tofu;
22
+ export const { loadEndpointBase, normalizeBaseUrl, buildStartupEndpointUrl, createSignature, persistAuthKey, readStoredAuthKey, ensureAuthentication, getEndpointSource, canonicalizePayload, getAuthKeyPath, } = tofu;
@@ -7,21 +7,25 @@ export function managementEnvPath() {
7
7
  return null;
8
8
  return path.join(home, 'opt-ai-sec', 'management', 'optimus_dev.env');
9
9
  }
10
- /** Resolve optimus environment label (file wins over shell OPTIMUS_ENVIRONMENT). */
10
+ /**
11
+ * Staging package: default staging when no management file (promotion rewrites to production).
12
+ * File present → environment= line in file, then OPTIMUS_ENVIRONMENT, then staging.
13
+ */
11
14
  export function readEnvironment() {
12
15
  const envPath = managementEnvPath();
13
16
  if (!envPath) {
14
17
  return 'staging';
15
18
  }
19
+ let content;
16
20
  try {
17
- const content = readFileSync(envPath, 'utf8');
18
- const match = content.match(/^(?:environment|ENVIRONMENT|OPTIMUS_ENVIRONMENT)\s*=\s*(.+)/m);
19
- if (match)
20
- return match[1].trim().toLowerCase();
21
+ content = readFileSync(envPath, 'utf8');
21
22
  }
22
23
  catch {
23
24
  return 'staging';
24
25
  }
26
+ const match = content?.match(/^(?:environment|ENVIRONMENT|OPTIMUS_ENVIRONMENT)\s*=\s*(.+)/m);
27
+ if (match)
28
+ return match[1].trim().toLowerCase();
25
29
  const fromEnv = process.env.OPTIMUS_ENVIRONMENT?.trim().toLowerCase();
26
30
  if (fromEnv)
27
31
  return fromEnv;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "log-llm-config-staging",
3
- "version": "1.3.89",
3
+ "version": "1.3.92",
4
4
  "description": "CLI helpers for logging hardware UUIDs and posting startup payloads to Optimus Security.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -58,6 +58,6 @@
58
58
  "dependencies": {
59
59
  "axios": "^1.15.2",
60
60
  "canonicalize": "^2.1.0",
61
- "optimus-tofu-staging": "^0.1.15"
61
+ "optimus-tofu-staging": "^0.1.17"
62
62
  }
63
63
  }