evolcore 0.0.33 → 0.0.35-test.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.
Files changed (152) hide show
  1. package/CHANGELOG.md +59 -0
  2. package/bin/ec.js +3 -2
  3. package/bin/install-codex-managed-hooks.mjs +38 -4
  4. package/dist/agents/baseagent-availability.js +20 -36
  5. package/dist/agents/claude-runner.js +93 -14
  6. package/dist/agents/codex/diagnostics.js +79 -22
  7. package/dist/agents/codex-runner.js +245 -47
  8. package/dist/agents/ecagent-runner.js +90 -27
  9. package/dist/agents/runner-types.js +5 -6
  10. package/dist/aun/aid/agentmd.js +13 -2
  11. package/dist/aun/aid/client.js +1 -1
  12. package/dist/aun/aid/identity.js +1 -1
  13. package/dist/aun/msg/managed-operation.js +16 -0
  14. package/dist/aun/msg/p2p.js +18 -2
  15. package/dist/channels/aun.js +123 -7
  16. package/dist/channels/daemon.js +6 -3
  17. package/dist/cli/aun-commands.js +39 -14
  18. package/dist/cli/ctl-command.js +3 -1
  19. package/dist/cli/daemon-commands.js +130 -23
  20. package/dist/cli/fs-command.js +2 -1
  21. package/dist/cli/getmeta-command.js +211 -0
  22. package/dist/cli/index.js +26 -6
  23. package/dist/cli/integrity-command.js +196 -0
  24. package/dist/cli/managed-command-guard.js +3 -0
  25. package/dist/cli/memory-command.js +200 -156
  26. package/dist/cli/thread-command.js +17 -7
  27. package/dist/cli/trigger-command.js +6 -1
  28. package/dist/config/config-field-policy.js +4 -0
  29. package/dist/config/config-manager.js +19 -0
  30. package/dist/config/contact-book-store.js +5 -0
  31. package/dist/config/resolved-config-op.js +25 -8
  32. package/dist/config/role-service.js +13 -0
  33. package/dist/config/runtime-env.js +16 -0
  34. package/dist/config-store.js +30 -0
  35. package/dist/core/audit/log-integrity.js +3 -1
  36. package/dist/core/auth/agent-delegation.js +108 -35
  37. package/dist/core/auth/delegation-diagnostics.js +414 -0
  38. package/dist/core/auth/operation-authorizer.js +22 -3
  39. package/dist/core/auth/operation-catalog.js +16 -0
  40. package/dist/core/channel-runtime.js +1 -1
  41. package/dist/core/command/agent-control.js +18 -26
  42. package/dist/core/command/command-handler.js +145 -5
  43. package/dist/core/command/daemon-diagnostics.js +1 -0
  44. package/dist/core/command/menu-catalog.js +3 -0
  45. package/dist/core/command/menu-handler.js +24 -7
  46. package/dist/core/command/menu-protocol.js +1 -0
  47. package/dist/core/command/slash-handler.js +2 -0
  48. package/dist/core/command/topic-slash.js +4 -7
  49. package/dist/core/daemon-bootstrap.js +4 -7
  50. package/dist/core/event-catalog.js +14 -0
  51. package/dist/core/file-integrity/read.js +61 -0
  52. package/dist/core/file-integrity/store.js +262 -0
  53. package/dist/core/ipc-registration.js +47 -2
  54. package/dist/core/memory/batch-meta.js +133 -0
  55. package/dist/core/memory/consolidation-context.js +132 -28
  56. package/dist/core/memory/consolidation-ops-records.js +14 -16
  57. package/dist/core/memory/consolidation-trigger.js +15 -7
  58. package/dist/core/memory/consolidation.js +146 -26
  59. package/dist/core/memory/index-manager.js +19 -28
  60. package/dist/core/memory/memory-admin.js +19 -14
  61. package/dist/core/memory/memory-document.js +53 -9
  62. package/dist/core/memory/memory-writer.js +50 -19
  63. package/dist/core/message/aun-ipc-sender.js +19 -1
  64. package/dist/core/message/im-renderer.js +20 -4
  65. package/dist/core/message/message-bridge.js +5 -4
  66. package/dist/core/message/message-log.js +1 -0
  67. package/dist/core/message/peer-mode.js +17 -0
  68. package/dist/core/message/response-engine.js +598 -50
  69. package/dist/core/permission/ec-command-parser.js +169 -44
  70. package/dist/core/permission/protected-paths.js +5 -1
  71. package/dist/core/permission/readonly-shell-query.js +43 -5
  72. package/dist/core/permission/session-path-grants.js +334 -0
  73. package/dist/core/permission/tool-canonical.js +226 -0
  74. package/dist/core/permission/tool-policy.js +60 -62
  75. package/dist/core/relation/peer-identity.js +87 -12
  76. package/dist/core/role/runtime-policy.js +21 -10
  77. package/dist/core/session/session-fs-store.js +123 -8
  78. package/dist/core/session/session-manager.js +131 -6
  79. package/dist/core/session/session-title.js +26 -1
  80. package/dist/core/skill/index-generator.js +17 -3
  81. package/dist/core/system-session/grants.js +40 -0
  82. package/dist/core/system-session/memory.js +289 -0
  83. package/dist/core/system-session/registry.js +74 -0
  84. package/dist/core/system-session/types.js +14 -0
  85. package/dist/core/thread/command-parser.js +6 -1
  86. package/dist/core/thread/ipc-operation.js +33 -16
  87. package/dist/core/thread/thread-operation.js +62 -24
  88. package/dist/core/thread/thread-service.js +258 -51
  89. package/dist/eck/kit-renderer.js +7 -2
  90. package/dist/eck/manifest-engine.js +24 -4
  91. package/dist/index.js +11 -2
  92. package/dist/ipc.js +51 -40
  93. package/dist/paths.js +70 -0
  94. package/dist/stats/billing.js +20 -8
  95. package/dist/trigger/feedback.js +6 -1
  96. package/dist/trigger/parser.js +8 -1
  97. package/dist/trigger/system-definitions.js +3 -3
  98. package/dist/utils/cross-platform.js +17 -5
  99. package/dist/utils/error-dict.json +18 -4
  100. package/dist/utils/error-utils.js +121 -0
  101. package/dist/utils/instance-registry.js +13 -8
  102. package/dist/utils/log-writer.js +12 -0
  103. package/dist/utils/process-introspect.js +11 -0
  104. package/kits/docs/context-assembly.md +0 -1
  105. package/kits/docs/evolcore/agent-create.md +5 -4
  106. package/kits/docs/evolcore/agent.md +2 -2
  107. package/kits/docs/evolcore/config.md +2 -2
  108. package/kits/docs/evolcore/ctl.md +2 -2
  109. package/kits/docs/evolcore/ec-capabilities.md +1 -1
  110. package/kits/docs/evolcore/fs-architecture.md +9 -10
  111. package/kits/docs/evolcore/fs.md +2 -2
  112. package/kits/docs/evolcore/group-collaboration.md +3 -3
  113. package/kits/docs/evolcore/group.md +14 -12
  114. package/kits/docs/evolcore/memory-architecture.md +4 -5
  115. package/kits/docs/evolcore/memory-consolidation.md +19 -16
  116. package/kits/docs/evolcore/memory-tags.md +3 -1
  117. package/kits/docs/evolcore/memory.md +24 -12
  118. package/kits/docs/evolcore/model.md +16 -0
  119. package/kits/docs/evolcore/msg.md +7 -7
  120. package/kits/docs/evolcore/stats.md +1 -1
  121. package/kits/docs/evolcore/thread-chain.md +30 -14
  122. package/kits/docs/prompt-loading-architecture.md +0 -1
  123. package/kits/eck_manifest.auxiliary.json +9 -0
  124. package/kits/eck_manifest.json +20 -20
  125. package/kits/eck_manifest.memory.json +20 -12
  126. package/kits/rules/01-overview.md +11 -0
  127. package/kits/rules/03-identity.md +6 -3
  128. package/kits/rules/06-channel.md +1 -1
  129. package/kits/rules/07-memory-and-thread.md +13 -16
  130. package/kits/schemas/_meta.json +7 -1
  131. package/kits/schemas/agent-config.schema.13.json +1 -1
  132. package/kits/schemas/daemon.schema.7.json +140 -0
  133. package/kits/skills/ec-group/SKILL.md +8 -5
  134. package/kits/skills/ec-skill/scripts/cli.mjs +1 -1
  135. package/kits/skills/ec-skill/scripts/skill.mjs +1 -1
  136. package/kits/skills/thread-ops/SKILL.md +18 -18
  137. package/kits/templates/memory-consolidation/forget.md +2 -2
  138. package/kits/templates/memory-consolidation/generalize.md +4 -4
  139. package/kits/templates/memory-consolidation/notes.md +12 -12
  140. package/kits/templates/memory-consolidation/profile.md +3 -3
  141. package/kits/templates/memory-consolidation/promote.md +3 -3
  142. package/kits/templates/memory-consolidation/workflow.md +42 -7
  143. package/kits/templates/message-fragments/handoff-request-to-target.md +1 -1
  144. package/kits/templates/system-fragments/bash-description.md +9 -0
  145. package/kits/templates/system-fragments/bootstrap.md +4 -3
  146. package/kits/templates/system-fragments/channel.md +2 -2
  147. package/kits/templates/system-fragments/memory.md +16 -9
  148. package/kits/templates/system-fragments/reply.md +6 -6
  149. package/kits/templates/system-fragments/session.md +1 -1
  150. package/package.json +4 -3
  151. package/dist/core/memory/memory-session-policy.js +0 -41
  152. package/dist/core/memory/memory-signature.js +0 -257
