@digitalpresence/cliclaw-auth 0.1.0 → 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 +49 -24
- 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/oauth-client-manager.d.ts.map +1 -1
- package/dist/oauth-client-manager.js +10 -1
- package/dist/oauth-client-manager.js.map +1 -1
- 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/dist/token-store.d.ts.map +1 -1
- package/dist/token-store.js +25 -6
- package/dist/token-store.js.map +1 -1
- package/package.json +1 -1
- package/src/agent-store.ts +26 -48
- package/src/claude-md-generator.ts +57 -29
- package/src/config.ts +4 -0
- package/src/index.ts +3 -1
- package/src/instance-store.ts +149 -0
- package/src/oauth-client-manager.ts +10 -1
- package/src/scoped-client-manager.ts +7 -10
- package/src/token-store.ts +24 -5
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"oauth-client-manager.d.ts","sourceRoot":"","sources":["../src/oauth-client-manager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AAEpC,O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gBAAgB,CAAC,CAAC,CAAC,CAAC,CAAC,GACpD,YAAY;IAcf,aAAa,IAAI,UAAU;IAI3B,YAAY,IAAI,MAAM,EAAE;CAYzB"}
|
|
@@ -43,7 +43,16 @@ export class OAuthClientManager {
|
|
|
43
43
|
return this.tokenStore;
|
|
44
44
|
}
|
|
45
45
|
listAccounts() {
|
|
46
|
-
|
|
46
|
+
const keys = this.tokenStore.list();
|
|
47
|
+
// Include both raw keys and bare account names (from integration:account format)
|
|
48
|
+
const accounts = new Set(keys);
|
|
49
|
+
for (const key of keys) {
|
|
50
|
+
const colonIdx = key.indexOf(":");
|
|
51
|
+
if (colonIdx !== -1) {
|
|
52
|
+
accounts.add(key.slice(colonIdx + 1));
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return [...accounts];
|
|
47
56
|
}
|
|
48
57
|
}
|
|
49
58
|
//# sourceMappingURL=oauth-client-manager.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"oauth-client-manager.js","sourceRoot":"","sources":["../src/oauth-client-manager.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAKpD,MAAM,OAAO,kBAAkB;IAInB;IACA;IACA;IALF,OAAO,GAAG,IAAI,GAAG,EAAwB,CAAC;IAElD,YACU,gBAAwB,EACxB,WAAmB,EACnB,UAAsB;QAFtB,qBAAgB,GAAhB,gBAAgB,CAAQ;QACxB,gBAAW,GAAX,WAAW,CAAQ;QACnB,eAAU,GAAV,UAAU,CAAY;IAC7B,CAAC;IAEJ,SAAS,CAAC,OAAe;QACvB,MAAM,QAAQ,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;QAC3C,IAAI,QAAQ;YAAE,OAAO,QAAQ,CAAC;QAE9B,MAAM,MAAM,GAAG,iBAAiB,CAAC,IAAI,CAAC,gBAAgB,EAAE,IAAI,CAAC,WAAW,CAAC,CAAC;QAC1E,MAAM,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,CAAC,EAAE,CAAC;gBACpB,QAAQ,CAAC,GAAG,CAAC,GAAG,CAAC,KAAK,CAAC,QAAQ,GAAG,CAAC,CAAC,CAAC,CAAC;YACxC,CAAC;QACH,CAAC;QACD,OAAO,CAAC,GAAG,QAAQ,CAAC,CAAC;IACvB,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,CAAC,CAAC,EAAE,CAAC;AACnF,CA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AC,CAAC;QACrD,CAAC;QACD,OAAO,IAAI,CAAC,KAAK,CAAC,cAAc,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;IACpD,CAAC;CACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"token-store.d.ts","sourceRoot":"","sources":["../src/token-store.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAMvD,qBAAa,UAAU;IACT,OAAO,CAAC,UAAU;gBAAV,UAAU,EAAE,MAAM;IAEtC,OAAO,CAAC,IAAI;IAWZ,OAAO,CAAC,IAAI;IAQZ,GAAG,CAAC,OAAO,EAAE,MAAM,GAAG,WAAW,GAAG,IAAI;
|
|
1
|
+
{"version":3,"file":"token-store.d.ts","sourceRoot":"","sources":["../src/token-store.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAMvD,qBAAa,UAAU;IACT,OAAO,CAAC,UAAU;gBAAV,UAAU,EAAE,MAAM;IAEtC,OAAO,CAAC,IAAI;IAWZ,OAAO,CAAC,IAAI;IAQZ,GAAG,CAAC,OAAO,EAAE,MAAM,GAAG,WAAW,GAAG,IAAI;IAaxC,GAAG,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,WAAW,GAAG,IAAI;IAM/C,GAAG,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO;IAI7B,MAAM,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO;IAmBhC,IAAI,IAAI,MAAM,EAAE;CAGjB"}
|
package/dist/token-store.js
CHANGED
|
@@ -25,7 +25,16 @@ export class TokenStore {
|
|
|
25
25
|
}
|
|
26
26
|
get(account) {
|
|
27
27
|
const data = this.load();
|
|
28
|
-
|
|
28
|
+
if (data[account])
|
|
29
|
+
return data[account];
|
|
30
|
+
// Fall back to integration:account key format (portal token injection)
|
|
31
|
+
for (const key of Object.keys(data)) {
|
|
32
|
+
const colonIdx = key.indexOf(":");
|
|
33
|
+
if (colonIdx !== -1 && key.slice(colonIdx + 1) === account) {
|
|
34
|
+
return data[key];
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return null;
|
|
29
38
|
}
|
|
30
39
|
set(account, tokens) {
|
|
31
40
|
const data = this.load();
|
|
@@ -37,11 +46,21 @@ export class TokenStore {
|
|
|
37
46
|
}
|
|
38
47
|
delete(account) {
|
|
39
48
|
const data = this.load();
|
|
40
|
-
if (
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
49
|
+
if (account in data) {
|
|
50
|
+
delete data[account];
|
|
51
|
+
this.save(data);
|
|
52
|
+
return true;
|
|
53
|
+
}
|
|
54
|
+
// Try integration:account key format
|
|
55
|
+
for (const key of Object.keys(data)) {
|
|
56
|
+
const colonIdx = key.indexOf(":");
|
|
57
|
+
if (colonIdx !== -1 && key.slice(colonIdx + 1) === account) {
|
|
58
|
+
delete data[key];
|
|
59
|
+
this.save(data);
|
|
60
|
+
return true;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return false;
|
|
45
64
|
}
|
|
46
65
|
list() {
|
|
47
66
|
return Object.keys(this.load());
|
package/dist/token-store.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"token-store.js","sourceRoot":"","sources":["../src/token-store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,IAAI,CAAC;AACxE,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAO/B,MAAM,OAAO,UAAU;IACD;IAApB,YAAoB,UAAkB;QAAlB,eAAU,GAAV,UAAU,CAAQ;IAAG,CAAC;IAElC,IAAI;QACV,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,UAAU,CAAC,EAAE,CAAC;YACjC,OAAO,EAAE,CAAC;QACZ,CAAC;QACD,IAAI,CAAC;YACH,OAAO,IAA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AM,CAAC,OAAe;QACpB,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC;QACzB,IAAI,OAAO,IAAI,IAAI,EAAE,CAAC;YACpB,OAAO,IAAI,CAAC,OAAO,CAAC,CAAC;YACrB,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YAChB,OAAO,IAAI,CAAC;QACd,CAAC;QACD,qCAAqC;QACrC,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;YACpC,MAAM,QAAQ,GAAG,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;YAClC,IAAI,QAAQ,KAAK,CAAC,CAAC,IAAI,GAAG,CAAC,KAAK,CAAC,QAAQ,GAAG,CAAC,CAAC,KAAK,OAAO,EAAE,CAAC;gBAC3D,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC;gBACjB,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;gBAChB,OAAO,IAAI,CAAC;YACd,CAAC;QACH,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC;IAED,IAAI;QACF,OAAO,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC;IAClC,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,44 +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
|
|
31
|
-
lines.push(`-
|
|
67
|
+
for (const integration of config.integrations) {
|
|
68
|
+
lines.push(`- \`cliclaw ${integration}\``);
|
|
32
69
|
}
|
|
33
|
-
lines.push("");
|
|
34
|
-
lines.push("IMPORTANT: ONLY access accounts listed above.");
|
|
35
|
-
lines.push("");
|
|
36
|
-
lines.push("Available integrations: " + integrations.map((i) => `\`cliclaw ${i}\``).join(", "));
|
|
37
70
|
}
|
|
38
|
-
|
|
39
|
-
lines.push("");
|
|
40
|
-
lines.push("## Memory");
|
|
41
|
-
lines.push(`Save, search, and remove memories with \`cliclaw agent memory --help\`. Your agent name is \`${config.name}\`.`);
|
|
42
71
|
lines.push("");
|
|
43
72
|
|
|
44
73
|
if (config.cronJobs && config.cronJobs.length > 0) {
|
|
@@ -47,17 +76,17 @@ export function generateClaudeMd(config: AgentConfig, memories: MemoryEntry[] =
|
|
|
47
76
|
for (const job of config.cronJobs) {
|
|
48
77
|
const status = job.enabled ? "enabled" : "disabled";
|
|
49
78
|
lines.push(`- **${job.id}** (${status}): \`${job.schedule}\``);
|
|
50
|
-
lines.push(` Task: ${job.
|
|
51
|
-
lines.push(`
|
|
79
|
+
lines.push(` Task file: ${job.taskFile}`);
|
|
80
|
+
lines.push(` Max iterations: ${job.maxIterations}`);
|
|
52
81
|
}
|
|
53
82
|
lines.push("");
|
|
54
83
|
}
|
|
55
84
|
|
|
56
85
|
if (memories.length === 0) {
|
|
57
|
-
lines.push("
|
|
86
|
+
lines.push("## Current Memories");
|
|
58
87
|
lines.push("No memories yet.");
|
|
59
88
|
} else {
|
|
60
|
-
lines.push("
|
|
89
|
+
lines.push("## Current Memories");
|
|
61
90
|
|
|
62
91
|
let displayMemories: MemoryEntry[];
|
|
63
92
|
let truncated = false;
|
|
@@ -65,7 +94,6 @@ export function generateClaudeMd(config: AgentConfig, memories: MemoryEntry[] =
|
|
|
65
94
|
if (memories.length > 50) {
|
|
66
95
|
const critical = memories.filter((m) => m.importance === 3);
|
|
67
96
|
const recent = memories.slice(-30);
|
|
68
|
-
// Merge critical + recent, deduplicate by id
|
|
69
97
|
const seen = new Set<string>();
|
|
70
98
|
displayMemories = [];
|
|
71
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
|
+
}
|