@agentuity/opencode 0.1.42 → 0.1.44

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.
Files changed (122) hide show
  1. package/README.md +9 -9
  2. package/dist/agents/architect.d.ts +1 -1
  3. package/dist/agents/architect.d.ts.map +1 -1
  4. package/dist/agents/architect.js +4 -0
  5. package/dist/agents/architect.js.map +1 -1
  6. package/dist/agents/builder.d.ts +1 -1
  7. package/dist/agents/builder.d.ts.map +1 -1
  8. package/dist/agents/builder.js +4 -0
  9. package/dist/agents/builder.js.map +1 -1
  10. package/dist/agents/expert.d.ts +1 -1
  11. package/dist/agents/expert.d.ts.map +1 -1
  12. package/dist/agents/expert.js +2 -2
  13. package/dist/agents/index.d.ts.map +1 -1
  14. package/dist/agents/index.js +4 -0
  15. package/dist/agents/index.js.map +1 -1
  16. package/dist/agents/lead.d.ts +1 -1
  17. package/dist/agents/lead.d.ts.map +1 -1
  18. package/dist/agents/lead.js +94 -11
  19. package/dist/agents/lead.js.map +1 -1
  20. package/dist/agents/memory/entities.d.ts +32 -0
  21. package/dist/agents/memory/entities.d.ts.map +1 -0
  22. package/dist/agents/memory/entities.js +168 -0
  23. package/dist/agents/memory/entities.js.map +1 -0
  24. package/dist/agents/memory/index.d.ts +4 -0
  25. package/dist/agents/memory/index.d.ts.map +1 -0
  26. package/dist/agents/memory/index.js +2 -0
  27. package/dist/agents/memory/index.js.map +1 -0
  28. package/dist/agents/memory/types.d.ts +71 -0
  29. package/dist/agents/memory/types.d.ts.map +1 -0
  30. package/dist/agents/memory/types.js +2 -0
  31. package/dist/agents/memory/types.js.map +1 -0
  32. package/dist/agents/memory.d.ts +1 -1
  33. package/dist/agents/memory.d.ts.map +1 -1
  34. package/dist/agents/memory.js +344 -7
  35. package/dist/agents/memory.js.map +1 -1
  36. package/dist/agents/product.d.ts +4 -0
  37. package/dist/agents/product.d.ts.map +1 -0
  38. package/dist/agents/product.js +333 -0
  39. package/dist/agents/product.js.map +1 -0
  40. package/dist/agents/reasoner.d.ts +16 -0
  41. package/dist/agents/reasoner.d.ts.map +1 -0
  42. package/dist/agents/reasoner.js +160 -0
  43. package/dist/agents/reasoner.js.map +1 -0
  44. package/dist/agents/reviewer.d.ts +1 -1
  45. package/dist/agents/reviewer.d.ts.map +1 -1
  46. package/dist/agents/reviewer.js +9 -0
  47. package/dist/agents/reviewer.js.map +1 -1
  48. package/dist/background/manager.d.ts +1 -0
  49. package/dist/background/manager.d.ts.map +1 -1
  50. package/dist/background/manager.js +7 -1
  51. package/dist/background/manager.js.map +1 -1
  52. package/dist/plugin/hooks/index.d.ts +2 -0
  53. package/dist/plugin/hooks/index.d.ts.map +1 -0
  54. package/dist/plugin/hooks/index.js +2 -0
  55. package/dist/plugin/hooks/index.js.map +1 -0
  56. package/dist/plugin/hooks/session-memory.d.ts.map +1 -1
  57. package/dist/plugin/hooks/session-memory.js +5 -0
  58. package/dist/plugin/hooks/session-memory.js.map +1 -1
  59. package/dist/plugin/hooks/tools.d.ts +11 -0
  60. package/dist/plugin/hooks/tools.d.ts.map +1 -1
  61. package/dist/plugin/hooks/tools.js +18 -1
  62. package/dist/plugin/hooks/tools.js.map +1 -1
  63. package/dist/plugin/plugin.d.ts.map +1 -1
  64. package/dist/plugin/plugin.js +203 -12
  65. package/dist/plugin/plugin.js.map +1 -1
  66. package/dist/tmux/executor.d.ts +43 -20
  67. package/dist/tmux/executor.d.ts.map +1 -1
  68. package/dist/tmux/executor.js +547 -243
  69. package/dist/tmux/executor.js.map +1 -1
  70. package/dist/tmux/index.d.ts +1 -1
  71. package/dist/tmux/index.d.ts.map +1 -1
  72. package/dist/tmux/index.js +1 -1
  73. package/dist/tmux/index.js.map +1 -1
  74. package/dist/tmux/manager.d.ts +37 -3
  75. package/dist/tmux/manager.d.ts.map +1 -1
  76. package/dist/tmux/manager.js +219 -96
  77. package/dist/tmux/manager.js.map +1 -1
  78. package/dist/tmux/types.d.ts +10 -0
  79. package/dist/tmux/types.d.ts.map +1 -1
  80. package/dist/tmux/types.js.map +1 -1
  81. package/dist/tmux/utils.d.ts +17 -0
  82. package/dist/tmux/utils.d.ts.map +1 -1
  83. package/dist/tmux/utils.js +39 -0
  84. package/dist/tmux/utils.js.map +1 -1
  85. package/dist/tools/background.d.ts +2 -0
  86. package/dist/tools/background.d.ts.map +1 -1
  87. package/dist/tools/background.js +3 -3
  88. package/dist/tools/background.js.map +1 -1
  89. package/dist/tools/delegate.d.ts +4 -0
  90. package/dist/tools/delegate.d.ts.map +1 -1
  91. package/dist/tools/delegate.js +18 -3
  92. package/dist/tools/delegate.js.map +1 -1
  93. package/dist/types.d.ts +2 -0
  94. package/dist/types.d.ts.map +1 -1
  95. package/dist/types.js +2 -0
  96. package/dist/types.js.map +1 -1
  97. package/package.json +3 -3
  98. package/src/agents/architect.ts +4 -0
  99. package/src/agents/builder.ts +4 -0
  100. package/src/agents/expert.ts +2 -2
  101. package/src/agents/index.ts +4 -0
  102. package/src/agents/lead.ts +94 -11
  103. package/src/agents/memory/entities.ts +220 -0
  104. package/src/agents/memory/index.ts +22 -0
  105. package/src/agents/memory/types.ts +76 -0
  106. package/src/agents/memory.ts +344 -7
  107. package/src/agents/product.ts +336 -0
  108. package/src/agents/reasoner.ts +182 -0
  109. package/src/agents/reviewer.ts +9 -0
  110. package/src/background/manager.ts +7 -1
  111. package/src/plugin/hooks/index.ts +1 -0
  112. package/src/plugin/hooks/session-memory.ts +5 -0
  113. package/src/plugin/hooks/tools.ts +24 -1
  114. package/src/plugin/plugin.ts +228 -12
  115. package/src/tmux/executor.ts +610 -249
  116. package/src/tmux/index.ts +5 -2
  117. package/src/tmux/manager.ts +241 -98
  118. package/src/tmux/types.ts +11 -0
  119. package/src/tmux/utils.ts +39 -0
  120. package/src/tools/background.ts +3 -3
  121. package/src/tools/delegate.ts +18 -3
  122. package/src/types.ts +2 -0
