@pi-orca/core 0.0.2-dev.20260413162335
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/README.md +228 -0
- package/defaults/config.yaml +28 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +8 -0
- package/dist/index.js.map +1 -0
- package/dist/types/agent.d.ts +72 -0
- package/dist/types/agent.d.ts.map +1 -0
- package/dist/types/agent.js +6 -0
- package/dist/types/agent.js.map +1 -0
- package/dist/types/archivable.d.ts +23 -0
- package/dist/types/archivable.d.ts.map +1 -0
- package/dist/types/archivable.js +47 -0
- package/dist/types/archivable.js.map +1 -0
- package/dist/types/config.d.ts +42 -0
- package/dist/types/config.d.ts.map +1 -0
- package/dist/types/config.js +42 -0
- package/dist/types/config.js.map +1 -0
- package/dist/types/index.d.ts +12 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +12 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/labels.d.ts +28 -0
- package/dist/types/labels.d.ts.map +1 -0
- package/dist/types/labels.js +45 -0
- package/dist/types/labels.js.map +1 -0
- package/dist/types/lock.d.ts +16 -0
- package/dist/types/lock.d.ts.map +1 -0
- package/dist/types/lock.js +6 -0
- package/dist/types/lock.js.map +1 -0
- package/dist/types/message.d.ts +29 -0
- package/dist/types/message.d.ts.map +1 -0
- package/dist/types/message.js +6 -0
- package/dist/types/message.js.map +1 -0
- package/dist/types/task.d.ts +45 -0
- package/dist/types/task.d.ts.map +1 -0
- package/dist/types/task.js +27 -0
- package/dist/types/task.js.map +1 -0
- package/dist/types/team.d.ts +38 -0
- package/dist/types/team.d.ts.map +1 -0
- package/dist/types/team.js +6 -0
- package/dist/types/team.js.map +1 -0
- package/dist/utils/autocomplete.d.ts +42 -0
- package/dist/utils/autocomplete.d.ts.map +1 -0
- package/dist/utils/autocomplete.js +111 -0
- package/dist/utils/autocomplete.js.map +1 -0
- package/dist/utils/config-loader.d.ts +17 -0
- package/dist/utils/config-loader.d.ts.map +1 -0
- package/dist/utils/config-loader.js +81 -0
- package/dist/utils/config-loader.js.map +1 -0
- package/dist/utils/dag.d.ts +34 -0
- package/dist/utils/dag.d.ts.map +1 -0
- package/dist/utils/dag.js +96 -0
- package/dist/utils/dag.js.map +1 -0
- package/dist/utils/duration.d.ts +21 -0
- package/dist/utils/duration.d.ts.map +1 -0
- package/dist/utils/duration.js +47 -0
- package/dist/utils/duration.js.map +1 -0
- package/dist/utils/filesystem.d.ts +53 -0
- package/dist/utils/filesystem.d.ts.map +1 -0
- package/dist/utils/filesystem.js +99 -0
- package/dist/utils/filesystem.js.map +1 -0
- package/dist/utils/heartbeat.d.ts +23 -0
- package/dist/utils/heartbeat.d.ts.map +1 -0
- package/dist/utils/heartbeat.js +53 -0
- package/dist/utils/heartbeat.js.map +1 -0
- package/dist/utils/index.d.ts +14 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +14 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/lock.d.ts +43 -0
- package/dist/utils/lock.d.ts.map +1 -0
- package/dist/utils/lock.js +89 -0
- package/dist/utils/lock.js.map +1 -0
- package/dist/utils/path.d.ts +88 -0
- package/dist/utils/path.d.ts.map +1 -0
- package/dist/utils/path.js +128 -0
- package/dist/utils/path.js.map +1 -0
- package/dist/utils/process.d.ts +20 -0
- package/dist/utils/process.d.ts.map +1 -0
- package/dist/utils/process.js +40 -0
- package/dist/utils/process.js.map +1 -0
- package/dist/utils/yaml.d.ts +30 -0
- package/dist/utils/yaml.d.ts.map +1 -0
- package/dist/utils/yaml.js +58 -0
- package/dist/utils/yaml.js.map +1 -0
- package/package.json +47 -0
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Path resolution utilities.
|
|
3
|
+
* Spec: §3.2 — Filesystem Helpers
|
|
4
|
+
*/
|
|
5
|
+
import { homedir } from "os";
|
|
6
|
+
import { join, dirname, basename } from "path";
|
|
7
|
+
/**
|
|
8
|
+
* Get current project slug.
|
|
9
|
+
* For now, returns the current directory basename.
|
|
10
|
+
* TODO: Integrate with Pi's project slug detection.
|
|
11
|
+
*
|
|
12
|
+
* @returns Project slug
|
|
13
|
+
*/
|
|
14
|
+
export function getProjectSlug() {
|
|
15
|
+
return basename(process.cwd());
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Get Orca runtime directory for a project.
|
|
19
|
+
* ~/.pi/agent/sessions/<project-slug>/orca/
|
|
20
|
+
*
|
|
21
|
+
* Override the base directory with PI_ORCA_BASE_DIR env var (used by tests).
|
|
22
|
+
*
|
|
23
|
+
* @param projectSlug - Project slug (defaults to current)
|
|
24
|
+
* @returns Absolute path to runtime directory
|
|
25
|
+
*/
|
|
26
|
+
export function getOrcaRuntimeDir(projectSlug) {
|
|
27
|
+
const slug = projectSlug || getProjectSlug();
|
|
28
|
+
const baseDir = process.env["PI_ORCA_BASE_DIR"] ||
|
|
29
|
+
join(homedir(), ".pi", "agent", "sessions");
|
|
30
|
+
return join(baseDir, slug, "orca");
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Get Orca tasks directory.
|
|
34
|
+
* ~/.pi/agent/sessions/<project-slug>/orca/tasks/
|
|
35
|
+
*
|
|
36
|
+
* @param projectSlug - Project slug (defaults to current)
|
|
37
|
+
* @returns Absolute path to tasks directory
|
|
38
|
+
*/
|
|
39
|
+
export function getOrcaTasksDir(projectSlug) {
|
|
40
|
+
return join(getOrcaRuntimeDir(projectSlug), "tasks");
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Get Orca messages store directory.
|
|
44
|
+
* ~/.pi/agent/sessions/<project-slug>/orca/messages/store/
|
|
45
|
+
*
|
|
46
|
+
* @param projectSlug - Project slug (defaults to current)
|
|
47
|
+
* @returns Absolute path to messages store
|
|
48
|
+
*/
|
|
49
|
+
export function getOrcaMessagesStoreDir(projectSlug) {
|
|
50
|
+
return join(getOrcaRuntimeDir(projectSlug), "messages", "store");
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Get Orca messages inbox directory for a session.
|
|
54
|
+
* ~/.pi/agent/sessions/<project-slug>/orca/messages/inbox/<session-id>/
|
|
55
|
+
*
|
|
56
|
+
* @param sessionId - Session ID
|
|
57
|
+
* @param projectSlug - Project slug (defaults to current)
|
|
58
|
+
* @returns Absolute path to inbox directory
|
|
59
|
+
*/
|
|
60
|
+
export function getOrcaMessagesInboxDir(sessionId, projectSlug) {
|
|
61
|
+
return join(getOrcaRuntimeDir(projectSlug), "messages", "inbox", sessionId);
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Get sibling .orca directory for a session JSONL file.
|
|
65
|
+
* Replaces .jsonl extension with .orca
|
|
66
|
+
*
|
|
67
|
+
* @param sessionPath - Path to session JSONL file (relative or absolute)
|
|
68
|
+
* @returns Absolute path to sibling .orca directory
|
|
69
|
+
*/
|
|
70
|
+
export function getOrcaSiblingDir(sessionPath) {
|
|
71
|
+
// If relative, make it absolute from sessions dir
|
|
72
|
+
let absolutePath = sessionPath;
|
|
73
|
+
if (!sessionPath.startsWith("/")) {
|
|
74
|
+
absolutePath = join(homedir(), ".pi", "agent", "sessions", sessionPath);
|
|
75
|
+
}
|
|
76
|
+
const dir = dirname(absolutePath);
|
|
77
|
+
const base = basename(absolutePath, ".jsonl");
|
|
78
|
+
return join(dir, `${base}.orca`);
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Get user-level Orca directory.
|
|
82
|
+
* ~/.pi/agent/orca/
|
|
83
|
+
*
|
|
84
|
+
* Override the base directory with PI_ORCA_USER_DIR env var (used by tests).
|
|
85
|
+
*
|
|
86
|
+
* @returns Absolute path to user Orca directory
|
|
87
|
+
*/
|
|
88
|
+
export function getUserOrcaDir() {
|
|
89
|
+
return process.env["PI_ORCA_USER_DIR"] || join(homedir(), ".pi", "agent", "orca");
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Get project-level Orca directory.
|
|
93
|
+
* <project>/.pi/orca/
|
|
94
|
+
*
|
|
95
|
+
* @param projectRoot - Project root directory (defaults to cwd)
|
|
96
|
+
* @returns Absolute path to project Orca directory
|
|
97
|
+
*/
|
|
98
|
+
export function getProjectOrcaDir(projectRoot) {
|
|
99
|
+
const root = projectRoot || process.cwd();
|
|
100
|
+
return join(root, ".pi", "orca");
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Resolve session path to absolute.
|
|
104
|
+
* If path is relative, resolves against ~/.pi/agent/sessions/
|
|
105
|
+
*
|
|
106
|
+
* @param sessionPath - Session path (relative or absolute)
|
|
107
|
+
* @returns Absolute path
|
|
108
|
+
*/
|
|
109
|
+
export function resolveSessionPath(sessionPath) {
|
|
110
|
+
if (sessionPath.startsWith("/")) {
|
|
111
|
+
return sessionPath;
|
|
112
|
+
}
|
|
113
|
+
return join(homedir(), ".pi", "agent", "sessions", sessionPath);
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Make session path relative to ~/.pi/agent/sessions/
|
|
117
|
+
*
|
|
118
|
+
* @param absolutePath - Absolute session path
|
|
119
|
+
* @returns Relative path
|
|
120
|
+
*/
|
|
121
|
+
export function makeSessionPathRelative(absolutePath) {
|
|
122
|
+
const sessionsDir = join(homedir(), ".pi", "agent", "sessions");
|
|
123
|
+
if (absolutePath.startsWith(sessionsDir)) {
|
|
124
|
+
return absolutePath.slice(sessionsDir.length + 1); // +1 for trailing /
|
|
125
|
+
}
|
|
126
|
+
return absolutePath;
|
|
127
|
+
}
|
|
128
|
+
//# sourceMappingURL=path.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"path.js","sourceRoot":"","sources":["../../src/utils/path.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,IAAI,CAAC;AAC7B,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,MAAM,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|
2
|
+
* Process and PID utilities.
|
|
3
|
+
* Spec: §3.8 — Stuck Task Detection
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Check if a PID is alive.
|
|
7
|
+
* Uses kill(pid, 0) to check without sending a signal.
|
|
8
|
+
* Spec: §3.8 — Stuck Task Detection
|
|
9
|
+
*
|
|
10
|
+
* @param pid - Process ID to check
|
|
11
|
+
* @returns true if process is alive
|
|
12
|
+
*/
|
|
13
|
+
export declare function isPidAlive(pid: number): boolean;
|
|
14
|
+
/**
|
|
15
|
+
* Get current process ID.
|
|
16
|
+
*
|
|
17
|
+
* @returns Current PID
|
|
18
|
+
*/
|
|
19
|
+
export declare function getCurrentPid(): number;
|
|
20
|
+
//# sourceMappingURL=process.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"process.d.ts","sourceRoot":"","sources":["../../src/utils/process.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;;;;GAOG;AACH,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAiB/C;AAED;;;;GAIG;AACH,wBAAgB,aAAa,IAAI,MAAM,CAEtC"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Process and PID utilities.
|
|
3
|
+
* Spec: §3.8 — Stuck Task Detection
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Check if a PID is alive.
|
|
7
|
+
* Uses kill(pid, 0) to check without sending a signal.
|
|
8
|
+
* Spec: §3.8 — Stuck Task Detection
|
|
9
|
+
*
|
|
10
|
+
* @param pid - Process ID to check
|
|
11
|
+
* @returns true if process is alive
|
|
12
|
+
*/
|
|
13
|
+
export function isPidAlive(pid) {
|
|
14
|
+
try {
|
|
15
|
+
// Signal 0 checks if process exists without actually sending a signal
|
|
16
|
+
process.kill(pid, 0);
|
|
17
|
+
return true;
|
|
18
|
+
}
|
|
19
|
+
catch (error) {
|
|
20
|
+
if (error.code === "ESRCH") {
|
|
21
|
+
// No such process
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
if (error.code === "EPERM") {
|
|
25
|
+
// Process exists but no permission to signal it
|
|
26
|
+
return true;
|
|
27
|
+
}
|
|
28
|
+
// Other errors - assume not alive
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Get current process ID.
|
|
34
|
+
*
|
|
35
|
+
* @returns Current PID
|
|
36
|
+
*/
|
|
37
|
+
export function getCurrentPid() {
|
|
38
|
+
return process.pid;
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=process.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"process.js","sourceRoot":"","sources":["../../src/utils/process.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;;;;GAOG;AACH,MAAM,UAAU,UAAU,CAAC,GAAW;IACpC,IAAI,CAAC;QACH,sEAAsE;QACtE,OAAO,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC;QACrB,OAAO,IAAI,CAAC;IACd,CAAC;IAAC,OAAO,KAAU,EAAE,CAAC;QACpB,IAAI,KAAK,CAAC,IAAI,KAAK,OAAO,EAAE,CAAC;YAC3B,kBAAkB;YAClB,OAAO,KAAK,CAAC;QACf,CAAC;QACD,IAAI,KAAK,CAAC,IAAI,KAAK,OAAO,EAAE,CAAC;YAC3B,gDAAgD;YAChD,OAAO,IAAI,CAAC;QACd,CAAC;QACD,kCAAkC;QAClC,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,aAAa;IAC3B,OAAO,OAAO,CAAC,GAAG,CAAC;AACrB,CAAC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* YAML frontmatter parsing utilities.
|
|
3
|
+
* Spec: §2.7 — YAML frontmatter parsing
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Result of parsing frontmatter.
|
|
7
|
+
*/
|
|
8
|
+
export interface FrontmatterResult<T> {
|
|
9
|
+
frontmatter: T;
|
|
10
|
+
body: string;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Parse markdown with YAML frontmatter.
|
|
14
|
+
* Spec: §2.7 — YAML frontmatter parsing
|
|
15
|
+
*
|
|
16
|
+
* @param content - Full file content
|
|
17
|
+
* @returns Parsed frontmatter and body
|
|
18
|
+
* @throws Error if frontmatter is malformed
|
|
19
|
+
*/
|
|
20
|
+
export declare function parseFrontmatter<T>(content: string): FrontmatterResult<T>;
|
|
21
|
+
/**
|
|
22
|
+
* Serialize frontmatter and body to markdown.
|
|
23
|
+
* Spec: §2.7 — YAML frontmatter parsing
|
|
24
|
+
*
|
|
25
|
+
* @param frontmatter - Object to serialize as frontmatter
|
|
26
|
+
* @param body - Body content
|
|
27
|
+
* @returns Markdown with YAML frontmatter
|
|
28
|
+
*/
|
|
29
|
+
export declare function serializeFrontmatter<T>(frontmatter: T, body: string): string;
|
|
30
|
+
//# sourceMappingURL=yaml.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"yaml.d.ts","sourceRoot":"","sources":["../../src/utils/yaml.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH;;GAEG;AACH,MAAM,WAAW,iBAAiB,CAAC,CAAC;IAClC,WAAW,EAAE,CAAC,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;CACd;AAED;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,OAAO,EAAE,MAAM,GAAG,iBAAiB,CAAC,CAAC,CAAC,CAmCzE;AAED;;;;;;;GAOG;AACH,wBAAgB,oBAAoB,CAAC,CAAC,EAAE,WAAW,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAG5E"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* YAML frontmatter parsing utilities.
|
|
3
|
+
* Spec: §2.7 — YAML frontmatter parsing
|
|
4
|
+
*/
|
|
5
|
+
import YAML from "yaml";
|
|
6
|
+
/**
|
|
7
|
+
* Parse markdown with YAML frontmatter.
|
|
8
|
+
* Spec: §2.7 — YAML frontmatter parsing
|
|
9
|
+
*
|
|
10
|
+
* @param content - Full file content
|
|
11
|
+
* @returns Parsed frontmatter and body
|
|
12
|
+
* @throws Error if frontmatter is malformed
|
|
13
|
+
*/
|
|
14
|
+
export function parseFrontmatter(content) {
|
|
15
|
+
const trimmed = content.trim();
|
|
16
|
+
// Check for frontmatter delimiters
|
|
17
|
+
if (!trimmed.startsWith("---")) {
|
|
18
|
+
return {
|
|
19
|
+
frontmatter: {},
|
|
20
|
+
body: content,
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
// Find end of frontmatter
|
|
24
|
+
const lines = trimmed.split("\n");
|
|
25
|
+
let endIndex = -1;
|
|
26
|
+
for (let i = 1; i < lines.length; i++) {
|
|
27
|
+
if (lines[i].trim() === "---") {
|
|
28
|
+
endIndex = i;
|
|
29
|
+
break;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
if (endIndex === -1) {
|
|
33
|
+
throw new Error("Malformed frontmatter: missing closing ---");
|
|
34
|
+
}
|
|
35
|
+
// Extract frontmatter and body
|
|
36
|
+
const frontmatterText = lines.slice(1, endIndex).join("\n");
|
|
37
|
+
const body = lines.slice(endIndex + 1).join("\n").trim();
|
|
38
|
+
try {
|
|
39
|
+
const frontmatter = YAML.parse(frontmatterText);
|
|
40
|
+
return { frontmatter, body };
|
|
41
|
+
}
|
|
42
|
+
catch (error) {
|
|
43
|
+
throw new Error(`Failed to parse YAML frontmatter: ${error}`);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Serialize frontmatter and body to markdown.
|
|
48
|
+
* Spec: §2.7 — YAML frontmatter parsing
|
|
49
|
+
*
|
|
50
|
+
* @param frontmatter - Object to serialize as frontmatter
|
|
51
|
+
* @param body - Body content
|
|
52
|
+
* @returns Markdown with YAML frontmatter
|
|
53
|
+
*/
|
|
54
|
+
export function serializeFrontmatter(frontmatter, body) {
|
|
55
|
+
const yamlText = YAML.stringify(frontmatter);
|
|
56
|
+
return `---\n${yamlText}---\n\n${body}`;
|
|
57
|
+
}
|
|
58
|
+
//# sourceMappingURL=yaml.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"yaml.js","sourceRoot":"","sources":["../../src/utils/yaml.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,IAAI,MAAM,MAAM,CAAC;AAUxB;;;;;;;GAOG;AACH,MAAM,UAAU,gBAAgB,CAAI,OAAe;IACjD,MAAM,OAAO,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC;IAE/B,mCAAmC;IACnC,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,KAAK,CAAC,EAAE,CAAC;QAC/B,OAAO;YACL,WAAW,EAAE,EAAO;YACpB,IAAI,EAAE,OAAO;SACd,CAAC;IACJ,CAAC;IAED,0BAA0B;IAC1B,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAClC,IAAI,QAAQ,GAAG,CAAC,CAAC,CAAC;IAClB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACtC,IAAI,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,KAAK,KAAK,EAAE,CAAC;YAC9B,QAAQ,GAAG,CAAC,CAAC;YACb,MAAM;QACR,CAAC;IACH,CAAC;IAED,IAAI,QAAQ,KAAK,CAAC,CAAC,EAAE,CAAC;QACpB,MAAM,IAAI,KAAK,CAAC,4CAA4C,CAAC,CAAC;IAChE,CAAC;IAED,+BAA+B;IAC/B,MAAM,eAAe,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,QAAQ,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC5D,MAAM,IAAI,GAAG,KAAK,CAAC,KAAK,CAAC,QAAQ,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,CAAC;IAEzD,IAAI,CAAC;QACH,MAAM,WAAW,GAAG,IAAI,CAAC,KAAK,CAAC,eAAe,CAAM,CAAC;QACrD,OAAO,EAAE,WAAW,EAAE,IAAI,EAAE,CAAC;IAC/B,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,IAAI,KAAK,CAAC,qCAAqC,KAAK,EAAE,CAAC,CAAC;IAChE,CAAC;AACH,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,oBAAoB,CAAI,WAAc,EAAE,IAAY;IAClE,MAAM,QAAQ,GAAG,IAAI,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC;IAC7C,OAAO,QAAQ,QAAQ,UAAU,IAAI,EAAE,CAAC;AAC1C,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@pi-orca/core",
|
|
3
|
+
"version": "0.0.2-dev.20260413162335",
|
|
4
|
+
"description": "Shared types and utilities for Pi Orca extension suite",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.js"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"dist",
|
|
16
|
+
"defaults"
|
|
17
|
+
],
|
|
18
|
+
"scripts": {
|
|
19
|
+
"build": "tsc -p tsconfig.json",
|
|
20
|
+
"clean": "rm -rf dist *.tsbuildinfo",
|
|
21
|
+
"typecheck": "tsc --noEmit",
|
|
22
|
+
"test": "vitest run",
|
|
23
|
+
"test:watch": "vitest"
|
|
24
|
+
},
|
|
25
|
+
"keywords": [
|
|
26
|
+
"pi-orca",
|
|
27
|
+
"pi-agent",
|
|
28
|
+
"utilities",
|
|
29
|
+
"types"
|
|
30
|
+
],
|
|
31
|
+
"author": "Bindu / Ba",
|
|
32
|
+
"license": "MIT",
|
|
33
|
+
"publishConfig": {
|
|
34
|
+
"access": "public"
|
|
35
|
+
},
|
|
36
|
+
"repository": {
|
|
37
|
+
"type": "git",
|
|
38
|
+
"url": "https://github.com/bwavell/pi-orca.git",
|
|
39
|
+
"directory": "packages/pi-orca-core"
|
|
40
|
+
},
|
|
41
|
+
"dependencies": {
|
|
42
|
+
"yaml": "^2.4.0"
|
|
43
|
+
},
|
|
44
|
+
"devDependencies": {
|
|
45
|
+
"@types/node": "^20.0.0"
|
|
46
|
+
}
|
|
47
|
+
}
|