dsh-spec-collab 0.3.1 → 0.4.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.
- package/CHANGELOG.md +8 -0
- package/README.md +9 -12
- package/lib/client.js +830 -617
- package/lib/index.js +33 -58
- package/lib/types/client/index.d.ts +2 -3
- package/lib/types/client/index.d.ts.map +1 -1
- package/lib/types/client/sidebar-anchor.d.ts.map +1 -1
- package/lib/types/index.d.ts +1 -1
- package/lib/types/index.d.ts.map +1 -1
- package/lib/types/review-runtime.d.ts +12 -3
- package/lib/types/review-runtime.d.ts.map +1 -1
- package/package.json +28 -27
- package/src/client/index.ts +2 -4
- package/src/client/sidebar-anchor.ts +2 -0
- package/src/index.ts +4 -4
- package/src/review-runtime.ts +29 -29
package/lib/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { homedir } from "node:os";
|
|
2
2
|
import { basename, dirname, extname, isAbsolute, join, normalize, relative, resolve } from "node:path";
|
|
3
|
-
import Schema from "schemastery";
|
|
3
|
+
import Schema from "@deepseek-ai/schemastery";
|
|
4
4
|
import { createHash, randomUUID } from "node:crypto";
|
|
5
5
|
import { closeSync, copyFileSync, existsSync, fsyncSync, mkdirSync, openSync, readFileSync, renameSync, rmSync, unlinkSync, writeFileSync } from "node:fs";
|
|
6
6
|
import { execFileSync } from "node:child_process";
|
|
@@ -2452,31 +2452,25 @@ function errorMessage(error) {
|
|
|
2452
2452
|
}
|
|
2453
2453
|
//#endregion
|
|
2454
2454
|
//#region src/review-runtime.ts
|
|
2455
|
-
function request(payload) {
|
|
2456
|
-
return {
|
|
2457
|
-
rpcId: `spec-collab-${crypto.randomUUID()}`,
|
|
2458
|
-
payload
|
|
2459
|
-
};
|
|
2460
|
-
}
|
|
2461
|
-
function failure(error) {
|
|
2462
|
-
return /* @__PURE__ */ new Error(`${error.code}: ${error.message}`);
|
|
2463
|
-
}
|
|
2464
2455
|
const FOLLOW_UP_METADATA = "\n\n<!-- dsh-spec-collab-follow-up:";
|
|
2465
2456
|
var DshReviewCoordinator = class {
|
|
2466
|
-
|
|
2457
|
+
host;
|
|
2467
2458
|
contexts;
|
|
2468
2459
|
prompts;
|
|
2469
2460
|
stageSessions = /* @__PURE__ */ new Map();
|
|
2470
|
-
|
|
2471
|
-
|
|
2461
|
+
lifetime = new AbortController();
|
|
2462
|
+
constructor(host, contexts = new ReviewContextCatalog(), prompts = {}) {
|
|
2463
|
+
this.host = host;
|
|
2472
2464
|
this.contexts = contexts;
|
|
2473
2465
|
this.prompts = resolveReviewPrompts(prompts);
|
|
2474
2466
|
}
|
|
2467
|
+
dispose() {
|
|
2468
|
+
this.lifetime.abort();
|
|
2469
|
+
this.stageSessions.clear();
|
|
2470
|
+
}
|
|
2475
2471
|
async reviewWorkspaces() {
|
|
2476
|
-
|
|
2477
|
-
|
|
2478
|
-
return listed.result.value.items.map((item) => ({
|
|
2479
|
-
workspaceId: item.workspaceId,
|
|
2472
|
+
return this.host.workspaceRegistry.list().map((item) => ({
|
|
2473
|
+
workspaceId: item.id,
|
|
2480
2474
|
title: item.title,
|
|
2481
2475
|
path: item.path
|
|
2482
2476
|
}));
|
|
@@ -2501,26 +2495,25 @@ var DshReviewCoordinator = class {
|
|
|
2501
2495
|
});
|
|
2502
2496
|
}
|
|
2503
2497
|
async conversation(sessionId) {
|
|
2504
|
-
const history = await this.
|
|
2505
|
-
if (!history.result.ok) throw failure(history.result.error);
|
|
2498
|
+
const history = await this.host.sessionController.inspect(sessionId, this.lifetime.signal);
|
|
2506
2499
|
const rows = [];
|
|
2507
2500
|
let skippedOrchestrationPrompt = false;
|
|
2508
|
-
for (const entry of history.
|
|
2509
|
-
if (entry.
|
|
2510
|
-
if (entry.
|
|
2501
|
+
for (const entry of history.events) {
|
|
2502
|
+
if (entry.type !== "user/message" && entry.type !== "assistant/message") continue;
|
|
2503
|
+
if (entry.type === "user/message" && !skippedOrchestrationPrompt) {
|
|
2511
2504
|
skippedOrchestrationPrompt = true;
|
|
2512
2505
|
continue;
|
|
2513
2506
|
}
|
|
2514
|
-
const value = entry.
|
|
2507
|
+
const value = entry.data;
|
|
2515
2508
|
const message = isObject(value) && "message" in value ? value.message : value;
|
|
2516
2509
|
let messageText = collectText(isObject(message) && "content" in message ? message.content : message).join("\n").trim();
|
|
2517
|
-
if (entry.
|
|
2510
|
+
if (entry.type === "user/message") {
|
|
2518
2511
|
const followUp = storedFollowUp(messageText) ?? extractPromptValue(messageText, this.prompts.followUp.trim(), "CONTENT") ?? extractPromptValue(messageText, DEFAULT_REVIEW_PROMPTS.followUp, "CONTENT");
|
|
2519
2512
|
if (followUp === void 0) continue;
|
|
2520
2513
|
messageText = followUp.trim();
|
|
2521
2514
|
}
|
|
2522
2515
|
if (messageText !== "") rows.push({
|
|
2523
|
-
role: entry.
|
|
2516
|
+
role: entry.type === "user/message" ? "user" : "assistant",
|
|
2524
2517
|
text: messageText
|
|
2525
2518
|
});
|
|
2526
2519
|
}
|
|
@@ -2531,15 +2524,7 @@ var DshReviewCoordinator = class {
|
|
|
2531
2524
|
if (content === "") throw new Error("追问内容不能为空");
|
|
2532
2525
|
const metadata = Buffer.from(content, "utf8").toString("base64url");
|
|
2533
2526
|
const promptText = `${renderPrompt(this.prompts.followUp, { CONTENT: content }).trim()}${FOLLOW_UP_METADATA}${metadata} -->`;
|
|
2534
|
-
|
|
2535
|
-
sessionId,
|
|
2536
|
-
mode: "queue",
|
|
2537
|
-
content: [{
|
|
2538
|
-
type: "text",
|
|
2539
|
-
text: promptText
|
|
2540
|
-
}]
|
|
2541
|
-
}));
|
|
2542
|
-
if (!prompted.result.ok) throw failure(prompted.result.error);
|
|
2527
|
+
await this.promptExisting(sessionId, promptText);
|
|
2543
2528
|
}
|
|
2544
2529
|
async inStageSession(requirement, existingSessionId, continuation, launch) {
|
|
2545
2530
|
const key = `${requirement.id}:${requirement.stage}:${requirement.stageCycle}`;
|
|
@@ -2573,43 +2558,30 @@ var DshReviewCoordinator = class {
|
|
|
2573
2558
|
}
|
|
2574
2559
|
}
|
|
2575
2560
|
async promptExisting(sessionId, promptText) {
|
|
2576
|
-
|
|
2561
|
+
await this.host.sessionController.prompt({
|
|
2562
|
+
requestId: `spec-collab-${crypto.randomUUID()}`,
|
|
2577
2563
|
sessionId,
|
|
2578
2564
|
mode: "queue",
|
|
2579
2565
|
content: [{
|
|
2580
2566
|
type: "text",
|
|
2581
2567
|
text: promptText
|
|
2582
2568
|
}]
|
|
2583
|
-
})
|
|
2584
|
-
if (!prompted.result.ok) throw failure(prompted.result.error);
|
|
2569
|
+
}, this.lifetime.signal);
|
|
2585
2570
|
}
|
|
2586
2571
|
async launch(title, promptText, workspaceId, agentPreset) {
|
|
2587
2572
|
if (agentPreset !== void 0) {
|
|
2588
|
-
const
|
|
2589
|
-
if (!presets.result.ok) throw failure(presets.result.error);
|
|
2590
|
-
const preset = presets.result.value.presets.find((item) => item.id === agentPreset);
|
|
2573
|
+
const preset = (await this.host.agentPresets.list()).find((item) => item.id === agentPreset);
|
|
2591
2574
|
if (preset === void 0 || preset.broken !== void 0) throw new Error("agent preset is unavailable");
|
|
2592
2575
|
}
|
|
2593
|
-
const
|
|
2576
|
+
const { sessionId } = await this.host.sessionController.create({
|
|
2594
2577
|
workspaceId,
|
|
2595
2578
|
...agentPreset === void 0 ? {} : { agentPreset }
|
|
2596
|
-
})
|
|
2597
|
-
|
|
2598
|
-
const sessionId = created.result.value.sessionId;
|
|
2599
|
-
const renamed = await this.api.sessions.rename(request({
|
|
2579
|
+
});
|
|
2580
|
+
await this.host.sessionController.rename({
|
|
2600
2581
|
sessionId,
|
|
2601
2582
|
title
|
|
2602
|
-
})
|
|
2603
|
-
|
|
2604
|
-
const prompted = await this.api.sessions.prompt(request({
|
|
2605
|
-
sessionId,
|
|
2606
|
-
mode: "queue",
|
|
2607
|
-
content: [{
|
|
2608
|
-
type: "text",
|
|
2609
|
-
text: promptText.replaceAll("{{SESSION_ID}}", sessionId)
|
|
2610
|
-
}]
|
|
2611
|
-
}));
|
|
2612
|
-
if (!prompted.result.ok) throw failure(prompted.result.error);
|
|
2583
|
+
});
|
|
2584
|
+
await this.promptExisting(sessionId, promptText.replaceAll("{{SESSION_ID}}", sessionId));
|
|
2613
2585
|
return sessionId;
|
|
2614
2586
|
}
|
|
2615
2587
|
async resolveWorkspace(workspaceId) {
|
|
@@ -3519,7 +3491,9 @@ function allSpecTools(engine) {
|
|
|
3519
3491
|
const name = "spec-collab";
|
|
3520
3492
|
const inject = [
|
|
3521
3493
|
"webServer",
|
|
3522
|
-
"
|
|
3494
|
+
"sessionController",
|
|
3495
|
+
"workspaceRegistry",
|
|
3496
|
+
"agentPresets",
|
|
3523
3497
|
"tools",
|
|
3524
3498
|
"systemPrompt"
|
|
3525
3499
|
];
|
|
@@ -3557,8 +3531,9 @@ function apply(ctx, config = {}) {
|
|
|
3557
3531
|
const contexts = new ReviewContextCatalog(config);
|
|
3558
3532
|
const prompts = resolveReviewPrompts(config.prompts);
|
|
3559
3533
|
const engine = new CollaborationEngine(join(dataRoot, "collaboration-v3.json"), new GitRequirementStore(config.repositoryPath ?? join(dataRoot, "repository")), { legacyPath: join(dataRoot, "collaboration-v2.json") });
|
|
3560
|
-
const coordinator = new DshReviewCoordinator(ctx
|
|
3534
|
+
const coordinator = new DshReviewCoordinator(ctx, contexts, prompts);
|
|
3561
3535
|
engine.setCoordinator(coordinator);
|
|
3536
|
+
ctx.effect(() => () => coordinator.dispose(), "spec-collab: review lifetime");
|
|
3562
3537
|
ctx.effect(() => {
|
|
3563
3538
|
const disposers = makeRoutes(engine, coordinator).map((route) => ctx.webServer.register(route));
|
|
3564
3539
|
return () => {
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
export declare
|
|
3
|
-
export declare function apply(ctx: ClientContext): void;
|
|
1
|
+
import type { Context } from '@deepseek-ai/cordis';
|
|
2
|
+
export declare function apply(ctx: Context): void;
|
|
4
3
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/client/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/client/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA;AAIlD,wBAAgB,KAAK,CAAC,GAAG,EAAE,OAAO,GAAG,IAAI,CASxC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sidebar-anchor.d.ts","sourceRoot":"","sources":["../../../src/client/sidebar-anchor.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,aAAa;IAC5B,OAAO,EAAE,iBAAiB,CAAA;IAC1B,SAAS,EAAE,QAAQ,GAAG,OAAO,CAAA;CAC9B;AAMD,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,QAAQ,GAAG,aAAa,GAAG,SAAS,
|
|
1
|
+
{"version":3,"file":"sidebar-anchor.d.ts","sourceRoot":"","sources":["../../../src/client/sidebar-anchor.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,aAAa;IAC5B,OAAO,EAAE,iBAAiB,CAAA;IAC1B,SAAS,EAAE,QAAQ,GAAG,OAAO,CAAA;CAC9B;AAMD,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,QAAQ,GAAG,aAAa,GAAG,SAAS,CAQ/E"}
|
package/lib/types/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Context } from '@deepseek-ai/cordis';
|
|
2
|
-
import Schema from 'schemastery';
|
|
2
|
+
import Schema from '@deepseek-ai/schemastery';
|
|
3
3
|
import { DEFAULT_REVIEW_PROMPTS, resolveReviewPrompts, type ReviewPromptConfig } from './prompts.ts';
|
|
4
4
|
import { type ReviewContextConfig } from './review-context.ts';
|
|
5
5
|
export { DEFAULT_REVIEW_PROMPTS, resolveReviewPrompts };
|
package/lib/types/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA;AAClD,OAAO,MAAM,MAAM,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA;AAClD,OAAO,MAAM,MAAM,0BAA0B,CAAA;AAM7C,OAAO,EAAE,sBAAsB,EAAE,oBAAoB,EAAE,KAAK,kBAAkB,EAAE,MAAM,cAAc,CAAA;AAEpG,OAAO,EAAwB,KAAK,mBAAmB,EAAE,MAAM,qBAAqB,CAAA;AAIpF,OAAO,EAAE,sBAAsB,EAAE,oBAAoB,EAAE,CAAA;AACvD,YAAY,EAAE,kBAAkB,EAAE,CAAA;AAElC,eAAO,MAAM,IAAI,gBAAgB,CAAA;AACjC,eAAO,MAAM,MAAM,UAAmG,CAAA;AACtH,MAAM,WAAW,MAAO,SAAQ,mBAAmB;IAAG,QAAQ,CAAC,EAAE,MAAM,CAAC;IAAC,cAAc,CAAC,EAAE,MAAM,CAAC;IAAC,OAAO,CAAC,EAAE,kBAAkB,CAAA;CAAE;AAUhI,eAAO,MAAM,MAAM,EAAE,MAAM,CAAC,MAAM,CAoBd,CAAA;AAEpB,wBAAgB,KAAK,CAAC,GAAG,EAAE,OAAO,EAAE,MAAM,GAAE,MAAW,GAAG,IAAI,CAc7D"}
|
|
@@ -1,14 +1,23 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { SessionController } from '@deepseek-ai/dsh-api-session-controller';
|
|
2
|
+
import type { AgentPresetRegistry } from '@deepseek-ai/dsh-agent-preset-registry';
|
|
3
|
+
import type { WorkspaceRegistry } from '@deepseek-ai/dsh-workspace';
|
|
2
4
|
import type { AiCoordinator } from './engine.ts';
|
|
3
5
|
import type { AiReviewRun, CommentThread, RequirementView, ReviewWorkspaceSummary } from './protocol.ts';
|
|
4
6
|
import { type ReviewPromptConfig } from './prompts.ts';
|
|
5
7
|
import { ReviewContextCatalog } from './review-context.ts';
|
|
8
|
+
export interface DshReviewHost {
|
|
9
|
+
sessionController: Pick<SessionController, 'create' | 'rename' | 'prompt' | 'inspect'>;
|
|
10
|
+
workspaceRegistry: Pick<WorkspaceRegistry, 'list'>;
|
|
11
|
+
agentPresets: Pick<AgentPresetRegistry, 'list'>;
|
|
12
|
+
}
|
|
6
13
|
export declare class DshReviewCoordinator implements AiCoordinator {
|
|
7
|
-
private readonly
|
|
14
|
+
private readonly host;
|
|
8
15
|
private readonly contexts;
|
|
9
16
|
private readonly prompts;
|
|
10
17
|
private readonly stageSessions;
|
|
11
|
-
|
|
18
|
+
private readonly lifetime;
|
|
19
|
+
constructor(host: DshReviewHost, contexts?: ReviewContextCatalog, prompts?: ReviewPromptConfig);
|
|
20
|
+
dispose(): void;
|
|
12
21
|
reviewWorkspaces(): Promise<ReviewWorkspaceSummary[]>;
|
|
13
22
|
assertWorkspaceAvailable(workspaceId: string): Promise<void>;
|
|
14
23
|
requestReview(input: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"review-runtime.d.ts","sourceRoot":"","sources":["../../src/review-runtime.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"review-runtime.d.ts","sourceRoot":"","sources":["../../src/review-runtime.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAwB,MAAM,yCAAyC,CAAA;AACtG,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,wCAAwC,CAAA;AACjF,OAAO,KAAK,EAAe,iBAAiB,EAAE,MAAM,4BAA4B,CAAA;AAChF,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAChD,OAAO,KAAK,EAAE,WAAW,EAAE,aAAa,EAAE,eAAe,EAAE,sBAAsB,EAAE,MAAM,eAAe,CAAA;AACxG,OAAO,EAA8G,KAAK,kBAAkB,EAAE,MAAM,cAAc,CAAA;AAClK,OAAO,EAAE,oBAAoB,EAAuB,MAAM,qBAAqB,CAAA;AAG/E,MAAM,WAAW,aAAa;IAC5B,iBAAiB,EAAE,IAAI,CAAC,iBAAiB,EAAE,QAAQ,GAAG,QAAQ,GAAG,QAAQ,GAAG,SAAS,CAAC,CAAA;IACtF,iBAAiB,EAAE,IAAI,CAAC,iBAAiB,EAAE,MAAM,CAAC,CAAA;IAClD,YAAY,EAAE,IAAI,CAAC,mBAAmB,EAAE,MAAM,CAAC,CAAA;CAChD;AAGD,qBAAa,oBAAqB,YAAW,aAAa;IAI5C,OAAO,CAAC,QAAQ,CAAC,IAAI;IAAiB,OAAO,CAAC,QAAQ,CAAC,QAAQ;IAH3E,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAuB;IAC/C,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAqC;IACnE,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAwB;gBACpB,IAAI,EAAE,aAAa,EAAmB,QAAQ,uBAA6B,EAAE,OAAO,GAAE,kBAAuB;IAG1I,OAAO,IAAI,IAAI;IACT,gBAAgB,IAAI,OAAO,CAAC,sBAAsB,EAAE,CAAC;IAGrD,wBAAwB,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAG5D,aAAa,CAAC,KAAK,EAAE;QAAE,WAAW,EAAE,eAAe,CAAC;QAAC,GAAG,EAAE,WAAW,CAAC;QAAC,SAAS,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,MAAM,CAAC;IAQ7G,mBAAmB,CAAC,KAAK,EAAE;QAAE,WAAW,EAAE,eAAe,CAAC;QAAC,OAAO,EAAE,aAAa,CAAC;QAAC,SAAS,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,MAAM,CAAC;IAQzH,YAAY,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,GAAG,WAAW,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAsB7F,QAAQ,CAAC,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;YAOhD,cAAc;IAW5B,OAAO,CAAC,oBAAoB;YACd,cAAc;YAOd,MAAM;YAUN,gBAAgB;CAK/B"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-spec-collab",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "AI-assisted requirement clarification and Git-backed Spec co-creation for DeepSeek Harness, ending at a human-confirmed Ready Spec.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"deepseek-harness",
|
|
@@ -36,10 +36,6 @@
|
|
|
36
36
|
"patch": "./cordis.patch.yml"
|
|
37
37
|
},
|
|
38
38
|
"client": {
|
|
39
|
-
"inject": [
|
|
40
|
-
"@deepseek-ai/dsh-client-runtime",
|
|
41
|
-
"@deepseek-ai/dsh-client-connection"
|
|
42
|
-
],
|
|
43
39
|
"platform": "web"
|
|
44
40
|
}
|
|
45
41
|
},
|
|
@@ -56,32 +52,24 @@
|
|
|
56
52
|
"publishConfig": {
|
|
57
53
|
"registry": "https://registry.npmjs.org"
|
|
58
54
|
},
|
|
59
|
-
"scripts": {
|
|
60
|
-
"clean": "node -e \"require('node:fs').rmSync('lib', { recursive: true, force: true })\"",
|
|
61
|
-
"build": "npm run clean && tsc -p tsconfig.build.json && tsdown",
|
|
62
|
-
"bundle": "tsdown",
|
|
63
|
-
"prepare": "npm run build",
|
|
64
|
-
"typecheck": "tsc --noEmit",
|
|
65
|
-
"test": "vitest run --maxWorkers=1 --minWorkers=1 --exclude tests/e2e/**",
|
|
66
|
-
"test:e2e": "playwright test"
|
|
67
|
-
},
|
|
68
55
|
"dependencies": {
|
|
69
56
|
"@toast-ui/editor": "3.2.2",
|
|
70
57
|
"lightningcss": "^1.32.0",
|
|
71
58
|
"markdown-it": "^14.1.0",
|
|
72
59
|
"prosemirror-inputrules": "^1.5.0",
|
|
73
|
-
"schemastery": "
|
|
60
|
+
"@deepseek-ai/schemastery": "~3.18.5"
|
|
74
61
|
},
|
|
75
62
|
"devDependencies": {
|
|
76
63
|
"@axe-core/playwright": "^4.10.0",
|
|
77
|
-
"@deepseek-ai/cordis": "
|
|
78
|
-
"@deepseek-ai/dsh-
|
|
79
|
-
"@deepseek-ai/dsh-
|
|
80
|
-
"@deepseek-ai/dsh-
|
|
81
|
-
"@deepseek-ai/dsh-host-webserver": "
|
|
82
|
-
"@deepseek-ai/dsh-llm": "
|
|
83
|
-
"@deepseek-ai/dsh-system-prompt": "
|
|
84
|
-
"@deepseek-ai/dsh-tools": "
|
|
64
|
+
"@deepseek-ai/cordis": "~4.0.5",
|
|
65
|
+
"@deepseek-ai/dsh-agent-preset-registry": "0.2.1-rc.5",
|
|
66
|
+
"@deepseek-ai/dsh-api-session-controller": "0.2.1-rc.5",
|
|
67
|
+
"@deepseek-ai/dsh-app-boot": "0.2.1-rc.5",
|
|
68
|
+
"@deepseek-ai/dsh-host-webserver": "0.2.1-rc.5",
|
|
69
|
+
"@deepseek-ai/dsh-llm": "0.2.1-rc.5",
|
|
70
|
+
"@deepseek-ai/dsh-system-prompt": "0.2.1-rc.5",
|
|
71
|
+
"@deepseek-ai/dsh-tools": "0.2.1-rc.5",
|
|
72
|
+
"@deepseek-ai/dsh-workspace": "0.2.1-rc.5",
|
|
85
73
|
"@playwright/test": "^1.55.0",
|
|
86
74
|
"@types/markdown-it": "^14.1.2",
|
|
87
75
|
"@types/node": "^22.20.0",
|
|
@@ -95,13 +83,26 @@
|
|
|
95
83
|
"vitest": "^3.0.0"
|
|
96
84
|
},
|
|
97
85
|
"peerDependencies": {
|
|
98
|
-
"@deepseek-ai/
|
|
86
|
+
"@deepseek-ai/cordis": "~4.0.5",
|
|
87
|
+
"@deepseek-ai/dsh-agent-preset-registry": "0.2.1-rc.5",
|
|
88
|
+
"@deepseek-ai/dsh-api-session-controller": "0.2.1-rc.5",
|
|
89
|
+
"@deepseek-ai/dsh-host-webserver": "0.2.1-rc.5",
|
|
90
|
+
"@deepseek-ai/dsh-system-prompt": "0.2.1-rc.5",
|
|
91
|
+
"@deepseek-ai/dsh-tools": "0.2.1-rc.5",
|
|
92
|
+
"@deepseek-ai/dsh-workspace": "0.2.1-rc.5",
|
|
99
93
|
"react": "^18.2.0",
|
|
100
94
|
"react-dom": "^18.2.0"
|
|
101
95
|
},
|
|
102
96
|
"engines": {
|
|
103
97
|
"node": ">=20"
|
|
104
98
|
},
|
|
105
|
-
"
|
|
106
|
-
"
|
|
107
|
-
}
|
|
99
|
+
"license": "Apache-2.0",
|
|
100
|
+
"scripts": {
|
|
101
|
+
"clean": "node -e \"require('node:fs').rmSync('lib', { recursive: true, force: true })\"",
|
|
102
|
+
"build": "npm run clean && tsc -p tsconfig.build.json && tsdown",
|
|
103
|
+
"bundle": "tsdown",
|
|
104
|
+
"typecheck": "tsc --noEmit",
|
|
105
|
+
"test": "vitest run --maxWorkers=1 --minWorkers=1 --exclude tests/e2e/**",
|
|
106
|
+
"test:e2e": "playwright test"
|
|
107
|
+
}
|
|
108
|
+
}
|
package/src/client/index.ts
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Context } from '@deepseek-ai/cordis'
|
|
2
2
|
import { SpecApi } from './api.ts'
|
|
3
3
|
import { mountSidebarEntry, mountWorkbench } from './mount.tsx'
|
|
4
4
|
|
|
5
|
-
export
|
|
6
|
-
|
|
7
|
-
export function apply(ctx: ClientContext): void {
|
|
5
|
+
export function apply(ctx: Context): void {
|
|
8
6
|
const api = new SpecApi()
|
|
9
7
|
const disposers: Array<() => void> = []
|
|
10
8
|
try {
|
|
@@ -10,6 +10,8 @@ function exactTextButton(document: Document, text: string): HTMLButtonElement |
|
|
|
10
10
|
export function findSidebarAnchor(document: Document): SidebarAnchor | undefined {
|
|
11
11
|
const skillCenter = document.querySelector<HTMLButtonElement>('button[aria-label="技能中心"]') ?? exactTextButton(document, '技能中心')
|
|
12
12
|
if (skillCenter !== undefined && skillCenter !== null) return { element: skillCenter, placement: 'after' }
|
|
13
|
+
const plugins = document.querySelector<HTMLButtonElement>('button[aria-label="插件"], button[aria-label="Plugins"]') ?? exactTextButton(document, '插件') ?? exactTextButton(document, 'Plugins')
|
|
14
|
+
if (plugins !== undefined && plugins !== null) return { element: plugins, placement: 'after' }
|
|
13
15
|
const settings = document.querySelector<HTMLButtonElement>('button[aria-label="设置"]') ?? exactTextButton(document, '设置')
|
|
14
16
|
if (settings !== undefined && settings !== null) return { element: settings, placement: 'before' }
|
|
15
17
|
return undefined
|
package/src/index.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { homedir } from 'node:os'
|
|
2
2
|
import { join } from 'node:path'
|
|
3
3
|
import type { Context } from '@deepseek-ai/cordis'
|
|
4
|
-
import Schema from 'schemastery'
|
|
5
|
-
import type {} from '@deepseek-ai/dsh-host-apiproxy'
|
|
4
|
+
import Schema from '@deepseek-ai/schemastery'
|
|
6
5
|
import type {} from '@deepseek-ai/dsh-host-webserver'
|
|
7
6
|
import type {} from '@deepseek-ai/dsh-system-prompt'
|
|
8
7
|
import type {} from '@deepseek-ai/dsh-tools'
|
|
@@ -18,7 +17,7 @@ export { DEFAULT_REVIEW_PROMPTS, resolveReviewPrompts }
|
|
|
18
17
|
export type { ReviewPromptConfig }
|
|
19
18
|
|
|
20
19
|
export const name = 'spec-collab'
|
|
21
|
-
export const inject = ['webServer', '
|
|
20
|
+
export const inject = ['webServer', 'sessionController', 'workspaceRegistry', 'agentPresets', 'tools', 'systemPrompt']
|
|
22
21
|
export interface Config extends ReviewContextConfig { dataRoot?: string; repositoryPath?: string; prompts?: ReviewPromptConfig }
|
|
23
22
|
|
|
24
23
|
const stringList = () => Schema.array(Schema.string()).default([])
|
|
@@ -56,8 +55,9 @@ export function apply(ctx: Context, config: Config = {}): void {
|
|
|
56
55
|
const contexts = new ReviewContextCatalog(config)
|
|
57
56
|
const prompts = resolveReviewPrompts(config.prompts)
|
|
58
57
|
const engine = new CollaborationEngine(join(dataRoot, 'collaboration-v3.json'), new GitRequirementStore(config.repositoryPath ?? join(dataRoot, 'repository')), { legacyPath: join(dataRoot, 'collaboration-v2.json') })
|
|
59
|
-
const coordinator = new DshReviewCoordinator(ctx
|
|
58
|
+
const coordinator = new DshReviewCoordinator(ctx, contexts, prompts)
|
|
60
59
|
engine.setCoordinator(coordinator)
|
|
60
|
+
ctx.effect(() => () => coordinator.dispose(), 'spec-collab: review lifetime')
|
|
61
61
|
ctx.effect(() => { const disposers = makeRoutes(engine, coordinator).map(route => ctx.webServer.register(route)); return () => { for (const dispose of disposers) dispose() } }, 'spec-collab: routes')
|
|
62
62
|
ctx.effect(() => { const disposers = allSpecTools(engine).map(tool => ctx.tools.register(tool)); return () => { for (const dispose of disposers) dispose() } }, 'spec-collab: tools')
|
|
63
63
|
ctx.effect(() => ctx.systemPrompt.section({
|
package/src/review-runtime.ts
CHANGED
|
@@ -1,24 +1,29 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { SessionController, SessionPromptRequest } from '@deepseek-ai/dsh-api-session-controller'
|
|
2
|
+
import type { AgentPresetRegistry } from '@deepseek-ai/dsh-agent-preset-registry'
|
|
3
|
+
import type { WorkspaceId, WorkspaceRegistry } from '@deepseek-ai/dsh-workspace'
|
|
2
4
|
import type { AiCoordinator } from './engine.ts'
|
|
3
5
|
import type { AiReviewRun, CommentThread, RequirementView, ReviewWorkspaceSummary } from './protocol.ts'
|
|
4
6
|
import { DEFAULT_REVIEW_PROMPTS, extractPromptValue, renderPrompt, resolveReviewPrompts, type ResolvedReviewPrompts, type ReviewPromptConfig } from './prompts.ts'
|
|
5
7
|
import { ReviewContextCatalog, reviewContextPrompt } from './review-context.ts'
|
|
6
8
|
import { readWorkspaceSnapshot } from './workspace-context.ts'
|
|
7
9
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
+
export interface DshReviewHost {
|
|
11
|
+
sessionController: Pick<SessionController, 'create' | 'rename' | 'prompt' | 'inspect'>
|
|
12
|
+
workspaceRegistry: Pick<WorkspaceRegistry, 'list'>
|
|
13
|
+
agentPresets: Pick<AgentPresetRegistry, 'list'>
|
|
14
|
+
}
|
|
10
15
|
const FOLLOW_UP_METADATA = '\n\n<!-- dsh-spec-collab-follow-up:'
|
|
11
16
|
|
|
12
17
|
export class DshReviewCoordinator implements AiCoordinator {
|
|
13
18
|
private readonly prompts: ResolvedReviewPrompts
|
|
14
19
|
private readonly stageSessions = new Map<string, Promise<string>>()
|
|
15
|
-
|
|
20
|
+
private readonly lifetime = new AbortController()
|
|
21
|
+
constructor(private readonly host: DshReviewHost, private readonly contexts = new ReviewContextCatalog(), prompts: ReviewPromptConfig = {}) {
|
|
16
22
|
this.prompts = resolveReviewPrompts(prompts)
|
|
17
23
|
}
|
|
24
|
+
dispose(): void { this.lifetime.abort(); this.stageSessions.clear() }
|
|
18
25
|
async reviewWorkspaces(): Promise<ReviewWorkspaceSummary[]> {
|
|
19
|
-
|
|
20
|
-
if (!listed.result.ok) throw failure(listed.result.error)
|
|
21
|
-
return listed.result.value.items.map(item => ({ workspaceId: item.workspaceId, title: item.title, path: item.path }))
|
|
26
|
+
return this.host.workspaceRegistry.list().map(item => ({ workspaceId: item.id, title: item.title, path: item.path }))
|
|
22
27
|
}
|
|
23
28
|
async assertWorkspaceAvailable(workspaceId: string): Promise<void> {
|
|
24
29
|
await this.resolveWorkspace(workspaceId)
|
|
@@ -40,25 +45,24 @@ export class DshReviewCoordinator implements AiCoordinator {
|
|
|
40
45
|
})
|
|
41
46
|
}
|
|
42
47
|
async conversation(sessionId: string): Promise<Array<{ role: 'user' | 'assistant'; text: string }>> {
|
|
43
|
-
const history = await this.
|
|
44
|
-
if (!history.result.ok) throw failure(history.result.error)
|
|
48
|
+
const history = await this.host.sessionController.inspect(sessionId as SessionPromptRequest['sessionId'], this.lifetime.signal)
|
|
45
49
|
const rows: Array<{ role: 'user' | 'assistant'; text: string }> = []
|
|
46
50
|
let skippedOrchestrationPrompt = false
|
|
47
|
-
for (const entry of history.
|
|
48
|
-
if (entry.
|
|
49
|
-
if (entry.
|
|
50
|
-
const value = entry.
|
|
51
|
+
for (const entry of history.events) {
|
|
52
|
+
if (entry.type !== 'user/message' && entry.type !== 'assistant/message') continue
|
|
53
|
+
if (entry.type === 'user/message' && !skippedOrchestrationPrompt) { skippedOrchestrationPrompt = true; continue }
|
|
54
|
+
const value = entry.data as unknown
|
|
51
55
|
const message = isObject(value) && 'message' in value ? value.message : value
|
|
52
56
|
const content = isObject(message) && 'content' in message ? message.content : message
|
|
53
57
|
let messageText = collectText(content).join('\n').trim()
|
|
54
|
-
if (entry.
|
|
58
|
+
if (entry.type === 'user/message') {
|
|
55
59
|
const followUp = storedFollowUp(messageText)
|
|
56
60
|
?? extractPromptValue(messageText, this.prompts.followUp.trim(), 'CONTENT')
|
|
57
61
|
?? extractPromptValue(messageText, DEFAULT_REVIEW_PROMPTS.followUp, 'CONTENT')
|
|
58
62
|
if (followUp === undefined) continue
|
|
59
63
|
messageText = followUp.trim()
|
|
60
64
|
}
|
|
61
|
-
if (messageText !== '') rows.push({ role: entry.
|
|
65
|
+
if (messageText !== '') rows.push({ role: entry.type === 'user/message' ? 'user' : 'assistant', text: messageText })
|
|
62
66
|
}
|
|
63
67
|
return rows
|
|
64
68
|
}
|
|
@@ -67,8 +71,7 @@ export class DshReviewCoordinator implements AiCoordinator {
|
|
|
67
71
|
if (content === '') throw new Error('追问内容不能为空')
|
|
68
72
|
const metadata = Buffer.from(content, 'utf8').toString('base64url')
|
|
69
73
|
const promptText = `${renderPrompt(this.prompts.followUp, { CONTENT: content }).trim()}${FOLLOW_UP_METADATA}${metadata} -->`
|
|
70
|
-
|
|
71
|
-
if (!prompted.result.ok) throw failure(prompted.result.error)
|
|
74
|
+
await this.promptExisting(sessionId, promptText)
|
|
72
75
|
}
|
|
73
76
|
private async inStageSession(requirement: RequirementView, existingSessionId: string | undefined, continuation: string, launch: () => Promise<string>): Promise<string> {
|
|
74
77
|
const key = `${requirement.id}:${requirement.stage}:${requirement.stageCycle}`
|
|
@@ -83,23 +86,20 @@ export class DshReviewCoordinator implements AiCoordinator {
|
|
|
83
86
|
}
|
|
84
87
|
private rememberStageSession(key: string, session: Promise<string>): void { this.stageSessions.delete(key); this.stageSessions.set(key, session); while (this.stageSessions.size > 100) { const oldest = this.stageSessions.keys().next().value as string | undefined; if (oldest === undefined) break; this.stageSessions.delete(oldest) } }
|
|
85
88
|
private async promptExisting(sessionId: string, promptText: string): Promise<void> {
|
|
86
|
-
|
|
87
|
-
|
|
89
|
+
await this.host.sessionController.prompt({
|
|
90
|
+
requestId: `spec-collab-${crypto.randomUUID()}` as SessionPromptRequest['requestId'],
|
|
91
|
+
sessionId: sessionId as SessionPromptRequest['sessionId'],
|
|
92
|
+
mode: 'queue', content: [{ type: 'text', text: promptText }],
|
|
93
|
+
}, this.lifetime.signal)
|
|
88
94
|
}
|
|
89
95
|
private async launch(title: string, promptText: string, workspaceId: string, agentPreset?: string): Promise<string> {
|
|
90
96
|
if (agentPreset !== undefined) {
|
|
91
|
-
const
|
|
92
|
-
if (!presets.result.ok) throw failure(presets.result.error)
|
|
93
|
-
const preset = presets.result.value.presets.find(item => item.id === agentPreset)
|
|
97
|
+
const preset = (await this.host.agentPresets.list()).find(item => item.id === agentPreset)
|
|
94
98
|
if (preset === undefined || preset.broken !== undefined) throw new Error('agent preset is unavailable')
|
|
95
99
|
}
|
|
96
|
-
const
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
const renamed = await this.api.sessions.rename(request({ sessionId, title }))
|
|
100
|
-
if (!renamed.result.ok) throw failure(renamed.result.error)
|
|
101
|
-
const prompted = await this.api.sessions.prompt(request({ sessionId, mode: 'queue' as const, content: [{ type: 'text' as const, text: promptText.replaceAll('{{SESSION_ID}}', sessionId) }] }))
|
|
102
|
-
if (!prompted.result.ok) throw failure(prompted.result.error)
|
|
100
|
+
const { sessionId } = await this.host.sessionController.create({ workspaceId: workspaceId as WorkspaceId, ...(agentPreset === undefined ? {} : { agentPreset }) })
|
|
101
|
+
await this.host.sessionController.rename({ sessionId, title })
|
|
102
|
+
await this.promptExisting(sessionId, promptText.replaceAll('{{SESSION_ID}}', sessionId))
|
|
103
103
|
return sessionId
|
|
104
104
|
}
|
|
105
105
|
private async resolveWorkspace(workspaceId: string): Promise<ReviewWorkspaceSummary> {
|