@botiverse/raft-daemon 0.70.2 → 0.71.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.
@@ -1412,6 +1412,18 @@ function defineTraceFields(definitions) {
1412
1412
  }
1413
1413
  return definitions;
1414
1414
  }
1415
+ var TRACE_LIFECYCLE_SHADOW_SIGNAL_SITE_VALUES = [
1416
+ "daemon_ingest",
1417
+ "delivery_ack",
1418
+ "hint_resolution",
1419
+ "lifecycle_plan",
1420
+ "preserve_rebroadcast",
1421
+ "ready_online",
1422
+ "runtime_error",
1423
+ "slock_action_status",
1424
+ "starting_resolve",
1425
+ "synthetic_repair"
1426
+ ];
1415
1427
  var TRACE_B0_FIELD_DEFINITIONS = defineTraceFields([
1416
1428
  { key: "row_kind", fieldClass: "query_axis", placement: "span_or_event", valueKind: "closed_enum", enumBinding: "stable" },
1417
1429
  { key: "trace_id", fieldClass: "query_axis", placement: "span", valueKind: "identity", highCardinality: true },
@@ -1434,10 +1446,13 @@ var TRACE_B0_FIELD_DEFINITIONS = defineTraceFields([
1434
1446
  { key: "route_pattern", fieldClass: "query_axis", placement: "span", valueKind: "route" },
1435
1447
  { key: "caller_kind", fieldClass: "query_axis", placement: "span", valueKind: "closed_enum", enumBinding: "stable" },
1436
1448
  { key: "server_id", fieldClass: "query_axis", placement: "span", valueKind: "identity", highCardinality: true },
1449
+ { key: "channel_id", fieldClass: "query_axis", placement: "span_or_event", valueKind: "identity", highCardinality: true },
1437
1450
  { key: "machine_id", fieldClass: "query_axis", placement: "span", valueKind: "identity", highCardinality: true },
1438
1451
  { key: "agent_id", fieldClass: "query_axis", placement: "span_or_event", valueKind: "identity", highCardinality: true },
1452
+ { key: "job_id", fieldClass: "query_axis", placement: "span_or_event", valueKind: "identity", highCardinality: true },
1439
1453
  { key: "launch_id", fieldClass: "query_axis", placement: "span", valueKind: "identity", highCardinality: true },
1440
1454
  { key: "session_id", fieldClass: "query_axis", placement: "span", valueKind: "identity", highCardinality: true },
1455
+ { key: "outcome", fieldClass: "query_axis", placement: "span_or_event", valueKind: "closed_enum", enumBinding: "pending_457" },
1441
1456
  { key: "observation_class", fieldClass: "query_axis", placement: "span_or_event", valueKind: "closed_enum", enumBinding: "pending_457" },
1442
1457
  { key: "action", fieldClass: "query_axis", placement: "span_or_event", valueKind: "closed_enum", enumBinding: "pending_457" },
1443
1458
  { key: "source", fieldClass: "query_axis", placement: "span_or_event", valueKind: "closed_enum", enumBinding: "pending_457" },
@@ -1447,6 +1462,7 @@ var TRACE_B0_FIELD_DEFINITIONS = defineTraceFields([
1447
1462
  { key: "error_class", fieldClass: "query_axis", placement: "span_or_event", valueKind: "closed_enum", enumBinding: "pending_457" },
1448
1463
  { key: "query_name", fieldClass: "query_axis", placement: "span_or_event", valueKind: "closed_enum", enumBinding: "query_registry" },
1449
1464
  { key: "phase", fieldClass: "query_axis", placement: "span_or_event", valueKind: "closed_enum", enumBinding: "pending_457" },
1465
+ { key: "eligibility_subcheck", fieldClass: "query_axis", placement: "event", valueKind: "closed_enum", enumBinding: "pending_457" },
1450
1466
  { key: "hint_source", fieldClass: "family_query_axis", placement: "event", valueKind: "closed_enum", scope: "family:activity" },
1451
1467
  { key: "resolved_activity", fieldClass: "family_query_axis", placement: "event", valueKind: "closed_enum", scope: "family:activity" },
1452
1468
  { key: "previous_activity", fieldClass: "family_query_axis", placement: "event", valueKind: "closed_enum", scope: "family:activity" },
@@ -1456,7 +1472,7 @@ var TRACE_B0_FIELD_DEFINITIONS = defineTraceFields([
1456
1472
  { key: "activity_source", fieldClass: "family_query_axis", placement: "event", valueKind: "closed_enum", scope: "family:activity" },
1457
1473
  { key: "status_bucket", fieldClass: "family_query_axis", placement: "event", valueKind: "closed_enum", scope: "family:activity" },
1458
1474
  { key: "shadow_agent_id", fieldClass: "family_query_axis", placement: "event", valueKind: "identity", scope: "family:lifecycle_shadow", highCardinality: true },
1459
- { key: "shadow_signal_site", fieldClass: "family_query_axis", placement: "event", valueKind: "closed_enum", scope: "family:lifecycle_shadow", enumBinding: "pending_457" },
1475
+ { key: "shadow_signal_site", fieldClass: "family_query_axis", placement: "event", valueKind: "closed_enum", scope: "family:lifecycle_shadow", enumBinding: "pending_457", enumValues: TRACE_LIFECYCLE_SHADOW_SIGNAL_SITE_VALUES },
1460
1476
  { key: "shadow_observation_class", fieldClass: "family_query_axis", placement: "event", valueKind: "closed_enum", scope: "family:lifecycle_shadow", enumBinding: "pending_457" },
1461
1477
  { key: "shadow_prior_projection", fieldClass: "family_query_axis", placement: "event", valueKind: "closed_enum", scope: "family:lifecycle_shadow", enumBinding: "pending_457" },
1462
1478
  { key: "shadow_projection", fieldClass: "family_query_axis", placement: "event", valueKind: "closed_enum", scope: "family:lifecycle_shadow", enumBinding: "pending_457" },
@@ -1466,6 +1482,8 @@ var TRACE_B0_FIELD_DEFINITIONS = defineTraceFields([
1466
1482
  { key: "shadow_direction", fieldClass: "family_query_axis", placement: "event", valueKind: "closed_enum", scope: "family:lifecycle_shadow", enumBinding: "pending_457" },
1467
1483
  { key: "shadow_plan_kind", fieldClass: "family_query_axis", placement: "event", valueKind: "closed_enum", scope: "family:lifecycle_shadow", enumBinding: "pending_457" },
1468
1484
  { key: "row_count", fieldClass: "detail", placement: "span_or_event", valueKind: "detail" },
1485
+ { key: "rows_copied", fieldClass: "detail", placement: "span_or_event", valueKind: "numeric" },
1486
+ { key: "batch_index", fieldClass: "detail", placement: "span_or_event", valueKind: "numeric" },
1469
1487
  { key: "retry_count", fieldClass: "detail", placement: "span_or_event", valueKind: "detail" },
1470
1488
  { key: "error_message", fieldClass: "detail", placement: "span_or_event", valueKind: "detail", contentRule: "scrub_and_short_retention" },
1471
1489
  { key: "query_text", fieldClass: "content_safety", placement: "span_or_event", valueKind: "content", contentRule: "scrub_and_short_retention" },
@@ -2023,6 +2041,24 @@ var agentApiKnowledgeGetResponseSchema = passthroughObject({
2023
2041
  contentType: z2.string(),
2024
2042
  content: z2.string()
2025
2043
  });
2044
+ var agentApiKnowledgeSearchQuerySchema = passthroughObject({
2045
+ query: z2.string().trim().min(1),
2046
+ scope: optionalStringSchema,
2047
+ reason: optionalStringSchema,
2048
+ turn_id: optionalStringSchema,
2049
+ trace_id: optionalStringSchema
2050
+ });
2051
+ var agentApiKnowledgeSearchResultSchema = passthroughObject({
2052
+ slug: z2.string(),
2053
+ title: z2.string(),
2054
+ firstScreen: z2.string()
2055
+ });
2056
+ var agentApiKnowledgeSearchResponseSchema = passthroughObject({
2057
+ ok: z2.literal(true),
2058
+ query: z2.string(),
2059
+ scope: z2.string().nullable(),
2060
+ results: z2.array(agentApiKnowledgeSearchResultSchema)
2061
+ });
2026
2062
  var agentApiMessageSearchQuerySchema = passthroughObject({
2027
2063
  q: optionalStringSchema,
2028
2064
  channel: optionalStringSchema,
@@ -2474,7 +2510,14 @@ var agentApiSendSentResponseSchema = passthroughObject({
2474
2510
  messageId: z2.string(),
2475
2511
  messageSeq: optionalNumberSchema,
2476
2512
  recentUnread: z2.array(agentApiMessageEnvelopeSchema).optional(),
2477
- pendingMentionActions: z2.array(agentApiMessageEnvelopeSchema).optional()
2513
+ pendingMentionActions: z2.array(agentApiMessageEnvelopeSchema).optional(),
2514
+ attention: passthroughObject({
2515
+ driveByJoinedToPost: passthroughObject({
2516
+ reason: optionalStringSchema,
2517
+ muteCommand: optionalStringSchema,
2518
+ stillArrives: optionalStringArraySchema
2519
+ }).optional()
2520
+ }).optional()
2478
2521
  });
2479
2522
  var agentApiSendResponseSchema = z2.discriminatedUnion("state", [
2480
2523
  agentApiSendSentResponseSchema,
@@ -2663,6 +2706,16 @@ var agentApiContract = {
2663
2706
  request: { query: agentApiKnowledgeGetQuerySchema },
2664
2707
  response: { body: agentApiKnowledgeGetResponseSchema }
2665
2708
  }),
2709
+ knowledgeSearch: route({
2710
+ key: "knowledgeSearch",
2711
+ method: "GET",
2712
+ path: "/knowledge/search",
2713
+ client: { resource: "knowledge", method: "search" },
2714
+ capability: "knowledge",
2715
+ description: "Search Slock Manual for Agents topics from the current server.",
2716
+ request: { query: agentApiKnowledgeSearchQuerySchema },
2717
+ response: { body: agentApiKnowledgeSearchResponseSchema }
2718
+ }),
2666
2719
  messageSend: route({
2667
2720
  key: "messageSend",
2668
2721
  method: "POST",
@@ -3327,7 +3380,8 @@ var SUPPORTED_TRANSLATION_LANGUAGE_CODES = [
3327
3380
  "es",
3328
3381
  "fr",
3329
3382
  "de",
3330
- "pt-br"
3383
+ "pt-br",
3384
+ "it"
3331
3385
  ];
3332
3386
  var SUPPORTED_TRANSLATION_LANGUAGE_SET = new Set(
3333
3387
  SUPPORTED_TRANSLATION_LANGUAGE_CODES
@@ -10092,15 +10146,37 @@ var KIMI_SDK_RUNTIME_SESSION_DESCRIPTOR = {
10092
10146
  busyDelivery: "direct",
10093
10147
  postTurn: "keep_alive"
10094
10148
  };
10095
- async function createKimiAgentSessionForContext(ctx, sessionId) {
10149
+ function composeStandingRoleAdditional(standingPrompt, wrapperPath) {
10150
+ const sections = [];
10151
+ if (standingPrompt) {
10152
+ sections.push(standingPrompt);
10153
+ }
10154
+ if (wrapperPath) {
10155
+ sections.push(
10156
+ `## CLI invocation note (Kimi SDK in-process runtime)
10157
+
10158
+ When you run \`raft\` CLI commands from your bash tool, **use this absolute path** because PATH is not pre-injected for the in-process Kimi SDK:
10159
+
10160
+ \`\`\`
10161
+ ${wrapperPath}
10162
+ \`\`\`
10163
+
10164
+ So instead of \`raft message send ...\`, run \`${wrapperPath} message send ...\` (every \`raft\` reference in the protocol above maps to this wrapper). The wrapper carries this agent's identity automatically; do not pass auth tokens explicitly.`
10165
+ );
10166
+ }
10167
+ return sections.join("\n\n---\n\n");
10168
+ }
10169
+ async function createKimiAgentSessionForContext(ctx, sessionId, deps = {}) {
10170
+ const createHarnessImpl = deps.createHarness ?? createKimiHarness;
10171
+ const prepareTransportImpl = deps.prepareTransport ?? prepareCliTransport;
10096
10172
  const sessionDir = buildKimiSessionDir(ctx.workingDirectory);
10097
10173
  mkdirSync2(sessionDir, { recursive: true });
10098
- const cliTransport = await prepareCliTransport(ctx, { NO_COLOR: "1" });
10174
+ const cliTransport = await prepareTransportImpl(ctx, { NO_COLOR: "1" });
10099
10175
  const spawnEnv = cliTransport.spawnEnv;
10100
10176
  const wrapperPath = cliTransport.wrapperPath;
10101
10177
  const homeDir = spawnEnv.KIMI_HOME || (process.env.HOME ? path10.join(process.env.HOME, ".kimi") : path10.join(ctx.workingDirectory, ".kimi"));
10102
10178
  mkdirSync2(homeDir, { recursive: true });
10103
- const harness = createKimiHarness({
10179
+ const harness = createHarnessImpl({
10104
10180
  homeDir,
10105
10181
  identity: {
10106
10182
  userAgentProduct: KIMI_CODE_USER_AGENT_PRODUCT,
@@ -10109,9 +10185,11 @@ async function createKimiAgentSessionForContext(ctx, sessionId) {
10109
10185
  }
10110
10186
  });
10111
10187
  const launchRuntimeFields = runtimeConfigToLaunchFields(hydrateRuntimeConfig(ctx.config));
10188
+ const roleAdditional = composeStandingRoleAdditional(ctx.standingPrompt, wrapperPath);
10112
10189
  const sessionFields = {
10113
10190
  workDir: ctx.workingDirectory,
10114
- ...launchRuntimeFields.model && launchRuntimeFields.model !== "default" ? { model: launchRuntimeFields.model } : {}
10191
+ ...launchRuntimeFields.model && launchRuntimeFields.model !== "default" ? { model: launchRuntimeFields.model } : {},
10192
+ ...roleAdditional ? { roleAdditional } : {}
10115
10193
  };
10116
10194
  let session;
10117
10195
  if (ctx.config.sessionId) {
@@ -10198,25 +10276,7 @@ var KimiSdkRuntimeSession = class {
10198
10276
  return { ok: true, acceptedAs: "prompt" };
10199
10277
  }
10200
10278
  composeFirstTurnPreamble(turnText) {
10201
- const sections = [];
10202
- if (this.ctx.standingPrompt) {
10203
- sections.push(this.ctx.standingPrompt);
10204
- }
10205
- if (this.wrapperPath) {
10206
- sections.push(
10207
- `## CLI invocation note (Kimi SDK in-process runtime)
10208
-
10209
- When you run \`raft\` CLI commands from your bash tool, **use this absolute path** because PATH is not pre-injected for the in-process Kimi SDK:
10210
-
10211
- \`\`\`
10212
- ${this.wrapperPath}
10213
- \`\`\`
10214
-
10215
- So instead of \`raft message send ...\`, run \`${this.wrapperPath} message send ...\` (every \`raft\` reference in the protocol above maps to this wrapper). The wrapper carries this agent's identity automatically; do not pass auth tokens explicitly.`
10216
- );
10217
- }
10218
- sections.push(turnText);
10219
- return sections.join("\n\n---\n\n");
10279
+ return turnText;
10220
10280
  }
10221
10281
  send(input) {
10222
10282
  if (this.didClose) return { ok: false, reason: "closed" };
@@ -10372,6 +10432,13 @@ function detectKimiSdkModels(home = resolveKimiHome(), ctx = {}) {
10372
10432
  }
10373
10433
  var KimiSdkDriver = class {
10374
10434
  id = "kimi-sdk";
10435
+ /**
10436
+ * Genuine native support: the standing prompt (and wrapper CLI note) are
10437
+ * mounted via the Kimi SDK's `roleAdditional` session option, which renders
10438
+ * into the base system prompt on every request and therefore survives context
10439
+ * compaction — no per-turn re-assertion needed. See
10440
+ * composeStandingRoleAdditional + createKimiAgentSessionForContext.
10441
+ */
10375
10442
  supportsNativeStandingPrompt = true;
10376
10443
  lifecycle = {
10377
10444
  kind: "persistent",
@@ -20693,6 +20760,7 @@ var DaemonConnection = class {
20693
20760
  slock_reason_present: Boolean(reason),
20694
20761
  slock_reason: reason
20695
20762
  }, "error");
20763
+ this.options.onHandshakeRejected?.({ statusCode, reason });
20696
20764
  response.resume();
20697
20765
  try {
20698
20766
  ws.terminate();
@@ -22361,7 +22429,7 @@ function resolveSlockCliPathOrEmpty(moduleUrl = import.meta.url) {
22361
22429
  }
22362
22430
  async function runBundledSlockCli(argv) {
22363
22431
  process.argv = [process.execPath, "slock", ...argv];
22364
- await import("./dist-CWN2CLOA.js");
22432
+ await import("./dist-R2LWKKE2.js");
22365
22433
  }
22366
22434
  function detectRuntimes(tracer = noopTracer) {
22367
22435
  const ids = [];
@@ -22563,6 +22631,7 @@ var DaemonCore = class {
22563
22631
  onMessage: (msg) => this.handleMessage(msg),
22564
22632
  onConnect: () => this.handleConnect(),
22565
22633
  onDisconnect: () => this.handleDisconnect(),
22634
+ onHandshakeRejected: (event) => this.handleHandshakeRejected(event),
22566
22635
  onTraceEvent: (name, attrs, status) => this.recordDaemonTrace(name, attrs, status)
22567
22636
  });
22568
22637
  this.connection = connection;
@@ -22659,10 +22728,14 @@ var DaemonCore = class {
22659
22728
  }
22660
22729
  async stop() {
22661
22730
  logger.info("[Slock Daemon] Shutting down...");
22731
+ const shutdownReason = this.resolveMachineShutdownReason();
22662
22732
  const span = this.tracer.startSpan("daemon.lifecycle.stop", {
22663
22733
  surface: "daemon",
22664
22734
  kind: "internal",
22665
- attrs: { machine_lock_present: Boolean(this.machineLock) }
22735
+ attrs: {
22736
+ machine_lock_present: Boolean(this.machineLock),
22737
+ shutdown_reason: shutdownReason
22738
+ }
22666
22739
  });
22667
22740
  this.reminderCache.clear();
22668
22741
  this.traceBundleUploader?.stop();
@@ -22671,6 +22744,19 @@ var DaemonCore = class {
22671
22744
  await this.agentManager.stopAll();
22672
22745
  span.addEvent("daemon.agents.stopped");
22673
22746
  } finally {
22747
+ if (this.connection.connected) {
22748
+ this.connection.send({ type: "machine:shutdown", reason: shutdownReason });
22749
+ span.addEvent("daemon.connection.shutdown_notice_sent", {
22750
+ outcome: "sent",
22751
+ shutdown_reason: shutdownReason
22752
+ });
22753
+ } else {
22754
+ span.addEvent("daemon.connection.shutdown_notice_sent", {
22755
+ outcome: "skipped",
22756
+ reason: "not_connected",
22757
+ shutdown_reason: shutdownReason
22758
+ });
22759
+ }
22674
22760
  this.connection.disconnect();
22675
22761
  span.addEvent("daemon.connection.disconnect_requested");
22676
22762
  this.machineLock?.release();
@@ -22679,6 +22765,9 @@ var DaemonCore = class {
22679
22765
  span.end("ok");
22680
22766
  }
22681
22767
  }
22768
+ resolveMachineShutdownReason() {
22769
+ return this.computerVersion ? "computer_stop" : "daemon_stop";
22770
+ }
22682
22771
  get connected() {
22683
22772
  return this.connection.connected;
22684
22773
  }
@@ -23299,6 +23388,9 @@ var DaemonCore = class {
23299
23388
  }, "cancelled");
23300
23389
  this.options.lifecycleHooks?.onDisconnect?.();
23301
23390
  }
23391
+ handleHandshakeRejected(event) {
23392
+ this.options.lifecycleHooks?.onHandshakeRejected?.(event);
23393
+ }
23302
23394
  };
23303
23395
 
23304
23396
  export {