@@ -0,0 +1,220 @@
1
+ import { dirname, join, resolve } from 'node:path';
2
+ import { z } from 'zod';
3
+ import type { EntityType } from './types';
4
+ import { loadCoderConfig } from '../../config/loader';
5
+
6
+ const ENTITY_TYPES: EntityType[] = ['user', 'org', 'project', 'repo', 'agent', 'model'];
7
+ const ENTITY_PREFIX = 'entity';
8
+
9
+ export interface EntityContext {
10
+ user?: { id: string; email?: string; name?: string };
11
+ org?: { id: string; name?: string };
12
+ project?: { id: string; name?: string };
13
+ repo?: { url?: string; path: string };
14
+ }
15
+
16
+ const WhoamiOrganizationSchema = z.object({
17
+ id: z.string(),
18
+ name: z.string(),
19
+ });
20
+
21
+ const WhoamiResponseSchema = z.object({
22
+ userId: z.string(),
23
+ firstName: z.string(),
24
+ lastName: z.string(),
25
+ organizations: z.array(WhoamiOrganizationSchema),
26
+ });
27
+
28
+ const AgentuityProjectConfigSchema = z.object({
29
+ projectId: z.string().optional(),
30
+ orgId: z.string().optional(),
31
+ });
32
+
33
+ type AgentuityProjectConfig = z.infer<typeof AgentuityProjectConfigSchema>;
34
+
35
+ async function runCommand(
36
+ command: string[],
37
+ cwd?: string
38
+ ): Promise<{
39
+ stdout: string;
40
+ stderr: string;
41
+ exitCode: number;
42
+ }> {
43
+ const proc = Bun.spawn(command, {
44
+ cwd,
45
+ stdout: 'pipe',
46
+ stderr: 'pipe',
47
+ });
48
+
49
+ const [stdout, stderr, exitCode] = await Promise.all([
50
+ new Response(proc.stdout).text(),
51
+ new Response(proc.stderr).text(),
52
+ proc.exited,
53
+ ]);
54
+
55
+ return {
56
+ stdout: stdout.trim(),
57
+ stderr: stderr.trim(),
58
+ exitCode,
59
+ };
60
+ }
61
+
62
+ async function fetchWhoami() {
63
+ const result = await runCommand(['agentuity', '--json', 'auth', 'whoami']);
64
+
65
+ if (result.exitCode !== 0 || !result.stdout) {
66
+ return undefined;
67
+ }
68
+
69
+ try {
70
+ const data = JSON.parse(result.stdout);
71
+ const parsed = WhoamiResponseSchema.safeParse(data);
72
+ return parsed.success ? parsed.data : undefined;
73
+ } catch {
74
+ return undefined;
75
+ }
76
+ }
77
+
78
+ function normalizeRepoIdentifier(value: string): string {
79
+ const trimmed = value.trim().replace(/\.git$/, '');
80
+
81
+ if (trimmed.startsWith('git@')) {
82
+ return trimmed.replace(/^git@/, '').replace(':', '/');
83
+ }
84
+
85
+ if (trimmed.startsWith('https://') || trimmed.startsWith('http://')) {
86
+ return trimmed.replace(/^https?:\/\//, '');
87
+ }
88
+
89
+ return trimmed;
90
+ }
91
+
92
+ function normalizePathIdentifier(value: string): string {
93
+ return value
94
+ .replace(/^[A-Za-z]:\\/, '')
95
+ .replace(/[\\/]+/g, '_')
96
+ .replace(/[^A-Za-z0-9._-]+/g, '_')
97
+ .replace(/^_+|_+$/g, '');
98
+ }
99
+
100
+ async function resolveRepoRemoteUrl(): Promise<string | undefined> {
101
+ const result = await runCommand(['git', 'remote', 'get-url', 'origin']);
102
+
103
+ if (result.exitCode !== 0 || !result.stdout) {
104
+ return undefined;
105
+ }
106
+
107
+ return result.stdout;
108
+ }
109
+
110
+ function isEntityType(value: string): value is EntityType {
111
+ return ENTITY_TYPES.includes(value as EntityType);
112
+ }
113
+
114
+ async function findProjectRoot(): Promise<string | undefined> {
115
+ let current = resolve(process.cwd());
116
+ let previous = '';
117
+
118
+ while (current !== previous) {
119
+ const candidate = Bun.file(join(current, 'agentuity.json'));
120
+ if (await candidate.exists()) {
121
+ return current;
122
+ }
123
+
124
+ previous = current;
125
+ current = dirname(current);
126
+ }
127
+
128
+ return undefined;
129
+ }
130
+
131
+ async function loadAgentuityProjectConfig(): Promise<AgentuityProjectConfig | undefined> {
132
+ const projectRoot = await findProjectRoot();
133
+ if (!projectRoot) return undefined;
134
+
135
+ const configFile = Bun.file(join(projectRoot, 'agentuity.json'));
136
+ if (!(await configFile.exists())) return undefined;
137
+
138
+ try {
139
+ const content = await configFile.text();
140
+ const parsed = AgentuityProjectConfigSchema.safeParse(JSON.parse(content));
141
+ return parsed.success ? parsed.data : undefined;
142
+ } catch {
143
+ return undefined;
144
+ }
145
+ }
146
+
147
+ export async function getEntityContext(): Promise<EntityContext> {
148
+ const [whoami, orgId, projectId, repoUrl] = await Promise.all([
149
+ fetchWhoami(),
150
+ resolveOrgId(),
151
+ resolveProjectId(),
152
+ resolveRepoRemoteUrl(),
153
+ ]);
154
+
155
+ const userName = whoami ? `${whoami.firstName} ${whoami.lastName}`.trim() : undefined;
156
+
157
+ return {
158
+ user: whoami
159
+ ? {
160
+ id: whoami.userId,
161
+ name: userName || undefined,
162
+ }
163
+ : undefined,
164
+ org: orgId ? { id: orgId } : undefined,
165
+ project: projectId ? { id: projectId } : undefined,
166
+ repo: {
167
+ url: repoUrl || undefined,
168
+ path: process.cwd(),
169
+ },
170
+ };
171
+ }
172
+
173
+ export function entityId(type: EntityType, id: string): string {
174
+ return `${ENTITY_PREFIX}:${type}:${id}`;
175
+ }
176
+
177
+ export function parseEntityId(entityIdValue: string): { type: EntityType; id: string } {
178
+ const [prefix, type, ...rest] = entityIdValue.split(':');
179
+
180
+ if (prefix !== ENTITY_PREFIX || !type || !isEntityType(type) || rest.length === 0) {
181
+ throw new Error(`Invalid entityId: ${entityIdValue}`);
182
+ }
183
+
184
+ return {
185
+ type,
186
+ id: rest.join(':'),
187
+ };
188
+ }
189
+
190
+ export function kvKey(entityIdValue: string): string {
191
+ return entityIdValue.startsWith(`${ENTITY_PREFIX}:`)
192
+ ? entityIdValue
193
+ : `${ENTITY_PREFIX}:${entityIdValue}`;
194
+ }
195
+
196
+ export async function resolveUserId(): Promise<string | undefined> {
197
+ const whoami = await fetchWhoami();
198
+ return whoami?.userId;
199
+ }
200
+
201
+ export async function resolveOrgId(): Promise<string | undefined> {
202
+ const config = await loadCoderConfig();
203
+ return config.org;
204
+ }
205
+
206
+ export async function resolveProjectId(): Promise<string | undefined> {
207
+ const config = await loadAgentuityProjectConfig();
208
+ return config?.projectId;
209
+ }
210
+
211
+ export async function resolveRepoId(): Promise<string | undefined> {
212
+ const repoUrl = await resolveRepoRemoteUrl();
213
+
214
+ if (repoUrl) {
215
+ return normalizeRepoIdentifier(repoUrl);
216
+ }
217
+
218
+ const cwd = normalizePathIdentifier(resolve(process.cwd()));
219
+ return cwd.length > 0 ? cwd : undefined;
220
+ }
@@ -0,0 +1,22 @@
1
+ export type {
2
+ AgentPerspective,
3
+ Conclusion,
4
+ Correction,
5
+ EntityRepresentation,
6
+ EntityType,
7
+ Pattern,
8
+ Relationship,
9
+ } from './types';
10
+
11
+ export type { EntityContext } from './entities';
12
+
13
+ export {
14
+ entityId,
15
+ getEntityContext,
16
+ kvKey,
17
+ parseEntityId,
18
+ resolveOrgId,
19
+ resolveProjectId,
20
+ resolveRepoId,
21
+ resolveUserId,
22
+ } from './entities';
@@ -0,0 +1,76 @@
1
+ export type EntityType = 'user' | 'org' | 'project' | 'repo' | 'agent' | 'model';
2
+
3
+ export interface EntityRepresentation {
4
+ entityId: string;
5
+ entityType: EntityType;
6
+ metadata: Record<string, unknown>;
7
+ conclusions: {
8
+ explicit?: Conclusion[];
9
+ deductive?: Conclusion[];
10
+ inductive?: Conclusion[];
11
+ abductive?: Conclusion[];
12
+ };
13
+ corrections: Correction[];
14
+ patterns: Pattern[];
15
+ relationships: Relationship[];
16
+ recentSessions: string[];
17
+ createdAt: string;
18
+ updatedAt: string;
19
+ lastReasonedAt?: string;
20
+ }
21
+
22
+ export interface Conclusion {
23
+ id: string;
24
+ type: 'explicit' | 'deductive' | 'inductive' | 'abductive';
25
+ content: string;
26
+ premises?: string[];
27
+ observations?: string[];
28
+ occurrences?: number;
29
+ confidence: 'high' | 'medium' | 'low' | 'uncertain';
30
+ sourceSession?: string;
31
+ sourceTimestamp?: string;
32
+ createdAt: string;
33
+ updatedAt?: string;
34
+ supersededBy?: string;
35
+ }
36
+
37
+ export interface Correction {
38
+ id: string;
39
+ content: string;
40
+ why: string;
41
+ confidence: 'high' | 'medium' | 'low';
42
+ sourceSession?: string;
43
+ createdAt: string;
44
+ }
45
+
46
+ export interface Pattern {
47
+ id: string;
48
+ name: string;
49
+ description: string;
50
+ occurrences: number;
51
+ examples?: string[];
52
+ tags?: string[];
53
+ createdAt: string;
54
+ updatedAt?: string;
55
+ }
56
+
57
+ export interface Relationship {
58
+ id: string;
59
+ fromEntity: string;
60
+ toEntity: string;
61
+ relationshipType: string;
62
+ metadata?: Record<string, unknown>;
63
+ createdAt: string;
64
+ }
65
+
66
+ export interface AgentPerspective {
67
+ perspectiveId: string;
68
+ observer: string;
69
+ observed: string;
70
+ observerModel?: string;
71
+ observedModel?: string;
72
+ conclusions: Conclusion[];
73
+ recommendations?: string[];
74
+ createdAt: string;
75
+ updatedAt: string;
76
+ }