@minidoll/agentkit-dsh-plugin 0.1.1 → 0.1.2

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 (2) hide show
  1. package/dist/index.js +18 -55
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -170,46 +170,9 @@ function findProjectRoot(candidates, sessionCwd) {
170
170
  }
171
171
 
172
172
  // src/inject.ts
173
- import { randomUUID } from "node:crypto";
174
173
  import { existsSync as existsSync4, readFileSync as readFileSync3, readdirSync as readdirSync2 } from "node:fs";
175
174
  import { join as join4 } from "node:path";
176
175
  var MAX_CONTEXT_BYTES = 900;
177
- var SOURCE_KIND = "agentkit-context";
178
- var factoryLoader = null;
179
- async function loadFactory() {
180
- factoryLoader ??= (async () => {
181
- try {
182
- const pkg = "@deepseek-ai/dsh-llm";
183
- const mod = await import(pkg);
184
- return typeof mod.createUserMessage === "function" ? mod.createUserMessage : null;
185
- } catch {
186
- return null;
187
- }
188
- })();
189
- return factoryLoader;
190
- }
191
- function handcraft(text) {
192
- return {
193
- role: "user",
194
- id: randomUUID(),
195
- content: [{ type: "text", text }],
196
- source: { kind: SOURCE_KIND }
197
- };
198
- }
199
- function assertUserMessage(value) {
200
- if (typeof value !== "object" || value === null) return false;
201
- const m = value;
202
- if (m.role !== "user") return false;
203
- if (typeof m.id !== "string" || m.id === "") return false;
204
- const src = m.source;
205
- if (src === void 0 || src.kind !== SOURCE_KIND) return false;
206
- const content = m.content;
207
- if (!Array.isArray(content) || content.length === 0) return false;
208
- return content.every((b) => {
209
- const blk = b;
210
- return blk.type === "text" && typeof blk.text === "string" && blk.text.length > 0;
211
- });
212
- }
213
176
  var INJECT_CONFIG_REL = ".agent/inject.json";
214
177
  function injectEnabled(root) {
215
178
  if (process.env.AGENTKIT_CONTEXT_INJECT === "1") return true;
@@ -287,16 +250,16 @@ function buildInjectText(input) {
287
250
  \u2026\uFF08\u5DF2\u622A\u65AD\uFF09`;
288
251
  return text;
289
252
  }
290
- async function buildAdditionalContexts(input) {
253
+ async function buildInjectBlock(input) {
291
254
  try {
292
255
  if (!injectEnabled(input.root)) {
293
256
  input.trace?.("inject skipped: disabled (no .agent/inject.json / env)");
294
- return { ok: false, reason: "inject disabled (no .agent/inject.json / env)" };
257
+ return { ok: false, reason: "inject disabled" };
295
258
  }
296
259
  const key = `${input.sessionId ?? ""}|${input.filePath ?? ""}`;
297
260
  if (injected.has(key)) {
298
261
  input.trace?.("inject skipped: already injected for this session+file");
299
- return { ok: false, reason: "already injected for this session+file" };
262
+ return { ok: false, reason: "already injected" };
300
263
  }
301
264
  const text = buildInjectText({
302
265
  root: input.root,
@@ -305,19 +268,16 @@ async function buildAdditionalContexts(input) {
305
268
  });
306
269
  if (text === null) {
307
270
  input.trace?.("inject skipped: nothing to inject for this path");
308
- return { ok: false, reason: "nothing to inject for this path" };
271
+ return { ok: false, reason: "nothing to inject" };
309
272
  }
310
- const factory = await loadFactory();
311
- const msg = factory !== null ? factory({ content: [{ type: "text", text }], source: { kind: SOURCE_KIND } }) : handcraft(text);
312
- if (!assertUserMessage(msg)) {
313
- input.trace?.(`inject rejected: shape check failed (${factory !== null ? "factory" : "handcraft"})`);
314
- return { ok: false, reason: "shape check failed" };
273
+ const block = { type: "text", text };
274
+ if (block.type !== "text" || typeof block.text !== "string" || block.text.length === 0) {
275
+ input.trace?.("inject rejected: bad text block");
276
+ return { ok: false, reason: "bad text block" };
315
277
  }
316
278
  injected.add(key);
317
- input.trace?.(
318
- `inject ok: ${String(text.length)}B via ${factory !== null ? "factory" : "handcraft"}`
319
- );
320
- return { ok: true, messages: [msg] };
279
+ input.trace?.(`inject ok: ${String(text.length)}B as tool-result content block`);
280
+ return { ok: true, block };
321
281
  } catch (err) {
322
282
  input.trace?.(`inject skipped: ${err.message}`);
323
283
  return { ok: false, reason: err.message };
@@ -508,13 +468,13 @@ function createProjectHooksPlugin(ctx) {
508
468
  });
509
469
  const filePath = inside[0];
510
470
  const sessionId = exec.agent?.session?.id ?? null;
511
- const r = await buildAdditionalContexts({
471
+ const r = await buildInjectBlock({
512
472
  root,
513
473
  ...filePath !== void 0 ? { filePath } : {},
514
474
  ...sessionId !== null ? { sessionId } : {},
515
475
  trace: (line) => trace(process.env.DSH_HOME ?? join6(homedir(), ".dsh"), line)
516
476
  });
517
- return r.ok && r.messages !== void 0 ? r.messages : null;
477
+ return r.ok ? r : null;
518
478
  } catch (err) {
519
479
  trace(
520
480
  process.env.DSH_HOME ?? join6(homedir(), ".dsh"),
@@ -523,12 +483,15 @@ function createProjectHooksPlugin(ctx) {
523
483
  return null;
524
484
  }
525
485
  };
526
- const handle = async (event, exec) => {
486
+ const handle = async (event, exec, result) => {
527
487
  try {
528
488
  const decision = await runHooks(event, exec);
529
489
  if (event === "PostToolUse" && decision.kind === "allow") {
530
490
  const injected2 = await tryInjectContext(exec);
531
- if (injected2 !== null) return { kind: "accept", additionalContexts: injected2 };
491
+ if (injected2 !== null && injected2.block !== void 0) {
492
+ const original = Array.isArray(result?.content) ? result.content.filter((b) => typeof b === "object" && b !== null) : [];
493
+ return { kind: "accept", content: [...original, injected2.block] };
494
+ }
532
495
  }
533
496
  return decision;
534
497
  } catch (err) {
@@ -654,7 +617,7 @@ function createProjectHooksPlugin(ctx) {
654
617
  return decision;
655
618
  };
656
619
  ctx.on("tools/pre-execute", (exec) => handle("PreToolUse", exec));
657
- ctx.on("tools/post-execute", (exec) => handle("PostToolUse", exec));
620
+ ctx.on("tools/post-execute", (exec, result) => handle("PostToolUse", exec, result));
658
621
  return state;
659
622
  }
660
623
  function apply(ctx) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@minidoll/agentkit-dsh-plugin",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "DeepSeek Harness 插件:项目自包含的 lifecycle hooks(配置随仓库走,per-session 发现)",
5
5
  "license": "MIT",
6
6
  "type": "module",