comisai 1.0.19 → 1.0.23

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 (154) hide show
  1. package/dist/cli-entry.js +0 -0
  2. package/node_modules/@comis/agent/dist/context-engine/context-engine.js +43 -2
  3. package/node_modules/@comis/agent/dist/context-engine/signature-replay-scrubber.d.ts +51 -0
  4. package/node_modules/@comis/agent/dist/context-engine/signature-replay-scrubber.js +110 -0
  5. package/node_modules/@comis/agent/dist/context-engine/signature-surrogate-guard.d.ts +54 -0
  6. package/node_modules/@comis/agent/dist/context-engine/signature-surrogate-guard.js +145 -0
  7. package/node_modules/@comis/agent/dist/context-engine/types-core.d.ts +17 -0
  8. package/node_modules/@comis/agent/dist/executor/error-classifier.d.ts +11 -1
  9. package/node_modules/@comis/agent/dist/executor/error-classifier.js +13 -0
  10. package/node_modules/@comis/agent/dist/executor/executor-context-engine-setup.d.ts +1 -0
  11. package/node_modules/@comis/agent/dist/executor/executor-context-engine-setup.js +55 -0
  12. package/node_modules/@comis/agent/dist/executor/executor-prompt-runner.js +106 -5
  13. package/node_modules/@comis/agent/dist/executor/executor-tool-assembly.js +1 -0
  14. package/node_modules/@comis/agent/dist/executor/pi-executor.d.ts +1 -4
  15. package/node_modules/@comis/agent/dist/executor/pi-executor.js +30 -3
  16. package/node_modules/@comis/agent/dist/executor/replay-drift-detector.d.ts +85 -0
  17. package/node_modules/@comis/agent/dist/executor/replay-drift-detector.js +92 -0
  18. package/node_modules/@comis/agent/dist/executor/signature-block-scrubber.d.ts +34 -0
  19. package/node_modules/@comis/agent/dist/executor/signature-block-scrubber.js +69 -0
  20. package/node_modules/@comis/agent/dist/executor/signed-replay-detector.d.ts +39 -0
  21. package/node_modules/@comis/agent/dist/executor/signed-replay-detector.js +72 -0
  22. package/node_modules/@comis/agent/package.json +1 -1
  23. package/node_modules/@comis/channels/package.json +1 -1
  24. package/node_modules/@comis/cli/dist/cli.js +0 -0
  25. package/node_modules/@comis/cli/package.json +1 -1
  26. package/node_modules/@comis/core/dist/config/git-manager.js +10 -4
  27. package/node_modules/@comis/core/dist/config/index.d.ts +1 -0
  28. package/node_modules/@comis/core/dist/config/index.js +2 -0
  29. package/node_modules/@comis/core/dist/config/managed-sections.d.ts +67 -0
  30. package/node_modules/@comis/core/dist/config/managed-sections.js +124 -0
  31. package/node_modules/@comis/core/dist/config/schema-agent.d.ts +28 -10
  32. package/node_modules/@comis/core/dist/config/schema-agent.js +6 -0
  33. package/node_modules/@comis/core/dist/config/schema-gateway.d.ts +2 -2
  34. package/node_modules/@comis/core/dist/config/schema.d.ts +65 -64
  35. package/node_modules/@comis/core/dist/event-bus/events-messaging.d.ts +16 -0
  36. package/node_modules/@comis/core/dist/exports/config.d.ts +1 -1
  37. package/node_modules/@comis/core/dist/exports/config.js +1 -1
  38. package/node_modules/@comis/core/package.json +1 -1
  39. package/node_modules/@comis/daemon/bundled-skills/skill-creator/scripts/init-skill.py +0 -0
  40. package/node_modules/@comis/daemon/bundled-skills/skill-creator/scripts/validate-skill.py +0 -0
  41. package/node_modules/@comis/daemon/dist/daemon.js +11 -4
  42. package/node_modules/@comis/daemon/dist/rpc/config-handlers.js +20 -7
  43. package/node_modules/@comis/daemon/dist/rpc/session-handlers.js +27 -1
  44. package/node_modules/@comis/daemon/dist/wiring/setup-gateway.d.ts +22 -0
  45. package/node_modules/@comis/daemon/dist/wiring/setup-gateway.js +34 -8
  46. package/node_modules/@comis/daemon/dist/wiring/setup-tools.js +14 -1
  47. package/node_modules/@comis/daemon/package.json +1 -1
  48. package/node_modules/@comis/gateway/package.json +1 -1
  49. package/node_modules/@comis/infra/dist/logging/log-fields.d.ts +2 -2
  50. package/node_modules/@comis/infra/package.json +1 -1
  51. package/node_modules/@comis/memory/package.json +1 -1
  52. package/node_modules/@comis/scheduler/package.json +1 -1
  53. package/node_modules/@comis/shared/package.json +1 -1
  54. package/node_modules/@comis/skills/dist/bridge/tool-metadata-registry.js +23 -8
  55. package/node_modules/@comis/skills/dist/builtin/platform/gateway-tool.d.ts +1 -1
  56. package/node_modules/@comis/skills/dist/builtin/platform/gateway-tool.js +18 -14
  57. package/node_modules/@comis/skills/dist/builtin/platform/unified-session-tool.js +1 -1
  58. package/node_modules/@comis/skills/dist/builtin/sandbox/detect-provider.d.ts +1 -0
  59. package/node_modules/@comis/skills/dist/builtin/sandbox/detect-provider.js +78 -5
  60. package/node_modules/@comis/skills/package.json +1 -1
  61. package/node_modules/@comis/web/package.json +1 -1
  62. package/package.json +24 -26
  63. package/node_modules/@comis/agent/dist/provider/response/strip-minimax-xml.d.ts +0 -9
  64. package/node_modules/@comis/agent/dist/provider/response/strip-minimax-xml.js +0 -17
  65. package/node_modules/@comis/agent/dist/provider/response/strip-model-tokens.d.ts +0 -13
  66. package/node_modules/@comis/agent/dist/provider/response/strip-model-tokens.js +0 -19
  67. package/node_modules/@comis/agent/dist/provider/response/strip-tool-text.d.ts +0 -11
  68. package/node_modules/@comis/agent/dist/provider/response/strip-tool-text.js +0 -32
  69. package/node_modules/@comis/agent/dist/safety/follow-through-detector.d.ts +0 -46
  70. package/node_modules/@comis/agent/dist/safety/follow-through-detector.js +0 -76
  71. package/node_modules/@comis/agent/dist/safety/post-compaction-safety.d.ts +0 -30
  72. package/node_modules/@comis/agent/dist/safety/post-compaction-safety.js +0 -51
  73. package/node_modules/@comis/agent/dist/safety/schema-normalizer.d.ts +0 -37
  74. package/node_modules/@comis/agent/dist/safety/schema-normalizer.js +0 -137
  75. package/node_modules/@comis/agent/dist/safety/schema-pruning.d.ts +0 -50
  76. package/node_modules/@comis/agent/dist/safety/schema-pruning.js +0 -112
  77. package/node_modules/@comis/agent/dist/safety/tool-image-sanitizer.d.ts +0 -43
  78. package/node_modules/@comis/agent/dist/safety/tool-image-sanitizer.js +0 -96
  79. package/node_modules/@comis/agent/dist/safety/tool-sanitizer.d.ts +0 -44
  80. package/node_modules/@comis/agent/dist/safety/tool-sanitizer.js +0 -94
  81. package/node_modules/@comis/channels/dist/shared/thinking-tag-filter.d.ts +0 -28
  82. package/node_modules/@comis/channels/dist/shared/thinking-tag-filter.js +0 -206
  83. package/node_modules/@comis/cli/dist/wizard/config-writer.d.ts +0 -25
  84. package/node_modules/@comis/cli/dist/wizard/config-writer.js +0 -144
  85. package/node_modules/@comis/cli/dist/wizard/flow-types.d.ts +0 -48
  86. package/node_modules/@comis/cli/dist/wizard/flow-types.js +0 -70
  87. package/node_modules/@comis/cli/dist/wizard/manual-flow.d.ts +0 -21
  88. package/node_modules/@comis/cli/dist/wizard/manual-flow.js +0 -345
  89. package/node_modules/@comis/cli/dist/wizard/quickstart-flow.d.ts +0 -21
  90. package/node_modules/@comis/cli/dist/wizard/quickstart-flow.js +0 -116
  91. package/node_modules/@comis/core/dist/config/schema-agent-model.d.ts +0 -135
  92. package/node_modules/@comis/core/dist/config/schema-agent-model.js +0 -114
  93. package/node_modules/@comis/core/dist/config/schema-agent-session.d.ts +0 -177
  94. package/node_modules/@comis/core/dist/config/schema-agent-session.js +0 -116
  95. package/node_modules/@comis/core/dist/config/schema-context-engine.d.ts +0 -92
  96. package/node_modules/@comis/core/dist/config/schema-context-engine.js +0 -92
  97. package/node_modules/@comis/core/dist/config/schema-context-guard.d.ts +0 -34
  98. package/node_modules/@comis/core/dist/config/schema-context-guard.js +0 -32
  99. package/node_modules/@comis/core/dist/config/schema-delivery-mirror.d.ts +0 -27
  100. package/node_modules/@comis/core/dist/config/schema-delivery-mirror.js +0 -26
  101. package/node_modules/@comis/core/dist/config/schema-delivery-queue.d.ts +0 -31
  102. package/node_modules/@comis/core/dist/config/schema-delivery-queue.js +0 -30
  103. package/node_modules/@comis/core/dist/config/schema-delivery-timing.d.ts +0 -41
  104. package/node_modules/@comis/core/dist/config/schema-delivery-timing.js +0 -31
  105. package/node_modules/@comis/core/dist/config/schema-monitoring.d.ts +0 -105
  106. package/node_modules/@comis/core/dist/config/schema-monitoring.js +0 -67
  107. package/node_modules/@comis/core/dist/ports/media-ports.d.ts +0 -278
  108. package/node_modules/@comis/core/dist/ports/media-ports.js +0 -1
  109. package/node_modules/@comis/core/dist/security/input-guard.d.ts +0 -46
  110. package/node_modules/@comis/core/dist/security/input-guard.js +0 -166
  111. package/node_modules/@comis/core/dist/security/scoped-secret-manager.d.ts +0 -38
  112. package/node_modules/@comis/core/dist/security/scoped-secret-manager.js +0 -94
  113. package/node_modules/@comis/daemon/dist/observability/delivery-context.d.ts +0 -37
  114. package/node_modules/@comis/daemon/dist/observability/delivery-context.js +0 -1
  115. package/node_modules/@comis/daemon/dist/observability/log-level-manager.d.ts +0 -23
  116. package/node_modules/@comis/daemon/dist/observability/log-level-manager.js +0 -34
  117. package/node_modules/@comis/daemon/dist/observability/log-transport.d.ts +0 -44
  118. package/node_modules/@comis/daemon/dist/observability/log-transport.js +0 -74
  119. package/node_modules/@comis/daemon/dist/observability/obs-write-buffer.d.ts +0 -53
  120. package/node_modules/@comis/daemon/dist/observability/obs-write-buffer.js +0 -68
  121. package/node_modules/@comis/daemon/dist/observability/types.d.ts +0 -6
  122. package/node_modules/@comis/daemon/dist/observability/types.js +0 -1
  123. package/node_modules/@comis/daemon/dist/wiring/seed-bundled-skills.d.ts +0 -41
  124. package/node_modules/@comis/daemon/dist/wiring/seed-bundled-skills.js +0 -84
  125. package/node_modules/@comis/daemon/dist/wiring/setup-delivery-mirror.d.ts +0 -24
  126. package/node_modules/@comis/daemon/dist/wiring/setup-delivery-mirror.js +0 -88
  127. package/node_modules/@comis/daemon/dist/wiring/setup-delivery-queue.d.ts +0 -31
  128. package/node_modules/@comis/daemon/dist/wiring/setup-delivery-queue.js +0 -132
  129. package/node_modules/@comis/daemon/dist/wiring/setup-monitoring.d.ts +0 -38
  130. package/node_modules/@comis/daemon/dist/wiring/setup-monitoring.js +0 -100
  131. package/node_modules/@comis/daemon/dist/wiring/setup-rpc-bridge.d.ts +0 -34
  132. package/node_modules/@comis/daemon/dist/wiring/setup-rpc-bridge.js +0 -52
  133. package/node_modules/@comis/daemon/dist/wiring/setup-task-extraction.d.ts +0 -41
  134. package/node_modules/@comis/daemon/dist/wiring/setup-task-extraction.js +0 -86
  135. package/node_modules/@comis/memory/dist/embedding-cache.d.ts +0 -36
  136. package/node_modules/@comis/memory/dist/embedding-cache.js +0 -94
  137. package/node_modules/@comis/skills/dist/bridge/tool-output-schemas.d.ts +0 -17
  138. package/node_modules/@comis/skills/dist/bridge/tool-output-schemas.js +0 -125
  139. package/node_modules/@comis/skills/dist/bridge/tool-parallelism-metadata.d.ts +0 -14
  140. package/node_modules/@comis/skills/dist/bridge/tool-parallelism-metadata.js +0 -92
  141. package/node_modules/@comis/skills/dist/bridge/tool-result-caps.d.ts +0 -14
  142. package/node_modules/@comis/skills/dist/bridge/tool-result-caps.js +0 -36
  143. package/node_modules/@comis/skills/dist/bridge/tool-search-hints.d.ts +0 -15
  144. package/node_modules/@comis/skills/dist/bridge/tool-search-hints.js +0 -68
  145. package/node_modules/@comis/skills/dist/bridge/tool-validators.d.ts +0 -11
  146. package/node_modules/@comis/skills/dist/bridge/tool-validators.js +0 -105
  147. package/node_modules/@comis/skills/dist/builtin/file/find-sort-wrapper.d.ts +0 -22
  148. package/node_modules/@comis/skills/dist/builtin/file/find-sort-wrapper.js +0 -95
  149. package/node_modules/@comis/skills/dist/builtin/file/grep-output-mode-wrapper.d.ts +0 -24
  150. package/node_modules/@comis/skills/dist/builtin/file/grep-output-mode-wrapper.js +0 -167
  151. package/node_modules/@comis/skills/dist/builtin/task-plan-tool.d.ts +0 -25
  152. package/node_modules/@comis/skills/dist/builtin/task-plan-tool.js +0 -67
  153. package/node_modules/@comis/skills/dist/integrations/mcp-tool-bridge.d.ts +0 -75
  154. package/node_modules/@comis/skills/dist/integrations/mcp-tool-bridge.js +0 -235
