@digitalpresence/cliclaw-auth 0.1.1 → 0.2.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/dist/agent-store.d.ts +6 -9
- package/dist/agent-store.d.ts.map +1 -1
- package/dist/agent-store.js +26 -38
- package/dist/agent-store.js.map +1 -1
- package/dist/claude-md-generator.d.ts +10 -1
- package/dist/claude-md-generator.d.ts.map +1 -1
- package/dist/claude-md-generator.js +48 -22
- package/dist/claude-md-generator.js.map +1 -1
- package/dist/config.d.ts +1 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +3 -0
- package/dist/config.js.map +1 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/dist/instance-store.d.ts +24 -0
- package/dist/instance-store.d.ts.map +1 -0
- package/dist/instance-store.js +118 -0
- package/dist/instance-store.js.map +1 -0
- package/dist/scoped-client-manager.d.ts +2 -3
- package/dist/scoped-client-manager.d.ts.map +1 -1
- package/dist/scoped-client-manager.js +9 -9
- package/dist/scoped-client-manager.js.map +1 -1
- package/package.json +1 -1
- package/src/agent-store.ts +26 -48
- package/src/claude-md-generator.ts +56 -27
- package/src/config.ts +4 -0
- package/src/index.ts +3 -1
- package/src/instance-store.ts +149 -0
- package/src/scoped-client-manager.ts +7 -10
package/dist/agent-store.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { MemoryStore } from "./memory-store.js";
|
|
2
|
+
/** @deprecated Use `integrations: string[]` on AgentConfig instead */
|
|
2
3
|
export interface AgentPermission {
|
|
3
4
|
integration: string;
|
|
4
5
|
account: string;
|
|
@@ -6,9 +7,8 @@ export interface AgentPermission {
|
|
|
6
7
|
export interface CronJobConfig {
|
|
7
8
|
id: string;
|
|
8
9
|
schedule: string;
|
|
9
|
-
|
|
10
|
+
taskFile: string;
|
|
10
11
|
maxIterations: number;
|
|
11
|
-
completionPromise: string;
|
|
12
12
|
enabled: boolean;
|
|
13
13
|
createdAt: string;
|
|
14
14
|
}
|
|
@@ -16,8 +16,7 @@ export interface AgentConfig {
|
|
|
16
16
|
name: string;
|
|
17
17
|
displayName: string;
|
|
18
18
|
role: string;
|
|
19
|
-
|
|
20
|
-
memory: string[];
|
|
19
|
+
integrations: string[];
|
|
21
20
|
cronJobs: CronJobConfig[];
|
|
22
21
|
createdAt: string;
|
|
23
22
|
updatedAt: string;
|
|
@@ -31,8 +30,6 @@ export declare class AgentStore {
|
|
|
31
30
|
private migrateIfNeeded;
|
|
32
31
|
private filePath;
|
|
33
32
|
workspacePath(name: string): string;
|
|
34
|
-
/** Get or create a per-client workspace, symlinking shared agent files */
|
|
35
|
-
clientWorkspacePath(agentName: string, userId: string): string;
|
|
36
33
|
get(name: string): AgentConfig | null;
|
|
37
34
|
save(config: AgentConfig): void;
|
|
38
35
|
delete(name: string): boolean;
|
|
@@ -40,10 +37,10 @@ export declare class AgentStore {
|
|
|
40
37
|
listNames(): string[];
|
|
41
38
|
/** Create workspace directory with config.json, CLAUDE.md, SOUL.md, ROLE.md */
|
|
42
39
|
scaffoldWorkspace(config: AgentConfig): void;
|
|
43
|
-
/** Get or create a MemoryStore for an agent
|
|
40
|
+
/** Get or create a MemoryStore for an agent */
|
|
44
41
|
getMemoryStore(name: string): MemoryStore;
|
|
45
|
-
/** Regenerate
|
|
46
|
-
|
|
42
|
+
/** Regenerate CONTEXT.md from current config */
|
|
43
|
+
regenerateContextMd(name: string): void;
|
|
47
44
|
addCronJob(agentName: string, job: CronJobConfig): void;
|
|
48
45
|
removeCronJob(agentName: string, jobId: string): void;
|
|
49
46
|
listCronJobs(agentName: string): CronJobConfig[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent-store.d.ts","sourceRoot":"","sources":["../src/agent-store.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"agent-store.d.ts","sourceRoot":"","sources":["../src/agent-store.ts"],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IAUzC,gDAAgD;IAChD,mBAAmB,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IASvC,UAAU,CAAC,SAAS,EAAE,MAAM,EAAE,GAAG,EAAE,aAAa,GAAG,IAAI;IASvD,aAAa,CAAC,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI;IAWrD,YAAY,CAAC,SAAS,EAAE,MAAM,GAAG,aAAa,EAAE;IAMhD,aAAa,CAAC,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,IAAI;IAUvE,OAAO,CAAC,mBAAmB;CAuB5B"}
|
package/dist/agent-store.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { existsSync, mkdirSync, readFileSync, writeFileSync, rmSync, readdirSync, renameSync, statSync,
|
|
1
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync, rmSync, readdirSync, renameSync, statSync, } from "fs";
|
|
2
2
|
import { join } from "path";
|
|
3
|
-
import {
|
|
3
|
+
import { generateContextMd } from "./claude-md-generator.js";
|
|
4
4
|
import { MemoryStore } from "./memory-store.js";
|
|
5
5
|
export class AgentStore {
|
|
6
6
|
agentsDir;
|
|
@@ -43,32 +43,28 @@ export class AgentStore {
|
|
|
43
43
|
workspacePath(name) {
|
|
44
44
|
return join(this.agentsDir, name);
|
|
45
45
|
}
|
|
46
|
-
/** Get or create a per-client workspace, symlinking shared agent files */
|
|
47
|
-
clientWorkspacePath(agentName, userId) {
|
|
48
|
-
const clientDir = join(this.agentsDir, agentName, "clients", userId);
|
|
49
|
-
if (!existsSync(clientDir)) {
|
|
50
|
-
mkdirSync(clientDir, { recursive: true });
|
|
51
|
-
}
|
|
52
|
-
// Symlink shared agent files into the client workspace
|
|
53
|
-
const agentDir = this.workspacePath(agentName);
|
|
54
|
-
for (const file of ["CLAUDE.md", "SOUL.md", "ROLE.md"]) {
|
|
55
|
-
const target = join(agentDir, file);
|
|
56
|
-
const link = join(clientDir, file);
|
|
57
|
-
if (existsSync(target) && !existsSync(link)) {
|
|
58
|
-
symlinkSync(target, link);
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
return clientDir;
|
|
62
|
-
}
|
|
63
46
|
get(name) {
|
|
64
47
|
const path = this.filePath(name);
|
|
65
48
|
if (!existsSync(path))
|
|
66
49
|
return null;
|
|
67
50
|
try {
|
|
68
|
-
const
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
51
|
+
const raw = JSON.parse(readFileSync(path, "utf-8"));
|
|
52
|
+
// Migrate legacy formats
|
|
53
|
+
if (!raw.cronJobs)
|
|
54
|
+
raw.cronJobs = [];
|
|
55
|
+
if (!raw.integrations) {
|
|
56
|
+
// Migrate from permissions[] → integrations[]
|
|
57
|
+
if (raw.permissions && Array.isArray(raw.permissions)) {
|
|
58
|
+
raw.integrations = [...new Set(raw.permissions.map((p) => p.integration))];
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
raw.integrations = [];
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
// Drop legacy fields
|
|
65
|
+
delete raw.permissions;
|
|
66
|
+
delete raw.memory;
|
|
67
|
+
return raw;
|
|
72
68
|
}
|
|
73
69
|
catch {
|
|
74
70
|
return null;
|
|
@@ -124,33 +120,25 @@ export class AgentStore {
|
|
|
124
120
|
writeFileSync(this.filePath(config.name), JSON.stringify(config, null, 2), "utf-8");
|
|
125
121
|
this.writeWorkspaceFiles(config, dir);
|
|
126
122
|
}
|
|
127
|
-
/** Get or create a MemoryStore for an agent
|
|
123
|
+
/** Get or create a MemoryStore for an agent */
|
|
128
124
|
getMemoryStore(name) {
|
|
129
125
|
let store = this.memoryStores.get(name);
|
|
130
126
|
if (store)
|
|
131
127
|
return store;
|
|
132
128
|
const memoryDir = join(this.workspacePath(name), "memory");
|
|
133
129
|
store = new MemoryStore(memoryDir);
|
|
134
|
-
// Lazy migration: move config.memory[] → JSONL
|
|
135
|
-
const config = this.get(name);
|
|
136
|
-
if (config && config.memory.length > 0) {
|
|
137
|
-
store.migrate(config.memory);
|
|
138
|
-
config.memory = [];
|
|
139
|
-
config.updatedAt = new Date().toISOString();
|
|
140
|
-
this.save(config);
|
|
141
|
-
}
|
|
142
130
|
this.memoryStores.set(name, store);
|
|
143
131
|
return store;
|
|
144
132
|
}
|
|
145
|
-
/** Regenerate
|
|
146
|
-
|
|
133
|
+
/** Regenerate CONTEXT.md from current config */
|
|
134
|
+
regenerateContextMd(name) {
|
|
147
135
|
const config = this.get(name);
|
|
148
136
|
if (!config)
|
|
149
137
|
return;
|
|
150
138
|
const dir = this.workspacePath(name);
|
|
151
139
|
const memoryStore = this.getMemoryStore(name);
|
|
152
140
|
const memories = memoryStore.list();
|
|
153
|
-
writeFileSync(join(dir, "
|
|
141
|
+
writeFileSync(join(dir, "CONTEXT.md"), generateContextMd(config, memories), "utf-8");
|
|
154
142
|
}
|
|
155
143
|
addCronJob(agentName, job) {
|
|
156
144
|
const config = this.get(agentName);
|
|
@@ -159,7 +147,7 @@ export class AgentStore {
|
|
|
159
147
|
config.cronJobs.push(job);
|
|
160
148
|
config.updatedAt = new Date().toISOString();
|
|
161
149
|
this.save(config);
|
|
162
|
-
this.
|
|
150
|
+
this.regenerateContextMd(agentName);
|
|
163
151
|
}
|
|
164
152
|
removeCronJob(agentName, jobId) {
|
|
165
153
|
const config = this.get(agentName);
|
|
@@ -171,7 +159,7 @@ export class AgentStore {
|
|
|
171
159
|
config.cronJobs.splice(idx, 1);
|
|
172
160
|
config.updatedAt = new Date().toISOString();
|
|
173
161
|
this.save(config);
|
|
174
|
-
this.
|
|
162
|
+
this.regenerateContextMd(agentName);
|
|
175
163
|
}
|
|
176
164
|
listCronJobs(agentName) {
|
|
177
165
|
const config = this.get(agentName);
|
|
@@ -193,7 +181,7 @@ export class AgentStore {
|
|
|
193
181
|
writeWorkspaceFiles(config, dir) {
|
|
194
182
|
const memoryStore = this.getMemoryStore(config.name);
|
|
195
183
|
const memories = memoryStore.list();
|
|
196
|
-
writeFileSync(join(dir, "
|
|
184
|
+
writeFileSync(join(dir, "CONTEXT.md"), generateContextMd(config, memories), "utf-8");
|
|
197
185
|
const soulPath = join(dir, "SOUL.md");
|
|
198
186
|
if (!existsSync(soulPath)) {
|
|
199
187
|
writeFileSync(soulPath, `# ${config.displayName}\n\nDefine this agent's personality and identity here.\n`, "utf-8");
|
package/dist/agent-store.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent-store.js","sourceRoot":"","sources":["../src/agent-store.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EACV,SAAS,EACT,YAAY,EACZ,aAAa,EACb,MAAM,EACN,WAAW,EACX,UAAU,EACV,QAAQ,
|
|
1
|
+
{"version":3,"file":"agent-store.js","sourceRoot":"","sources":["../src/agent-store.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EACV,SAAS,EACT,YAAY,EACZ,aAAa,EACb,MAAM,EACN,WAAW,EACX,UAAU,EACV,QAAQ,GACT,MAAM,IAAI,CAAC;AACZ,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAC5B,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAC7D,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AA2BhD,MAAM,OAAO,UAAU;IAGD;IAFZ,YAAY,GAAG,IAAI,GAAG,EAAuB,CAAC;IAEtD,YAAoB,SAAiB;QAAjB,cAAS,GAAT,SAAS,CAAQ;IAAG,CAAC;IAEjC,SAAS;QACf,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC;YAChC,SAAS,CAAC,IAAI,CAAC,SAAS,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;QACjD,CAAC;QACD,IAAI,CAAC,eAAe,EAAE,CAAC;IACzB,CAAC;IAED,0EAA0E;IAClE,eAAe;QACrB,MAAM,OAAO,GAAG,W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AAW,CAAC,IAAI,EAAE,CAAC;QACpC,aAAa,CAAC,IAAI,CAAC,GAAG,EAAE,YAAY,CAAC,EAAE,iBAAiB,CAAC,MAAM,EAAE,QAAQ,CAAC,EAAE,OAAO,CAAC,CAAC;QAErF,MAAM,QAAQ,GAAG,IAAI,CAAC,GAAG,EAAE,SAAS,CAAC,CAAC;QACtC,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE,CAAC;YAC1B,aAAa,CACX,QAAQ,EACR,KAAK,MAAM,CAAC,WAAW,0DAA0D,EACjF,OAAO,CACR,CAAC;QACJ,CAAC;QAED,MAAM,QAAQ,GAAG,IAAI,CAAC,GAAG,EAAE,SAAS,CAAC,CAAC;QACtC,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE,CAAC;YAC1B,aAAa,CACX,QAAQ,EACR,KAAK,MAAM,CAAC,WAAW,cAAc,MAAM,CAAC,IAAI,wDAAwD,EACxG,OAAO,CACR,CAAC;QACJ,CAAC;IACH,CAAC;CACF"}
|
|
@@ -1,4 +1,13 @@
|
|
|
1
1
|
import type { AgentConfig } from "./agent-store.js";
|
|
2
2
|
import type { MemoryEntry } from "./memory-store.js";
|
|
3
|
-
|
|
3
|
+
/**
|
|
4
|
+
* Generates the universal ~/.cliclaw/CLAUDE.md shared by all agents.
|
|
5
|
+
* Contains safety rules, CLI usage patterns, memory instructions, and behavioral guidelines.
|
|
6
|
+
*/
|
|
7
|
+
export declare function generateUniversalClaudeMd(): string;
|
|
8
|
+
/**
|
|
9
|
+
* Generates per-instance CONTEXT.md with agent-specific context:
|
|
10
|
+
* name, integrations, cron schedules, and current memories.
|
|
11
|
+
*/
|
|
12
|
+
export declare function generateContextMd(config: AgentConfig, memories?: MemoryEntry[]): string;
|
|
4
13
|
//# sourceMappingURL=claude-md-generator.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"claude-md-generator.d.ts","sourceRoot":"","sources":["../src/claude-md-generator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAErD,wBAAgB,
|
|
1
|
+
{"version":3,"file":"claude-md-generator.d.ts","sourceRoot":"","sources":["../src/claude-md-generator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAErD;;;GAGG;AACH,wBAAgB,yBAAyB,IAAI,MAAM,CAyClD;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,WAAW,EAAE,QAAQ,GAAE,WAAW,EAAO,GAAG,MAAM,CAmE3F"}
|
|
@@ -1,13 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Generates the universal ~/.cliclaw/CLAUDE.md shared by all agents.
|
|
3
|
+
* Contains safety rules, CLI usage patterns, memory instructions, and behavioral guidelines.
|
|
4
|
+
*/
|
|
5
|
+
export function generateUniversalClaudeMd() {
|
|
6
6
|
const lines = [];
|
|
7
|
-
lines.push(
|
|
7
|
+
lines.push("# Agent Instructions");
|
|
8
8
|
lines.push("");
|
|
9
|
-
lines.push("Read SOUL.md
|
|
10
|
-
lines.push("
|
|
9
|
+
lines.push("Read SOUL.md, ROLE.md, and CONTEXT.md before doing anything.");
|
|
10
|
+
lines.push("");
|
|
11
|
+
lines.push("## Safety Rules");
|
|
12
|
+
lines.push("- Never access files outside your workspace directory");
|
|
13
|
+
lines.push("- Never modify or read system files, environment files, or credentials outside your workspace");
|
|
14
|
+
lines.push("- Never attempt to escalate permissions or bypass security boundaries");
|
|
15
|
+
lines.push("- Never share credentials, tokens, or sensitive data in your responses");
|
|
16
|
+
lines.push("- If a task requires access you don't have, say so — don't try to work around it");
|
|
11
17
|
lines.push("");
|
|
12
18
|
lines.push("## CLI Usage");
|
|
13
19
|
lines.push("All integrations are accessed via the `cliclaw` CLI. Always pass `--account <account>` to specify which account to use.");
|
|
@@ -15,45 +21,65 @@ export function generateClaudeMd(config, memories = []) {
|
|
|
15
21
|
lines.push("For detailed usage of any command, run:");
|
|
16
22
|
lines.push(" `cliclaw <command> --help` or `cliclaw <command> <subcommand> --help`");
|
|
17
23
|
lines.push("");
|
|
24
|
+
lines.push("## Memory");
|
|
25
|
+
lines.push("Save, search, and remove memories with `cliclaw agent memory --help`.");
|
|
26
|
+
lines.push("Your agent name is in CONTEXT.md — use it for all memory commands.");
|
|
27
|
+
lines.push("");
|
|
28
|
+
lines.push("### Memory Guidelines");
|
|
29
|
+
lines.push("- Save important facts, preferences, and context that will be useful across conversations");
|
|
30
|
+
lines.push("- Use descriptive tags to categorize memories for easy retrieval");
|
|
31
|
+
lines.push("- Search existing memories before adding duplicates");
|
|
32
|
+
lines.push("- Use importance levels: 1 (low), 2 (normal), 3 (critical)");
|
|
33
|
+
lines.push("");
|
|
34
|
+
lines.push("## General Guidelines");
|
|
35
|
+
lines.push("- Be concise and direct in responses");
|
|
36
|
+
lines.push("- When running CLI commands, check `--help` first if unsure about options");
|
|
37
|
+
lines.push("- When in a client workspace, read CLIENT_INTEGRATIONS.md for available account names");
|
|
38
|
+
lines.push("- If no CLIENT_INTEGRATIONS.md exists, use `--account default`");
|
|
39
|
+
return lines.join("\n");
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Generates per-instance CONTEXT.md with agent-specific context:
|
|
43
|
+
* name, integrations, cron schedules, and current memories.
|
|
44
|
+
*/
|
|
45
|
+
export function generateContextMd(config, memories = []) {
|
|
46
|
+
const lines = [];
|
|
47
|
+
lines.push(`# ${config.displayName} — Context`);
|
|
48
|
+
lines.push("");
|
|
49
|
+
lines.push(`Agent name: \`${config.name}\``);
|
|
50
|
+
lines.push("");
|
|
18
51
|
lines.push("## Permitted Integrations");
|
|
19
|
-
if (
|
|
20
|
-
lines.push("No
|
|
52
|
+
if (config.integrations.length === 0) {
|
|
53
|
+
lines.push("No integrations configured.");
|
|
21
54
|
}
|
|
22
55
|
else {
|
|
23
|
-
for (const integration of integrations) {
|
|
56
|
+
for (const integration of config.integrations) {
|
|
24
57
|
lines.push(`- \`cliclaw ${integration}\``);
|
|
25
58
|
}
|
|
26
|
-
lines.push("");
|
|
27
|
-
lines.push("When running in a client workspace, read CLIENT_INTEGRATIONS.md for available account names.");
|
|
28
|
-
lines.push("If no CLIENT_INTEGRATIONS.md exists, use `--account default`.");
|
|
29
59
|
}
|
|
30
60
|
lines.push("");
|
|
31
|
-
lines.push("## Memory");
|
|
32
|
-
lines.push(`Save, search, and remove memories with \`cliclaw agent memory --help\`. Your agent name is \`${config.name}\`.`);
|
|
33
|
-
lines.push("");
|
|
34
61
|
if (config.cronJobs && config.cronJobs.length > 0) {
|
|
35
62
|
lines.push("## Scheduled Tasks");
|
|
36
63
|
lines.push("");
|
|
37
64
|
for (const job of config.cronJobs) {
|
|
38
65
|
const status = job.enabled ? "enabled" : "disabled";
|
|
39
66
|
lines.push(`- **${job.id}** (${status}): \`${job.schedule}\``);
|
|
40
|
-
lines.push(` Task: ${job.
|
|
41
|
-
lines.push(`
|
|
67
|
+
lines.push(` Task file: ${job.taskFile}`);
|
|
68
|
+
lines.push(` Max iterations: ${job.maxIterations}`);
|
|
42
69
|
}
|
|
43
70
|
lines.push("");
|
|
44
71
|
}
|
|
45
72
|
if (memories.length === 0) {
|
|
46
|
-
lines.push("
|
|
73
|
+
lines.push("## Current Memories");
|
|
47
74
|
lines.push("No memories yet.");
|
|
48
75
|
}
|
|
49
76
|
else {
|
|
50
|
-
lines.push("
|
|
77
|
+
lines.push("## Current Memories");
|
|
51
78
|
let displayMemories;
|
|
52
79
|
let truncated = false;
|
|
53
80
|
if (memories.length > 50) {
|
|
54
81
|
const critical = memories.filter((m) => m.importance === 3);
|
|
55
82
|
const recent = memories.slice(-30);
|
|
56
|
-
// Merge critical + recent, deduplicate by id
|
|
57
83
|
const seen = new Set();
|
|
58
84
|
displayMemories = [];
|
|
59
85
|
for (const m of [...critical, ...recent]) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"claude-md-generator.js","sourceRoot":"","sources":["../src/claude-md-generator.ts"],"names":[],"mappings":"AAGA,MAAM,UAAU,
|
|
1
|
+
{"version":3,"file":"claude-md-generator.js","sourceRoot":"","sources":["../src/claude-md-generator.ts"],"names":[],"mappings":"AAGA;;;GAGG;AACH,MAAM,UAAU,yBAAyB;IACvC,MAAM,KAAK,GAAa,EAAE,CAAC;IAE3B,KAAK,CAAC,IAAI,CAAC,sBAAsB,CAAC,CAAC;IACnC,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACf,KAAK,CAAC,IAAI,CAAC,8DAA8D,CAAC,CAAC;IAC3E,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IAEf,KAAK,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC;IAC9B,KAAK,CAAC,IAAI,CAAC,uDAAuD,CAAC,CAAC;IACpE,KAAK,CAAC,IAAI,CAAC,+FAA+F,CAAC,CAAC;IAC5G,KAAK,CAAC,IAAI,CAAC,uEAAuE,CAAC,CAAC;IACpF,KAAK,CAAC,IAAI,CAAC,wEAAwE,CAAC,CAAC;IACrF,KAAK,CAAC,IAAI,CAAC,kFAAkF,CAAC,CAAC;IAC/F,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IAEf,KAAK,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;IAC3B,KAAK,CAAC,IAAI,CAAC,yHAAyH,CAAC,CAAC;IACtI,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACf,KAAK,CAAC,IAAI,CAAC,yCAAyC,CAAC,CAAC;IACtD,KAAK,CAAC,IAAI,CAAC,yEAAyE,CAAC,CAAC;IACtF,KAAK,CAAC,IAAI,CAAC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IAAI,SAAS,EAAE,CAAC;YACd,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;YACf,KAAK,CAAC,IAAI,CAAC,IAAI,QAAQ,CAAC,MAAM,gFAAgF,CAAC,CAAC;QAClH,CAAC;IACH,CAAC;IAED,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC1B,CAAC"}
|
package/dist/config.d.ts
CHANGED
|
@@ -5,5 +5,6 @@ export interface CliclawConfig {
|
|
|
5
5
|
export declare function getConfigDir(): string;
|
|
6
6
|
export declare function getTokensPath(): string;
|
|
7
7
|
export declare function getAgentsDir(): string;
|
|
8
|
+
export declare function getInstancesDir(): string;
|
|
8
9
|
export declare function loadConfig(): CliclawConfig;
|
|
9
10
|
//# sourceMappingURL=config.d.ts.map
|
package/dist/config.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAIA,MAAM,WAAW,aAAa;IAC5B,kBAAkB,EAAE,MAAM,CAAC;IAC3B,UAAU,EAAE,MAAM,CAAC;CACpB;AAKD,wBAAgB,YAAY,IAAI,MAAM,CAErC;AAED,wBAAgB,aAAa,IAAI,MAAM,CAEtC;AAED,wBAAgB,YAAY,IAAI,MAAM,CAErC;AAED,wBAAgB,UAAU,IAAI,aAAa,CAwB1C"}
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAIA,MAAM,WAAW,aAAa;IAC5B,kBAAkB,EAAE,MAAM,CAAC;IAC3B,UAAU,EAAE,MAAM,CAAC;CACpB;AAKD,wBAAgB,YAAY,IAAI,MAAM,CAErC;AAED,wBAAgB,aAAa,IAAI,MAAM,CAEtC;AAED,wBAAgB,YAAY,IAAI,MAAM,CAErC;AAED,wBAAgB,eAAe,IAAI,MAAM,CAExC;AAED,wBAAgB,UAAU,IAAI,aAAa,CAwB1C"}
|
package/dist/config.js
CHANGED
|
@@ -12,6 +12,9 @@ export function getTokensPath() {
|
|
|
12
12
|
export function getAgentsDir() {
|
|
13
13
|
return join(CONFIG_DIR, "agents");
|
|
14
14
|
}
|
|
15
|
+
export function getInstancesDir() {
|
|
16
|
+
return join(CONFIG_DIR, "instances");
|
|
17
|
+
}
|
|
15
18
|
export function loadConfig() {
|
|
16
19
|
if (!existsSync(CONFIG_DIR)) {
|
|
17
20
|
mkdirSync(CONFIG_DIR, { recursive: true });
|
package/dist/config.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,IAAI,CAAC;AACzD,OAAO,EAAE,OAAO,EAAE,MAAM,IAAI,CAAC;AAC7B,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAO5B,MAAM,UAAU,GAAG,OAAO,CAAC,GAAG,CAAC,YAAY,IAAI,IAAI,CAAC,OAAO,EAAE,EAAE,UAAU,CAAC,CAAC;AAC3E,MAAM,WAAW,GAAG,IAAI,CAAC,UAAU,EAAE,aAAa,CAAC,CAAC;AAEpD,MAAM,UAAU,YAAY;IAC1B,OAAO,UAAU,CAAC;AACpB,CAAC;AAED,MAAM,UAAU,aAAa;IAC3B,OAAO,OAAO,CAAC,GAAG,CAAC,mBAAmB,IAAI,IAAI,CAAC,UAAU,EAAE,aAAa,CAAC,CAAC;AAC5E,CAAC;AAED,MAAM,UAAU,YAAY;IAC1B,OAAO,IAAI,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC;AACpC,CAAC;AAED,MAAM,UAAU,UAAU;IACxB,IAAI,CAAC,UAAU,CAAC,UAAU,CAAC,EAAE,CAAC;QAC5B,SAAS,CAAC,UAAU,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IAC7C,CAAC;IAED,IAAI,CAAC,UAAU,C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,UAAU,EAAE,WAAW,CAAC,CAAC;AACvC,CAAC;AAED,MAAM,UAAU,UAAU;IACxB,IAAI,CAAC,UAAU,CAAC,UAAU,CAAC,EAAE,CAAC;QAC5B,SAAS,CAAC,UAAU,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IAC7C,CAAC;IAED,IAAI,CAAC,UAAU,CAAC,WAAW,CAAC,EAAE,CAAC;QAC7B,MAAM,IAAI,KAAK,CACb,0BAA0B,WAAW,IAAI;YACzC,mBAAmB;YACnB,yBAAyB;YACzB,6GAA6G,CAC9G,CAAC;IACJ,CAAC;IAED,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC,CAAC;IAE3D,IAAI,CAAC,GAAG,CAAC,kBAAkB,EAAE,CAAC;QAC5B,MAAM,IAAI,KAAK,CAAC,wDAAwD,CAAC,CAAC;IAC5E,CAAC;IAED,OAAO;QACL,kBAAkB,EAAE,GAAG,CAAC,kBAAkB;QAC1C,UAAU,EAAE,GAAG,CAAC,UAAU,IAAI,IAAI;KACnC,CAAC;AACJ,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ export { TokenStore } from "./token-store.js";
|
|
|
2
2
|
export { OAuthClientManager } from "./oauth-client-manager.js";
|
|
3
3
|
export { AgentStore } from "./agent-store.js";
|
|
4
4
|
export type { AgentConfig, AgentPermission, CronJobConfig } from "./agent-store.js";
|
|
5
|
+
export { getInstancesDir } from "./config.js";
|
|
5
6
|
export { ScopedClientManager, PermissionDeniedError } from "./scoped-client-manager.js";
|
|
6
7
|
export { createOAuthClient, getAuthUrl } from "./gmail-auth.js";
|
|
7
8
|
export { createGDriveOAuthClient, getGDriveAuthUrl } from "./gdrive-auth.js";
|
|
@@ -14,7 +15,8 @@ export { loadConfig, getConfigDir, getTokensPath, getAgentsDir } from "./config.
|
|
|
14
15
|
export { INTEGRATIONS } from "./integration-registry.js";
|
|
15
16
|
export type { IntegrationDef } from "./integration-registry.js";
|
|
16
17
|
export type { CliclawConfig } from "./config.js";
|
|
17
|
-
export {
|
|
18
|
+
export { generateUniversalClaudeMd, generateContextMd } from "./claude-md-generator.js";
|
|
19
|
+
export { InstanceStore } from "./instance-store.js";
|
|
18
20
|
export { MemoryStore } from "./memory-store.js";
|
|
19
21
|
export type { MemoryEntry } from "./memory-store.js";
|
|
20
22
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAC/D,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,YAAY,EAAE,WAAW,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACpF,OAAO,EAAE,mBAAmB,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AACxF,OAAO,EAAE,iBAAiB,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAChE,OAAO,EAAE,uBAAuB,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAC7E,OAAO,EAAE,wBAAwB,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAChF,OAAO,EAAE,wBAAwB,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAChF,OAAO,EAAE,yBAAyB,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AACnF,OAAO,EAAE,sBAAsB,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAC1E,OAAO,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AACzD,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,aAAa,EAAE,YAAY,EAAE,MAA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AA2B,CAAC;AAChE,YAAY,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,EAAE,yBAAyB,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AACxF,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,YAAY,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export { TokenStore } from "./token-store.js";
|
|
2
2
|
export { OAuthClientManager } from "./oauth-client-manager.js";
|
|
3
3
|
export { AgentStore } from "./agent-store.js";
|
|
4
|
+
export { getInstancesDir } from "./config.js";
|
|
4
5
|
export { ScopedClientManager, PermissionDeniedError } from "./scoped-client-manager.js";
|
|
5
6
|
export { createOAuthClient, getAuthUrl } from "./gmail-auth.js";
|
|
6
7
|
export { createGDriveOAuthClient, getGDriveAuthUrl } from "./gdrive-auth.js";
|
|
@@ -11,6 +12,7 @@ export { createFormsOAuthClient, getFormsAuthUrl } from "./forms-auth.js";
|
|
|
11
12
|
export { waitForOAuthCallback } from "./oauth-server.js";
|
|
12
13
|
export { loadConfig, getConfigDir, getTokensPath, getAgentsDir } from "./config.js";
|
|
13
14
|
export { INTEGRATIONS } from "./integration-registry.js";
|
|
14
|
-
export {
|
|
15
|
+
export { generateUniversalClaudeMd, generateContextMd } from "./claude-md-generator.js";
|
|
16
|
+
export { InstanceStore } from "./instance-store.js";
|
|
15
17
|
export { MemoryStore } from "./memory-store.js";
|
|
16
18
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,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BAAwB,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAChF,OAAO,EAAE,wBAAwB,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAChF,OAAO,EAAE,yBAAyB,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AACnF,OAAO,EAAE,sBAAsB,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAC1E,OAAO,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AACzD,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AACpF,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAGzD,OAAO,EAAE,yBAAyB,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AACxF,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { AgentStore } from "./agent-store.js";
|
|
2
|
+
export declare class InstanceStore {
|
|
3
|
+
private instancesDir;
|
|
4
|
+
private agentStore;
|
|
5
|
+
constructor(instancesDir: string, agentStore: AgentStore);
|
|
6
|
+
private ensureDir;
|
|
7
|
+
/** Get the root path for an instance */
|
|
8
|
+
getInstancePath(agentName: string, userId: string): string;
|
|
9
|
+
/** Get the workspace subdir (what gets mounted into Docker) */
|
|
10
|
+
getWorkspacePath(agentName: string, userId: string): string;
|
|
11
|
+
/** Create a new instance by copying template files and generating CONTEXT.md */
|
|
12
|
+
createInstance(agentName: string, userId: string): string;
|
|
13
|
+
/** Re-copy template files and regenerate CONTEXT.md after agent config changes */
|
|
14
|
+
syncInstance(agentName: string, userId: string): void;
|
|
15
|
+
/** Delete an instance */
|
|
16
|
+
deleteInstance(agentName: string, userId: string): boolean;
|
|
17
|
+
/** List all instances, optionally filtered by agent name */
|
|
18
|
+
listInstances(agentName?: string): Array<{
|
|
19
|
+
agentName: string;
|
|
20
|
+
userId: string;
|
|
21
|
+
path: string;
|
|
22
|
+
}>;
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=instance-store.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"instance-store.d.ts","sourceRoot":"","sources":["../src/instance-store.ts"],"names":[],"mappings":"AAWA,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAK9C,qBAAa,aAAa;IAEtB,OAAO,CAAC,YAAY;IACpB,OAAO,CAAC,UAAU;gBADV,YAAY,EAAE,MAAM,EACpB,UAAU,EAAE,UAAU;IAGhC,OAAO,CAAC,SAAS;IAMjB,wCAAwC;IACxC,eAAe,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM;IAI1D,+DAA+D;IAC/D,gBAAgB,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM;IAI3D,gFAAgF;IAChF,cAAc,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM;IAwCzD,kFAAkF;IAClF,YAAY,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI;IAmCrD,yBAAyB;IACzB,cAAc,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO;IAO1D,4DAA4D;IAC5D,aAAa,CAAC,SAAS,CAAC,EAAE,MAAM,GAAG,KAAK,CAAC;QAAE,SAAS,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC;CAwB9F"}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { existsSync, mkdirSync, writeFileSync, cpSync, rmSync, readdirSync, statSync, } from "fs";
|
|
2
|
+
import { join } from "path";
|
|
3
|
+
import { generateUniversalClaudeMd, generateContextMd } from "./claude-md-generator.js";
|
|
4
|
+
import { MemoryStore } from "./memory-store.js";
|
|
5
|
+
import { getConfigDir } from "./config.js";
|
|
6
|
+
export class InstanceStore {
|
|
7
|
+
instancesDir;
|
|
8
|
+
agentStore;
|
|
9
|
+
constructor(instancesDir, agentStore) {
|
|
10
|
+
this.instancesDir = instancesDir;
|
|
11
|
+
this.agentStore = agentStore;
|
|
12
|
+
}
|
|
13
|
+
ensureDir(path) {
|
|
14
|
+
if (!existsSync(path)) {
|
|
15
|
+
mkdirSync(path, { recursive: true });
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
/** Get the root path for an instance */
|
|
19
|
+
getInstancePath(agentName, userId) {
|
|
20
|
+
return join(this.instancesDir, agentName, userId);
|
|
21
|
+
}
|
|
22
|
+
/** Get the workspace subdir (what gets mounted into Docker) */
|
|
23
|
+
getWorkspacePath(agentName, userId) {
|
|
24
|
+
return join(this.getInstancePath(agentName, userId), "workspace");
|
|
25
|
+
}
|
|
26
|
+
/** Create a new instance by copying template files and generating CONTEXT.md */
|
|
27
|
+
createInstance(agentName, userId) {
|
|
28
|
+
const config = this.agentStore.get(agentName);
|
|
29
|
+
if (!config)
|
|
30
|
+
throw new Error(`Agent "${agentName}" not found`);
|
|
31
|
+
const instancePath = this.getInstancePath(agentName, userId);
|
|
32
|
+
this.ensureDir(instancePath);
|
|
33
|
+
this.ensureDir(join(instancePath, "workspace"));
|
|
34
|
+
this.ensureDir(join(instancePath, "memory"));
|
|
35
|
+
this.ensureDir(join(instancePath, "cron"));
|
|
36
|
+
// Copy universal CLAUDE.md
|
|
37
|
+
const universalClaudeMd = join(getConfigDir(), "CLAUDE.md");
|
|
38
|
+
if (existsSync(universalClaudeMd)) {
|
|
39
|
+
cpSync(universalClaudeMd, join(instancePath, "CLAUDE.md"));
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
// Generate it if it doesn't exist yet
|
|
43
|
+
writeFileSync(join(instancePath, "CLAUDE.md"), generateUniversalClaudeMd(), "utf-8");
|
|
44
|
+
}
|
|
45
|
+
// Copy agent template files
|
|
46
|
+
const agentDir = this.agentStore.workspacePath(agentName);
|
|
47
|
+
for (const file of ["SOUL.md", "ROLE.md"]) {
|
|
48
|
+
const src = join(agentDir, file);
|
|
49
|
+
if (existsSync(src)) {
|
|
50
|
+
cpSync(src, join(instancePath, file));
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
// Generate CONTEXT.md
|
|
54
|
+
const memoryStore = new MemoryStore(join(instancePath, "memory"));
|
|
55
|
+
const memories = memoryStore.list();
|
|
56
|
+
writeFileSync(join(instancePath, "CONTEXT.md"), generateContextMd(config, memories), "utf-8");
|
|
57
|
+
return instancePath;
|
|
58
|
+
}
|
|
59
|
+
/** Re-copy template files and regenerate CONTEXT.md after agent config changes */
|
|
60
|
+
syncInstance(agentName, userId) {
|
|
61
|
+
const config = this.agentStore.get(agentName);
|
|
62
|
+
if (!config)
|
|
63
|
+
throw new Error(`Agent "${agentName}" not found`);
|
|
64
|
+
const instancePath = this.getInstancePath(agentName, userId);
|
|
65
|
+
if (!existsSync(instancePath)) {
|
|
66
|
+
this.createInstance(agentName, userId);
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
// Re-copy template files
|
|
70
|
+
const agentDir = this.agentStore.workspacePath(agentName);
|
|
71
|
+
for (const file of ["SOUL.md", "ROLE.md"]) {
|
|
72
|
+
const src = join(agentDir, file);
|
|
73
|
+
if (existsSync(src)) {
|
|
74
|
+
cpSync(src, join(instancePath, file));
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
// Re-copy universal CLAUDE.md
|
|
78
|
+
const universalClaudeMd = join(getConfigDir(), "CLAUDE.md");
|
|
79
|
+
if (existsSync(universalClaudeMd)) {
|
|
80
|
+
cpSync(universalClaudeMd, join(instancePath, "CLAUDE.md"));
|
|
81
|
+
}
|
|
82
|
+
// Regenerate CONTEXT.md
|
|
83
|
+
const memoryStore = new MemoryStore(join(instancePath, "memory"));
|
|
84
|
+
const memories = memoryStore.list();
|
|
85
|
+
writeFileSync(join(instancePath, "CONTEXT.md"), generateContextMd(config, memories), "utf-8");
|
|
86
|
+
}
|
|
87
|
+
/** Delete an instance */
|
|
88
|
+
deleteInstance(agentName, userId) {
|
|
89
|
+
const instancePath = this.getInstancePath(agentName, userId);
|
|
90
|
+
if (!existsSync(instancePath))
|
|
91
|
+
return false;
|
|
92
|
+
rmSync(instancePath, { recursive: true });
|
|
93
|
+
return true;
|
|
94
|
+
}
|
|
95
|
+
/** List all instances, optionally filtered by agent name */
|
|
96
|
+
listInstances(agentName) {
|
|
97
|
+
const results = [];
|
|
98
|
+
if (!existsSync(this.instancesDir))
|
|
99
|
+
return results;
|
|
100
|
+
const agentDirs = agentName ? [agentName] : readdirSync(this.instancesDir).filter((entry) => {
|
|
101
|
+
const entryPath = join(this.instancesDir, entry);
|
|
102
|
+
return statSync(entryPath).isDirectory();
|
|
103
|
+
});
|
|
104
|
+
for (const agent of agentDirs) {
|
|
105
|
+
const agentPath = join(this.instancesDir, agent);
|
|
106
|
+
if (!existsSync(agentPath))
|
|
107
|
+
continue;
|
|
108
|
+
for (const userId of readdirSync(agentPath)) {
|
|
109
|
+
const userPath = join(agentPath, userId);
|
|
110
|
+
if (statSync(userPath).isDirectory()) {
|
|
111
|
+
results.push({ agentName: agent, userId, path: userPath });
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
return results;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
//# sourceMappingURL=instance-store.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"instance-store.js","sourceRoot":"","sources":["../src/instance-store.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EACV,SAAS,EAET,aAAa,EACb,MAAM,EACN,MAAM,EACN,WAAW,EACX,QAAQ,GACT,MAAM,IAAI,CAAC;AACZ,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAE5B,OAAO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Q,CAAC,CAAC,WAAW,EAAE,EAAE,CAAC;oBACrC,OAAO,CAAC,IAAI,CAAC,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC,CAAC;gBAC7D,CAAC;YACH,CAAC;QACH,CAAC;QAED,OAAO,OAAO,CAAC;IACjB,CAAC;CACF"}
|
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
import { google } from "googleapis";
|
|
2
2
|
import { OAuthClientManager } from "./oauth-client-manager.js";
|
|
3
3
|
import { TokenStore } from "./token-store.js";
|
|
4
|
-
import type { AgentPermission } from "./agent-store.js";
|
|
5
4
|
type OAuth2Client = InstanceType<typeof google.auth.OAuth2>;
|
|
6
5
|
export declare class PermissionDeniedError extends Error {
|
|
7
6
|
constructor(integration: string, account: string);
|
|
8
7
|
}
|
|
9
8
|
export declare class ScopedClientManager {
|
|
10
9
|
private inner;
|
|
11
|
-
private
|
|
12
|
-
constructor(inner: OAuthClientManager,
|
|
10
|
+
private integrations;
|
|
11
|
+
constructor(inner: OAuthClientManager, integrations: string[]);
|
|
13
12
|
private hasPermission;
|
|
14
13
|
getClient(accountKey: string): OAuth2Client;
|
|
15
14
|
listAccounts(): string[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scoped-client-manager.d.ts","sourceRoot":"","sources":["../src/scoped-client-manager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AACpC,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAC/D,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"scoped-client-manager.d.ts","sourceRoot":"","sources":["../src/scoped-client-manager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AACpC,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAC/D,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAE9C,KAAK,YAAY,GAAG,YAAY,CAAC,OAAO,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;AAE5D,qBAAa,qBAAsB,SAAQ,KAAK;gBAClC,WAAW,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM;CAIjD;AAUD,qBAAa,mBAAmB;IAE5B,OAAO,CAAC,KAAK;IACb,OAAO,CAAC,YAAY;gBADZ,KAAK,EAAE,kBAAkB,EACzB,YAAY,EAAE,MAAM,EAAE;IAGhC,OAAO,CAAC,aAAa;IAIrB,SAAS,CAAC,UAAU,EAAE,MAAM,GAAG,YAAY;IAQ3C,YAAY,IAAI,MAAM,EAAE;IAOxB,aAAa,IAAI,UAAU;IAI3B,YAAY,IAAI,YAAY;IAI5B,cAAc,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,CAAC,YAAY,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,YAAY;CAOrG"}
|
|
@@ -13,25 +13,25 @@ function parseAccountKey(key) {
|
|
|
13
13
|
}
|
|
14
14
|
export class ScopedClientManager {
|
|
15
15
|
inner;
|
|
16
|
-
|
|
17
|
-
constructor(inner,
|
|
16
|
+
integrations;
|
|
17
|
+
constructor(inner, integrations) {
|
|
18
18
|
this.inner = inner;
|
|
19
|
-
this.
|
|
19
|
+
this.integrations = integrations;
|
|
20
20
|
}
|
|
21
|
-
hasPermission(integration
|
|
22
|
-
return this.
|
|
21
|
+
hasPermission(integration) {
|
|
22
|
+
return this.integrations.includes(integration);
|
|
23
23
|
}
|
|
24
24
|
getClient(accountKey) {
|
|
25
25
|
const { integration, account } = parseAccountKey(accountKey);
|
|
26
|
-
if (!this.hasPermission(integration
|
|
26
|
+
if (!this.hasPermission(integration)) {
|
|
27
27
|
throw new PermissionDeniedError(integration, account);
|
|
28
28
|
}
|
|
29
29
|
return this.inner.getClient(accountKey);
|
|
30
30
|
}
|
|
31
31
|
listAccounts() {
|
|
32
32
|
return this.inner.listAccounts().filter((key) => {
|
|
33
|
-
const { integration
|
|
34
|
-
return this.hasPermission(integration
|
|
33
|
+
const { integration } = parseAccountKey(key);
|
|
34
|
+
return this.hasPermission(integration);
|
|
35
35
|
});
|
|
36
36
|
}
|
|
37
37
|
getTokenStore() {
|
|
@@ -42,7 +42,7 @@ export class ScopedClientManager {
|
|
|
42
42
|
}
|
|
43
43
|
setCredentials(account, tokens) {
|
|
44
44
|
const { integration, account: acct } = parseAccountKey(account);
|
|
45
|
-
if (!this.hasPermission(integration
|
|
45
|
+
if (!this.hasPermission(integration)) {
|
|
46
46
|
throw new PermissionDeniedError(integration, acct);
|
|
47
47
|
}
|
|
48
48
|
return this.inner.setCredentials(account, tokens);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scoped-client-manager.js","sourceRoot":"","sources":["../src/scoped-client-manager.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"scoped-client-manager.js","sourceRoot":"","sources":["../src/scoped-client-manager.ts"],"names":[],"mappings":"AAMA,MAAM,OAAO,qBAAsB,SAAQ,KAAK;IAC9C,YAAY,WAAmB,EAAE,OAAe;QAC9C,KAAK,CAAC,sCAAsC,WAAW,IAAI,OAAO,EAAE,CAAC,CAAC;QACtE,IAAI,CAAC,IAAI,GAAG,uBAAuB,CAAC;IACtC,CAAC;CACF;AAED,SAAS,eAAe,CAAC,GAAW;IAClC,MAAM,QAAQ,GAAG,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IAClC,IAAI,QAAQ,KAAK,CAAC,CAAC,EAAE,CAAC;QACpB,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,OAAO,EAAE,GAAG,EAAE,CAAC;IAChD,CAAC;IACD,OAAO,EAAE,WAAW,EAAE,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE,QAAQ,CAAC,EAAE,OAAO,EAAE,GAAG,CAAC,KAAK,CAAC,QAAQ,GAAG,C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AqB,CAAC,WAAW,EAAE,IAAI,CAAC,CAAC;QACrD,CAAC;QACD,OAAO,IAAI,CAAC,KAAK,CAAC,cAAc,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;IACpD,CAAC;CACF"}
|
package/package.json
CHANGED
package/src/agent-store.ts
CHANGED
|
@@ -7,14 +7,12 @@ import {
|
|
|
7
7
|
readdirSync,
|
|
8
8
|
renameSync,
|
|
9
9
|
statSync,
|
|
10
|
-
unlinkSync,
|
|
11
|
-
symlinkSync,
|
|
12
|
-
lstatSync,
|
|
13
10
|
} from "fs";
|
|
14
11
|
import { join } from "path";
|
|
15
|
-
import {
|
|
12
|
+
import { generateContextMd } from "./claude-md-generator.js";
|
|
16
13
|
import { MemoryStore } from "./memory-store.js";
|
|
17
14
|
|
|
15
|
+
/** @deprecated Use `integrations: string[]` on AgentConfig instead */
|
|
18
16
|
export interface AgentPermission {
|
|
19
17
|
integration: string;
|
|
20
18
|
account: string;
|
|
@@ -23,9 +21,8 @@ export interface AgentPermission {
|
|
|
23
21
|
export interface CronJobConfig {
|
|
24
22
|
id: string;
|
|
25
23
|
schedule: string;
|
|
26
|
-
|
|
24
|
+
taskFile: string; // relative path to markdown task description
|
|
27
25
|
maxIterations: number;
|
|
28
|
-
completionPromise: string;
|
|
29
26
|
enabled: boolean;
|
|
30
27
|
createdAt: string;
|
|
31
28
|
}
|
|
@@ -34,8 +31,7 @@ export interface AgentConfig {
|
|
|
34
31
|
name: string;
|
|
35
32
|
displayName: string;
|
|
36
33
|
role: string;
|
|
37
|
-
|
|
38
|
-
memory: string[];
|
|
34
|
+
integrations: string[]; // integration IDs (e.g. ["gmail", "gdrive"])
|
|
39
35
|
cronJobs: CronJobConfig[];
|
|
40
36
|
createdAt: string;
|
|
41
37
|
updatedAt: string;
|
|
@@ -83,33 +79,25 @@ export class AgentStore {
|
|
|
83
79
|
return join(this.agentsDir, name);
|
|
84
80
|
}
|
|
85
81
|
|
|
86
|
-
/** Get or create a per-client workspace, symlinking shared agent files */
|
|
87
|
-
clientWorkspacePath(agentName: string, userId: string): string {
|
|
88
|
-
const clientDir = join(this.agentsDir, agentName, "clients", userId);
|
|
89
|
-
if (!existsSync(clientDir)) {
|
|
90
|
-
mkdirSync(clientDir, { recursive: true });
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
// Symlink shared agent files into the client workspace
|
|
94
|
-
const agentDir = this.workspacePath(agentName);
|
|
95
|
-
for (const file of ["CLAUDE.md", "SOUL.md", "ROLE.md"]) {
|
|
96
|
-
const target = join(agentDir, file);
|
|
97
|
-
const link = join(clientDir, file);
|
|
98
|
-
if (existsSync(target) && !existsSync(link)) {
|
|
99
|
-
symlinkSync(target, link);
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
return clientDir;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
82
|
get(name: string): AgentConfig | null {
|
|
107
83
|
const path = this.filePath(name);
|
|
108
84
|
if (!existsSync(path)) return null;
|
|
109
85
|
try {
|
|
110
|
-
const
|
|
111
|
-
|
|
112
|
-
|
|
86
|
+
const raw = JSON.parse(readFileSync(path, "utf-8"));
|
|
87
|
+
// Migrate legacy formats
|
|
88
|
+
if (!raw.cronJobs) raw.cronJobs = [];
|
|
89
|
+
if (!raw.integrations) {
|
|
90
|
+
// Migrate from permissions[] → integrations[]
|
|
91
|
+
if (raw.permissions && Array.isArray(raw.permissions)) {
|
|
92
|
+
raw.integrations = [...new Set(raw.permissions.map((p: AgentPermission) => p.integration))];
|
|
93
|
+
} else {
|
|
94
|
+
raw.integrations = [];
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
// Drop legacy fields
|
|
98
|
+
delete raw.permissions;
|
|
99
|
+
delete raw.memory;
|
|
100
|
+
return raw as AgentConfig;
|
|
113
101
|
} catch {
|
|
114
102
|
return null;
|
|
115
103
|
}
|
|
@@ -170,35 +158,25 @@ export class AgentStore {
|
|
|
170
158
|
this.writeWorkspaceFiles(config, dir);
|
|
171
159
|
}
|
|
172
160
|
|
|
173
|
-
/** Get or create a MemoryStore for an agent
|
|
161
|
+
/** Get or create a MemoryStore for an agent */
|
|
174
162
|
getMemoryStore(name: string): MemoryStore {
|
|
175
163
|
let store = this.memoryStores.get(name);
|
|
176
164
|
if (store) return store;
|
|
177
165
|
|
|
178
166
|
const memoryDir = join(this.workspacePath(name), "memory");
|
|
179
167
|
store = new MemoryStore(memoryDir);
|
|
180
|
-
|
|
181
|
-
// Lazy migration: move config.memory[] → JSONL
|
|
182
|
-
const config = this.get(name);
|
|
183
|
-
if (config && config.memory.length > 0) {
|
|
184
|
-
store.migrate(config.memory);
|
|
185
|
-
config.memory = [];
|
|
186
|
-
config.updatedAt = new Date().toISOString();
|
|
187
|
-
this.save(config);
|
|
188
|
-
}
|
|
189
|
-
|
|
190
168
|
this.memoryStores.set(name, store);
|
|
191
169
|
return store;
|
|
192
170
|
}
|
|
193
171
|
|
|
194
|
-
/** Regenerate
|
|
195
|
-
|
|
172
|
+
/** Regenerate CONTEXT.md from current config */
|
|
173
|
+
regenerateContextMd(name: string): void {
|
|
196
174
|
const config = this.get(name);
|
|
197
175
|
if (!config) return;
|
|
198
176
|
const dir = this.workspacePath(name);
|
|
199
177
|
const memoryStore = this.getMemoryStore(name);
|
|
200
178
|
const memories = memoryStore.list();
|
|
201
|
-
writeFileSync(join(dir, "
|
|
179
|
+
writeFileSync(join(dir, "CONTEXT.md"), generateContextMd(config, memories), "utf-8");
|
|
202
180
|
}
|
|
203
181
|
|
|
204
182
|
addCronJob(agentName: string, job: CronJobConfig): void {
|
|
@@ -207,7 +185,7 @@ export class AgentStore {
|
|
|
207
185
|
config.cronJobs.push(job);
|
|
208
186
|
config.updatedAt = new Date().toISOString();
|
|
209
187
|
this.save(config);
|
|
210
|
-
this.
|
|
188
|
+
this.regenerateContextMd(agentName);
|
|
211
189
|
}
|
|
212
190
|
|
|
213
191
|
removeCronJob(agentName: string, jobId: string): void {
|
|
@@ -218,7 +196,7 @@ export class AgentStore {
|
|
|
218
196
|
config.cronJobs.splice(idx, 1);
|
|
219
197
|
config.updatedAt = new Date().toISOString();
|
|
220
198
|
this.save(config);
|
|
221
|
-
this.
|
|
199
|
+
this.regenerateContextMd(agentName);
|
|
222
200
|
}
|
|
223
201
|
|
|
224
202
|
listCronJobs(agentName: string): CronJobConfig[] {
|
|
@@ -240,7 +218,7 @@ export class AgentStore {
|
|
|
240
218
|
private writeWorkspaceFiles(config: AgentConfig, dir: string): void {
|
|
241
219
|
const memoryStore = this.getMemoryStore(config.name);
|
|
242
220
|
const memories = memoryStore.list();
|
|
243
|
-
writeFileSync(join(dir, "
|
|
221
|
+
writeFileSync(join(dir, "CONTEXT.md"), generateContextMd(config, memories), "utf-8");
|
|
244
222
|
|
|
245
223
|
const soulPath = join(dir, "SOUL.md");
|
|
246
224
|
if (!existsSync(soulPath)) {
|
|
@@ -1,43 +1,73 @@
|
|
|
1
1
|
import type { AgentConfig } from "./agent-store.js";
|
|
2
2
|
import type { MemoryEntry } from "./memory-store.js";
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
// Deduplicate integrations for the summary
|
|
10
|
-
const integrations = [...new Set(permissions.map((p) => p.integration))];
|
|
11
|
-
|
|
4
|
+
/**
|
|
5
|
+
* Generates the universal ~/.cliclaw/CLAUDE.md shared by all agents.
|
|
6
|
+
* Contains safety rules, CLI usage patterns, memory instructions, and behavioral guidelines.
|
|
7
|
+
*/
|
|
8
|
+
export function generateUniversalClaudeMd(): string {
|
|
12
9
|
const lines: string[] = [];
|
|
13
10
|
|
|
14
|
-
lines.push(
|
|
11
|
+
lines.push("# Agent Instructions");
|
|
15
12
|
lines.push("");
|
|
16
|
-
lines.push("Read SOUL.md
|
|
17
|
-
lines.push("Read ROLE.md for your capabilities and instructions.");
|
|
13
|
+
lines.push("Read SOUL.md, ROLE.md, and CONTEXT.md before doing anything.");
|
|
18
14
|
lines.push("");
|
|
15
|
+
|
|
16
|
+
lines.push("## Safety Rules");
|
|
17
|
+
lines.push("- Never access files outside your workspace directory");
|
|
18
|
+
lines.push("- Never modify or read system files, environment files, or credentials outside your workspace");
|
|
19
|
+
lines.push("- Never attempt to escalate permissions or bypass security boundaries");
|
|
20
|
+
lines.push("- Never share credentials, tokens, or sensitive data in your responses");
|
|
21
|
+
lines.push("- If a task requires access you don't have, say so — don't try to work around it");
|
|
22
|
+
lines.push("");
|
|
23
|
+
|
|
19
24
|
lines.push("## CLI Usage");
|
|
20
25
|
lines.push("All integrations are accessed via the `cliclaw` CLI. Always pass `--account <account>` to specify which account to use.");
|
|
21
26
|
lines.push("");
|
|
22
27
|
lines.push("For detailed usage of any command, run:");
|
|
23
28
|
lines.push(" `cliclaw <command> --help` or `cliclaw <command> <subcommand> --help`");
|
|
24
29
|
lines.push("");
|
|
25
|
-
lines.push("## Permitted Integrations");
|
|
26
30
|
|
|
27
|
-
|
|
28
|
-
|
|
31
|
+
lines.push("## Memory");
|
|
32
|
+
lines.push("Save, search, and remove memories with `cliclaw agent memory --help`.");
|
|
33
|
+
lines.push("Your agent name is in CONTEXT.md — use it for all memory commands.");
|
|
34
|
+
lines.push("");
|
|
35
|
+
lines.push("### Memory Guidelines");
|
|
36
|
+
lines.push("- Save important facts, preferences, and context that will be useful across conversations");
|
|
37
|
+
lines.push("- Use descriptive tags to categorize memories for easy retrieval");
|
|
38
|
+
lines.push("- Search existing memories before adding duplicates");
|
|
39
|
+
lines.push("- Use importance levels: 1 (low), 2 (normal), 3 (critical)");
|
|
40
|
+
lines.push("");
|
|
41
|
+
|
|
42
|
+
lines.push("## General Guidelines");
|
|
43
|
+
lines.push("- Be concise and direct in responses");
|
|
44
|
+
lines.push("- When running CLI commands, check `--help` first if unsure about options");
|
|
45
|
+
lines.push("- When in a client workspace, read CLIENT_INTEGRATIONS.md for available account names");
|
|
46
|
+
lines.push("- If no CLIENT_INTEGRATIONS.md exists, use `--account default`");
|
|
47
|
+
|
|
48
|
+
return lines.join("\n");
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Generates per-instance CONTEXT.md with agent-specific context:
|
|
53
|
+
* name, integrations, cron schedules, and current memories.
|
|
54
|
+
*/
|
|
55
|
+
export function generateContextMd(config: AgentConfig, memories: MemoryEntry[] = []): string {
|
|
56
|
+
const lines: string[] = [];
|
|
57
|
+
|
|
58
|
+
lines.push(`# ${config.displayName} — Context`);
|
|
59
|
+
lines.push("");
|
|
60
|
+
lines.push(`Agent name: \`${config.name}\``);
|
|
61
|
+
lines.push("");
|
|
62
|
+
|
|
63
|
+
lines.push("## Permitted Integrations");
|
|
64
|
+
if (config.integrations.length === 0) {
|
|
65
|
+
lines.push("No integrations configured.");
|
|
29
66
|
} else {
|
|
30
|
-
for (const integration of integrations) {
|
|
67
|
+
for (const integration of config.integrations) {
|
|
31
68
|
lines.push(`- \`cliclaw ${integration}\``);
|
|
32
69
|
}
|
|
33
|
-
lines.push("");
|
|
34
|
-
lines.push("When running in a client workspace, read CLIENT_INTEGRATIONS.md for available account names.");
|
|
35
|
-
lines.push("If no CLIENT_INTEGRATIONS.md exists, use `--account default`.");
|
|
36
70
|
}
|
|
37
|
-
|
|
38
|
-
lines.push("");
|
|
39
|
-
lines.push("## Memory");
|
|
40
|
-
lines.push(`Save, search, and remove memories with \`cliclaw agent memory --help\`. Your agent name is \`${config.name}\`.`);
|
|
41
71
|
lines.push("");
|
|
42
72
|
|
|
43
73
|
if (config.cronJobs && config.cronJobs.length > 0) {
|
|
@@ -46,17 +76,17 @@ export function generateClaudeMd(config: AgentConfig, memories: MemoryEntry[] =
|
|
|
46
76
|
for (const job of config.cronJobs) {
|
|
47
77
|
const status = job.enabled ? "enabled" : "disabled";
|
|
48
78
|
lines.push(`- **${job.id}** (${status}): \`${job.schedule}\``);
|
|
49
|
-
lines.push(` Task: ${job.
|
|
50
|
-
lines.push(`
|
|
79
|
+
lines.push(` Task file: ${job.taskFile}`);
|
|
80
|
+
lines.push(` Max iterations: ${job.maxIterations}`);
|
|
51
81
|
}
|
|
52
82
|
lines.push("");
|
|
53
83
|
}
|
|
54
84
|
|
|
55
85
|
if (memories.length === 0) {
|
|
56
|
-
lines.push("
|
|
86
|
+
lines.push("## Current Memories");
|
|
57
87
|
lines.push("No memories yet.");
|
|
58
88
|
} else {
|
|
59
|
-
lines.push("
|
|
89
|
+
lines.push("## Current Memories");
|
|
60
90
|
|
|
61
91
|
let displayMemories: MemoryEntry[];
|
|
62
92
|
let truncated = false;
|
|
@@ -64,7 +94,6 @@ export function generateClaudeMd(config: AgentConfig, memories: MemoryEntry[] =
|
|
|
64
94
|
if (memories.length > 50) {
|
|
65
95
|
const critical = memories.filter((m) => m.importance === 3);
|
|
66
96
|
const recent = memories.slice(-30);
|
|
67
|
-
// Merge critical + recent, deduplicate by id
|
|
68
97
|
const seen = new Set<string>();
|
|
69
98
|
displayMemories = [];
|
|
70
99
|
for (const m of [...critical, ...recent]) {
|
package/src/config.ts
CHANGED
|
@@ -22,6 +22,10 @@ export function getAgentsDir(): string {
|
|
|
22
22
|
return join(CONFIG_DIR, "agents");
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
+
export function getInstancesDir(): string {
|
|
26
|
+
return join(CONFIG_DIR, "instances");
|
|
27
|
+
}
|
|
28
|
+
|
|
25
29
|
export function loadConfig(): CliclawConfig {
|
|
26
30
|
if (!existsSync(CONFIG_DIR)) {
|
|
27
31
|
mkdirSync(CONFIG_DIR, { recursive: true });
|
package/src/index.ts
CHANGED
|
@@ -2,6 +2,7 @@ export { TokenStore } from "./token-store.js";
|
|
|
2
2
|
export { OAuthClientManager } from "./oauth-client-manager.js";
|
|
3
3
|
export { AgentStore } from "./agent-store.js";
|
|
4
4
|
export type { AgentConfig, AgentPermission, CronJobConfig } from "./agent-store.js";
|
|
5
|
+
export { getInstancesDir } from "./config.js";
|
|
5
6
|
export { ScopedClientManager, PermissionDeniedError } from "./scoped-client-manager.js";
|
|
6
7
|
export { createOAuthClient, getAuthUrl } from "./gmail-auth.js";
|
|
7
8
|
export { createGDriveOAuthClient, getGDriveAuthUrl } from "./gdrive-auth.js";
|
|
@@ -14,6 +15,7 @@ export { loadConfig, getConfigDir, getTokensPath, getAgentsDir } from "./config.
|
|
|
14
15
|
export { INTEGRATIONS } from "./integration-registry.js";
|
|
15
16
|
export type { IntegrationDef } from "./integration-registry.js";
|
|
16
17
|
export type { CliclawConfig } from "./config.js";
|
|
17
|
-
export {
|
|
18
|
+
export { generateUniversalClaudeMd, generateContextMd } from "./claude-md-generator.js";
|
|
19
|
+
export { InstanceStore } from "./instance-store.js";
|
|
18
20
|
export { MemoryStore } from "./memory-store.js";
|
|
19
21
|
export type { MemoryEntry } from "./memory-store.js";
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import {
|
|
2
|
+
existsSync,
|
|
3
|
+
mkdirSync,
|
|
4
|
+
readFileSync,
|
|
5
|
+
writeFileSync,
|
|
6
|
+
cpSync,
|
|
7
|
+
rmSync,
|
|
8
|
+
readdirSync,
|
|
9
|
+
statSync,
|
|
10
|
+
} from "fs";
|
|
11
|
+
import { join } from "path";
|
|
12
|
+
import { AgentStore } from "./agent-store.js";
|
|
13
|
+
import { generateUniversalClaudeMd, generateContextMd } from "./claude-md-generator.js";
|
|
14
|
+
import { MemoryStore } from "./memory-store.js";
|
|
15
|
+
import { getConfigDir } from "./config.js";
|
|
16
|
+
|
|
17
|
+
export class InstanceStore {
|
|
18
|
+
constructor(
|
|
19
|
+
private instancesDir: string,
|
|
20
|
+
private agentStore: AgentStore,
|
|
21
|
+
) {}
|
|
22
|
+
|
|
23
|
+
private ensureDir(path: string): void {
|
|
24
|
+
if (!existsSync(path)) {
|
|
25
|
+
mkdirSync(path, { recursive: true });
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** Get the root path for an instance */
|
|
30
|
+
getInstancePath(agentName: string, userId: string): string {
|
|
31
|
+
return join(this.instancesDir, agentName, userId);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** Get the workspace subdir (what gets mounted into Docker) */
|
|
35
|
+
getWorkspacePath(agentName: string, userId: string): string {
|
|
36
|
+
return join(this.getInstancePath(agentName, userId), "workspace");
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** Create a new instance by copying template files and generating CONTEXT.md */
|
|
40
|
+
createInstance(agentName: string, userId: string): string {
|
|
41
|
+
const config = this.agentStore.get(agentName);
|
|
42
|
+
if (!config) throw new Error(`Agent "${agentName}" not found`);
|
|
43
|
+
|
|
44
|
+
const instancePath = this.getInstancePath(agentName, userId);
|
|
45
|
+
this.ensureDir(instancePath);
|
|
46
|
+
this.ensureDir(join(instancePath, "workspace"));
|
|
47
|
+
this.ensureDir(join(instancePath, "memory"));
|
|
48
|
+
this.ensureDir(join(instancePath, "cron"));
|
|
49
|
+
|
|
50
|
+
// Copy universal CLAUDE.md
|
|
51
|
+
const universalClaudeMd = join(getConfigDir(), "CLAUDE.md");
|
|
52
|
+
if (existsSync(universalClaudeMd)) {
|
|
53
|
+
cpSync(universalClaudeMd, join(instancePath, "CLAUDE.md"));
|
|
54
|
+
} else {
|
|
55
|
+
// Generate it if it doesn't exist yet
|
|
56
|
+
writeFileSync(join(instancePath, "CLAUDE.md"), generateUniversalClaudeMd(), "utf-8");
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// Copy agent template files
|
|
60
|
+
const agentDir = this.agentStore.workspacePath(agentName);
|
|
61
|
+
for (const file of ["SOUL.md", "ROLE.md"]) {
|
|
62
|
+
const src = join(agentDir, file);
|
|
63
|
+
if (existsSync(src)) {
|
|
64
|
+
cpSync(src, join(instancePath, file));
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// Generate CONTEXT.md
|
|
69
|
+
const memoryStore = new MemoryStore(join(instancePath, "memory"));
|
|
70
|
+
const memories = memoryStore.list();
|
|
71
|
+
writeFileSync(
|
|
72
|
+
join(instancePath, "CONTEXT.md"),
|
|
73
|
+
generateContextMd(config, memories),
|
|
74
|
+
"utf-8",
|
|
75
|
+
);
|
|
76
|
+
|
|
77
|
+
return instancePath;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/** Re-copy template files and regenerate CONTEXT.md after agent config changes */
|
|
81
|
+
syncInstance(agentName: string, userId: string): void {
|
|
82
|
+
const config = this.agentStore.get(agentName);
|
|
83
|
+
if (!config) throw new Error(`Agent "${agentName}" not found`);
|
|
84
|
+
|
|
85
|
+
const instancePath = this.getInstancePath(agentName, userId);
|
|
86
|
+
if (!existsSync(instancePath)) {
|
|
87
|
+
this.createInstance(agentName, userId);
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// Re-copy template files
|
|
92
|
+
const agentDir = this.agentStore.workspacePath(agentName);
|
|
93
|
+
for (const file of ["SOUL.md", "ROLE.md"]) {
|
|
94
|
+
const src = join(agentDir, file);
|
|
95
|
+
if (existsSync(src)) {
|
|
96
|
+
cpSync(src, join(instancePath, file));
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// Re-copy universal CLAUDE.md
|
|
101
|
+
const universalClaudeMd = join(getConfigDir(), "CLAUDE.md");
|
|
102
|
+
if (existsSync(universalClaudeMd)) {
|
|
103
|
+
cpSync(universalClaudeMd, join(instancePath, "CLAUDE.md"));
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// Regenerate CONTEXT.md
|
|
107
|
+
const memoryStore = new MemoryStore(join(instancePath, "memory"));
|
|
108
|
+
const memories = memoryStore.list();
|
|
109
|
+
writeFileSync(
|
|
110
|
+
join(instancePath, "CONTEXT.md"),
|
|
111
|
+
generateContextMd(config, memories),
|
|
112
|
+
"utf-8",
|
|
113
|
+
);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/** Delete an instance */
|
|
117
|
+
deleteInstance(agentName: string, userId: string): boolean {
|
|
118
|
+
const instancePath = this.getInstancePath(agentName, userId);
|
|
119
|
+
if (!existsSync(instancePath)) return false;
|
|
120
|
+
rmSync(instancePath, { recursive: true });
|
|
121
|
+
return true;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/** List all instances, optionally filtered by agent name */
|
|
125
|
+
listInstances(agentName?: string): Array<{ agentName: string; userId: string; path: string }> {
|
|
126
|
+
const results: Array<{ agentName: string; userId: string; path: string }> = [];
|
|
127
|
+
|
|
128
|
+
if (!existsSync(this.instancesDir)) return results;
|
|
129
|
+
|
|
130
|
+
const agentDirs = agentName ? [agentName] : readdirSync(this.instancesDir).filter((entry) => {
|
|
131
|
+
const entryPath = join(this.instancesDir, entry);
|
|
132
|
+
return statSync(entryPath).isDirectory();
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
for (const agent of agentDirs) {
|
|
136
|
+
const agentPath = join(this.instancesDir, agent);
|
|
137
|
+
if (!existsSync(agentPath)) continue;
|
|
138
|
+
|
|
139
|
+
for (const userId of readdirSync(agentPath)) {
|
|
140
|
+
const userPath = join(agentPath, userId);
|
|
141
|
+
if (statSync(userPath).isDirectory()) {
|
|
142
|
+
results.push({ agentName: agent, userId, path: userPath });
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
return results;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { google } from "googleapis";
|
|
2
2
|
import { OAuthClientManager } from "./oauth-client-manager.js";
|
|
3
3
|
import { TokenStore } from "./token-store.js";
|
|
4
|
-
import type { AgentPermission } from "./agent-store.js";
|
|
5
4
|
|
|
6
5
|
type OAuth2Client = InstanceType<typeof google.auth.OAuth2>;
|
|
7
6
|
|
|
@@ -23,18 +22,16 @@ function parseAccountKey(key: string): { integration: string; account: string }
|
|
|
23
22
|
export class ScopedClientManager {
|
|
24
23
|
constructor(
|
|
25
24
|
private inner: OAuthClientManager,
|
|
26
|
-
private
|
|
25
|
+
private integrations: string[],
|
|
27
26
|
) {}
|
|
28
27
|
|
|
29
|
-
private hasPermission(integration: string
|
|
30
|
-
return this.
|
|
31
|
-
(p) => p.integration === integration,
|
|
32
|
-
);
|
|
28
|
+
private hasPermission(integration: string): boolean {
|
|
29
|
+
return this.integrations.includes(integration);
|
|
33
30
|
}
|
|
34
31
|
|
|
35
32
|
getClient(accountKey: string): OAuth2Client {
|
|
36
33
|
const { integration, account } = parseAccountKey(accountKey);
|
|
37
|
-
if (!this.hasPermission(integration
|
|
34
|
+
if (!this.hasPermission(integration)) {
|
|
38
35
|
throw new PermissionDeniedError(integration, account);
|
|
39
36
|
}
|
|
40
37
|
return this.inner.getClient(accountKey);
|
|
@@ -42,8 +39,8 @@ export class ScopedClientManager {
|
|
|
42
39
|
|
|
43
40
|
listAccounts(): string[] {
|
|
44
41
|
return this.inner.listAccounts().filter((key) => {
|
|
45
|
-
const { integration
|
|
46
|
-
return this.hasPermission(integration
|
|
42
|
+
const { integration } = parseAccountKey(key);
|
|
43
|
+
return this.hasPermission(integration);
|
|
47
44
|
});
|
|
48
45
|
}
|
|
49
46
|
|
|
@@ -57,7 +54,7 @@ export class ScopedClientManager {
|
|
|
57
54
|
|
|
58
55
|
setCredentials(account: string, tokens: Parameters<OAuth2Client["setCredentials"]>[0]): OAuth2Client {
|
|
59
56
|
const { integration, account: acct } = parseAccountKey(account);
|
|
60
|
-
if (!this.hasPermission(integration
|
|
57
|
+
if (!this.hasPermission(integration)) {
|
|
61
58
|
throw new PermissionDeniedError(integration, acct);
|
|
62
59
|
}
|
|
63
60
|
return this.inner.setCredentials(account, tokens);
|