@digitalpresence/cliclaw-auth 0.1.1 → 0.3.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 +15 -1
- package/dist/claude-md-generator.d.ts.map +1 -1
- package/dist/claude-md-generator.js +61 -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 +5 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -2
- package/dist/index.js.map +1 -1
- package/dist/instance-store.d.ts +25 -0
- package/dist/instance-store.d.ts.map +1 -0
- package/dist/instance-store.js +106 -0
- package/dist/instance-store.js.map +1 -0
- package/dist/integration-registry.d.ts +11 -0
- package/dist/integration-registry.d.ts.map +1 -1
- package/dist/integration-registry.js +32 -0
- package/dist/integration-registry.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 +4 -3
- package/dist/token-store.d.ts.map +1 -1
- package/dist/token-store.js.map +1 -1
- package/package.json +7 -3
- package/src/agent-store.ts +26 -48
- package/src/claude-md-generator.ts +74 -26
- package/src/config.ts +4 -0
- package/src/index.ts +5 -3
- package/src/instance-store.ts +136 -0
- package/src/integration-registry.ts +44 -0
- package/src/scoped-client-manager.ts +7 -10
- package/src/token-store.ts +5 -4
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"instance-store.js","sourceRoot":"","sources":["../src/instance-store.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EACV,SAAS,EACT,YAAY,EACZ,a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
|
|
4
5
|
scopes: string[];
|
|
5
6
|
}
|
|
7
|
+
export interface ProviderConfig {
|
|
8
|
+
authUrl: string;
|
|
9
|
+
tokenUrl: string;
|
|
10
|
+
userInfoUrl: string;
|
|
11
|
+
clientIdEnv: string;
|
|
12
|
+
clientSecretEnv: string;
|
|
13
|
+
extraScopes: string[];
|
|
14
|
+
extraAuthParams: Record<string, string>;
|
|
15
|
+
}
|
|
16
|
+
export declare const PROVIDERS: Record<string, ProviderConfig>;
|
|
6
17
|
export declare const INTEGRATIONS: Record<string, IntegrationDef>;
|
|
7
18
|
//# sourceMappingURL=integration-registry.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"integration-registry.d.ts","sourceRoot":"","sources":["../src/integration-registry.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,cAAc;IAC7B,EAAE,EAAE,MAAM,CAAC;IACX,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,MAAM,EAAE,CAAC;CAClB;AAED,eAAO,MAAM,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,cAAc,
|
|
1
|
+
{"version":3,"file":"integration-registry.d.ts","sourceRoot":"","sources":["../src/integration-registry.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,cAAc;IAC7B,EAAE,EAAE,MAAM,CAAC;IACX,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,EAAE,CAAC;CAClB;AAED,MAAM,WAAW,cAAc;IAC7B,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,MAAM,CAAC;IACpB,eAAe,EAAE,MAAM,CAAC;IACxB,WAAW,EAAE,MAAM,EAAE,CAAC;IACtB,eAAe,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACzC;AAED,eAAO,MAAM,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,cAAc,CAmBpD,CAAC;AAEF,eAAO,MAAM,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,cAAc,CAqDvD,CAAC"}
|
|
@@ -1,17 +1,40 @@
|
|
|
1
|
+
export const PROVIDERS = {
|
|
2
|
+
google: {
|
|
3
|
+
authUrl: "https://accounts.google.com/o/oauth2/v2/auth",
|
|
4
|
+
tokenUrl: "https://oauth2.googleapis.com/token",
|
|
5
|
+
userInfoUrl: "https://www.googleapis.com/oauth2/v2/userinfo",
|
|
6
|
+
clientIdEnv: "GOOGLE_CLIENT_ID",
|
|
7
|
+
clientSecretEnv: "GOOGLE_CLIENT_SECRET",
|
|
8
|
+
extraScopes: ["openid", "email", "profile"],
|
|
9
|
+
extraAuthParams: { access_type: "offline", prompt: "consent" },
|
|
10
|
+
},
|
|
11
|
+
github: {
|
|
12
|
+
authUrl: "https://github.com/login/oauth/authorize",
|
|
13
|
+
tokenUrl: "https://github.com/login/oauth/access_token",
|
|
14
|
+
userInfoUrl: "https://api.github.com/user",
|
|
15
|
+
clientIdEnv: "GITHUB_CLIENT_ID",
|
|
16
|
+
clientSecretEnv: "GITHUB_CLIENT_SECRET",
|
|
17
|
+
extraScopes: [],
|
|
18
|
+
extraAuthParams: {},
|
|
19
|
+
},
|
|
20
|
+
};
|
|
1
21
|
export const INTEGRATIONS = {
|
|
2
22
|
gmail: {
|
|
3
23
|
id: "gmail",
|
|
4
24
|
displayName: "Gmail",
|
|
25
|
+
provider: "google",
|
|
5
26
|
scopes: ["https://www.googleapis.com/auth/gmail.modify"],
|
|
6
27
|
},
|
|
7
28
|
gdrive: {
|
|
8
29
|
id: "gdrive",
|
|
9
30
|
displayName: "Google Drive",
|
|
31
|
+
provider: "google",
|
|
10
32
|
scopes: ["https://www.googleapis.com/auth/drive"],
|
|
11
33
|
},
|
|
12
34
|
gsheets: {
|
|
13
35
|
id: "gsheets",
|
|
14
36
|
displayName: "Google Sheets",
|
|
37
|
+
provider: "google",
|
|
15
38
|
scopes: [
|
|
16
39
|
"https://www.googleapis.com/auth/spreadsheets",
|
|
17
40
|
"https://www.googleapis.com/auth/drive",
|
|
@@ -20,6 +43,7 @@ export const INTEGRATIONS = {
|
|
|
20
43
|
gslides: {
|
|
21
44
|
id: "gslides",
|
|
22
45
|
displayName: "Google Slides",
|
|
46
|
+
provider: "google",
|
|
23
47
|
scopes: [
|
|
24
48
|
"https://www.googleapis.com/auth/presentations",
|
|
25
49
|
"https://www.googleapis.com/auth/drive.file",
|
|
@@ -28,16 +52,24 @@ export const INTEGRATIONS = {
|
|
|
28
52
|
calendar: {
|
|
29
53
|
id: "calendar",
|
|
30
54
|
displayName: "Google Calendar",
|
|
55
|
+
provider: "google",
|
|
31
56
|
scopes: ["https://www.googleapis.com/auth/calendar"],
|
|
32
57
|
},
|
|
33
58
|
forms: {
|
|
34
59
|
id: "forms",
|
|
35
60
|
displayName: "Google Forms",
|
|
61
|
+
provider: "google",
|
|
36
62
|
scopes: [
|
|
37
63
|
"https://www.googleapis.com/auth/forms.body",
|
|
38
64
|
"https://www.googleapis.com/auth/forms.responses.readonly",
|
|
39
65
|
"https://www.googleapis.com/auth/drive.metadata.readonly",
|
|
40
66
|
],
|
|
41
67
|
},
|
|
68
|
+
github: {
|
|
69
|
+
id: "github",
|
|
70
|
+
displayName: "GitHub",
|
|
71
|
+
provider: "github",
|
|
72
|
+
scopes: ["repo", "read:user", "user:email"],
|
|
73
|
+
},
|
|
42
74
|
};
|
|
43
75
|
//# sourceMappingURL=integration-registry.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"integration-registry.js","sourceRoot":"","sources":["../src/integration-registry.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"integration-registry.js","sourceRoot":"","sources":["../src/integration-registry.ts"],"names":[],"mappings":"AAiBA,MAAM,CAAC,MAAM,SAAS,GAAmC;IACvD,MAAM,EAAE;QACN,OAAO,EAAE,8CAA8C;QACvD,QAAQ,EAAE,qCA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ACX,WAAW,EAAE,cAAc;QAC3B,QAAQ,EAAE,QAAQ;QAClB,MAAM,EAAE;YACN,4CAA4C;YAC5C,0DAA0D;YAC1D,yDAAyD;SAC1D;KACF;IACD,MAAM,EAAE;QACN,EAAE,EAAE,QAAQ;QACZ,WAAW,EAAE,QAAQ;QACrB,QAAQ,EAAE,QAAQ;QAClB,MAAM,EAAE,CAAC,MAAM,EAAE,WAAW,EAAE,YAAY,CAAC;KAC5C;CACF,CAAC"}
|
|
@@ -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,Q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AAI,CAAC,aAAa,CAAC,WAAW,CAAC,EAAE,CAAC;YACrC,MAAM,IAAI,qBAAqB,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/dist/token-store.d.ts
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
|
|
1
|
+
type OAuthCredentials = Record<string, any>;
|
|
2
2
|
export declare class TokenStore {
|
|
3
3
|
private tokensPath;
|
|
4
4
|
constructor(tokensPath: string);
|
|
5
5
|
private load;
|
|
6
6
|
private save;
|
|
7
|
-
get(account: string):
|
|
8
|
-
set(account: string, tokens:
|
|
7
|
+
get(account: string): OAuthCredentials | null;
|
|
8
|
+
set(account: string, tokens: OAuthCredentials): void;
|
|
9
9
|
has(account: string): boolean;
|
|
10
10
|
delete(account: string): boolean;
|
|
11
11
|
list(): string[];
|
|
12
12
|
}
|
|
13
|
+
export {};
|
|
13
14
|
//# sourceMappingURL=token-store.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"token-store.d.ts","sourceRoot":"","sources":["../src/token-store.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"token-store.d.ts","sourceRoot":"","sources":["../src/token-store.ts"],"names":[],"mappings":"AAGA,KAAK,gBAAgB,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;AAM5C,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,gBAAgB,GAAG,IAAI;IAa7C,GAAG,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,gBAAgB,GAAG,IAAI;IAMpD,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.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;
|
|
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;AAQ/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,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,IAAI,CAAC,UAAU,EAAE,OAAO,CAAC,CAAc,CAAC;QACzE,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,EAAE,CAAC;QACZ,CAAC;IACH,CAAC;IAEO,IAAI,CAAC,IAAe;QAC1B,MAAM,GAAG,GAAG,OAAO,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;QACrC,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC;YACrB,SAAS,CAAC,GAAG,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;QACtC,CAAC;QACD,aAAa,CAAC,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC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AAI,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
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@digitalpresence/cliclaw-auth",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"type": "module",
|
|
5
|
-
"main": "
|
|
6
|
-
"types": "
|
|
5
|
+
"main": "src/index.ts",
|
|
6
|
+
"types": "src/index.ts",
|
|
7
7
|
"exports": {
|
|
8
8
|
".": {
|
|
9
|
+
"import": "./src/index.ts",
|
|
10
|
+
"types": "./src/index.ts"
|
|
11
|
+
},
|
|
12
|
+
"./dist": {
|
|
9
13
|
"import": "./dist/index.js",
|
|
10
14
|
"types": "./dist/index.d.ts"
|
|
11
15
|
}
|
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,92 @@
|
|
|
1
1
|
import type { AgentConfig } from "./agent-store.js";
|
|
2
2
|
import type { MemoryEntry } from "./memory-store.js";
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
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
|
+
* When soul/role/context are provided, they are inlined so the agent doesn't waste turns reading files.
|
|
8
|
+
*/
|
|
9
|
+
export function generateUniversalClaudeMd(sections?: {
|
|
10
|
+
soul?: string;
|
|
11
|
+
role?: string;
|
|
12
|
+
context?: string;
|
|
13
|
+
}): string {
|
|
14
|
+
const lines: string[] = [];
|
|
6
15
|
|
|
7
|
-
|
|
16
|
+
lines.push("# Agent Instructions");
|
|
17
|
+
lines.push("");
|
|
8
18
|
|
|
9
|
-
|
|
10
|
-
|
|
19
|
+
if (sections?.soul || sections?.role || sections?.context) {
|
|
20
|
+
if (sections.soul) {
|
|
21
|
+
lines.push(sections.soul.trim());
|
|
22
|
+
lines.push("");
|
|
23
|
+
}
|
|
24
|
+
if (sections.role) {
|
|
25
|
+
lines.push(sections.role.trim());
|
|
26
|
+
lines.push("");
|
|
27
|
+
}
|
|
28
|
+
if (sections.context) {
|
|
29
|
+
lines.push(sections.context.trim());
|
|
30
|
+
lines.push("");
|
|
31
|
+
}
|
|
32
|
+
}
|
|
11
33
|
|
|
12
|
-
const lines: string[] = [];
|
|
13
34
|
|
|
14
|
-
lines.push(
|
|
15
|
-
lines.push("");
|
|
16
|
-
lines.push("
|
|
17
|
-
lines.push("
|
|
35
|
+
lines.push("## Safety Rules");
|
|
36
|
+
lines.push("- Never access files outside your workspace directory");
|
|
37
|
+
lines.push("- Never modify or read system files, environment files, or credentials outside your workspace");
|
|
38
|
+
lines.push("- Never attempt to escalate permissions or bypass security boundaries");
|
|
39
|
+
lines.push("- Never share credentials, tokens, or sensitive data in your responses");
|
|
40
|
+
lines.push("- If a task requires access you don't have, say so — don't try to work around it");
|
|
18
41
|
lines.push("");
|
|
42
|
+
|
|
19
43
|
lines.push("## CLI Usage");
|
|
20
44
|
lines.push("All integrations are accessed via the `cliclaw` CLI. Always pass `--account <account>` to specify which account to use.");
|
|
21
45
|
lines.push("");
|
|
22
46
|
lines.push("For detailed usage of any command, run:");
|
|
23
47
|
lines.push(" `cliclaw <command> --help` or `cliclaw <command> <subcommand> --help`");
|
|
24
48
|
lines.push("");
|
|
25
|
-
lines.push("## Permitted Integrations");
|
|
26
49
|
|
|
27
|
-
|
|
28
|
-
|
|
50
|
+
lines.push("## Memory");
|
|
51
|
+
lines.push("Save, search, and remove memories with `cliclaw agent memory --help`.");
|
|
52
|
+
lines.push("Your agent name is in CONTEXT.md — use it for all memory commands.");
|
|
53
|
+
lines.push("");
|
|
54
|
+
lines.push("### Memory Guidelines");
|
|
55
|
+
lines.push("- Save important facts, preferences, and context that will be useful across conversations");
|
|
56
|
+
lines.push("- Use descriptive tags to categorize memories for easy retrieval");
|
|
57
|
+
lines.push("- Search existing memories before adding duplicates");
|
|
58
|
+
lines.push("- Use importance levels: 1 (low), 2 (normal), 3 (critical)");
|
|
59
|
+
lines.push("");
|
|
60
|
+
|
|
61
|
+
lines.push("## General Guidelines");
|
|
62
|
+
lines.push("- Be concise and direct in responses");
|
|
63
|
+
lines.push("- When running CLI commands, check `--help` first if unsure about options");
|
|
64
|
+
lines.push("- When in a client workspace, read CLIENT_INTEGRATIONS.md for available account names");
|
|
65
|
+
lines.push("- If no CLIENT_INTEGRATIONS.md exists, use `--account default`");
|
|
66
|
+
|
|
67
|
+
return lines.join("\n");
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Generates per-instance CONTEXT.md with agent-specific context:
|
|
72
|
+
* name, integrations, cron schedules, and current memories.
|
|
73
|
+
*/
|
|
74
|
+
export function generateContextMd(config: AgentConfig, memories: MemoryEntry[] = []): string {
|
|
75
|
+
const lines: string[] = [];
|
|
76
|
+
|
|
77
|
+
lines.push(`# ${config.displayName} — Context`);
|
|
78
|
+
lines.push("");
|
|
79
|
+
lines.push(`Agent name: \`${config.name}\``);
|
|
80
|
+
lines.push("");
|
|
81
|
+
|
|
82
|
+
lines.push("## Permitted Integrations");
|
|
83
|
+
if (config.integrations.length === 0) {
|
|
84
|
+
lines.push("No integrations configured.");
|
|
29
85
|
} else {
|
|
30
|
-
for (const integration of integrations) {
|
|
86
|
+
for (const integration of config.integrations) {
|
|
31
87
|
lines.push(`- \`cliclaw ${integration}\``);
|
|
32
88
|
}
|
|
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
89
|
}
|
|
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
90
|
lines.push("");
|
|
42
91
|
|
|
43
92
|
if (config.cronJobs && config.cronJobs.length > 0) {
|
|
@@ -46,17 +95,17 @@ export function generateClaudeMd(config: AgentConfig, memories: MemoryEntry[] =
|
|
|
46
95
|
for (const job of config.cronJobs) {
|
|
47
96
|
const status = job.enabled ? "enabled" : "disabled";
|
|
48
97
|
lines.push(`- **${job.id}** (${status}): \`${job.schedule}\``);
|
|
49
|
-
lines.push(` Task: ${job.
|
|
50
|
-
lines.push(`
|
|
98
|
+
lines.push(` Task file: ${job.taskFile}`);
|
|
99
|
+
lines.push(` Max iterations: ${job.maxIterations}`);
|
|
51
100
|
}
|
|
52
101
|
lines.push("");
|
|
53
102
|
}
|
|
54
103
|
|
|
55
104
|
if (memories.length === 0) {
|
|
56
|
-
lines.push("
|
|
105
|
+
lines.push("## Current Memories");
|
|
57
106
|
lines.push("No memories yet.");
|
|
58
107
|
} else {
|
|
59
|
-
lines.push("
|
|
108
|
+
lines.push("## Current Memories");
|
|
60
109
|
|
|
61
110
|
let displayMemories: MemoryEntry[];
|
|
62
111
|
let truncated = false;
|
|
@@ -64,7 +113,6 @@ export function generateClaudeMd(config: AgentConfig, memories: MemoryEntry[] =
|
|
|
64
113
|
if (memories.length > 50) {
|
|
65
114
|
const critical = memories.filter((m) => m.importance === 3);
|
|
66
115
|
const recent = memories.slice(-30);
|
|
67
|
-
// Merge critical + recent, deduplicate by id
|
|
68
116
|
const seen = new Set<string>();
|
|
69
117
|
displayMemories = [];
|
|
70
118
|
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";
|
|
@@ -11,9 +12,10 @@ export { createCalendarOAuthClient, getCalendarAuthUrl } from "./calendar-auth.j
|
|
|
11
12
|
export { createFormsOAuthClient, getFormsAuthUrl } from "./forms-auth.js";
|
|
12
13
|
export { waitForOAuthCallback } from "./oauth-server.js";
|
|
13
14
|
export { loadConfig, getConfigDir, getTokensPath, getAgentsDir } from "./config.js";
|
|
14
|
-
export { INTEGRATIONS } from "./integration-registry.js";
|
|
15
|
-
export type { IntegrationDef } from "./integration-registry.js";
|
|
15
|
+
export { INTEGRATIONS, PROVIDERS } from "./integration-registry.js";
|
|
16
|
+
export type { IntegrationDef, ProviderConfig } 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";
|