@@ -3,8 +3,10 @@ import os from 'node:os';
3
3
  import path from 'node:path';
4
4
  import { spawnSync } from 'node:child_process';
5
5
  import { createHash } from 'node:crypto';
6
+ import { createRequire } from 'node:module';
7
+ import { fileURLToPath } from 'node:url';
6
8
  import { parse as parseToml } from 'smol-toml';
7
- const managedHookInstaller = await import(new URL('../../../bin/install-codex-managed-hooks.mjs', import.meta.url).href);
9
+ import { TARGET_PACKAGE_ROOT_ENV } from '../../product.js';
8
10
  export function checkCodexProjectPath(value, options = {}) {
9
11
  const configured = typeof value === 'string' ? value.trim() : '';
10
12
  if (!configured) {
@@ -65,12 +67,6 @@ function decodeProbeOutput(buffer) {
65
67
  return new TextDecoder('gb18030').decode(buffer);
66
68
  }
67
69
  }
68
- function windowsCommandArg(value) {
69
- return '"' + value.replaceAll('"', '\\"') + '"';
70
- }
71
- function expectedWindowsHookCommand(nodePath, hookPath) {
72
- return windowsCommandArg(nodePath) + ' ' + windowsCommandArg(hookPath) + ' %EVOLCORE_INSTANCE_SOCKET%';
73
- }
74
70
  /**
75
71
  * Run synthetic Windows shell probes for the managed Codex hook.
76
72
  *
@@ -104,13 +100,20 @@ export function runCodexHookLaunchDiagnostic(options = {}) {
104
100
  throw new Error('No Windows managed hook directory configured.');
105
101
  const managedDir = path.resolve(options.managedDir || configuredDir);
106
102
  const hookPath = path.join(managedDir, 'pre-tool-use.mjs');
107
- const expected = expectedWindowsHookCommand(nodePath, hookPath);
103
+ let expected;
108
104
  const handlers = Array.isArray(config.hooks?.PreToolUse)
109
105
  ? config.hooks.PreToolUse.flatMap((group) => group?.hooks || [])
110
106
  : [];
111
- const handler = handlers.find((item) => (item?.type === 'command'
112
- && (item.command_windows ?? item.commandWindows) === expected));
113
- if (!handler || /[\r\n%;&|<>]/.test(nodePath + hookPath)) {
107
+ const handler = handlers.find((item) => {
108
+ if (item?.type !== 'command' || item.async === true)
109
+ return false;
110
+ const command = parseManagedCommand(item.command_windows ?? item.commandWindows, hookPath);
111
+ if (!command || !sameRuntimePath(command.nodePath, nodePath, options.platform ?? process.platform))
112
+ return false;
113
+ expected = item.command_windows ?? item.commandWindows;
114
+ return true;
115
+ });
116
+ if (!handler || !expected || /[\r\n%;&|<>]/.test(nodePath + hookPath)) {
114
117
  throw new Error('Managed command differs from the expected EvolCore command for this Node path; no hooks executed.');
115
118
  }
116
119
  fs.mkdirSync(path.dirname(output), { recursive: true, mode: 0o700 });
@@ -202,9 +205,34 @@ function samePackageRoot(embedded, expected) {
202
205
  };
203
206
  return normalize(embedded) === normalize(expected) || resolved(embedded) === resolved(expected);
204
207
  }
208
+ /**
209
+ * Windows accepts an executable path without its `.exe` suffix. Older
210
+ * installations may therefore bind `...\\node` while the current Node
211
+ * process reports `...\\node.exe`; these are the same runtime and must not
212
+ * trigger an elevated repair on every startup.
213
+ */
214
+ function sameRuntimePath(embedded, expected, platform) {
215
+ if (samePackageRoot(embedded, expected))
216
+ return true;
217
+ if (platform !== 'win32' || !embedded)
218
+ return false;
219
+ const appendExe = (value) => path.extname(value) ? value : `${value}.exe`;
220
+ return samePackageRoot(appendExe(embedded), expected)
221
+ || samePackageRoot(embedded, appendExe(expected));
222
+ }
205
223
  function normalizedPath(value) {
206
224
  return path.normalize(String(value || '')).replace(/[\\/]+$/, '').toLowerCase();
207
225
  }
226
+ function parseManagedCommand(value, hookPath) {
227
+ if (typeof value !== 'string')
228
+ return null;
229
+ const match = /^"([^"\r\n]+)"\s+"([^"\r\n]+)"\s+%EVOLCORE_INSTANCE_SOCKET%$/i.exec(value.trim());
230
+ if (!match || !path.isAbsolute(match[1]) || /[%!]/.test(match[1] + match[2]))
231
+ return null;
232
+ if (normalizedPath(match[2]) !== normalizedPath(hookPath))
233
+ return null;
234
+ return { nodePath: match[1] };
235
+ }
208
236
  function runtimeFileMayExist(file) {
209
237
  try {
210
238
  return fs.statSync(file).isFile();
@@ -213,9 +241,6 @@ function runtimeFileMayExist(file) {
213
241
  return !['ENOENT', 'ENOTDIR'].includes(error?.code || '');
214
242
  }
215
243
  }
216
- function managedBinding(source, launcher, hookPath) {
217
- return managedHookInstaller.managedBinding(source, launcher, hookPath);
218
- }
219
244
  /** Read-only inspection of the machine-wide Windows Codex managed hook. */
220
245
  export function inspectCodexManagedHook(options = {}) {
221
246
  const paths = codexManagedHookPaths(options);
@@ -224,6 +249,21 @@ export function inspectCodexManagedHook(options = {}) {
224
249
  const requirements = path.resolve(options.requirements || paths.requirements);
225
250
  const managedDir = path.resolve(options.managedDir || paths.managedDir);
226
251
  const hookPath = path.join(managedDir, 'pre-tool-use.mjs');
252
+ let managedHookInstaller;
253
+ try {
254
+ const installer = fileURLToPath(new URL('../../../bin/install-codex-managed-hooks.mjs', import.meta.url));
255
+ managedHookInstaller = createRequire(import.meta.url)(installer);
256
+ if (typeof managedHookInstaller.managedBinding !== 'function') {
257
+ throw new Error('managedBinding export is unavailable');
258
+ }
259
+ }
260
+ catch (error) {
261
+ const detail = error instanceof Error ? error.message : String(error);
262
+ return {
263
+ status: 'unsafe', requirements, managedDir, hookPath,
264
+ reason: `managed-hook installer could not be loaded: ${detail}`,
265
+ };
266
+ }
227
267
  const configDirState = realDirectoryState(path.dirname(requirements));
228
268
  const managedDirState = realDirectoryState(managedDir);
229
269
  if ([configDirState, managedDirState].includes('unsafe')) {
@@ -286,9 +326,9 @@ export function inspectCodexManagedHook(options = {}) {
286
326
  catch (error) {
287
327
  return { status: 'unavailable', requirements, managedDir, hookPath, reason: error instanceof Error ? error.message : String(error) };
288
328
  }
289
- const expectedPackageRoot = path.resolve(options.packageRoot || process.cwd());
329
+ const expectedPackageRoot = path.resolve(process.env[TARGET_PACKAGE_ROOT_ENV] || options.packageRoot || process.cwd());
290
330
  try {
291
- const binding = managedBinding(source, launcher, hookPath);
331
+ const binding = managedHookInstaller.managedBinding(source, launcher, hookPath);
292
332
  if (!binding || config.allow_managed_hooks_only !== true || config.features?.hooks !== true
293
333
  || normalizedPath(config.hooks?.windows_managed_dir) !== normalizedPath(managedDir)
294
334
  || (config.hooks?.managed_dir !== undefined
@@ -297,7 +337,7 @@ export function inspectCodexManagedHook(options = {}) {
297
337
  }
298
338
  const { embeddedPackageRoot, managedNodePath } = binding;
299
339
  const packageMatches = samePackageRoot(embeddedPackageRoot, expectedPackageRoot);
300
- const nodeMatches = samePackageRoot(managedNodePath, options.nodePath || process.execPath);
340
+ const nodeMatches = sameRuntimePath(managedNodePath, options.nodePath || process.execPath, options.platform ?? process.platform);
301
341
  const repairFingerprint = createHash('sha256').update(source).update('\0').update(launcher).digest('hex');
302
342
  if (packageMatches && nodeMatches)
303
343
  return { status: 'installed', requirements, managedDir, hookPath };
@@ -356,9 +396,10 @@ export async function ensureCodexManagedHook(options) {
356
396
  });
357
397
  if (!paths)
358
398
  return { status: 'skipped', reason: 'Windows managed hooks are not applicable on this platform' };
399
+ const packageRoot = process.env[TARGET_PACKAGE_ROOT_ENV] || options.packageRoot;
359
400
  const inspectOptions = {
360
401
  platform: platformName,
361
- packageRoot: options.packageRoot,
402
+ packageRoot,
362
403
  requirements: options.requirements || paths.requirements,
363
404
  managedDir: options.managedDir || paths.managedDir,
364
405
  programData: options.programData,
@@ -388,7 +429,9 @@ export async function ensureCodexManagedHook(options) {
388
429
  || rechecked.repairAmbiguous !== state.repairAmbiguous) {
389
430
  return { ...rechecked, repaired: false, error: 'managed-hook state changed during the startup check; retry to confirm the current binding' };
390
431
  }
391
- const installer = path.join(path.resolve(options.packageRoot), 'bin', 'install-codex-managed-hooks.mjs');
432
+ const installer = process.env[TARGET_PACKAGE_ROOT_ENV]
433
+ ? fileURLToPath(new URL('../../../bin/install-codex-managed-hooks.mjs', import.meta.url))
434
+ : path.join(path.resolve(packageRoot), 'bin', 'install-codex-managed-hooks.mjs');
392
435
  if (!fs.existsSync(installer)) {
393
436
  return { ...state, repaired: false, error: `managed-hook installer is missing: ${installer}` };
394
437
  }
@@ -412,15 +455,29 @@ export async function ensureCodexManagedHook(options) {
412
455
  if (result.error)
413
456
  return { ok: false, detail: result.error.message };
414
457
  if (result.status !== 0) {
415
- const detail = (result.stderr || '').replace(/#<\s*CLIXML[\s\S]*?<\/Objs>\s*/gi, '').trim();
416
- return { ok: false, detail: detail || `installer exited with code ${result.status}` };
458
+ const stderrDetail = (result.stderr || '').replace(/#<\s*CLIXML[\s\S]*?<\/Objs>\s*/gi, '').trim();
459
+ // The elevated child process runs in a separate window and its stderr is
460
+ // not captured through the Start-Process pipe. Read the structured failure
461
+ // record the installer writes to ProgramData before exiting.
462
+ let fileDetail;
463
+ try {
464
+ const failurePath = path.join(path.dirname(path.resolve(inspectOptions.requirements || paths.requirements)), '.evolcore-install-failure.json');
465
+ const raw = fs.readFileSync(failurePath, 'utf8');
466
+ const parsed = JSON.parse(raw);
467
+ if (typeof parsed.message === 'string' && parsed.message)
468
+ fileDetail = parsed.message;
469
+ fs.rmSync(failurePath, { force: true });
470
+ }
471
+ catch { /* best-effort */ }
472
+ const detail = fileDetail || stderrDetail || `installer exited with code ${result.status}`;
473
+ return { ok: false, detail };
417
474
  }
418
475
  return { ok: true };
419
476
  });
420
477
  options.onInstallRequired?.(state);
421
478
  let elevated;
422
479
  try {
423
- elevated = runElevated(installer, path.resolve(options.packageRoot));
480
+ elevated = runElevated(installer, path.resolve(packageRoot));
424
481
  }
425
482
  catch (error) {
426
483
  elevated = { ok: false, detail: error instanceof Error ? error.message : String(error) };