oh-my-knowledge 1.0.0 → 1.1.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 (57) hide show
  1. package/dist/assets/agent-skills/omk/SKILL.md +1 -1
  2. package/dist/dsh-plugin/core-adapter.js +12 -6
  3. package/dist/dsh-plugin/core-protocol.d.ts +1 -1
  4. package/dist/dsh-plugin/core-protocol.js +1 -1
  5. package/dist/dsh-plugin/host-executor.d.ts +1 -3
  6. package/dist/dsh-plugin/host-executor.js +10 -7
  7. package/dist/dsh-plugin/index.d.ts +6 -2
  8. package/dist/dsh-plugin/index.js +36 -21
  9. package/dist/dsh-plugin/knowledge.d.ts +40 -0
  10. package/dist/dsh-plugin/knowledge.js +55 -0
  11. package/dist/dsh-plugin/observe.d.ts +24 -6
  12. package/dist/dsh-plugin/observe.js +84 -44
  13. package/dist/dsh-plugin/protocol.js +2 -1
  14. package/dist/dsh-plugin/trace-adapter.js +24 -0
  15. package/dist/knowledge/adapters/trace-source-reader.js +3 -1
  16. package/dist/observe/trace/adapters/dsh/trace.d.ts +1 -1
  17. package/dist/observe/trace/adapters/dsh/trace.js +8 -9
  18. package/dist/observe/trace/source.d.ts +3 -1
  19. package/dist/observe/trace/source.js +9 -2
  20. package/dist/studio/web/.next/BUILD_ID +1 -1
  21. package/dist/studio/web/.next/app-path-routes-manifest.json +3 -3
  22. package/dist/studio/web/.next/build-manifest.json +2 -2
  23. package/dist/studio/web/.next/prerender-manifest.json +3 -3
  24. package/dist/studio/web/.next/server/app/_global-error/page_client-reference-manifest.js +1 -1
  25. package/dist/studio/web/.next/server/app/_global-error.html +1 -1
  26. package/dist/studio/web/.next/server/app/_global-error.rsc +1 -1
  27. package/dist/studio/web/.next/server/app/_global-error.segments/_full.segment.rsc +1 -1
  28. package/dist/studio/web/.next/server/app/_global-error.segments/_global-error/__PAGE__.segment.rsc +1 -1
  29. package/dist/studio/web/.next/server/app/_global-error.segments/_tree.segment.rsc +1 -1
  30. package/dist/studio/web/.next/server/app/_not-found/page_client-reference-manifest.js +1 -1
  31. package/dist/studio/web/.next/server/app/agents/page_client-reference-manifest.js +1 -1
  32. package/dist/studio/web/.next/server/app/knowledge/candidates/page_client-reference-manifest.js +1 -1
  33. package/dist/studio/web/.next/server/app/knowledge/entities/page_client-reference-manifest.js +1 -1
  34. package/dist/studio/web/.next/server/app/knowledge/library/page_client-reference-manifest.js +1 -1
  35. package/dist/studio/web/.next/server/app/knowledge/page_client-reference-manifest.js +1 -1
  36. package/dist/studio/web/.next/server/app/knowledge/skills/[skillName]/page_client-reference-manifest.js +1 -1
  37. package/dist/studio/web/.next/server/app/measure/[runId]/page_client-reference-manifest.js +1 -1
  38. package/dist/studio/web/.next/server/app/measure/page_client-reference-manifest.js +1 -1
  39. package/dist/studio/web/.next/server/app/observe/conversations/[threadId]/page_client-reference-manifest.js +1 -1
  40. package/dist/studio/web/.next/server/app/observe/conversations/[threadId]/tasks/[turnId]/page_client-reference-manifest.js +1 -1
  41. package/dist/studio/web/.next/server/app/observe/health/[analysisId]/page_client-reference-manifest.js +1 -1
  42. package/dist/studio/web/.next/server/app/observe/health/page_client-reference-manifest.js +1 -1
  43. package/dist/studio/web/.next/server/app/observe/health-diff/page_client-reference-manifest.js +1 -1
  44. package/dist/studio/web/.next/server/app/observe/inbox/page_client-reference-manifest.js +1 -1
  45. package/dist/studio/web/.next/server/app/observe/page_client-reference-manifest.js +1 -1
  46. package/dist/studio/web/.next/server/app/observe/skill-trend/[skillName]/page_client-reference-manifest.js +1 -1
  47. package/dist/studio/web/.next/server/app/studio-fault/page_client-reference-manifest.js +1 -1
  48. package/dist/studio/web/.next/server/app-paths-manifest.json +3 -3
  49. package/dist/studio/web/.next/server/middleware-build-manifest.js +1 -1
  50. package/dist/studio/web/.next/server/pages/500.html +1 -1
  51. package/dist/studio/web/.next/server/preview-props.json +3 -3
  52. package/dist/studio/web/.next/server/server-reference-manifest.json +1 -1
  53. package/dist/studio/web/.next/trace +108 -108
  54. package/dist/studio/web/.next/trace-build +1 -1
  55. package/package.json +1 -1
  56. /package/dist/studio/web/.next/static/{scyR1oH1_xcujwAsrOo96 → F6SLtRCtjJZgWolqG66Lu}/_buildManifest.js +0 -0
  57. /package/dist/studio/web/.next/static/{scyR1oH1_xcujwAsrOo96 → F6SLtRCtjJZgWolqG66Lu}/_ssgManifest.js +0 -0
