tarsk 0.3.31 → 0.3.32
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/dist/index.js
CHANGED
|
@@ -1,7 +1,95 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { createRequire } from "node:module";
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __export = (target, all) => {
|
|
5
|
+
for (var name in all)
|
|
6
|
+
__defProp(target, name, {
|
|
7
|
+
get: all[name],
|
|
8
|
+
enumerable: true,
|
|
9
|
+
configurable: true,
|
|
10
|
+
set: (newValue) => all[name] = () => newValue
|
|
11
|
+
});
|
|
12
|
+
};
|
|
13
|
+
var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
|
|
3
14
|
var __require = /* @__PURE__ */ createRequire(import.meta.url);
|
|
4
15
|
|
|
16
|
+
// ../shared/dist/models.js
|
|
17
|
+
var AVAILABLE_PROGRAMS;
|
|
18
|
+
var init_models = __esm(() => {
|
|
19
|
+
AVAILABLE_PROGRAMS = ["VS Code", "Cursor", "Windsurf", "Xcode", "Android Studio", "Kiro"];
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
// ../shared/dist/commit-methods.js
|
|
23
|
+
function getCommitMethodConfig(methodId) {
|
|
24
|
+
return CommitMethodConfigs[methodId];
|
|
25
|
+
}
|
|
26
|
+
function isValidCommitMethod(value) {
|
|
27
|
+
return typeof value === "string" && Object.values(CommitMethods).includes(value);
|
|
28
|
+
}
|
|
29
|
+
var CommitMethods, CommitMethodConfigs;
|
|
30
|
+
var init_commit_methods = __esm(() => {
|
|
31
|
+
(function(CommitMethods2) {
|
|
32
|
+
CommitMethods2["PullRequest"] = "pull-request";
|
|
33
|
+
CommitMethods2["Direct"] = "direct";
|
|
34
|
+
})(CommitMethods || (CommitMethods = {}));
|
|
35
|
+
CommitMethodConfigs = {
|
|
36
|
+
[CommitMethods.PullRequest]: {
|
|
37
|
+
id: CommitMethods.PullRequest,
|
|
38
|
+
name: "Pull Requests",
|
|
39
|
+
description: "Creates a feature branch and allows you to create pull requests."
|
|
40
|
+
},
|
|
41
|
+
[CommitMethods.Direct]: {
|
|
42
|
+
id: CommitMethods.Direct,
|
|
43
|
+
name: "Direct Commits",
|
|
44
|
+
description: "Commits directly to the main branch without creating feature branches."
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
// ../shared/dist/package-managers.js
|
|
50
|
+
function getSetupScriptForPackageManager(pm) {
|
|
51
|
+
return PACKAGE_MANAGER_SETUP_SCRIPTS[pm];
|
|
52
|
+
}
|
|
53
|
+
function isValidPackageManager(value) {
|
|
54
|
+
return typeof value === "string" && PACKAGE_MANAGER_IDS.includes(value);
|
|
55
|
+
}
|
|
56
|
+
var PACKAGE_MANAGER_CONFIGS, PACKAGE_MANAGER_IDS, PACKAGE_MANAGER_SETUP_SCRIPTS;
|
|
57
|
+
var init_package_managers = __esm(() => {
|
|
58
|
+
PACKAGE_MANAGER_CONFIGS = {
|
|
59
|
+
bun: { id: "bun", label: "bun" },
|
|
60
|
+
npm: { id: "npm", label: "npm" },
|
|
61
|
+
yarn: { id: "yarn", label: "yarn" },
|
|
62
|
+
pnpm: { id: "pnpm", label: "pnpm" }
|
|
63
|
+
};
|
|
64
|
+
PACKAGE_MANAGER_IDS = ["bun", "npm", "yarn", "pnpm"];
|
|
65
|
+
PACKAGE_MANAGER_SETUP_SCRIPTS = {
|
|
66
|
+
bun: "bun install",
|
|
67
|
+
npm: "npm install",
|
|
68
|
+
yarn: "yarn install",
|
|
69
|
+
pnpm: "pnpm install"
|
|
70
|
+
};
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
// ../shared/dist/index.js
|
|
74
|
+
var exports_dist = {};
|
|
75
|
+
__export(exports_dist, {
|
|
76
|
+
isValidPackageManager: () => isValidPackageManager,
|
|
77
|
+
isValidCommitMethod: () => isValidCommitMethod,
|
|
78
|
+
getSetupScriptForPackageManager: () => getSetupScriptForPackageManager,
|
|
79
|
+
getCommitMethodConfig: () => getCommitMethodConfig,
|
|
80
|
+
PACKAGE_MANAGER_SETUP_SCRIPTS: () => PACKAGE_MANAGER_SETUP_SCRIPTS,
|
|
81
|
+
PACKAGE_MANAGER_IDS: () => PACKAGE_MANAGER_IDS,
|
|
82
|
+
PACKAGE_MANAGER_CONFIGS: () => PACKAGE_MANAGER_CONFIGS,
|
|
83
|
+
CommitMethods: () => CommitMethods,
|
|
84
|
+
CommitMethodConfigs: () => CommitMethodConfigs,
|
|
85
|
+
AVAILABLE_PROGRAMS: () => AVAILABLE_PROGRAMS
|
|
86
|
+
});
|
|
87
|
+
var init_dist = __esm(() => {
|
|
88
|
+
init_models();
|
|
89
|
+
init_commit_methods();
|
|
90
|
+
init_package_managers();
|
|
91
|
+
});
|
|
92
|
+
|
|
5
93
|
// src/index.ts
|
|
6
94
|
import { Hono as Hono10 } from "hono";
|
|
7
95
|
import { cors } from "hono/cors";
|
|
@@ -9,7 +97,7 @@ import { serve } from "@hono/node-server";
|
|
|
9
97
|
import { serveStatic } from "@hono/node-server/serve-static";
|
|
10
98
|
import path3 from "path";
|
|
11
99
|
import open2 from "open";
|
|
12
|
-
import { fileURLToPath as
|
|
100
|
+
import { fileURLToPath as fileURLToPath3 } from "url";
|
|
13
101
|
|
|
14
102
|
// src/managers/project-manager.ts
|
|
15
103
|
import { randomUUID } from "crypto";
|
|
@@ -245,43 +333,9 @@ async function suggestRunCommand(projectPath) {
|
|
|
245
333
|
}
|
|
246
334
|
}
|
|
247
335
|
|
|
248
|
-
//
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
var CommitMethods;
|
|
252
|
-
(function(CommitMethods2) {
|
|
253
|
-
CommitMethods2["PullRequest"] = "pull-request";
|
|
254
|
-
CommitMethods2["Direct"] = "direct";
|
|
255
|
-
})(CommitMethods || (CommitMethods = {}));
|
|
256
|
-
var CommitMethodConfigs = {
|
|
257
|
-
[CommitMethods.PullRequest]: {
|
|
258
|
-
id: CommitMethods.PullRequest,
|
|
259
|
-
name: "Pull Requests",
|
|
260
|
-
description: "Creates a feature branch and allows you to create pull requests."
|
|
261
|
-
},
|
|
262
|
-
[CommitMethods.Direct]: {
|
|
263
|
-
id: CommitMethods.Direct,
|
|
264
|
-
name: "Direct Commits",
|
|
265
|
-
description: "Commits directly to the main branch without creating feature branches."
|
|
266
|
-
}
|
|
267
|
-
};
|
|
268
|
-
function isValidCommitMethod(value) {
|
|
269
|
-
return typeof value === "string" && Object.values(CommitMethods).includes(value);
|
|
270
|
-
}
|
|
271
|
-
// ../shared/dist/package-managers.js
|
|
272
|
-
var PACKAGE_MANAGER_IDS = ["bun", "npm", "yarn", "pnpm"];
|
|
273
|
-
var PACKAGE_MANAGER_SETUP_SCRIPTS = {
|
|
274
|
-
bun: "bun install",
|
|
275
|
-
npm: "npm install",
|
|
276
|
-
yarn: "yarn install",
|
|
277
|
-
pnpm: "pnpm install"
|
|
278
|
-
};
|
|
279
|
-
function getSetupScriptForPackageManager(pm) {
|
|
280
|
-
return PACKAGE_MANAGER_SETUP_SCRIPTS[pm];
|
|
281
|
-
}
|
|
282
|
-
function isValidPackageManager(value) {
|
|
283
|
-
return typeof value === "string" && PACKAGE_MANAGER_IDS.includes(value);
|
|
284
|
-
}
|
|
336
|
+
// src/managers/project-manager.ts
|
|
337
|
+
init_dist();
|
|
338
|
+
|
|
285
339
|
// src/scaffold/runner.ts
|
|
286
340
|
import { readFileSync, existsSync } from "fs";
|
|
287
341
|
import { join as join2, dirname } from "path";
|
|
@@ -541,6 +595,7 @@ function getScaffoldTemplates() {
|
|
|
541
595
|
registerScaffoldHandler("capacitor-plugin", capacitorPluginHandler);
|
|
542
596
|
|
|
543
597
|
// src/managers/project-manager.ts
|
|
598
|
+
init_dist();
|
|
544
599
|
import open from "open";
|
|
545
600
|
|
|
546
601
|
class ProjectManagerImpl {
|
|
@@ -1856,7 +1911,9 @@ import { Agent } from "@mariozechner/pi-agent-core";
|
|
|
1856
1911
|
import {
|
|
1857
1912
|
getModel
|
|
1858
1913
|
} from "@mariozechner/pi-ai";
|
|
1859
|
-
import { resolve, isAbsolute as isAbsolute2 } from "path";
|
|
1914
|
+
import { resolve, dirname as dirname5, isAbsolute as isAbsolute2 } from "path";
|
|
1915
|
+
import { readFileSync as readFileSync3 } from "fs";
|
|
1916
|
+
import { fileURLToPath as fileURLToPath2 } from "url";
|
|
1860
1917
|
|
|
1861
1918
|
// src/tools/bash.ts
|
|
1862
1919
|
import { randomBytes as randomBytes2 } from "node:crypto";
|
|
@@ -3503,6 +3560,20 @@ var getErrorCode = (error) => {
|
|
|
3503
3560
|
}
|
|
3504
3561
|
return;
|
|
3505
3562
|
};
|
|
3563
|
+
function loadAgentSystemPrompt() {
|
|
3564
|
+
const DEFAULT_PROMPT = "You are a helpful coding assistant. You have access to read, bash, edit, and write tools. Use them to explore and modify the codebase as needed.";
|
|
3565
|
+
try {
|
|
3566
|
+
const __filename2 = fileURLToPath2(import.meta.url);
|
|
3567
|
+
const __dirname3 = dirname5(__filename2);
|
|
3568
|
+
const agentsPath = resolve(__dirname3, "../../agents.md");
|
|
3569
|
+
const content = readFileSync3(agentsPath, "utf-8");
|
|
3570
|
+
console.log("[ai] Successfully loaded agents.md for system prompt");
|
|
3571
|
+
return content.trim();
|
|
3572
|
+
} catch (error) {
|
|
3573
|
+
console.warn("[ai] Could not load agents.md, using default prompt:", error);
|
|
3574
|
+
return DEFAULT_PROMPT;
|
|
3575
|
+
}
|
|
3576
|
+
}
|
|
3506
3577
|
|
|
3507
3578
|
class PiExecutorImpl {
|
|
3508
3579
|
metadataManager;
|
|
@@ -3549,9 +3620,11 @@ class PiExecutorImpl {
|
|
|
3549
3620
|
provider: resolvedModel.provider
|
|
3550
3621
|
});
|
|
3551
3622
|
const tools = createCodingTools(cwd);
|
|
3623
|
+
const systemPrompt = loadAgentSystemPrompt();
|
|
3624
|
+
console.log("[ai] System prompt loaded from agents.md");
|
|
3552
3625
|
const agent = new Agent({
|
|
3553
3626
|
initialState: {
|
|
3554
|
-
systemPrompt
|
|
3627
|
+
systemPrompt,
|
|
3555
3628
|
model: resolvedModel,
|
|
3556
3629
|
tools
|
|
3557
3630
|
},
|
|
@@ -3698,7 +3771,7 @@ class PiExecutorImpl {
|
|
|
3698
3771
|
|
|
3699
3772
|
// src/managers/conversation-manager.ts
|
|
3700
3773
|
import { promises as fs2 } from "fs";
|
|
3701
|
-
import { join as join8, dirname as
|
|
3774
|
+
import { join as join8, dirname as dirname6 } from "path";
|
|
3702
3775
|
import { randomUUID as randomUUID3 } from "crypto";
|
|
3703
3776
|
var CONVERSATION_FILE = "conversation-history.json";
|
|
3704
3777
|
|
|
@@ -3772,9 +3845,19 @@ class ConversationManagerImpl {
|
|
|
3772
3845
|
}
|
|
3773
3846
|
async saveConversationHistory(threadPath, history) {
|
|
3774
3847
|
const filePath = this.getConversationFilePath(threadPath);
|
|
3775
|
-
await fs2.mkdir(
|
|
3848
|
+
await fs2.mkdir(dirname6(filePath), { recursive: true });
|
|
3776
3849
|
await fs2.writeFile(filePath, JSON.stringify(history, null, 2), "utf-8");
|
|
3777
3850
|
}
|
|
3851
|
+
async clearChatHistory(threadPath) {
|
|
3852
|
+
const filePath = this.getConversationFilePath(threadPath);
|
|
3853
|
+
try {
|
|
3854
|
+
await fs2.unlink(filePath);
|
|
3855
|
+
} catch (error) {
|
|
3856
|
+
if (error instanceof Error && error.code !== "ENOENT") {
|
|
3857
|
+
throw error;
|
|
3858
|
+
}
|
|
3859
|
+
}
|
|
3860
|
+
}
|
|
3778
3861
|
getConversationFilePath(threadPath) {
|
|
3779
3862
|
const threadId = threadPath.split(/[\\/]/).pop() || "unknown";
|
|
3780
3863
|
const conversationsDir = join8(this.metadataDir, "conversations");
|
|
@@ -3802,6 +3885,7 @@ class ProcessingStateManagerImpl {
|
|
|
3802
3885
|
}
|
|
3803
3886
|
|
|
3804
3887
|
// src/routes/projects.ts
|
|
3888
|
+
init_dist();
|
|
3805
3889
|
import { Hono } from "hono";
|
|
3806
3890
|
|
|
3807
3891
|
// src/lib/stream-helper.ts
|
|
@@ -3844,6 +3928,7 @@ class ResponseBuilder {
|
|
|
3844
3928
|
}
|
|
3845
3929
|
|
|
3846
3930
|
// src/routes/projects.ts
|
|
3931
|
+
init_dist();
|
|
3847
3932
|
function createProjectRoutes(projectManager, threadManager) {
|
|
3848
3933
|
const router = new Hono;
|
|
3849
3934
|
router.post("/", async (c) => {
|
|
@@ -4454,6 +4539,52 @@ function createThreadRoutes(threadManager, gitManager, conversationManager) {
|
|
|
4454
4539
|
return c.json(response, statusCode);
|
|
4455
4540
|
}
|
|
4456
4541
|
});
|
|
4542
|
+
router.post("/:id/open", async (c) => {
|
|
4543
|
+
try {
|
|
4544
|
+
const threadId = c.req.param("id");
|
|
4545
|
+
const body = await c.req.json();
|
|
4546
|
+
const { program } = body;
|
|
4547
|
+
if (!threadId) {
|
|
4548
|
+
const { response: response2, statusCode: statusCode2 } = ResponseBuilder.error("INVALID_REQUEST", "Thread ID is required", 400);
|
|
4549
|
+
return c.json(response2, statusCode2);
|
|
4550
|
+
}
|
|
4551
|
+
if (!program) {
|
|
4552
|
+
const { response: response2, statusCode: statusCode2 } = ResponseBuilder.error("INVALID_REQUEST", "Program is required", 400);
|
|
4553
|
+
return c.json(response2, statusCode2);
|
|
4554
|
+
}
|
|
4555
|
+
const { AVAILABLE_PROGRAMS: AVAILABLE_PROGRAMS2 } = await Promise.resolve().then(() => (init_dist(), exports_dist));
|
|
4556
|
+
if (!AVAILABLE_PROGRAMS2.includes(program)) {
|
|
4557
|
+
const { response: response2, statusCode: statusCode2 } = ResponseBuilder.error("INVALID_REQUEST", `Invalid program. Must be one of: ${AVAILABLE_PROGRAMS2.join(", ")}`, 400);
|
|
4558
|
+
return c.json(response2, statusCode2);
|
|
4559
|
+
}
|
|
4560
|
+
const thread = await threadManager.getThread(threadId);
|
|
4561
|
+
if (!thread) {
|
|
4562
|
+
const { response: response2, statusCode: statusCode2 } = ResponseBuilder.error("THREAD_NOT_FOUND", `Thread not found: ${threadId}`, 404);
|
|
4563
|
+
return c.json(response2, statusCode2);
|
|
4564
|
+
}
|
|
4565
|
+
const { spawn: spawn7 } = await import("child_process");
|
|
4566
|
+
const threadPath = thread.path;
|
|
4567
|
+
if (program === "VS Code") {
|
|
4568
|
+
spawn7("code", [threadPath], { detached: true });
|
|
4569
|
+
} else if (program === "Cursor") {
|
|
4570
|
+
spawn7("cursor", [threadPath], { detached: true });
|
|
4571
|
+
} else if (program === "Windsurf") {
|
|
4572
|
+
spawn7("windsurf", [threadPath], { detached: true });
|
|
4573
|
+
} else if (program === "Xcode") {
|
|
4574
|
+
spawn7("open", ["-a", "Xcode", threadPath], { detached: true });
|
|
4575
|
+
} else if (program === "Android Studio") {
|
|
4576
|
+
spawn7("open", ["-a", "Android Studio", threadPath], { detached: true });
|
|
4577
|
+
} else if (program === "Kiro") {
|
|
4578
|
+
spawn7("kiro", [threadPath], { detached: true });
|
|
4579
|
+
}
|
|
4580
|
+
const { response, statusCode } = ResponseBuilder.success({ success: true, message: `Thread opened in ${program}` });
|
|
4581
|
+
return c.json(response, statusCode);
|
|
4582
|
+
} catch (error) {
|
|
4583
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
4584
|
+
const { response, statusCode } = ResponseBuilder.error("OPEN_PROGRAM_ERROR", "Failed to open thread", 500, errorMessage);
|
|
4585
|
+
return c.json(response, statusCode);
|
|
4586
|
+
}
|
|
4587
|
+
});
|
|
4457
4588
|
return router;
|
|
4458
4589
|
}
|
|
4459
4590
|
|
|
@@ -4613,6 +4744,26 @@ User: ${content}` : content;
|
|
|
4613
4744
|
return c.json(response, statusCode);
|
|
4614
4745
|
}
|
|
4615
4746
|
});
|
|
4747
|
+
router.delete("/:threadId", async (c) => {
|
|
4748
|
+
try {
|
|
4749
|
+
const threadId = c.req.param("threadId");
|
|
4750
|
+
if (!threadId || typeof threadId !== "string") {
|
|
4751
|
+
const { response: response2, statusCode: statusCode2 } = ResponseBuilder.error("INVALID_REQUEST", "threadId is required and must be a string", 400);
|
|
4752
|
+
return c.json(response2, statusCode2);
|
|
4753
|
+
}
|
|
4754
|
+
const thread = await threadManager.getThread(threadId);
|
|
4755
|
+
if (!thread) {
|
|
4756
|
+
const { response: response2, statusCode: statusCode2 } = ResponseBuilder.error("THREAD_NOT_FOUND", `Thread not found: ${threadId}`, 404);
|
|
4757
|
+
return c.json(response2, statusCode2);
|
|
4758
|
+
}
|
|
4759
|
+
await conversationManager.clearChatHistory(thread.path);
|
|
4760
|
+
const { response, statusCode } = ResponseBuilder.success({ message: "Chat history cleared" }, 200);
|
|
4761
|
+
return c.json(response, statusCode);
|
|
4762
|
+
} catch (error) {
|
|
4763
|
+
const { response, statusCode } = ResponseBuilder.error("CLEAR_CHAT_ERROR", "Failed to clear chat history", 500, error instanceof Error ? error.message : String(error));
|
|
4764
|
+
return c.json(response, statusCode);
|
|
4765
|
+
}
|
|
4766
|
+
});
|
|
4616
4767
|
return router;
|
|
4617
4768
|
}
|
|
4618
4769
|
|
|
@@ -5603,7 +5754,7 @@ function createModelRoutes(metadataManager) {
|
|
|
5603
5754
|
// src/routes/git.ts
|
|
5604
5755
|
import { Hono as Hono6 } from "hono";
|
|
5605
5756
|
import { spawn as spawn7 } from "child_process";
|
|
5606
|
-
import { existsSync as existsSync6, readFileSync as
|
|
5757
|
+
import { existsSync as existsSync6, readFileSync as readFileSync4, statSync as statSync3 } from "fs";
|
|
5607
5758
|
import { join as join10 } from "path";
|
|
5608
5759
|
import { isAbsolute as isAbsolute3, normalize, resolve as resolve2 } from "path";
|
|
5609
5760
|
import {
|
|
@@ -6141,7 +6292,7 @@ function createGitRoutes(metadataManager) {
|
|
|
6141
6292
|
try {
|
|
6142
6293
|
if (statSync3(fullPath).isDirectory())
|
|
6143
6294
|
continue;
|
|
6144
|
-
const content =
|
|
6295
|
+
const content = readFileSync4(fullPath, "utf-8");
|
|
6145
6296
|
const safeContent = content.length > maxFileSize ? content.slice(0, maxFileSize) + `
|
|
6146
6297
|
...(truncated)` : content;
|
|
6147
6298
|
const linesForDiff = safeContent.split(/\r?\n/).map((l) => `+${l}`).join(`
|
|
@@ -6670,7 +6821,8 @@ function createScaffoldRoutes(projectManager) {
|
|
|
6670
6821
|
}
|
|
6671
6822
|
|
|
6672
6823
|
// src/index.ts
|
|
6673
|
-
|
|
6824
|
+
init_dist();
|
|
6825
|
+
var __filename2 = fileURLToPath3(import.meta.url);
|
|
6674
6826
|
var __dirname3 = path3.dirname(__filename2);
|
|
6675
6827
|
var args = process.argv.slice(2);
|
|
6676
6828
|
var isDebug = args.includes("--debug");
|