@@ -1,52 +0,0 @@
1
- /**
2
- * RPC bridge setup: rpcCall outer wrapper with deferred dispatch wiring.
3
- *
4
- * Extracted from daemon.ts to isolate the rpcCall closure pattern (debug/error
5
- * logging, classifyRpcError) and the deferred rpcCallInner assignment. The
6
- * rpcCall function is needed by setupTools (early in the boot sequence), but
7
- * rpcCallInner depends on heartbeatRunner from setupMonitoring (later in the
8
- * sequence). This module encapsulates the deferred wiring via wireDispatch().
9
- *
10
- * @module
11
- */
12
- import { createRpcDispatch, classifyRpcError } from "../rpc/rpc-dispatch.js";
13
- // ---------------------------------------------------------------------------
14
- // Setup function
15
- // ---------------------------------------------------------------------------
16
- /**
17
- * Create the rpcCall wrapper and deferred dispatch mechanism.
18
- *
19
- * The returned rpcCall can be passed to setupTools immediately. After
20
- * setupMonitoring resolves the heartbeatRunner TDZ, call wireDispatch()
21
- * with the full RpcDispatchDeps to wire the real dispatch function.
22
- *
23
- * @param deps.gatewayLogger - Logger for RPC call tracing
24
- * @returns rpcCall function and wireDispatch callback
25
- */
26
- export function setupRpcBridge(deps) {
27
- const { gatewayLogger } = deps;
28
- // Deferred inner dispatch — assigned by wireDispatch() after all deps are ready
29
- let rpcCallInner;
30
- const rpcCall = async (method, params) => {
31
- const rpcStartMs = Date.now();
32
- try {
33
- return await rpcCallInner(method, params);
34
- }
35
- catch (err) {
36
- const errMsg = err instanceof Error ? err.message : String(err);
37
- const classified = classifyRpcError(errMsg);
38
- gatewayLogger.debug({
39
- method,
40
- err: errMsg,
41
- durationMs: Date.now() - rpcStartMs,
42
- hint: classified.hint,
43
- errorKind: classified.errorKind,
44
- }, "[rpcCall] failed");
45
- throw err;
46
- }
47
- };
48
- const wireDispatch = (dispatchDeps) => {
49
- rpcCallInner = createRpcDispatch(dispatchDeps);
50
- };
51
- return { rpcCall, wireDispatch };
52
- }
@@ -1,41 +0,0 @@
1
- /**
2
- * Task extraction setup: per-agent task extractors with pluggable LLM extraction.
3
- *
4
- * Extracted as a wiring module following setup-monitoring.ts pattern.
5
- * Task extraction runs AFTER successful agent execution, extracting
6
- * commitments and follow-ups from conversation text.
7
- *
8
- * Feature-gated: config.scheduler.tasks.enabled (default: false).
9
- *
10
- * @module
11
- */
12
- import type { AppContainer } from "@comis/core";
13
- import type { ComisLogger } from "@comis/infra";
14
- import { type TaskExtractor } from "@comis/scheduler";
15
- /** Dependencies for task extraction setup. */
16
- export interface TaskExtractionDeps {
17
- /** Bootstrap output (config.scheduler.tasks, eventBus). */
18
- container: AppContainer;
19
- /** Per-agent workspace directories (from setupAgents result). */
20
- workspaceDirs: Map<string, string>;
21
- /** Module-bound logger for scheduler subsystem. */
22
- schedulerLogger: ComisLogger;
23
- }
24
- /** All services produced by the task extraction setup phase. */
25
- export interface TaskExtractionResult {
26
- /** Per-agent task extractors (only for agents with tasks enabled). */
27
- taskExtractors: Map<string, TaskExtractor>;
28
- /**
29
- * Callback for the execution pipeline. If task extraction is disabled
30
- * for the given agent (or globally), this is a no-op.
31
- */
32
- extractFromConversation: (conversationText: string, sessionKey: string, agentId: string) => Promise<void>;
33
- }
34
- /**
35
- * Create per-agent task extractors and return an extraction callback
36
- * for the execution pipeline.
37
- *
38
- * The extraction callback is safe to call unconditionally -- it checks
39
- * the feature gate internally and returns immediately if disabled.
40
- */
41
- export declare function setupTaskExtraction(deps: TaskExtractionDeps): TaskExtractionResult;
@@ -1,86 +0,0 @@
1
- /**
2
- * Task extraction setup: per-agent task extractors with pluggable LLM extraction.
3
- *
4
- * Extracted as a wiring module following setup-monitoring.ts pattern.
5
- * Task extraction runs AFTER successful agent execution, extracting
6
- * commitments and follow-ups from conversation text.
7
- *
8
- * Feature-gated: config.scheduler.tasks.enabled (default: false).
9
- *
10
- * @module
11
- */
12
- import { safePath } from "@comis/core";
13
- import { createTaskExtractor, createTaskStore, } from "@comis/scheduler";
14
- // ---------------------------------------------------------------------------
15
- // Setup function
16
- // ---------------------------------------------------------------------------
17
- /**
18
- * Create per-agent task extractors and return an extraction callback
19
- * for the execution pipeline.
20
- *
21
- * The extraction callback is safe to call unconditionally -- it checks
22
- * the feature gate internally and returns immediately if disabled.
23
- */
24
- export function setupTaskExtraction(deps) {
25
- const { container, workspaceDirs, schedulerLogger } = deps;
26
- const tasksConfig = container.config.scheduler.tasks;
27
- const agents = container.config.agents;
28
- const taskExtractors = new Map();
29
- if (!tasksConfig.enabled) {
30
- schedulerLogger.debug("Task extraction disabled globally");
31
- return {
32
- taskExtractors,
33
- extractFromConversation: async () => { },
34
- };
35
- }
36
- for (const [agentId] of Object.entries(agents)) {
37
- const agentWorkspace = workspaceDirs.get(agentId);
38
- if (!agentWorkspace)
39
- continue;
40
- const storePath = safePath(agentWorkspace, ".scheduler", "tasks.json");
41
- const store = createTaskStore(storePath);
42
- // Pluggable extraction function -- in production this would wrap an LLM call.
43
- // For now, create a placeholder that returns empty tasks. The daemon can
44
- // override this with a real LLM-based extraction when the agent executor
45
- // integration is fully wired (Phase TBD).
46
- const extractFn = async () => {
47
- // TODO: Wire to agent executor LLM call for real extraction
48
- return { tasks: [], reasoning: "Extraction function not yet wired to LLM" };
49
- };
50
- const extractor = createTaskExtractor({
51
- extractFn,
52
- store,
53
- logger: schedulerLogger.child({ agentId, component: "task-extractor" }),
54
- config: {
55
- enabled: tasksConfig.enabled,
56
- confidenceThreshold: tasksConfig.confidenceThreshold,
57
- },
58
- eventBus: container.eventBus,
59
- });
60
- taskExtractors.set(agentId, extractor);
61
- schedulerLogger.debug({ agentId }, "Task extractor created");
62
- }
63
- if (taskExtractors.size > 0) {
64
- schedulerLogger.info({ extractorCount: taskExtractors.size }, "Task extraction enabled for agents");
65
- }
66
- async function extractFromConversation(conversationText, sessionKey, agentId) {
67
- const extractor = taskExtractors.get(agentId);
68
- if (!extractor)
69
- return;
70
- try {
71
- const tasks = await extractor.extract(conversationText, sessionKey);
72
- if (tasks.length > 0) {
73
- schedulerLogger.info({ agentId, taskCount: tasks.length, sessionKey }, "Tasks extracted from conversation");
74
- }
75
- }
76
- catch (err) {
77
- schedulerLogger.warn({
78
- agentId,
79
- err: err instanceof Error ? err.message : String(err),
80
- hint: "Task extraction failed but does not block message processing",
81
- errorKind: "internal",
82
- }, "Task extraction error");
83
- }
84
- }
85
- return { taskExtractors, extractFromConversation };
86
- }
@@ -1,36 +0,0 @@
1
- /**
2
- * Cached embedding port decorator (MEM-07).
3
- *
4
- * Wraps any EmbeddingPort with an LRU cache keyed by SHA-256 content
5
- * hashes. Previously-seen text returns immediately without calling
6
- * the inner provider. embedBatch splits texts into cache hits and
7
- * misses, only calling the inner provider for misses.
8
- */
9
- import type { EmbeddingPort } from "@comis/core";
10
- export interface EmbeddingCacheOptions {
11
- /** Maximum number of cached embeddings. Default: 10_000 */
12
- maxEntries: number;
13
- /** TTL in milliseconds. Default: undefined (no TTL, LRU only).
14
- * Recommended: 86_400_000 (24 hours) for long-running daemons. */
15
- ttlMs?: number;
16
- }
17
- /** Snapshot of embedding cache statistics (Phase 511). */
18
- export interface EmbeddingCacheStats {
19
- entries: number;
20
- maxEntries: number;
21
- hitRate: number;
22
- hits: number;
23
- misses: number;
24
- provider: string;
25
- }
26
- /**
27
- * Create a cached EmbeddingPort decorator that wraps the given inner
28
- * provider with an LRU content-hash cache.
29
- *
30
- * @param inner - The underlying EmbeddingPort to delegate cache misses to
31
- * @param options - Cache configuration (maxEntries)
32
- * @returns An EmbeddingPort with transparent caching
33
- */
34
- export declare function createCachedEmbeddingPort(inner: EmbeddingPort, options: EmbeddingCacheOptions): EmbeddingPort & {
35
- getCacheStats(): EmbeddingCacheStats;
36
- };
@@ -1,94 +0,0 @@
1
- /**
2
- * Cached embedding port decorator (MEM-07).
3
- *
4
- * Wraps any EmbeddingPort with an LRU cache keyed by SHA-256 content
5
- * hashes. Previously-seen text returns immediately without calling
6
- * the inner provider. embedBatch splits texts into cache hits and
7
- * misses, only calling the inner provider for misses.
8
- */
9
- import { ok } from "@comis/shared";
10
- import { createHash } from "node:crypto";
11
- import { LRUCache } from "lru-cache";
12
- /**
13
- * Create a cached EmbeddingPort decorator that wraps the given inner
14
- * provider with an LRU content-hash cache.
15
- *
16
- * @param inner - The underlying EmbeddingPort to delegate cache misses to
17
- * @param options - Cache configuration (maxEntries)
18
- * @returns An EmbeddingPort with transparent caching
19
- */
20
- export function createCachedEmbeddingPort(inner, options) {
21
- const cache = new LRUCache({
22
- max: options.maxEntries,
23
- ...(options.ttlMs ? { ttl: options.ttlMs } : {}),
24
- });
25
- let hits = 0;
26
- let misses = 0;
27
- function hashText(text) {
28
- return createHash("sha256").update(text).digest("hex");
29
- }
30
- return {
31
- provider: inner.provider,
32
- dimensions: inner.dimensions,
33
- modelId: inner.modelId,
34
- async embed(text) {
35
- const key = hashText(text);
36
- const cached = cache.get(key);
37
- if (cached) {
38
- hits++;
39
- return ok(cached);
40
- }
41
- misses++;
42
- const result = await inner.embed(text);
43
- if (result.ok)
44
- cache.set(key, result.value);
45
- return result;
46
- },
47
- async embedBatch(texts) {
48
- // Split into hits and misses
49
- const results = [];
50
- const missIndices = [];
51
- const missTexts = [];
52
- for (let i = 0; i < texts.length; i++) {
53
- const key = hashText(texts[i]);
54
- const cached = cache.get(key);
55
- if (cached) {
56
- hits++;
57
- results.push(cached);
58
- }
59
- else {
60
- misses++;
61
- results.push(null);
62
- missIndices.push(i);
63
- missTexts.push(texts[i]);
64
- }
65
- }
66
- // If all cached, return immediately
67
- if (missTexts.length === 0) {
68
- return ok(results);
69
- }
70
- // Embed misses in a single batch
71
- const batchResult = await inner.embedBatch(missTexts);
72
- if (!batchResult.ok)
73
- return batchResult;
74
- // Merge: fill in misses and cache them
75
- for (let j = 0; j < missIndices.length; j++) {
76
- const idx = missIndices[j];
77
- results[idx] = batchResult.value[j];
78
- cache.set(hashText(missTexts[j]), batchResult.value[j]);
79
- }
80
- return ok(results);
81
- },
82
- getCacheStats() {
83
- const total = hits + misses;
84
- return {
85
- entries: cache.size,
86
- maxEntries: cache.max,
87
- hitRate: total > 0 ? hits / total : 0,
88
- hits,
89
- misses,
90
- provider: inner.provider,
91
- };
92
- },
93
- };
94
- }
@@ -1,17 +0,0 @@
1
- /**
2
- * Per-tool output schemas (Phase 568: SCHEMA-01 through SCHEMA-05).
3
- *
4
- * Registers outputSchema for 6 priority tools to describe their actual output
5
- * format. Schemas are informational only -- delivered to the LLM via JIT guide
6
- * injection to help predict result structure. Never validated at runtime.
7
- *
8
- * - grep, find: Text output (type: "string") -- NOT JSON
9
- * - exec, memory_search, web_search, sessions_list: JSON output (type: "object")
10
- *
11
- * Import this module for side effects only -- it runs registerToolMetadata()
12
- * calls at module scope. Imported from tool-bridge.ts to ensure schemas are
13
- * registered before assembleToolPipeline() runs.
14
- *
15
- * @module
16
- */
17
- export {};
@@ -1,125 +0,0 @@
1
- /**
2
- * Per-tool output schemas (Phase 568: SCHEMA-01 through SCHEMA-05).
3
- *
4
- * Registers outputSchema for 6 priority tools to describe their actual output
5
- * format. Schemas are informational only -- delivered to the LLM via JIT guide
6
- * injection to help predict result structure. Never validated at runtime.
7
- *
8
- * - grep, find: Text output (type: "string") -- NOT JSON
9
- * - exec, memory_search, web_search, sessions_list: JSON output (type: "object")
10
- *
11
- * Import this module for side effects only -- it runs registerToolMetadata()
12
- * calls at module scope. Imported from tool-bridge.ts to ensure schemas are
13
- * registered before assembleToolPipeline() runs.
14
- *
15
- * @module
16
- */
17
- import { registerToolMetadata } from "@comis/core";
18
- // ---------------------------------------------------------------------------
19
- // Text-output tools (pi-coding-agent, post-processed wrappers)
20
- // ---------------------------------------------------------------------------
21
- registerToolMetadata("grep", {
22
- outputSchema: {
23
- type: "string",
24
- description: "Text output (not JSON). Default mode: `filepath:linenum: content` per line. " +
25
- "files_with_matches mode: one filepath per line. " +
26
- "count mode: `filepath: N matches` per line, sorted descending. " +
27
- "Trailing `[...]` notices indicate truncation or limits.",
28
- },
29
- });
30
- registerToolMetadata("find", {
31
- outputSchema: {
32
- type: "string",
33
- description: "Text output (not JSON). Newline-separated file paths sorted by modification time (most recent first). " +
34
- "Paths relative to workspace root. Trailing `[...]` notices for truncation.",
35
- },
36
- });
37
- // ---------------------------------------------------------------------------
38
- // JSON-output tools (jsonResult() or JSON.stringify)
39
- // ---------------------------------------------------------------------------
40
- registerToolMetadata("exec", {
41
- outputSchema: {
42
- type: "object",
43
- description: "Shell command execution result",
44
- properties: {
45
- exitCode: { type: "number", description: "0 = success, 124 = timeout" },
46
- stdout: { type: "string", description: "Standard output" },
47
- stderr: { type: "string", description: "Standard error" },
48
- description: { type: "string", description: "User-provided command label" },
49
- truncated: { type: "boolean", description: "True when output exceeded buffer" },
50
- fullOutputPath: { type: "string", description: "Path to full output on disk" },
51
- },
52
- },
53
- });
54
- registerToolMetadata("memory_search", {
55
- outputSchema: {
56
- type: "object",
57
- description: "Memory search results",
58
- properties: {
59
- results: {
60
- type: "array",
61
- description: "Matching entries (content max 500 chars each)",
62
- items: {
63
- type: "object",
64
- properties: {
65
- id: { type: "string" },
66
- content: { type: "string" },
67
- score: { type: "number" },
68
- tags: { type: "array", items: { type: "string" } },
69
- createdAt: { type: "number", description: "Epoch ms" },
70
- },
71
- },
72
- },
73
- },
74
- },
75
- });
76
- registerToolMetadata("web_search", {
77
- outputSchema: {
78
- type: "object",
79
- description: "Web search results. List-based providers (Brave/Tavily) return results[]. " +
80
- "Perplexity/Grok return { content, citations } instead.",
81
- properties: {
82
- query: { type: "string" },
83
- provider: { type: "string" },
84
- tookMs: { type: "number" },
85
- results: {
86
- type: "array",
87
- description: "List-based provider results",
88
- items: {
89
- type: "object",
90
- properties: {
91
- title: { type: "string" },
92
- url: { type: "string" },
93
- description: { type: "string" },
94
- },
95
- },
96
- },
97
- },
98
- },
99
- });
100
- registerToolMetadata("sessions_list", {
101
- outputSchema: {
102
- type: "object",
103
- description: "Active sessions listing",
104
- properties: {
105
- sessions: {
106
- type: "array",
107
- items: {
108
- type: "object",
109
- properties: {
110
- sessionKey: { type: "string" },
111
- agentId: { type: "string" },
112
- userId: { type: "string" },
113
- channelId: { type: "string" },
114
- kind: { type: "string" },
115
- messageCount: { type: "number" },
116
- totalTokens: { type: "number" },
117
- updatedAt: { type: "number" },
118
- createdAt: { type: "number" },
119
- },
120
- },
121
- },
122
- total: { type: "number", description: "Total session count" },
123
- },
124
- },
125
- });
@@ -1,14 +0,0 @@
1
- /**
2
- * Per-tool parallelism metadata (Phase 565: PAR-04).
3
- *
4
- * Registers isReadOnly and isConcurrencySafe for all 51 built-in tools.
5
- * Uses merge semantics so Phase 564 maxResultSizeChars entries are preserved
6
- * when this module registers additional fields for the same tools.
7
- *
8
- * Import this module for side effects only -- it runs registerToolMetadata()
9
- * calls at module scope. Imported from tool-bridge.ts to ensure parallelism
10
- * metadata is registered before assembleToolPipeline() runs.
11
- *
12
- * @module
13
- */
14
- export {};
@@ -1,92 +0,0 @@
1
- /**
2
- * Per-tool parallelism metadata (Phase 565: PAR-04).
3
- *
4
- * Registers isReadOnly and isConcurrencySafe for all 51 built-in tools.
5
- * Uses merge semantics so Phase 564 maxResultSizeChars entries are preserved
6
- * when this module registers additional fields for the same tools.
7
- *
8
- * Import this module for side effects only -- it runs registerToolMetadata()
9
- * calls at module scope. Imported from tool-bridge.ts to ensure parallelism
10
- * metadata is registered before assembleToolPipeline() runs.
11
- *
12
- * @module
13
- */
14
- import { registerToolMetadata } from "@comis/core";
15
- // ===========================================================================
16
- // Read-only tools (25) -- { isReadOnly: true }
17
- // Safe for optimistic parallel execution with other read-only tools.
18
- // ===========================================================================
19
- // --- File system reads ---
20
- registerToolMetadata("read", { isReadOnly: true });
21
- registerToolMetadata("grep", { isReadOnly: true, searchHint: "search file contents with regex pattern ripgrep" });
22
- registerToolMetadata("find", { isReadOnly: true });
23
- registerToolMetadata("ls", { isReadOnly: true });
24
- // --- Web reads ---
25
- registerToolMetadata("web_search", { isReadOnly: true });
26
- registerToolMetadata("web_fetch", { isReadOnly: true });
27
- registerToolMetadata("browser", { isReadOnly: true });
28
- // --- Memory/session reads ---
29
- registerToolMetadata("memory_search", { isReadOnly: true });
30
- registerToolMetadata("memory_get", { isReadOnly: true });
31
- registerToolMetadata("session_search", { isReadOnly: true });
32
- // --- Session reads ---
33
- registerToolMetadata("sessions_list", { isReadOnly: true });
34
- registerToolMetadata("session_status", { isReadOnly: true });
35
- registerToolMetadata("sessions_history", { isReadOnly: true });
36
- registerToolMetadata("agents_list", { isReadOnly: true });
37
- // --- Context reads ---
38
- registerToolMetadata("ctx_search", { isReadOnly: true });
39
- registerToolMetadata("ctx_inspect", { isReadOnly: true });
40
- registerToolMetadata("ctx_expand", { isReadOnly: true });
41
- registerToolMetadata("ctx_recall", { isReadOnly: true });
42
- // --- Media analysis ---
43
- registerToolMetadata("image_analyze", { isReadOnly: true });
44
- registerToolMetadata("describe_video", { isReadOnly: true });
45
- registerToolMetadata("extract_document", { isReadOnly: true });
46
- registerToolMetadata("transcribe_audio", { isReadOnly: true });
47
- // --- Platform reads ---
48
- registerToolMetadata("obs_query", { isReadOnly: true });
49
- registerToolMetadata("models_manage", { isReadOnly: true });
50
- // --- Discovery ---
51
- registerToolMetadata("discover_tools", { isReadOnly: true });
52
- // ===========================================================================
53
- // Mutating tools (25) -- { isReadOnly: false }
54
- // Must not be executed in parallel with other mutating tools.
55
- // ===========================================================================
56
- // --- File writes ---
57
- registerToolMetadata("edit", { isReadOnly: false });
58
- registerToolMetadata("write", { isReadOnly: false });
59
- registerToolMetadata("apply_patch", { isReadOnly: false });
60
- // --- Exec/process ---
61
- registerToolMetadata("exec", { isReadOnly: false });
62
- registerToolMetadata("process", { isReadOnly: false });
63
- // --- Memory writes ---
64
- registerToolMetadata("memory_store", { isReadOnly: false });
65
- registerToolMetadata("memory_manage", { isReadOnly: false });
66
- // --- Session management ---
67
- registerToolMetadata("sessions_manage", { isReadOnly: false });
68
- registerToolMetadata("sessions_send", { isReadOnly: false });
69
- registerToolMetadata("sessions_spawn", { isReadOnly: false });
70
- registerToolMetadata("subagents", { isReadOnly: false });
71
- // --- Platform management ---
72
- registerToolMetadata("pipeline", { isReadOnly: false });
73
- registerToolMetadata("cron", { isReadOnly: false });
74
- registerToolMetadata("gateway", { isReadOnly: false });
75
- registerToolMetadata("heartbeat_manage", { isReadOnly: false });
76
- registerToolMetadata("channels_manage", { isReadOnly: false });
77
- registerToolMetadata("tokens_manage", { isReadOnly: false });
78
- registerToolMetadata("skills_manage", { isReadOnly: false });
79
- registerToolMetadata("mcp_manage", { isReadOnly: false });
80
- registerToolMetadata("agents_manage", { isReadOnly: false });
81
- // --- Channel actions ---
82
- registerToolMetadata("whatsapp_action", { isReadOnly: false });
83
- registerToolMetadata("discord_action", { isReadOnly: false });
84
- registerToolMetadata("telegram_action", { isReadOnly: false });
85
- registerToolMetadata("slack_action", { isReadOnly: false });
86
- // --- Media generation ---
87
- registerToolMetadata("tts_synthesize", { isReadOnly: false });
88
- // ===========================================================================
89
- // Concurrency-safe mutating tool (1) -- { isReadOnly: false, isConcurrencySafe: true }
90
- // Sends to independent channels with no ordering dependencies.
91
- // ===========================================================================
92
- registerToolMetadata("message", { isReadOnly: false, isConcurrencySafe: true });
@@ -1,14 +0,0 @@
1
- /**
2
- * Per-tool result size caps (Phase 564: TRUNC-02).
3
- *
4
- * Registers maxResultSizeChars for tools that can produce large text output.
5
- * Values are calibrated per TRUNC-03 to avoid triple truncation stacking
6
- * with the per-tool bouncer (default 50K) and turn budget (200K aggregate).
7
- *
8
- * Import this module for side effects only -- it runs registerToolMetadata()
9
- * calls at module scope. Imported from tool-bridge.ts to ensure caps are
10
- * registered before assembleToolPipeline() runs.
11
- *
12
- * @module
13
- */
14
- export {};
@@ -1,36 +0,0 @@
1
- /**
2
- * Per-tool result size caps (Phase 564: TRUNC-02).
3
- *
4
- * Registers maxResultSizeChars for tools that can produce large text output.
5
- * Values are calibrated per TRUNC-03 to avoid triple truncation stacking
6
- * with the per-tool bouncer (default 50K) and turn budget (200K aggregate).
7
- *
8
- * Import this module for side effects only -- it runs registerToolMetadata()
9
- * calls at module scope. Imported from tool-bridge.ts to ensure caps are
10
- * registered before assembleToolPipeline() runs.
11
- *
12
- * @module
13
- */
14
- import { registerToolMetadata } from "@comis/core";
15
- // ---------------------------------------------------------------------------
16
- // File tools (from @mariozechner/pi-coding-agent via createComisFileTools)
17
- // ---------------------------------------------------------------------------
18
- registerToolMetadata("grep", { maxResultSizeChars: 100_000 });
19
- registerToolMetadata("read", { maxResultSizeChars: 200_000 });
20
- registerToolMetadata("find", { maxResultSizeChars: 50_000 });
21
- registerToolMetadata("ls", { maxResultSizeChars: 20_000 });
22
- // ---------------------------------------------------------------------------
23
- // Exec tool
24
- // ---------------------------------------------------------------------------
25
- registerToolMetadata("exec", { maxResultSizeChars: 100_000 });
26
- // ---------------------------------------------------------------------------
27
- // Web tools
28
- // ---------------------------------------------------------------------------
29
- registerToolMetadata("web_fetch", { maxResultSizeChars: 150_000 });
30
- registerToolMetadata("web_search", { maxResultSizeChars: 50_000 });
31
- // ---------------------------------------------------------------------------
32
- // Platform tools (RPC-based, created in daemon wiring)
33
- // ---------------------------------------------------------------------------
34
- registerToolMetadata("sessions_history", { maxResultSizeChars: 100_000 });
35
- registerToolMetadata("obs_query", { maxResultSizeChars: 100_000 });
36
- registerToolMetadata("memory_search", { maxResultSizeChars: 50_000 });
@@ -1,15 +0,0 @@
1
- /**
2
- * Per-tool search hints for deferred tool discovery (Phase 569: DISC-01, DISC-03).
3
- *
4
- * Registers searchHint for all 35 deferrable tools. Each hint is max 80 chars,
5
- * lowercase, space-separated keyword synonyms that enrich BM25 matching in
6
- * discover_tools. Uses merge semantics so existing metadata (isReadOnly,
7
- * maxResultSizeChars, outputSchema, etc.) is preserved.
8
- *
9
- * Import this module for side effects only -- it runs registerToolMetadata()
10
- * calls at module scope. Imported from tool-bridge.ts to ensure hints are
11
- * registered before discover_tools execute() reads them.
12
- *
13
- * @module
14
- */
15
- export {};