@@ -118,7 +118,7 @@ Codex 是 omk 的一等 runtime。未显式指定执行器时,`omk eval` / `do
118
118
 
119
119
  如果当前 DSH profile 已安装 `oh-my-knowledge` bundle,使用 `/omk eval <eval.yaml>`。该路径直接复用现有 DSH 的模型、凭证、工具与 sandbox,并为每条用例创建隔离 session;不要要求用户另起 DSH runtime。
120
120
 
121
- 查看真实 DSH 任务轨迹时,先运行 `/omk observe` 列出最近已结束的 session,再运行 `/omk observe <session-id>`。OMK 通过当前 profile 的 `sessionPersistence` 只读摄取一致快照,并返回 Studio 任务轨迹链接;不要求用户导出或定位 JSONL/SQLite 文件。首版不实时跟随正在写入的 session,也不默认选择发起 observe 命令的当前 session。
121
+ 在 DSH 中提炼并复用项目知识时,另开一个同目录会话,用 `/omk observe` 选取已结束的 session,再用 `/omk observe <session-id>` 打开 Studio。通过「提炼这轮」选择来源消息、确认发送,并核对、保留或修订候选。项目知识保存在会话创建目录的 `.omk/knowledge`。后续同项目任务可用 `omk_knowledge_retrieve` 查询当前已保留的修订,检查正文的适用条件并引用知识及修订 ID。
122
122
 
123
123
  ## 第三步:按需检测评测项目结构
124
124
 
@@ -1,4 +1,5 @@
1
1
  import { randomUUID } from 'node:crypto';
2
+ import { DSH_KNOWLEDGE_TOOL } from './knowledge.js';
2
3
  import { JsonValueSchema, RuntimeIdentitySchema, canonicalizeJson, deepFreezeCanonicalJson, digestCanonicalJson, } from '../eval-core/contracts/index.js';
3
4
  import { ExecutionPortFailure, } from '../eval-core/execution/index.js';
4
5
  import { createDshHostRuntimeFingerprint } from '../executors/core/runtime-fingerprint.js';
@@ -103,7 +104,8 @@ function toolSchemas(values) {
103
104
  }
104
105
  function effectiveToolSchemas(schemas, target) {
105
106
  const disableSkills = target.config.behavior.allowedSkills !== undefined;
106
- const available = new Set(schemas.map(({ name }) => name));
107
+ const effective = schemas.filter(({ name }) => name !== DSH_KNOWLEDGE_TOOL);
108
+ const available = new Set(effective.map(({ name }) => name));
107
109
  const toolControls = [
108
110
  target.target.executionControls.defaults.tools,
109
111
  ...target.target.executionControls.sampleOverrides.flatMap((override) => (override.tools === undefined ? [] : [override.tools])),
@@ -121,7 +123,7 @@ function effectiveToolSchemas(schemas, target) {
121
123
  throw new TypeError('DSH Host runtime-default skill discovery requires the skill tool in a tool allow-list.');
122
124
  }
123
125
  }
124
- return Object.freeze([...schemas]);
126
+ return Object.freeze(effective);
125
127
  }
126
128
  function captureHost(input, target) {
127
129
  if (typeof input.host?.agents?.create !== 'function'
@@ -540,7 +542,7 @@ async function executeDshHost(host, target, runState, trialState, attempt, opera
540
542
  model: target.binding.qualification.model,
541
543
  },
542
544
  signal: attempt.signal,
543
- setup(agentContext) {
545
+ setup(agentContext, agent) {
544
546
  if (host.composeFrom !== undefined) {
545
547
  const currentPreset = host.composeFrom(agentContext);
546
548
  if (currentPreset !== host.activeAgentPreset) {
@@ -554,7 +556,8 @@ async function executeDshHost(host, target, runState, trialState, attempt, opera
554
556
  complete: true,
555
557
  });
556
558
  agentContext.systemPrompt.suppressRuntimeContext();
557
- if (allowedTools !== undefined || skillsDisabled) {
559
+ const knowledgeToolVisible = agentContext.tools?.get(DSH_KNOWLEDGE_TOOL, agent) !== undefined;
560
+ if (allowedTools !== undefined || skillsDisabled || knowledgeToolVisible) {
558
561
  if (agentContext.tools === undefined
559
562
  || typeof agentContext.tools.guard !== 'function') {
560
563
  fail('OMK_DSH_HOST_TOOL_POLICY_UNAVAILABLE', 'infrastructure', 'DSH Host tool policy enforcement is unavailable during session setup.');
@@ -562,10 +565,13 @@ async function executeDshHost(host, target, runState, trialState, attempt, opera
562
565
  if (allowedTools !== undefined && effectiveToolNames.length > 0) {
563
566
  agentContext.tools.restrict({ allow: effectiveToolNames });
564
567
  }
565
- else if (deniedTools.length > 0) {
566
- agentContext.tools.restrict({ deny: deniedTools });
568
+ else if (deniedTools.length > 0 || knowledgeToolVisible) {
569
+ agentContext.tools.restrict({ deny: knowledgeToolVisible ? [...deniedTools, DSH_KNOWLEDGE_TOOL] : deniedTools });
567
570
  }
568
571
  agentContext.tools.guard(({ name }) => {
572
+ if (name === DSH_KNOWLEDGE_TOOL) {
573
+ return 'OMK evaluation policy disabled project knowledge retrieval.';
574
+ }
569
575
  if (skillsDisabled && name === 'skill') {
570
576
  return 'OMK evaluation policy disabled skill discovery.';
571
577
  }
@@ -1,6 +1,6 @@
1
1
  import { type CoreSchemaValidator, type ExecutorCapabilities, type JsonValue, type UsageRecord } from '../eval-core/contracts/index.js';
2
2
  import { type DshHostRunResult } from './protocol.js';
3
- export declare const DSH_HOST_CORE_ADAPTER_IMPLEMENTATION_VERSION: "2.0.2";
3
+ export declare const DSH_HOST_CORE_ADAPTER_IMPLEMENTATION_VERSION: "2.0.3";
4
4
  export interface ParsedDshHostCoreResult {
5
5
  readonly output?: string;
6
6
  readonly trace: JsonValue;
@@ -4,7 +4,7 @@ import { ExecutionPortFailure } from '../eval-core/execution/index.js';
4
4
  import { SOURCE_NEUTRAL_TRACE_WITHOUT_MOCKS_SCHEMA_DESCRIPTOR, SOURCE_NEUTRAL_TRACE_SCHEMA_VERSION, SourceNeutralTraceWithoutMocksSchema, } from '../eval-runtime/traces/source-neutral.js';
5
5
  import { buildDshHostResult } from './protocol.js';
6
6
  import { supportsDshTraceEventType } from './trace-adapter.js';
7
- export const DSH_HOST_CORE_ADAPTER_IMPLEMENTATION_VERSION = '2.0.2';
7
+ export const DSH_HOST_CORE_ADAPTER_IMPLEMENTATION_VERSION = '2.0.3';
8
8
  const SCHEMA_DESCRIPTORS = {
9
9
  input: { valueKind: 'json-value' },
10
10
  output: { valueKind: 'string' },
@@ -2,7 +2,6 @@ import type { ExecutorFn } from '../executors/contracts/ports.js';
2
2
  type UnknownRecord = Record<string, unknown>;
3
3
  export interface DshSessionLike {
4
4
  readonly id: string;
5
- readonly events: readonly UnknownRecord[];
6
5
  readonly header: {
7
6
  readonly cwd?: string;
8
7
  readonly parentSession?: string;
@@ -25,7 +24,6 @@ export interface DshAgentLike {
25
24
  }>): void;
26
25
  }
27
26
  interface DshAgentScopeLike {
28
- readonly agent?: DshAgentLike;
29
27
  readonly systemPrompt: {
30
28
  section(section: {
31
29
  readonly name: string;
@@ -69,7 +67,7 @@ export interface DshHostContextLike {
69
67
  readonly model: string;
70
68
  };
71
69
  readonly signal?: AbortSignal;
72
- readonly setup: (ctx: DshAgentScopeLike) => void;
70
+ readonly setup: (ctx: DshAgentScopeLike, agent: DshAgentLike) => void;
73
71
  }): Promise<DshAgentHandleLike>;
74
72
  };
75
73
  readonly tools?: {
@@ -1,4 +1,5 @@
1
1
  import { randomUUID } from 'node:crypto';
2
+ import { DSH_KNOWLEDGE_TOOL } from './knowledge.js';
2
3
  import { buildDshHostResult } from './protocol.js';
3
4
  import { createDshHostRuntimeFingerprint } from '../executors/core/runtime-fingerprint.js';
4
5
  import { DEFAULT_TIMEOUT_MS } from '../executors/core/limits.js';
@@ -122,7 +123,7 @@ export function createDshHostExecutor(ctx, options = {}) {
122
123
  : undefined;
123
124
  // Preserve host schema order because DSH sends this order to the model; it is part of runtime identity.
124
125
  const toolSchemas = ctx.tools?.schemas(options.parentAgent)
125
- .filter((schema) => schema.name !== 'skill');
126
+ .filter((schema) => schema.name !== 'skill' && schema.name !== DSH_KNOWLEDGE_TOOL);
126
127
  const runtimeFingerprint = (model) => (createDshHostRuntimeFingerprint(model, {
127
128
  ...(provider ? { provider } : {}),
128
129
  ...(activeAgentPreset
@@ -173,7 +174,7 @@ export function createDshHostExecutor(ctx, options = {}) {
173
174
  ...(provider ? { provider } : {}),
174
175
  model: input.model,
175
176
  },
176
- setup(agentCtx) {
177
+ setup(agentCtx, agent) {
177
178
  if (options.parentAgent) {
178
179
  const composedPreset = ctx.agentPresets.composeFrom(agentCtx, options.parentAgent.ctx);
179
180
  if (composedPreset !== activeAgentPreset) {
@@ -187,9 +188,11 @@ export function createDshHostExecutor(ctx, options = {}) {
187
188
  complete: true,
188
189
  });
189
190
  agentCtx.systemPrompt.suppressRuntimeContext();
190
- const scopedAgent = agentCtx.agent;
191
- if (agentCtx.tools?.get('skill', scopedAgent) !== undefined) {
192
- agentCtx.tools.restrict({ deny: ['skill'] });
191
+ const tools = agentCtx.tools;
192
+ if (tools) {
193
+ const deny = ['skill', DSH_KNOWLEDGE_TOOL].filter(name => tools.get(name, agent) !== undefined);
194
+ if (deny.length > 0)
195
+ tools.restrict({ deny });
193
196
  }
194
197
  },
195
198
  });
@@ -198,10 +201,10 @@ export function createDshHostExecutor(ctx, options = {}) {
198
201
  const timeoutMs = input.timeoutMs ?? DEFAULT_TIMEOUT_MS;
199
202
  const { outcome, cleanupTimedOut } = await waitForIdle(handle.agent, timeoutMs, signal, cleanupTimeoutMs);
200
203
  const wallClockDurationMs = Date.now() - startedAt;
201
- const events = [...handle.agent.session.events];
202
204
  const result = buildDshHostResult({
203
205
  rootSessionId,
204
- finalResponse: lastAssistantText(events),
206
+ finalResponse: lastAssistantText(orderedEvents
207
+ .filter(({ sessionId }) => sessionId === rootSessionId).map(({ event }) => event)),
205
208
  events: orderedEvents,
206
209
  childSessionIds: [...descendants],
207
210
  }, wallClockDurationMs);
@@ -1,4 +1,5 @@
1
1
  import { type DshAgentLike, type DshHostContextLike } from './host-executor.js';
2
+ import { dshKnowledgeTool } from './knowledge.js';
2
3
  export { DSH_HOST_CORE_ADAPTER_IMPLEMENTATION_VERSION, createDshHostCoreExecutorAdapter, createDshHostCoreSchemaValidators, type CreateDshHostCoreExecutorAdapterInput, type DshHostCoreConfiguration, } from './core-adapter.js';
3
4
  import { type DshSessionPersistenceLike } from './observe.js';
4
5
  interface DshCommandInvocationLike {
@@ -13,6 +14,9 @@ type DshCommandResultLike = Readonly<Record<'kind', 'success'> & {
13
14
  }>;
14
15
  interface DshPluginContextLike extends DshHostContextLike {
15
16
  get?(name: 'sessionPersistence'): DshSessionPersistenceLike | undefined;
17
+ readonly tools: NonNullable<DshHostContextLike['tools']> & {
18
+ register(tool: typeof dshKnowledgeTool): () => void;
19
+ };
16
20
  readonly commands: {
17
21
  register(definition: {
18
22
  readonly name: string;
@@ -26,5 +30,5 @@ interface DshPluginContextLike extends DshHostContextLike {
26
30
  }
27
31
  export declare const name = "omk-dsh-plugin";
28
32
  export declare const inject: string[];
29
- /** Register `/omk eval` and `/omk observe` in every DSH command-capable surface. */
30
- export declare function apply(ctx: DshPluginContextLike): () => void;
33
+ /** Register the human command and the Agent's read-only project knowledge tool. */
34
+ export declare const apply: (ctx: DshPluginContextLike) => (() => Promise<void>);
@@ -1,7 +1,7 @@
1
1
  import { dirname, resolve } from 'node:path';
2
- import { projectLayout } from '../storage/layout.js';
3
2
  import { loadEvalConfig } from '../eval-workflows/inputs/eval-config.js';
4
3
  import { runDshCoreEvaluation } from './core-command.js';
4
+ import { canonicalDshProject, dshKnowledgeTool, dshProjectLayout } from './knowledge.js';
5
5
  export { DSH_HOST_CORE_ADAPTER_IMPLEMENTATION_VERSION, createDshHostCoreExecutorAdapter, createDshHostCoreSchemaValidators, } from './core-adapter.js';
6
6
  import { createDshConversationCatalog, dshTraceIngestionSummary, listDshObserveCandidates, readDshObservedGroup, } from './observe.js';
7
7
  export const name = 'omk-dsh-plugin';
@@ -12,8 +12,10 @@ const HELP = [
12
12
  '受控评测:/omk eval <eval.yaml>',
13
13
  '查看最近任务:/omk observe',
14
14
  '打开任务轨迹:/omk observe <session-id>',
15
+ '在 Studio 里提炼这轮,并保留或修订候选。',
16
+ '复用:请 DSH Agent 用 omk_knowledge_retrieve 查询当前项目已保留的知识。',
15
17
  '',
16
- '文档:https://oh-my-knowledge.pages.dev/zh/reference/executors',
18
+ '文档:https://oh-my-knowledge.pages.dev/zh/guides/observe-production#在-deepseek-harness-中沉淀和复用知识',
17
19
  ].join('\n');
18
20
  const USAGE = '用法:/omk eval <eval.yaml> 或 /omk observe [session-id];运行 /omk 查看帮助。';
19
21
  function unquote(value) {
@@ -92,16 +94,19 @@ function persistenceFor(ctx) {
92
94
  if (!persistence) {
93
95
  throw new Error('当前 DSH profile 没有启用 sessionPersistence;/omk eval 仍可使用,但任务轨迹需要配置 JSONL 或 SQLite persistence backend。');
94
96
  }
97
+ if (typeof persistence.list !== 'function' || typeof persistence.open !== 'function') {
98
+ throw new Error('当前 DSH 会话存储缺少只读句柄接口,请升级 DSH。');
99
+ }
95
100
  return persistence;
96
101
  }
97
- async function studioUrl(invocation, state) {
102
+ async function studioUrl(layout, state) {
98
103
  if (state.disposed)
99
104
  throw new Error('OMK DSH 插件已关闭。');
100
105
  if (state.serverUrl)
101
106
  return state.serverUrl;
102
107
  if (state.starting)
103
108
  return state.starting;
104
- state.starting = startStudio(invocation, state);
109
+ state.starting = startStudio(layout, state);
105
110
  try {
106
111
  return await state.starting;
107
112
  }
@@ -109,9 +114,7 @@ async function studioUrl(invocation, state) {
109
114
  state.starting = undefined;
110
115
  }
111
116
  }
112
- async function startStudio(invocation, state) {
113
- const cwd = invocation.agent.session.header.cwd ?? process.cwd();
114
- const layout = projectLayout(cwd);
117
+ async function startStudio(layout, state) {
115
118
  const { createNextStudioServer } = await import('../studio/http/next-server.js');
116
119
  const { createStudioDirectorySources } = await import('../studio/application/directory-sources.js');
117
120
  if (state.disposed)
@@ -149,10 +152,17 @@ async function startStudio(invocation, state) {
149
152
  }
150
153
  async function executeObserveCommand(ctx, invocation, sessionId, state) {
151
154
  const persistence = persistenceFor(ctx);
155
+ const layout = dshProjectLayout(invocation.agent.session.header.cwd);
156
+ const project = dirname(layout.root);
157
+ const currentSession = String(invocation.agent.session.id);
158
+ const readOptions = {
159
+ signal: invocation.signal,
160
+ includesCwd: (cwd) => canonicalDshProject(cwd) === project,
161
+ };
152
162
  if (!sessionId) {
153
163
  const candidates = await listDshObserveCandidates(persistence, {
154
- excludeSessionId: String(invocation.agent.session.id),
155
- signal: invocation.signal,
164
+ ...readOptions,
165
+ excludeSessionId: currentSession,
156
166
  });
157
167
  if (candidates.length === 0) {
158
168
  return {
@@ -170,7 +180,9 @@ async function executeObserveCommand(ctx, invocation, sessionId, state) {
170
180
  ].join('\n'),
171
181
  };
172
182
  }
173
- const group = await readDshObservedGroup(persistence, sessionId, invocation.signal);
183
+ if (sessionId === currentSession)
184
+ throw new Error('请从另一个 DSH session 打开这条会话。');
185
+ const group = await readDshObservedGroup(persistence, sessionId, readOptions);
174
186
  const selected = group.traces.find((trace) => trace.session.runId === sessionId);
175
187
  if (!selected)
176
188
  throw new Error(`DSH session 一致快照缺少目标 session:${sessionId}。`);
@@ -189,8 +201,7 @@ async function executeObserveCommand(ctx, invocation, sessionId, state) {
189
201
  }).join(';');
190
202
  throw new Error(`DSH session group 无法形成完整任务轨迹:${details}。`);
191
203
  }
192
- const cwd = invocation.agent.session.header.cwd ?? process.cwd();
193
- const observationsDir = projectLayout(cwd).observeInboxDir;
204
+ const observationsDir = layout.observeInboxDir;
194
205
  const { buildObservationInboxReportFromTraceSessions, buildObserveDiagnosticsFromReport, saveObservationInboxReport, } = await import('../observe/inbox/index.js');
195
206
  const { loadObservationReviewState } = await import('../observe/inbox/review-state.js');
196
207
  const report = buildObservationInboxReportFromTraceSessions(`dsh:${group.rootSessionId}`, group.traces.map((trace) => trace.session), dshTraceIngestionSummary(group), { reviewState: loadObservationReviewState(observationsDir) });
@@ -199,24 +210,27 @@ async function executeObserveCommand(ctx, invocation, sessionId, state) {
199
210
  report.diagnostics = buildObserveDiagnosticsFromReport(report, { skillChains: chains });
200
211
  const inboxPath = saveObservationInboxReport(report, observationsDir);
201
212
  const target = state.catalog.upsert(group);
202
- const baseUrl = await studioUrl(invocation, state);
203
- const trajectoryUrl = `${baseUrl}/observe/conversations/${encodeURIComponent(target.threadId)}/tasks/${encodeURIComponent(target.turnId)}`;
213
+ const baseUrl = await studioUrl(layout, state);
214
+ const trajectoryUrl = new URL(`/observe/conversations/${encodeURIComponent(target.threadId)}/tasks/${encodeURIComponent(target.turnId)}`, baseUrl);
215
+ trajectoryUrl.searchParams.set('workspace', layout.knowledgeDir);
204
216
  return {
205
217
  kind: 'success',
206
218
  text: [
207
219
  `已只读摄取 DSH session:${sessionId}`,
208
220
  `任务状态:${selected.integrity.status}`,
209
- `任务轨迹:${trajectoryUrl}`,
221
+ `任务轨迹与知识提炼:${trajectoryUrl}`,
210
222
  `观测收件箱:${inboxPath}`,
211
223
  ].join('\n'),
212
224
  };
213
225
  }
214
- /** Register `/omk eval` and `/omk observe` in every DSH command-capable surface. */
215
- export function apply(ctx) {
226
+ /** Register the human command and the Agent's read-only project knowledge tool. */
227
+ // Cordis treats constructible callbacks as classes. Use a function without a prototype so it collects the disposer.
228
+ export const apply = (ctx) => {
216
229
  const observeState = { catalog: createDshConversationCatalog() };
230
+ const disposeTool = ctx.tools.register(dshKnowledgeTool);
217
231
  const disposeCommand = ctx.commands.register({
218
232
  name: 'omk',
219
- description: '在当前 DeepSeek Harness 中运行 OMK 对照评测或查看任务轨迹',
233
+ description: '在当前 DeepSeek Harness 中运行 OMK 对照评测、查看任务轨迹和提炼知识',
220
234
  input: { hint: 'eval <eval.yaml> | observe [session-id]' },
221
235
  async handler(invocation) {
222
236
  const command = parseCommand(invocation.rawInput);
@@ -237,9 +251,10 @@ export function apply(ctx) {
237
251
  }
238
252
  },
239
253
  });
240
- return () => {
254
+ return async () => {
241
255
  observeState.disposed = true;
242
256
  disposeCommand();
243
- void observeState.server?.stop().catch(() => undefined);
257
+ disposeTool();
258
+ await observeState.server?.stop();
244
259
  };
245
- }
260
+ };
@@ -0,0 +1,40 @@
1
+ import { projectLayout } from '../storage/layout.js';
2
+ export declare const DSH_KNOWLEDGE_TOOL = "omk_knowledge_retrieve";
3
+ export declare function canonicalDshProject(cwd: string | undefined): string | undefined;
4
+ export declare function dshProjectLayout(cwd: string | undefined): ReturnType<typeof projectLayout>;
5
+ export declare const dshKnowledgeTool: {
6
+ name: string;
7
+ description: string;
8
+ parameters: {
9
+ type: string;
10
+ properties: {
11
+ query: {
12
+ type: string;
13
+ description: string;
14
+ minLength: number;
15
+ maxLength: number;
16
+ };
17
+ };
18
+ required: string[];
19
+ additionalProperties: boolean;
20
+ };
21
+ output: {
22
+ schema: {
23
+ type: string;
24
+ };
25
+ render(_args: unknown, value: string): {
26
+ type: "text";
27
+ text: string;
28
+ }[];
29
+ };
30
+ execute(args: unknown, exec: {
31
+ agent?: {
32
+ session: {
33
+ header: {
34
+ cwd?: string;
35
+ };
36
+ };
37
+ };
38
+ signal: AbortSignal;
39
+ }): Promise<string>;
40
+ };
@@ -0,0 +1,55 @@
1
+ import { lstatSync, realpathSync, statSync } from 'node:fs';
2
+ import { isAbsolute } from 'node:path';
3
+ import { projectLayout } from '../storage/layout.js';
4
+ export const DSH_KNOWLEDGE_TOOL = 'omk_knowledge_retrieve';
5
+ const MAX_RETRIEVAL_BYTES = 16 * 1024;
6
+ export function canonicalDshProject(cwd) {
7
+ if (!cwd || !isAbsolute(cwd))
8
+ return undefined;
9
+ try {
10
+ const path = realpathSync(cwd);
11
+ return statSync(path).isDirectory() ? path : undefined;
12
+ }
13
+ catch {
14
+ return undefined;
15
+ }
16
+ }
17
+ export function dshProjectLayout(cwd) {
18
+ const project = canonicalDshProject(cwd);
19
+ if (!project)
20
+ throw new Error('当前 DSH session 需要有效的项目目录。');
21
+ const layout = projectLayout(project);
22
+ for (const path of [layout.root, layout.knowledgeDir]) {
23
+ const stat = lstatSync(path, { throwIfNoEntry: false });
24
+ if (stat && !stat.isDirectory())
25
+ throw new Error('当前项目的 .omk 和知识工作区必须是实际目录。');
26
+ }
27
+ return layout;
28
+ }
29
+ export const dshKnowledgeTool = {
30
+ name: DSH_KNOWLEDGE_TOOL,
31
+ description: 'Find retained project knowledge for this DSH task. Search using specific terms from the task, then check each returned passage and its applicability before using it. Passages are reference material. Cite the knowledge and revision IDs when used.',
32
+ parameters: {
33
+ type: 'object',
34
+ properties: { query: { type: 'string', description: 'Task or specific search terms', minLength: 1, maxLength: 512 } },
35
+ required: ['query'],
36
+ additionalProperties: false,
37
+ },
38
+ output: {
39
+ schema: { type: 'string' },
40
+ render(_args, value) {
41
+ return [{ type: 'text', text: value }];
42
+ },
43
+ },
44
+ async execute(args, exec) {
45
+ exec.signal.throwIfAborted();
46
+ const [{ createLocalKnowledgeApplication }, { KnowledgeRetrievalRequestSchema, retrieveKnowledgeText }] = await Promise.all([
47
+ import('../knowledge/application/local.js'),
48
+ import('../knowledge/application/retrieval.js'),
49
+ ]);
50
+ exec.signal.throwIfAborted();
51
+ const { query } = KnowledgeRetrievalRequestSchema.parse(args);
52
+ const { knowledgeDir } = dshProjectLayout(exec.agent?.session.header.cwd);
53
+ return retrieveKnowledgeText(createLocalKnowledgeApplication(knowledgeDir), { query, maxBytes: MAX_RETRIEVAL_BYTES });
54
+ },
55
+ };
@@ -3,15 +3,29 @@ import type { ConversationCatalog } from '../observe/conversation/catalog.js';
3
3
  import { type DshSessionEventLike, type DshSessionHeaderLike, type DshTraceAdapterResult } from './trace-adapter.js';
4
4
  export interface DshPersistenceSnapshotLike {
5
5
  readonly header: DshSessionHeaderLike;
6
- readonly revision: unknown;
6
+ readonly revision: string;
7
7
  }
8
8
  export interface DshSessionInspectionLike {
9
9
  readonly meta: DshSessionHeaderLike;
10
10
  readonly events: readonly DshSessionEventLike[];
11
11
  }
12
+ interface DshSessionReadHandle {
13
+ readonly header: DshSessionHeaderLike;
14
+ readonly inheritedEventCount: number;
15
+ read(offset?: number, length?: number, options?: {
16
+ signal?: AbortSignal;
17
+ }): Promise<{
18
+ readonly events: readonly DshSessionEventLike[];
19
+ }>;
20
+ close(): Promise<void>;
21
+ }
12
22
  export interface DshSessionPersistenceLike {
13
- listSnapshots(signal?: AbortSignal): Promise<readonly DshPersistenceSnapshotLike[]>;
14
- inspect(id: string, signal?: AbortSignal): Promise<DshSessionInspectionLike>;
23
+ list(options?: {
24
+ signal?: AbortSignal;
25
+ }): Promise<readonly DshPersistenceSnapshotLike[]>;
26
+ open(id: string, access: 'read', options?: {
27
+ signal?: AbortSignal;
28
+ }): Promise<DshSessionReadHandle>;
15
29
  }
16
30
  export interface DshObserveCandidate {
17
31
  sessionId: string;
@@ -28,13 +42,16 @@ export interface DshObservedGroup {
28
42
  }
29
43
  /** Count every valid DSH logical record as parsed, including chunks consolidated into messages. */
30
44
  export declare function dshTraceIngestionSummary(group: DshObservedGroup): TraceIngestionSummary;
45
+ type SessionReadOptions = {
46
+ signal?: AbortSignal;
47
+ includesCwd?: (cwd: string | undefined) => boolean;
48
+ };
31
49
  /** Read one root+descendant group through the logical persistence seam without mutating it. */
32
- export declare function readDshObservedGroup(persistence: DshSessionPersistenceLike, selectedSessionId: string, signal?: AbortSignal): Promise<DshObservedGroup>;
50
+ export declare function readDshObservedGroup(persistence: DshSessionPersistenceLike, selectedSessionId: string, { signal, includesCwd }?: SessionReadOptions): Promise<DshObservedGroup>;
33
51
  /** List recent terminal root sessions; the command's own live session stays out of the default result. */
34
- export declare function listDshObserveCandidates(persistence: DshSessionPersistenceLike, options?: {
52
+ export declare function listDshObserveCandidates(persistence: DshSessionPersistenceLike, options?: SessionReadOptions & {
35
53
  excludeSessionId?: string;
36
54
  limit?: number;
37
- signal?: AbortSignal;
38
55
  }): Promise<DshObserveCandidate[]>;
39
56
  export interface DshCatalogTarget {
40
57
  threadId: string;
@@ -45,3 +62,4 @@ export interface MutableDshConversationCatalog extends ConversationCatalog {
45
62
  }
46
63
  /** Static snapshot catalog used by Studio; importing another session updates it without adding a parallel UI. */
47
64
  export declare function createDshConversationCatalog(): MutableDshConversationCatalog;
65
+ export {};