deekseek-cli 0.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 (3) hide show
  1. package/README.md +11 -0
  2. package/dist/index.js +1052 -0
  3. package/package.json +22 -0
package/README.md ADDED
@@ -0,0 +1,11 @@
1
+ # deekseek-cli
2
+
3
+ Future-ready DeepSeek coding-agent CLI framework preview.
4
+
5
+ ```bash
6
+ npm install -g deekseek-cli
7
+ deepseek -p "smoke"
8
+ deepseek -p "smoke" --output stream-json
9
+ ```
10
+
11
+ This first package contains the deterministic headless smoke path and thin CLI host adapter. Production model credentials and live provider behavior are intentionally outside this initial framework preview.
package/dist/index.js ADDED
@@ -0,0 +1,1052 @@
1
+ #!/usr/bin/env node
2
+ #!/usr/bin/env node
3
+
4
+ // ../../packages/platform-contracts/src/ids.ts
5
+ function asId(value) {
6
+ return value;
7
+ }
8
+
9
+ // ../../packages/model-gateway/src/index.ts
10
+ var defaultDeepSeekProfile = {
11
+ id: asId("model-deepseek-default"),
12
+ providerId: asId("provider-deepseek"),
13
+ model: "deepseek-chat",
14
+ temperature: 0
15
+ };
16
+ var DeterministicMockModelGateway = class {
17
+ async *stream(request) {
18
+ yield { kind: "delta", text: `DeepSeek mock response: ${request.prompt}` };
19
+ yield {
20
+ kind: "usage",
21
+ inputTokens: await this.countTokens(request.prompt, request.profile),
22
+ outputTokens: 6
23
+ };
24
+ yield { kind: "done" };
25
+ }
26
+ async countTokens(text, _profile) {
27
+ return text.trim().length === 0 ? 0 : text.trim().split(/\s+/).length;
28
+ }
29
+ };
30
+
31
+ // ../../packages/runtime/src/index.ts
32
+ var HeadlessAgentRuntime = class {
33
+ constructor(deps) {
34
+ this.deps = deps;
35
+ }
36
+ deps;
37
+ disposed = false;
38
+ async startSession(request = {}) {
39
+ const sessionId = await this.deps.sessions.create({
40
+ workspaceRoot: request.workspaceRoot ?? "",
41
+ agentId: request.agentId ?? ""
42
+ });
43
+ await this.appendSessionEvent(sessionId, "session.started", { workspaceRoot: request.workspaceRoot ?? "" });
44
+ return sessionId;
45
+ }
46
+ async *runTurn(request) {
47
+ if (this.disposed) {
48
+ throw new Error("Runtime disposed");
49
+ }
50
+ const sessionId = request.sessionId ?? await this.startSession(request.agentId ? { agentId: request.agentId } : {});
51
+ const turnId = asId(`turn-${sessionId}`);
52
+ const agentDefinition = request.agentId ? (await this.deps.agents.listDefinitions()).find((definition) => definition.id === request.agentId) ?? await this.deps.agents.getDefault() : await this.deps.agents.getDefault();
53
+ const agent = await this.deps.agents.createInstance(agentDefinition.id, sessionId);
54
+ const trace = this.trace(sessionId, "runtime");
55
+ const started = {
56
+ kind: "turn.started",
57
+ sessionId,
58
+ turnId,
59
+ agentId: agent.definition.id,
60
+ trace,
61
+ data: { prompt: request.prompt, agentInstanceId: agent.id }
62
+ };
63
+ await this.recordRuntimeEvent(started);
64
+ yield started;
65
+ const graph = await this.deps.workflow.createGraph({ sessionId, prompt: request.prompt });
66
+ for await (const event of this.deps.workflow.runGraph(graph, { sessionId, prompt: request.prompt })) {
67
+ await this.recordRuntimeEvent(event);
68
+ yield event;
69
+ }
70
+ const busRecorded = {
71
+ kind: "bus.recorded",
72
+ sessionId,
73
+ turnId,
74
+ taskId: graph.taskId,
75
+ agentId: agent.definition.id,
76
+ trace,
77
+ data: {
78
+ topic: "runtime.event",
79
+ replayRecords: this.deps.bus.getReplayRecords(sessionId).length
80
+ }
81
+ };
82
+ await this.recordRuntimeEvent(busRecorded);
83
+ yield busRecorded;
84
+ const checkpoint = await this.deps.workflow.createCheckpoint(graph, { reason: "single-turn-start" });
85
+ await this.deps.sessions.snapshot(sessionId, { checkpointId: checkpoint.id, workflowId: graph.id });
86
+ const projection = await this.deps.context.project(sessionId, request.prompt);
87
+ const tools = (await this.deps.capabilities.listModelVisible()).map((manifest) => ({
88
+ id: manifest.id,
89
+ name: manifest.name,
90
+ version: manifest.version,
91
+ sideEffect: manifest.sideEffect,
92
+ permissions: manifest.permissions
93
+ }));
94
+ const modelEvents = this.deps.models.stream({
95
+ profile: defaultDeepSeekProfile,
96
+ prompt: projection.prompt,
97
+ tools
98
+ });
99
+ for await (const modelEvent of modelEvents) {
100
+ const runtimeEvent = await this.modelEventToRuntimeEvent(modelEvent, sessionId, turnId, agent.definition.id, trace);
101
+ if (runtimeEvent) {
102
+ await this.recordRuntimeEvent(runtimeEvent);
103
+ yield runtimeEvent;
104
+ }
105
+ }
106
+ const completed = {
107
+ kind: "turn.completed",
108
+ sessionId,
109
+ turnId,
110
+ taskId: graph.taskId,
111
+ agentId: agent.definition.id,
112
+ trace,
113
+ data: {
114
+ workflowId: graph.id,
115
+ checkpointId: checkpoint.id,
116
+ status: "completed"
117
+ }
118
+ };
119
+ await this.recordRuntimeEvent(completed);
120
+ yield completed;
121
+ }
122
+ async interrupt(sessionId, reason) {
123
+ await this.appendSessionEvent(sessionId, "runtime.interrupted", { reason });
124
+ }
125
+ async dispose() {
126
+ this.disposed = true;
127
+ }
128
+ async modelEventToRuntimeEvent(modelEvent, sessionId, turnId, agentId, trace) {
129
+ if (modelEvent.kind === "delta") {
130
+ return {
131
+ kind: "model.delta",
132
+ sessionId,
133
+ turnId,
134
+ agentId,
135
+ trace,
136
+ data: { text: modelEvent.text }
137
+ };
138
+ }
139
+ if (modelEvent.kind === "usage") {
140
+ await this.deps.usage.record({
141
+ sessionId,
142
+ inputTokens: modelEvent.inputTokens,
143
+ outputTokens: modelEvent.outputTokens,
144
+ costMicros: 0,
145
+ elapsedMs: 0
146
+ });
147
+ return {
148
+ kind: "usage.updated",
149
+ sessionId,
150
+ turnId,
151
+ agentId,
152
+ trace,
153
+ data: {
154
+ inputTokens: modelEvent.inputTokens,
155
+ outputTokens: modelEvent.outputTokens
156
+ }
157
+ };
158
+ }
159
+ if (modelEvent.kind === "error") {
160
+ return {
161
+ kind: "runtime.error",
162
+ sessionId,
163
+ turnId,
164
+ agentId,
165
+ trace,
166
+ data: {},
167
+ error: modelEvent.error
168
+ };
169
+ }
170
+ return void 0;
171
+ }
172
+ async recordRuntimeEvent(event) {
173
+ await this.appendSessionEvent(event.sessionId, event.kind, event.data);
174
+ await this.deps.bus.publish(this.toBusEnvelope(event));
175
+ await this.deps.observability.emit({
176
+ kind: event.kind === "usage.updated" ? "usage" : "trace",
177
+ at: (/* @__PURE__ */ new Date(0)).toISOString(),
178
+ name: event.kind,
179
+ fields: event.data
180
+ });
181
+ }
182
+ async appendSessionEvent(sessionId, kind, payload) {
183
+ const events = await this.deps.sessions.events(sessionId);
184
+ const event = {
185
+ sessionId,
186
+ sequence: events.length + 1,
187
+ kind,
188
+ at: (/* @__PURE__ */ new Date(0)).toISOString(),
189
+ payload,
190
+ redaction: { class: "internal" }
191
+ };
192
+ await this.deps.sessions.append(event);
193
+ }
194
+ toBusEnvelope(event) {
195
+ return {
196
+ protocolVersion: "1",
197
+ schemaVersion: "1.0.0",
198
+ id: `bus-${event.kind}-${event.sessionId}`,
199
+ type: "event",
200
+ createdAt: (/* @__PURE__ */ new Date(0)).toISOString(),
201
+ trace: event.trace,
202
+ redaction: { class: "internal" },
203
+ compatibility: { schemaVersion: "1.0.0" },
204
+ payload: {
205
+ kind: event.kind,
206
+ data: event.data
207
+ },
208
+ topic: { name: "runtime.event", owner: "runtime", trustBoundary: "core" },
209
+ producer: "runtime",
210
+ correlationId: event.trace.correlationId,
211
+ sessionId: event.sessionId,
212
+ replayable: true
213
+ };
214
+ }
215
+ trace(sessionId, scope) {
216
+ return {
217
+ traceId: asId(`trace-${scope}-${sessionId}`),
218
+ spanId: asId(`span-${scope}-${sessionId}`),
219
+ correlationId: asId(`corr-${scope}-${sessionId}`),
220
+ sessionId
221
+ };
222
+ }
223
+ };
224
+ function createHeadlessRuntime(deps) {
225
+ return new HeadlessAgentRuntime(deps);
226
+ }
227
+
228
+ // ../../packages/testing-regression/src/harness/index.ts
229
+ var DeterministicRegressionHarness = class {
230
+ async normalize(trace) {
231
+ return {
232
+ ...trace,
233
+ protocol: [...trace.protocol],
234
+ bus: [...trace.bus],
235
+ runtime: [...trace.runtime],
236
+ sessions: [...trace.sessions]
237
+ };
238
+ }
239
+ async replay(trace) {
240
+ const failures = [];
241
+ if (!trace.name) failures.push("missing trace name");
242
+ if (trace.runtime.length === 0) failures.push("runtime trace is empty");
243
+ return { ok: failures.length === 0, failures };
244
+ }
245
+ async assertSemantic(trace, assertion) {
246
+ const expectedKind = assertion.expectedKind;
247
+ if (typeof expectedKind === "string" && !trace.runtime.some((event) => event.kind === expectedKind)) {
248
+ return { ok: false, failures: [`missing runtime event kind ${expectedKind}`] };
249
+ }
250
+ return { ok: true, failures: [] };
251
+ }
252
+ };
253
+
254
+ // ../../packages/agent-management/src/index.ts
255
+ var defaultAgent = {
256
+ id: asId("agent-default"),
257
+ name: "default",
258
+ version: "1.0.0",
259
+ source: "built-in",
260
+ modelProfileId: asId("model-deepseek-default"),
261
+ promptProfile: "coding-agent",
262
+ scopes: {
263
+ capabilities: ["*"],
264
+ context: ["workspace", "session"],
265
+ memory: ["working", "session", "project"],
266
+ policy: ["default"],
267
+ skills: ["trusted"],
268
+ commands: ["*"],
269
+ hooks: ["trusted"]
270
+ }
271
+ };
272
+ var InMemoryAgentManager = class {
273
+ definitions = /* @__PURE__ */ new Map([[defaultAgent.id, defaultAgent]]);
274
+ instances = /* @__PURE__ */ new Map();
275
+ async register(definition) {
276
+ if (this.definitions.has(definition.id)) {
277
+ throw new Error(`Agent definition already registered: ${definition.id}`);
278
+ }
279
+ this.definitions.set(definition.id, definition);
280
+ }
281
+ async getDefault() {
282
+ return defaultAgent;
283
+ }
284
+ async createInstance(definitionId, sessionId) {
285
+ const definition = this.definitions.get(definitionId);
286
+ if (!definition) {
287
+ throw new Error(`Unknown agent definition: ${definitionId}`);
288
+ }
289
+ const instance = {
290
+ id: asId(`agent-instance-${sessionId}`),
291
+ definition,
292
+ sessionId,
293
+ status: "running"
294
+ };
295
+ this.instances.set(instance.id, instance);
296
+ return instance;
297
+ }
298
+ async getInstance(instanceId) {
299
+ return this.instances.get(instanceId);
300
+ }
301
+ async listDefinitions() {
302
+ return [...this.definitions.values()];
303
+ }
304
+ };
305
+
306
+ // ../../packages/capability-registry/src/index.ts
307
+ var InMemoryCapabilityRegistry = class {
308
+ manifests = /* @__PURE__ */ new Map();
309
+ executors = /* @__PURE__ */ new Map();
310
+ async register(manifest, executor) {
311
+ if (this.manifests.has(manifest.id)) throw new Error(`Capability already registered: ${manifest.id}`);
312
+ this.manifests.set(manifest.id, manifest);
313
+ if (executor) this.executors.set(manifest.id, executor);
314
+ }
315
+ async get(id) {
316
+ return this.manifests.get(id);
317
+ }
318
+ async listModelVisible() {
319
+ return [...this.manifests.values()].filter((manifest) => manifest.enabled && manifest.trust !== "untrusted");
320
+ }
321
+ async execute(id, input) {
322
+ const executor = this.executors.get(id);
323
+ if (!executor) {
324
+ return { ok: false, error: { code: "CAPABILITY_NOT_EXECUTABLE", message: String(id), retryable: false, redaction: { class: "public" } } };
325
+ }
326
+ return executor(input);
327
+ }
328
+ };
329
+
330
+ // ../../packages/code-intelligence/src/index.ts
331
+ var NullCodeIntelligenceService = class {
332
+ async diagnostics(_root) {
333
+ return [];
334
+ }
335
+ async symbols(query) {
336
+ return query ? [{ name: query, path: "<memory>", line: 1 }] : [];
337
+ }
338
+ async definitions(symbol) {
339
+ return symbol ? [{ name: symbol, path: "<memory>", line: 1 }] : [];
340
+ }
341
+ async invalidate(_path) {
342
+ }
343
+ };
344
+
345
+ // ../../packages/command-system/src/index.ts
346
+ var InMemoryCommandSystem = class {
347
+ manifests = /* @__PURE__ */ new Map();
348
+ aliases = /* @__PURE__ */ new Map();
349
+ handlers = /* @__PURE__ */ new Map();
350
+ async register(manifest, handler) {
351
+ this.manifests.set(manifest.id, manifest);
352
+ this.aliases.set(manifest.name, manifest.id);
353
+ for (const alias of manifest.aliases) this.aliases.set(alias, manifest.id);
354
+ if (handler) this.handlers.set(manifest.id, handler);
355
+ }
356
+ async invoke(nameOrAlias, input) {
357
+ const id = this.aliases.get(nameOrAlias);
358
+ const handler = id ? this.handlers.get(id) : void 0;
359
+ if (!handler) {
360
+ return { ok: false, error: { code: "COMMAND_NOT_FOUND", message: nameOrAlias, retryable: false, redaction: { class: "public" } } };
361
+ }
362
+ return handler(input);
363
+ }
364
+ async help() {
365
+ return [...this.manifests.values()];
366
+ }
367
+ };
368
+
369
+ // ../../packages/communication-protocol/src/index.ts
370
+ var PipelineProtocolRouter = class {
371
+ constructor(stages, handler) {
372
+ this.stages = stages;
373
+ this.handler = handler;
374
+ }
375
+ stages;
376
+ handler;
377
+ async route(envelope) {
378
+ let current = envelope;
379
+ for (const stage of this.stages) {
380
+ current = await stage.handle(current);
381
+ }
382
+ return this.handler(current);
383
+ }
384
+ };
385
+
386
+ // ../../packages/concurrency-orchestration/src/index.ts
387
+ var DeterministicScheduler = class {
388
+ taskEvents = [];
389
+ lockChains = /* @__PURE__ */ new Map();
390
+ cancelled = /* @__PURE__ */ new Map();
391
+ async run(scope, work) {
392
+ const cancelledReason = this.cancelled.get(scope.id);
393
+ if (cancelledReason) {
394
+ this.record(scope.id, "cancelled", cancelledReason);
395
+ throw new Error(`Task cancelled: ${cancelledReason}`);
396
+ }
397
+ if (scope.deadlineMs !== void 0 && scope.deadlineMs <= 0) {
398
+ this.record(scope.id, "timed-out", "deadline elapsed before task start");
399
+ throw new Error("Task deadline elapsed");
400
+ }
401
+ this.record(scope.id, "running");
402
+ try {
403
+ const result = await work();
404
+ const cancelledAfterWork = this.cancelled.get(scope.id);
405
+ if (cancelledAfterWork) {
406
+ this.record(scope.id, "cancelled", cancelledAfterWork);
407
+ throw new Error(`Task cancelled: ${cancelledAfterWork}`);
408
+ }
409
+ this.record(scope.id, "completed");
410
+ return result;
411
+ } catch (error) {
412
+ if (this.cancelled.has(scope.id)) throw error;
413
+ this.record(scope.id, "failed", error instanceof Error ? error.message : "unknown");
414
+ throw error;
415
+ }
416
+ }
417
+ async withLock(lock, work) {
418
+ const key = `${lock.kind}:${lock.key}`;
419
+ const previous = this.lockChains.get(key) ?? Promise.resolve();
420
+ let release;
421
+ const current = new Promise((resolve2) => {
422
+ release = resolve2;
423
+ });
424
+ this.lockChains.set(
425
+ key,
426
+ previous.then(() => current)
427
+ );
428
+ await previous;
429
+ try {
430
+ return await work();
431
+ } finally {
432
+ release();
433
+ if (this.lockChains.get(key) === current) {
434
+ this.lockChains.delete(key);
435
+ }
436
+ }
437
+ }
438
+ async cancel(taskId, reason) {
439
+ this.cancelled.set(taskId, reason);
440
+ this.record(taskId, "cancelled", reason);
441
+ }
442
+ events() {
443
+ return [...this.taskEvents];
444
+ }
445
+ record(taskId, status, reason) {
446
+ this.taskEvents.push({
447
+ taskId,
448
+ status,
449
+ at: (/* @__PURE__ */ new Date(0)).toISOString(),
450
+ ...reason ? { reason } : {}
451
+ });
452
+ }
453
+ };
454
+
455
+ // ../../packages/config/src/index.ts
456
+ var InMemoryConfigStore = class {
457
+ values = /* @__PURE__ */ new Map();
458
+ async get(key) {
459
+ return this.values.get(key);
460
+ }
461
+ async set(key, value) {
462
+ this.values.set(key, value);
463
+ }
464
+ async profile() {
465
+ return {
466
+ name: "default",
467
+ values: Object.fromEntries(this.values)
468
+ };
469
+ }
470
+ };
471
+
472
+ // ../../packages/context-engine/src/index.ts
473
+ var InMemoryContextEngine = class {
474
+ nodes = /* @__PURE__ */ new Map();
475
+ async addNode(sessionId, node) {
476
+ const current = this.nodes.get(sessionId) ?? [];
477
+ current.push(node);
478
+ this.nodes.set(sessionId, current);
479
+ }
480
+ async project(sessionId, prompt) {
481
+ const nodes = this.nodes.get(sessionId) ?? [];
482
+ return {
483
+ prompt: [...nodes.map((node) => node.content), prompt].join("\n"),
484
+ nodes
485
+ };
486
+ }
487
+ };
488
+
489
+ // ../../packages/credential-auth-management/src/index.ts
490
+ var FakeCredentialManager = class {
491
+ records = /* @__PURE__ */ new Map();
492
+ async resolve(ref) {
493
+ return this.records.get(ref);
494
+ }
495
+ async put(record) {
496
+ this.records.set(record.ref, record);
497
+ }
498
+ redact(value) {
499
+ return value.length <= 4 ? "****" : `${value.slice(0, 2)}****${value.slice(-2)}`;
500
+ }
501
+ };
502
+
503
+ // ../../packages/distribution-update-management/src/index.ts
504
+ var currentRelease = {
505
+ version: "0.1.0",
506
+ channel: "dev",
507
+ signedMetadata: "development-unsigned",
508
+ compatibility: ["framework-0.1"]
509
+ };
510
+ var StaticDistributionUpdateManager = class {
511
+ async current() {
512
+ return currentRelease;
513
+ }
514
+ async checkForUpdate() {
515
+ return void 0;
516
+ }
517
+ async catalogs() {
518
+ return [];
519
+ }
520
+ };
521
+
522
+ // ../../packages/evolution-engine/src/index.ts
523
+ var InMemoryEvolutionEngine = class {
524
+ gates = /* @__PURE__ */ new Map();
525
+ migrations = [];
526
+ async isEnabled(gate) {
527
+ return this.gates.get(gate)?.enabled ?? false;
528
+ }
529
+ async setGate(gate) {
530
+ this.gates.set(gate.name, gate);
531
+ }
532
+ async checkCompatibility(subject) {
533
+ return typeof subject.schemaVersion === "string" ? [] : ["missing schemaVersion"];
534
+ }
535
+ async recordMigration(record) {
536
+ this.migrations.push(record);
537
+ }
538
+ };
539
+
540
+ // ../../packages/extension-system/src/index.ts
541
+ var InMemoryExtensionManager = class {
542
+ manifests = /* @__PURE__ */ new Map();
543
+ async load(manifest) {
544
+ if (manifest.trust === "untrusted") throw new Error("Untrusted extensions are disabled by default");
545
+ this.manifests.set(manifest.id, manifest);
546
+ }
547
+ async list() {
548
+ return [...this.manifests.values()];
549
+ }
550
+ async contributions(point) {
551
+ return [...this.manifests.values()].map((manifest) => manifest.contributions[point]).filter((value) => typeof value === "object" && value !== null && !Array.isArray(value));
552
+ }
553
+ };
554
+
555
+ // ../../packages/hook-system/src/index.ts
556
+ var InMemoryHookSystem = class {
557
+ manifests = [];
558
+ handlers = /* @__PURE__ */ new Map();
559
+ async register(manifest, handler) {
560
+ this.manifests.push(manifest);
561
+ if (handler) this.handlers.set(manifest.id, handler);
562
+ }
563
+ async run(point, input) {
564
+ const hooks = this.manifests.filter((manifest) => manifest.point === point).sort((a, b) => a.order - b.order);
565
+ const results = [];
566
+ for (const hook of hooks) {
567
+ const handler = this.handlers.get(hook.id);
568
+ if (handler) results.push(await handler(input));
569
+ }
570
+ return results;
571
+ }
572
+ };
573
+
574
+ // ../../packages/mcp-gateway/src/index.ts
575
+ var FakeMcpGateway = class {
576
+ servers = /* @__PURE__ */ new Map();
577
+ async connect(manifest) {
578
+ if (manifest.trust === "untrusted") throw new Error("Untrusted MCP servers are disabled by default");
579
+ this.servers.set(manifest.id, manifest);
580
+ }
581
+ async listTools(namespace) {
582
+ return [...this.servers.values()].filter((server) => !namespace || server.namespace === namespace).map((server) => ({ namespace: server.namespace, name: "fake.tool" }));
583
+ }
584
+ async callTool(namespace, name, input) {
585
+ return { namespace, name, input, ok: true };
586
+ }
587
+ };
588
+
589
+ // ../../packages/memory-cache-management/src/index.ts
590
+ var InMemoryMemoryManager = class {
591
+ entries = [];
592
+ async put(entry) {
593
+ this.entries.push(entry);
594
+ }
595
+ async query(scope) {
596
+ return this.entries.filter((entry) => entry.scope === scope);
597
+ }
598
+ };
599
+ var InMemoryCacheManager = class {
600
+ entries = /* @__PURE__ */ new Map();
601
+ async get(key) {
602
+ return this.entries.get(key);
603
+ }
604
+ async set(entry) {
605
+ this.entries.set(entry.key, entry);
606
+ }
607
+ async invalidate(namespace) {
608
+ let count = 0;
609
+ for (const [key, entry] of this.entries) {
610
+ if (entry.namespace === namespace) {
611
+ this.entries.delete(key);
612
+ count++;
613
+ }
614
+ }
615
+ return count;
616
+ }
617
+ };
618
+
619
+ // ../../packages/observability/src/index.ts
620
+ var InMemoryObservabilitySink = class {
621
+ events = [];
622
+ async emit(event) {
623
+ this.events.push(event);
624
+ }
625
+ async drain() {
626
+ return [...this.events];
627
+ }
628
+ };
629
+
630
+ // ../../packages/platform-abstraction/src/index.ts
631
+ import { readFile as fsReadFile, writeFile as fsWriteFile, readdir } from "node:fs/promises";
632
+ import { join, resolve } from "node:path";
633
+ import { spawn } from "node:child_process";
634
+ var NodePlatformRuntime = class {
635
+ os;
636
+ constructor(os = process.platform === "win32" ? "windows" : process.platform === "darwin" ? "macos" : "linux") {
637
+ this.os = os;
638
+ }
639
+ resolvePath(...parts) {
640
+ return resolve(...parts);
641
+ }
642
+ async readFile(path) {
643
+ return fsReadFile(path, "utf8");
644
+ }
645
+ async writeFile(path, content) {
646
+ await fsWriteFile(path, content, "utf8");
647
+ }
648
+ async findFiles(pattern, root) {
649
+ const files = [];
650
+ await walk(root, files);
651
+ return files.filter((file) => file.includes(pattern));
652
+ }
653
+ async searchText(pattern, root) {
654
+ const files = [];
655
+ await walk(root, files);
656
+ const results = [];
657
+ for (const file of files) {
658
+ const content = await fsReadFile(file, "utf8").catch(() => "");
659
+ const lines = content.split(/\r?\n/);
660
+ lines.forEach((line, index) => {
661
+ if (line.includes(pattern)) {
662
+ results.push({
663
+ path: file,
664
+ line: index + 1,
665
+ text: line,
666
+ engine: "js",
667
+ fallbackReason: "deterministic-js-fallback"
668
+ });
669
+ }
670
+ });
671
+ }
672
+ return results;
673
+ }
674
+ async runProcess(command, args, options = {}) {
675
+ return new Promise((resolvePromise) => {
676
+ const child = spawn(command, [...args], {
677
+ cwd: typeof options.cwd === "string" ? options.cwd : void 0,
678
+ shell: false
679
+ });
680
+ let stdout = "";
681
+ let stderr = "";
682
+ child.stdout.on("data", (chunk) => {
683
+ stdout += String(chunk);
684
+ });
685
+ child.stderr.on("data", (chunk) => {
686
+ stderr += String(chunk);
687
+ });
688
+ child.on("close", (exitCode) => resolvePromise({ exitCode: exitCode ?? 0, stdout, stderr }));
689
+ child.on("error", (error) => resolvePromise({ exitCode: 1, stdout, stderr: error.message }));
690
+ });
691
+ }
692
+ async availability() {
693
+ return {
694
+ os: this.os,
695
+ searchFallbacks: ["rg", "grep", "select-string", "js"]
696
+ };
697
+ }
698
+ };
699
+ var FakePlatformRuntime = class extends NodePlatformRuntime {
700
+ constructor(os = "fake") {
701
+ super(os);
702
+ }
703
+ async runProcess(command, args) {
704
+ return {
705
+ exitCode: 0,
706
+ stdout: JSON.stringify({ command, args }),
707
+ stderr: ""
708
+ };
709
+ }
710
+ };
711
+ async function walk(root, files) {
712
+ for (const entry of await readdir(root, { withFileTypes: true }).catch(() => [])) {
713
+ if (entry.name === "node_modules" || entry.name === ".git") continue;
714
+ const path = join(root, entry.name);
715
+ if (entry.isDirectory()) {
716
+ await walk(path, files);
717
+ } else {
718
+ files.push(path);
719
+ }
720
+ }
721
+ }
722
+
723
+ // ../../packages/plugin-system/src/index.ts
724
+ var InMemoryPluginManager = class {
725
+ plugins = /* @__PURE__ */ new Map();
726
+ async install(manifest) {
727
+ this.plugins.set(manifest.id, manifest);
728
+ return { added: manifest.permissions, removed: [] };
729
+ }
730
+ async uninstall(id) {
731
+ this.plugins.delete(id);
732
+ }
733
+ async list() {
734
+ return [...this.plugins.values()];
735
+ }
736
+ };
737
+
738
+ // ../../packages/policy-sandbox/src/index.ts
739
+ var DefaultPolicyEngine = class {
740
+ async decide(request) {
741
+ if (request.action.includes("delete") || request.action.includes("secret")) {
742
+ return { action: "ask", reason: "Potentially sensitive action requires approval" };
743
+ }
744
+ if (request.resource.includes("untrusted")) {
745
+ return { action: "quarantine", reason: "Untrusted resource" };
746
+ }
747
+ return { action: "allow", reason: "Default development policy" };
748
+ }
749
+ };
750
+ var HeadlessApprovalBroker = class {
751
+ constructor(defaultApproved = false) {
752
+ this.defaultApproved = defaultApproved;
753
+ }
754
+ defaultApproved;
755
+ async requestApproval(request) {
756
+ return {
757
+ approved: this.defaultApproved,
758
+ reason: this.defaultApproved ? `Approved: ${request.prompt}` : `Denied by headless default: ${request.prompt}`
759
+ };
760
+ }
761
+ };
762
+ var DevelopmentSandboxRuntime = class {
763
+ async *run(request) {
764
+ yield {
765
+ kind: "recorded",
766
+ mode: "development",
767
+ metadata: {
768
+ command: request.command,
769
+ args: request.args,
770
+ controls: request.controls,
771
+ enforcement: "not-production"
772
+ }
773
+ };
774
+ }
775
+ };
776
+
777
+ // ../../packages/remote-runtime-connectivity/src/index.ts
778
+ var NoopRemoteRuntimeConnectivity = class {
779
+ bindings = /* @__PURE__ */ new Map();
780
+ async bind(binding) {
781
+ this.bindings.set(binding.id, binding);
782
+ }
783
+ async reconnect(id) {
784
+ return this.bindings.get(id);
785
+ }
786
+ async cancelRemote(_id, _reason) {
787
+ }
788
+ };
789
+
790
+ // ../../packages/runtime-message-bus/src/index.ts
791
+ var InMemoryRuntimeMessageBus = class {
792
+ records = [];
793
+ subscribers = /* @__PURE__ */ new Map();
794
+ maxRecords;
795
+ constructor(options = {}) {
796
+ this.maxRecords = options.maxRecords ?? 1e3;
797
+ }
798
+ async publish(envelope) {
799
+ if (this.records.length >= this.maxRecords) {
800
+ throw new Error("BUS_BACKPRESSURE");
801
+ }
802
+ if (envelope.replayable) {
803
+ this.records.push(envelope);
804
+ }
805
+ for (const listener of this.subscribers.get(envelope.topic.name) ?? []) {
806
+ listener(envelope);
807
+ }
808
+ }
809
+ async *subscribe(subscription) {
810
+ const queue = [];
811
+ const listener = (envelope) => queue.push(envelope);
812
+ const listeners = this.subscribers.get(subscription.topic) ?? [];
813
+ listeners.push(listener);
814
+ this.subscribers.set(subscription.topic, listeners);
815
+ try {
816
+ while (true) {
817
+ if (queue.length > 0) {
818
+ yield queue.shift();
819
+ } else {
820
+ await new Promise((resolve2) => setTimeout(resolve2, 0));
821
+ }
822
+ }
823
+ } finally {
824
+ const current = this.subscribers.get(subscription.topic) ?? [];
825
+ this.subscribers.set(
826
+ subscription.topic,
827
+ current.filter((item) => item !== listener)
828
+ );
829
+ }
830
+ }
831
+ getReplayRecords(sessionId) {
832
+ return sessionId ? this.records.filter((record) => record.sessionId === sessionId) : [...this.records];
833
+ }
834
+ };
835
+
836
+ // ../../packages/session-store/src/index.ts
837
+ var InMemorySessionStore = class {
838
+ next = 1;
839
+ eventsBySession = /* @__PURE__ */ new Map();
840
+ async create(_metadata = {}) {
841
+ const id = asId(`session-${this.next++}`);
842
+ this.eventsBySession.set(id, []);
843
+ return id;
844
+ }
845
+ async append(event) {
846
+ const events = this.eventsBySession.get(event.sessionId) ?? [];
847
+ events.push(event);
848
+ this.eventsBySession.set(event.sessionId, events);
849
+ }
850
+ async events(sessionId) {
851
+ return [...this.eventsBySession.get(sessionId) ?? []];
852
+ }
853
+ async snapshot(sessionId, payload) {
854
+ return {
855
+ sessionId,
856
+ eventCount: this.eventsBySession.get(sessionId)?.length ?? 0,
857
+ checkpointId: `checkpoint-${sessionId}`,
858
+ payload
859
+ };
860
+ }
861
+ };
862
+
863
+ // ../../packages/skill-system/src/index.ts
864
+ var InMemorySkillSystem = class {
865
+ manifests = /* @__PURE__ */ new Map();
866
+ async register(manifest) {
867
+ this.manifests.set(manifest.id, manifest);
868
+ }
869
+ async activate(name, _context) {
870
+ return [...this.manifests.values()].find((manifest) => manifest.name === name && manifest.trust !== "untrusted");
871
+ }
872
+ async list() {
873
+ return [...this.manifests.values()];
874
+ }
875
+ };
876
+
877
+ // ../../packages/usage-budget-management/src/index.ts
878
+ var InMemoryUsageBudgetManager = class {
879
+ records = [];
880
+ async record(record) {
881
+ this.records.push(record);
882
+ }
883
+ async check() {
884
+ return { allowed: true };
885
+ }
886
+ async total(sessionId) {
887
+ return this.records.filter((record) => record.sessionId === sessionId).reduce(
888
+ (acc, record) => ({
889
+ sessionId,
890
+ inputTokens: acc.inputTokens + record.inputTokens,
891
+ outputTokens: acc.outputTokens + record.outputTokens,
892
+ costMicros: acc.costMicros + record.costMicros,
893
+ elapsedMs: acc.elapsedMs + record.elapsedMs
894
+ }),
895
+ { sessionId, inputTokens: 0, outputTokens: 0, costMicros: 0, elapsedMs: 0 }
896
+ );
897
+ }
898
+ };
899
+
900
+ // ../../packages/workflow-orchestration/src/index.ts
901
+ var SingleTurnWorkflowOrchestrator = class {
902
+ async createGraph(request) {
903
+ const step = {
904
+ id: asId("step-model-response"),
905
+ name: "model-response",
906
+ dependsOn: [],
907
+ status: "pending"
908
+ };
909
+ return {
910
+ id: asId(`workflow-${request.sessionId}`),
911
+ taskId: asId(`task-${request.sessionId}`),
912
+ steps: [step]
913
+ };
914
+ }
915
+ async *runGraph(graph, request) {
916
+ yield {
917
+ kind: "workflow.step",
918
+ sessionId: request.sessionId,
919
+ taskId: graph.taskId,
920
+ trace: {
921
+ traceId: asId(`trace-${graph.id}`),
922
+ spanId: asId(`span-${graph.id}`),
923
+ correlationId: asId(`corr-${graph.id}`),
924
+ sessionId: request.sessionId
925
+ },
926
+ data: {
927
+ workflowId: graph.id,
928
+ stepId: graph.steps[0]?.id ?? "",
929
+ status: "running"
930
+ }
931
+ };
932
+ }
933
+ async createCheckpoint(graph) {
934
+ return {
935
+ id: `checkpoint-${graph.id}`,
936
+ sessionId: asId(String(graph.taskId).replace("task-", "")),
937
+ workflowId: graph.id,
938
+ createdAt: (/* @__PURE__ */ new Date(0)).toISOString(),
939
+ metadata: { taskId: graph.taskId }
940
+ };
941
+ }
942
+ async validateGraph(graph) {
943
+ return graph.steps.length === 0 ? ["workflow graph must contain at least one step"] : [];
944
+ }
945
+ };
946
+
947
+ // ../../packages/workspace-state-management/src/index.ts
948
+ import { createHash } from "node:crypto";
949
+ import { readFile } from "node:fs/promises";
950
+ var InMemoryWorkspaceStateManager = class {
951
+ transactions = [];
952
+ async identify(roots) {
953
+ return {
954
+ id: asId(`workspace-${createHash("sha1").update(roots.join("|")).digest("hex").slice(0, 8)}`),
955
+ roots,
956
+ trusted: true
957
+ };
958
+ }
959
+ async snapshot(path) {
960
+ const content = await readFile(path, "utf8").catch(() => "");
961
+ return {
962
+ path,
963
+ contentHash: createHash("sha1").update(content).digest("hex"),
964
+ capturedAt: (/* @__PURE__ */ new Date(0)).toISOString()
965
+ };
966
+ }
967
+ async transact(transaction) {
968
+ this.transactions.push(transaction);
969
+ }
970
+ };
971
+
972
+ // ../../packages/testing-regression/src/fakes/index.ts
973
+ function createDeterministicRuntimeDependencies() {
974
+ const runtimePlaceholder = async () => ({
975
+ envelope: {},
976
+ ok: false,
977
+ error: {
978
+ code: "ROUTER_NOT_BOUND",
979
+ message: "Protocol router is not bound to runtime in deterministic dependencies",
980
+ retryable: false,
981
+ redaction: { class: "public" }
982
+ }
983
+ });
984
+ return {
985
+ protocol: new PipelineProtocolRouter([], runtimePlaceholder),
986
+ bus: new InMemoryRuntimeMessageBus(),
987
+ workflow: new SingleTurnWorkflowOrchestrator(),
988
+ concurrency: new DeterministicScheduler(),
989
+ agents: new InMemoryAgentManager(),
990
+ models: new DeterministicMockModelGateway(),
991
+ capabilities: new InMemoryCapabilityRegistry(),
992
+ commands: new InMemoryCommandSystem(),
993
+ skills: new InMemorySkillSystem(),
994
+ hooks: new InMemoryHookSystem(),
995
+ mcp: new FakeMcpGateway(),
996
+ plugins: new InMemoryPluginManager(),
997
+ extensions: new InMemoryExtensionManager(),
998
+ context: new InMemoryContextEngine(),
999
+ memory: new InMemoryMemoryManager(),
1000
+ cache: new InMemoryCacheManager(),
1001
+ credentials: new FakeCredentialManager(),
1002
+ usage: new InMemoryUsageBudgetManager(),
1003
+ workspaceState: new InMemoryWorkspaceStateManager(),
1004
+ policy: new DefaultPolicyEngine(),
1005
+ approvals: new HeadlessApprovalBroker(false),
1006
+ sandbox: new DevelopmentSandboxRuntime(),
1007
+ sessions: new InMemorySessionStore(),
1008
+ platform: new FakePlatformRuntime(),
1009
+ evolution: new InMemoryEvolutionEngine(),
1010
+ codeIntelligence: new NullCodeIntelligenceService(),
1011
+ remote: new NoopRemoteRuntimeConnectivity(),
1012
+ distribution: new StaticDistributionUpdateManager(),
1013
+ config: new InMemoryConfigStore(),
1014
+ observability: new InMemoryObservabilitySink(),
1015
+ regression: new DeterministicRegressionHarness()
1016
+ };
1017
+ }
1018
+
1019
+ // src/index.ts
1020
+ function parseCliArgs(args) {
1021
+ const promptIndex = args.indexOf("-p");
1022
+ const prompt = promptIndex >= 0 ? args[promptIndex + 1] ?? "" : args.join(" ");
1023
+ const outputFlagIndex = args.indexOf("--output");
1024
+ const output = outputFlagIndex >= 0 && args[outputFlagIndex + 1] === "stream-json" ? "stream-json" : "text";
1025
+ return { prompt, output };
1026
+ }
1027
+ function renderText(event) {
1028
+ if (event.kind === "model.delta") return String(event.data.text ?? "");
1029
+ if (event.kind === "turn.completed") return "[completed]";
1030
+ return `[${event.kind}]`;
1031
+ }
1032
+ function renderStreamJson(event) {
1033
+ return JSON.stringify(event);
1034
+ }
1035
+ async function runCli(args, write = console.log) {
1036
+ const options = parseCliArgs(args);
1037
+ const runtime = createHeadlessRuntime(createDeterministicRuntimeDependencies());
1038
+ for await (const event of runtime.runTurn({ prompt: options.prompt })) {
1039
+ write(options.output === "stream-json" ? renderStreamJson(event) : renderText(event));
1040
+ }
1041
+ await runtime.dispose();
1042
+ }
1043
+ var entryPath = process.argv[1]?.replace(/\\/g, "/") ?? "";
1044
+ if (entryPath.endsWith("/src/apps/cli/src/index.ts") || entryPath.endsWith("/src/apps/cli/src/index.js")) {
1045
+ await runCli(process.argv.slice(2));
1046
+ }
1047
+ export {
1048
+ parseCliArgs,
1049
+ renderStreamJson,
1050
+ renderText,
1051
+ runCli
1052
+ };
package/package.json ADDED
@@ -0,0 +1,22 @@
1
+ {
2
+ "name": "deekseek-cli",
3
+ "version": "0.1.0",
4
+ "type": "module",
5
+ "exports": {
6
+ ".": "./dist/index.js"
7
+ },
8
+ "files": [
9
+ "dist",
10
+ "README.md"
11
+ ],
12
+ "scripts": {
13
+ "build": "esbuild src/index.ts --bundle --platform=node --format=esm --target=node22 --outfile=dist/index.js --banner:js=\"#!/usr/bin/env node\""
14
+ },
15
+ "dependencies": {},
16
+ "publishConfig": {
17
+ "access": "public"
18
+ },
19
+ "bin": {
20
+ "deepseek": "./dist/index.js"
21
+ }
22
+ }