@mandible-ai/mandible 0.2.0 → 0.3.1

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 (101) hide show
  1. package/README.md +169 -58
  2. package/dist/examples/code-pipeline/colonies.d.ts +10 -0
  3. package/dist/examples/code-pipeline/colonies.d.ts.map +1 -0
  4. package/dist/examples/code-pipeline/colonies.js +112 -0
  5. package/dist/examples/code-pipeline/colonies.js.map +1 -0
  6. package/dist/examples/code-pipeline/docker.d.ts +3 -0
  7. package/dist/examples/code-pipeline/docker.d.ts.map +1 -0
  8. package/dist/examples/code-pipeline/docker.js +63 -0
  9. package/dist/examples/code-pipeline/docker.js.map +1 -0
  10. package/dist/examples/code-pipeline/index.js +44 -228
  11. package/dist/examples/code-pipeline/index.js.map +1 -1
  12. package/dist/examples/code-pipeline/with-providers.js +1 -2
  13. package/dist/examples/code-pipeline/with-providers.js.map +1 -1
  14. package/dist/examples/github-colony/mandible.config.d.ts +1 -10
  15. package/dist/examples/github-colony/mandible.config.d.ts.map +1 -1
  16. package/dist/examples/github-colony/mandible.config.js +16 -24
  17. package/dist/examples/github-colony/mandible.config.js.map +1 -1
  18. package/dist/examples/repo-maintenance/fixer.d.ts +11 -4
  19. package/dist/examples/repo-maintenance/fixer.d.ts.map +1 -1
  20. package/dist/examples/repo-maintenance/fixer.js +130 -123
  21. package/dist/examples/repo-maintenance/fixer.js.map +1 -1
  22. package/dist/examples/repo-maintenance/mandible.config.d.ts +1 -10
  23. package/dist/examples/repo-maintenance/mandible.config.d.ts.map +1 -1
  24. package/dist/examples/repo-maintenance/mandible.config.js +14 -14
  25. package/dist/examples/repo-maintenance/mandible.config.js.map +1 -1
  26. package/dist/examples/repo-maintenance/scout.d.ts +11 -4
  27. package/dist/examples/repo-maintenance/scout.d.ts.map +1 -1
  28. package/dist/examples/repo-maintenance/scout.js +102 -95
  29. package/dist/examples/repo-maintenance/scout.js.map +1 -1
  30. package/dist/examples/repo-maintenance/seed.js +19 -37
  31. package/dist/examples/repo-maintenance/seed.js.map +1 -1
  32. package/dist/src/cloud/client.d.ts +1 -1
  33. package/dist/src/cloud/client.d.ts.map +1 -1
  34. package/dist/src/cloud/client.js +1 -1
  35. package/dist/src/cloud/client.js.map +1 -1
  36. package/dist/src/cloud/index.d.ts +1 -3
  37. package/dist/src/cloud/index.d.ts.map +1 -1
  38. package/dist/src/cloud/index.js +0 -1
  39. package/dist/src/cloud/index.js.map +1 -1
  40. package/dist/src/cloud/types.d.ts +5 -9
  41. package/dist/src/cloud/types.d.ts.map +1 -1
  42. package/dist/src/core/types.d.ts +43 -0
  43. package/dist/src/core/types.d.ts.map +1 -1
  44. package/dist/src/core/types.js +10 -0
  45. package/dist/src/core/types.js.map +1 -1
  46. package/dist/src/dsl/index.d.ts +1 -0
  47. package/dist/src/dsl/index.d.ts.map +1 -1
  48. package/dist/src/dsl/index.js +1 -0
  49. package/dist/src/dsl/index.js.map +1 -1
  50. package/dist/src/dsl/mandible.d.ts +62 -0
  51. package/dist/src/dsl/mandible.d.ts.map +1 -0
  52. package/dist/src/dsl/mandible.js +140 -0
  53. package/dist/src/dsl/mandible.js.map +1 -0
  54. package/dist/src/environments/filesystem/adapter.d.ts.map +1 -1
  55. package/dist/src/environments/filesystem/adapter.js.map +1 -1
  56. package/dist/src/hosts/docker.d.ts +67 -0
  57. package/dist/src/hosts/docker.d.ts.map +1 -0
  58. package/dist/src/hosts/docker.js +135 -0
  59. package/dist/src/hosts/docker.js.map +1 -0
  60. package/dist/src/hosts/index.d.ts +5 -0
  61. package/dist/src/hosts/index.d.ts.map +1 -0
  62. package/dist/src/hosts/index.js +3 -0
  63. package/dist/src/hosts/index.js.map +1 -0
  64. package/dist/src/hosts/local.d.ts +41 -0
  65. package/dist/src/hosts/local.d.ts.map +1 -0
  66. package/dist/src/hosts/local.js +84 -0
  67. package/dist/src/hosts/local.js.map +1 -0
  68. package/dist/src/index.d.ts +8 -3
  69. package/dist/src/index.d.ts.map +1 -1
  70. package/dist/src/index.js +8 -1
  71. package/dist/src/index.js.map +1 -1
  72. package/dist/src/providers/claude-code.d.ts.map +1 -1
  73. package/dist/src/providers/claude-code.js +3 -5
  74. package/dist/src/providers/claude-code.js.map +1 -1
  75. package/dist/src/providers/types.d.ts +0 -9
  76. package/dist/src/providers/types.d.ts.map +1 -1
  77. package/package.json +11 -6
  78. package/dist/examples/docker-pipeline/index.d.ts +0 -3
  79. package/dist/examples/docker-pipeline/index.d.ts.map +0 -1
  80. package/dist/examples/docker-pipeline/index.js +0 -235
  81. package/dist/examples/docker-pipeline/index.js.map +0 -1
  82. package/dist/examples/remote-pipeline/index.d.ts +0 -3
  83. package/dist/examples/remote-pipeline/index.d.ts.map +0 -1
  84. package/dist/examples/remote-pipeline/index.js +0 -154
  85. package/dist/examples/remote-pipeline/index.js.map +0 -1
  86. package/dist/src/environments/remote/adapter.d.ts +0 -61
  87. package/dist/src/environments/remote/adapter.d.ts.map +0 -1
  88. package/dist/src/environments/remote/adapter.js +0 -392
  89. package/dist/src/environments/remote/adapter.js.map +0 -1
  90. package/dist/src/environments/remote/index.d.ts +0 -5
  91. package/dist/src/environments/remote/index.d.ts.map +0 -1
  92. package/dist/src/environments/remote/index.js +0 -3
  93. package/dist/src/environments/remote/index.js.map +0 -1
  94. package/dist/src/environments/remote/protocol.d.ts +0 -124
  95. package/dist/src/environments/remote/protocol.d.ts.map +0 -1
  96. package/dist/src/environments/remote/protocol.js +0 -24
  97. package/dist/src/environments/remote/protocol.js.map +0 -1
  98. package/dist/src/providers/agent.d.ts +0 -23
  99. package/dist/src/providers/agent.d.ts.map +0 -1
  100. package/dist/src/providers/agent.js +0 -184
  101. package/dist/src/providers/agent.js.map +0 -1
@@ -1,124 +0,0 @@
1
- import type { Signal } from '../../core/types.js';
2
- import type { RuntimeEventData } from '../../core/events.js';
3
- export type ClientMessage = ObserveRequest | DepositRequest | WithdrawRequest | ClaimRequest | ReleaseRequest | SubscribeRequest | UnsubscribeRequest | SnapshotRequest | HistoryRequest | DecayRequest | AuthRequest | EventForward;
4
- export interface ObserveRequest {
5
- type: 'observe';
6
- id: string;
7
- query: SerializableSignalQuery;
8
- }
9
- export interface DepositRequest {
10
- type: 'deposit';
11
- id: string;
12
- signal: {
13
- type: string;
14
- payload: Record<string, unknown>;
15
- meta?: Partial<SerializableSignalMeta>;
16
- };
17
- }
18
- export interface WithdrawRequest {
19
- type: 'withdraw';
20
- id: string;
21
- signalId: string;
22
- }
23
- export interface ClaimRequest {
24
- type: 'claim';
25
- id: string;
26
- signalId: string;
27
- claimant: string;
28
- leaseDuration?: number;
29
- }
30
- export interface ReleaseRequest {
31
- type: 'release';
32
- id: string;
33
- signalId: string;
34
- }
35
- export interface SubscribeRequest {
36
- type: 'subscribe';
37
- id: string;
38
- query: SerializableSignalQuery;
39
- }
40
- export interface UnsubscribeRequest {
41
- type: 'unsubscribe';
42
- id: string;
43
- subscriptionId: string;
44
- }
45
- export interface SnapshotRequest {
46
- type: 'snapshot';
47
- id: string;
48
- }
49
- export interface HistoryRequest {
50
- type: 'history';
51
- id: string;
52
- query: SerializableSignalQuery & {
53
- includeWithdrawn?: boolean;
54
- };
55
- }
56
- export interface DecayRequest {
57
- type: 'decay';
58
- id: string;
59
- }
60
- export interface AuthRequest {
61
- type: 'auth';
62
- apiKey: string;
63
- colony?: string;
64
- publicKey?: string;
65
- project: string;
66
- }
67
- export interface EventForward {
68
- type: 'event';
69
- data: RuntimeEventData;
70
- }
71
- export interface EventRelayMessage {
72
- type: 'event';
73
- data: import('../../core/events.js').RuntimeEventData;
74
- }
75
- export type ServerMessage = ResultMessage | ErrorMessage | SignalPush | AuthenticatedMessage | EventRelayMessage;
76
- export interface ResultMessage {
77
- type: 'result';
78
- id: string;
79
- data: unknown;
80
- }
81
- export interface ErrorMessage {
82
- type: 'error';
83
- id: string;
84
- code: string;
85
- message: string;
86
- }
87
- export interface SignalPush {
88
- type: 'signal';
89
- subscriptionId: string;
90
- signal: Signal;
91
- }
92
- export interface AuthenticatedMessage {
93
- type: 'authenticated';
94
- project: string;
95
- environment: string;
96
- }
97
- export interface SerializableSignalQuery {
98
- type?: string | string[];
99
- minConcentration?: number;
100
- unclaimed?: boolean;
101
- tags?: string[];
102
- after?: number;
103
- limit?: number;
104
- }
105
- export interface SerializableSignalMeta {
106
- deposited_by: string;
107
- concentration?: number;
108
- ttl?: number;
109
- tags?: string[];
110
- caused_by?: string[];
111
- signature?: string;
112
- signer?: string;
113
- }
114
- export declare const ErrorCodes: {
115
- readonly AUTH_REQUIRED: "AUTH_REQUIRED";
116
- readonly AUTH_FAILED: "AUTH_FAILED";
117
- readonly INVALID_MESSAGE: "INVALID_MESSAGE";
118
- readonly SIGNAL_NOT_FOUND: "SIGNAL_NOT_FOUND";
119
- readonly CLAIM_FAILED: "CLAIM_FAILED";
120
- readonly VALIDATION_ERROR: "VALIDATION_ERROR";
121
- readonly INTERNAL_ERROR: "INTERNAL_ERROR";
122
- readonly RATE_LIMITED: "RATE_LIMITED";
123
- };
124
- //# sourceMappingURL=protocol.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"protocol.d.ts","sourceRoot":"","sources":["../../../../src/environments/remote/protocol.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,MAAM,EAAwC,MAAM,qBAAqB,CAAC;AACxF,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAM7D,MAAM,MAAM,aAAa,GACrB,cAAc,GACd,cAAc,GACd,eAAe,GACf,YAAY,GACZ,cAAc,GACd,gBAAgB,GAChB,kBAAkB,GAClB,eAAe,GACf,cAAc,GACd,YAAY,GACZ,WAAW,GACX,YAAY,CAAC;AAEjB,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,SAAS,CAAC;IAChB,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,uBAAuB,CAAC;CAChC;AAED,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,SAAS,CAAC;IAChB,EAAE,EAAE,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,MAAM,CAAC;CAGhB;AAED,MAAM,WAAW,sBAAsB;IACrC,YAAY,EAAE,MAAM,CAAC;IACrB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;IAChB,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;IACrB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAMD,eAAO,MAAM,UAAU;;;;;;;;;CASb,CAAC"}
@@ -1,24 +0,0 @@
1
- // ============================================================
2
- // Remote Environment — WebSocket Protocol Types
3
- // ============================================================
4
- // Defines the contract between the RemoteEnvironment client
5
- // (open source, runs on developer machines and in colony zones)
6
- // and any compatible signal server implementation.
7
- //
8
- // This protocol is intentionally simple: request-response with
9
- // correlation IDs, plus server-pushed subscription messages.
10
- // ============================================================
11
- // ----------------------------------------------------------
12
- // Protocol error codes
13
- // ----------------------------------------------------------
14
- export const ErrorCodes = {
15
- AUTH_REQUIRED: 'AUTH_REQUIRED',
16
- AUTH_FAILED: 'AUTH_FAILED',
17
- INVALID_MESSAGE: 'INVALID_MESSAGE',
18
- SIGNAL_NOT_FOUND: 'SIGNAL_NOT_FOUND',
19
- CLAIM_FAILED: 'CLAIM_FAILED',
20
- VALIDATION_ERROR: 'VALIDATION_ERROR',
21
- INTERNAL_ERROR: 'INTERNAL_ERROR',
22
- RATE_LIMITED: 'RATE_LIMITED',
23
- };
24
- //# sourceMappingURL=protocol.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"protocol.js","sourceRoot":"","sources":["../../../../src/environments/remote/protocol.ts"],"names":[],"mappings":"AAAA,+DAA+D;AAC/D,gDAAgD;AAChD,+DAA+D;AAC/D,4DAA4D;AAC5D,gEAAgE;AAChE,mDAAmD;AACnD,EAAE;AACF,+DAA+D;AAC/D,6DAA6D;AAC7D,+DAA+D;AAsK/D,6DAA6D;AAC7D,uBAAuB;AACvB,6DAA6D;AAE7D,MAAM,CAAC,MAAM,UAAU,GAAG;IACxB,aAAa,EAAE,eAAe;IAC9B,WAAW,EAAE,aAAa;IAC1B,eAAe,EAAE,iBAAiB;IAClC,gBAAgB,EAAE,kBAAkB;IACpC,YAAY,EAAE,cAAc;IAC5B,gBAAgB,EAAE,kBAAkB;IACpC,cAAc,EAAE,gBAAgB;IAChC,YAAY,EAAE,cAAc;CACpB,CAAC"}
@@ -1,23 +0,0 @@
1
- import type { AgentProviderConfig, ActionHandler, BedrockConfig } from './types.js';
2
- /**
3
- * Creates an action handler powered by the Claude Agent SDK.
4
- *
5
- * The SDK must be installed separately:
6
- * npm install @anthropic-ai/claude-agent-sdk
7
- *
8
- * The handler:
9
- * 1. Builds a prompt from the signal
10
- * 2. Spawns a Claude agent session via the SDK's query() AsyncGenerator
11
- * 3. Consumes all messages, calling onMessage for observability
12
- * 4. Extracts the final result (text, cost, duration, usage)
13
- * 5. Maps the agent's output to signal deposits
14
- * 6. Optionally withdraws the triggering signal
15
- */
16
- export declare function withAgent<T = Record<string, unknown>>(config: AgentProviderConfig<T>): ActionHandler<T>;
17
- /**
18
- * Builds env vars for routing the Claude Agent SDK through AWS Bedrock.
19
- * Exported for testing.
20
- */
21
- export declare function buildBedrockEnv(config: BedrockConfig): Record<string, string>;
22
- export declare function buildDefaultSystemPrompt(colonyName: string): string;
23
- //# sourceMappingURL=agent.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"agent.d.ts","sourceRoot":"","sources":["../../../src/providers/agent.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,mBAAmB,EAAe,aAAa,EAAiB,aAAa,EAAE,MAAM,YAAY,CAAC;AAEhH;;;;;;;;;;;;;GAaG;AACH,wBAAgB,SAAS,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACnD,MAAM,EAAE,mBAAmB,CAAC,CAAC,CAAC,GAC7B,aAAa,CAAC,CAAC,CAAC,CA6FlB;AAuDD;;;GAGG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,aAAa,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAuB7E;AAED,wBAAgB,wBAAwB,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,CAOnE"}
@@ -1,184 +0,0 @@
1
- // PURPOSE: withAgent — Claude Agent SDK provider for full agentic colony actions.
2
- // Wraps the Claude Agent SDK AsyncGenerator to give colonies coding capabilities.
3
- /**
4
- * Creates an action handler powered by the Claude Agent SDK.
5
- *
6
- * The SDK must be installed separately:
7
- * npm install @anthropic-ai/claude-agent-sdk
8
- *
9
- * The handler:
10
- * 1. Builds a prompt from the signal
11
- * 2. Spawns a Claude agent session via the SDK's query() AsyncGenerator
12
- * 3. Consumes all messages, calling onMessage for observability
13
- * 4. Extracts the final result (text, cost, duration, usage)
14
- * 5. Maps the agent's output to signal deposits
15
- * 6. Optionally withdraws the triggering signal
16
- */
17
- export function withAgent(config) {
18
- const { model = 'claude-sonnet-4-5-20250929', prompt, systemPrompt, allowedTools, tools, disallowedTools, workingDirectory, maxTurns, maxBudgetUsd = 1.0, permissionMode = 'bypassPermissions', onMessage, env, bedrock, output, autoWithdraw = true, } = config;
19
- // Resolve allowedTools with backward compat for deprecated `tools`
20
- const resolvedAllowedTools = allowedTools ?? tools;
21
- return async (signal, ctx) => {
22
- // 1. Resolve the prompt
23
- const resolvedPrompt = typeof prompt === 'function'
24
- ? await prompt(signal)
25
- : prompt;
26
- // 2. Resolve working directory
27
- const cwd = typeof workingDirectory === 'function'
28
- ? workingDirectory(signal)
29
- : workingDirectory;
30
- // 3. Call Claude Agent SDK
31
- let agentResult;
32
- try {
33
- // Dynamic import — SDK is an optional peer dependency
34
- const sdk = await import('@anthropic-ai/claude-agent-sdk');
35
- const queryOptions = {
36
- model,
37
- systemPrompt: systemPrompt ?? buildDefaultSystemPrompt(ctx.colony),
38
- cwd: cwd ?? process.cwd(),
39
- permissionMode,
40
- allowDangerouslySkipPermissions: permissionMode === 'bypassPermissions',
41
- maxBudgetUsd,
42
- };
43
- if (resolvedAllowedTools)
44
- queryOptions.allowedTools = resolvedAllowedTools;
45
- if (disallowedTools)
46
- queryOptions.disallowedTools = disallowedTools;
47
- if (maxTurns !== undefined)
48
- queryOptions.maxTurns = maxTurns;
49
- // Merge Bedrock env vars with user-provided env (user takes precedence)
50
- const bedrockEnv = bedrock ? buildBedrockEnv(bedrock) : undefined;
51
- const mergedEnv = bedrockEnv || env
52
- ? { ...bedrockEnv, ...env }
53
- : undefined;
54
- if (mergedEnv)
55
- queryOptions.env = mergedEnv;
56
- const generator = sdk.query({
57
- prompt: resolvedPrompt,
58
- options: queryOptions,
59
- });
60
- agentResult = await consumeGenerator(generator, onMessage);
61
- }
62
- catch (err) {
63
- if (err.code === 'ERR_MODULE_NOT_FOUND' || err.code === 'MODULE_NOT_FOUND') {
64
- throw new Error('withAgent requires @anthropic-ai/claude-agent-sdk. Install it:\n' +
65
- ' npm install @anthropic-ai/claude-agent-sdk');
66
- }
67
- throw err;
68
- }
69
- // 4. Deposit output signals
70
- const deposits = resolveOutput(output, agentResult, signal);
71
- for (const deposit of deposits) {
72
- await ctx.deposit(deposit.type, deposit.payload ?? { ...agentResult }, {
73
- causedBy: [signal.id],
74
- tags: deposit.tags,
75
- ttl: deposit.ttl,
76
- });
77
- }
78
- // 5. Withdraw the triggering signal
79
- if (autoWithdraw) {
80
- await ctx.withdraw(signal.id);
81
- }
82
- ctx.log(`Agent completed (${agentResult.subtype}). Cost: $${agentResult.costUsd.toFixed(4)}, Duration: ${agentResult.durationMs}ms. Deposited ${deposits.length} signal(s).`);
83
- };
84
- }
85
- // ----------------------------------------------------------
86
- // Helpers
87
- // ----------------------------------------------------------
88
- /**
89
- * Consumes the SDK's AsyncGenerator, collecting all messages and
90
- * extracting the final result from the SDKResultMessage.
91
- */
92
- async function consumeGenerator(generator, onMessage) {
93
- const messages = [];
94
- let resultMessage = null;
95
- for await (const message of generator) {
96
- messages.push(message);
97
- // Call observability callback (errors must not crash the agent)
98
- if (onMessage) {
99
- try {
100
- onMessage(message);
101
- }
102
- catch { /* swallow */ }
103
- }
104
- // Capture the result message when it arrives
105
- if (message.type === 'result') {
106
- resultMessage = message;
107
- }
108
- }
109
- if (!resultMessage) {
110
- return {
111
- text: '',
112
- costUsd: 0,
113
- durationMs: 0,
114
- usage: { input_tokens: 0, output_tokens: 0 },
115
- subtype: 'error_during_execution',
116
- messages,
117
- };
118
- }
119
- return {
120
- text: resultMessage.result ?? resultMessage.errors?.join('\n') ?? '',
121
- costUsd: resultMessage.total_cost_usd ?? 0,
122
- durationMs: resultMessage.duration_ms ?? 0,
123
- usage: {
124
- input_tokens: resultMessage.usage?.input_tokens ?? 0,
125
- output_tokens: resultMessage.usage?.output_tokens ?? 0,
126
- },
127
- subtype: resultMessage.subtype ?? 'success',
128
- messages,
129
- };
130
- }
131
- /**
132
- * Builds env vars for routing the Claude Agent SDK through AWS Bedrock.
133
- * Exported for testing.
134
- */
135
- export function buildBedrockEnv(config) {
136
- const env = {
137
- CLAUDE_CODE_USE_BEDROCK: '1',
138
- AWS_REGION: config.region,
139
- };
140
- if (config.model)
141
- env.ANTHROPIC_MODEL = config.model;
142
- if (config.accessKeyId)
143
- env.AWS_ACCESS_KEY_ID = config.accessKeyId;
144
- if (config.secretAccessKey)
145
- env.AWS_SECRET_ACCESS_KEY = config.secretAccessKey;
146
- if (config.sessionToken)
147
- env.AWS_SESSION_TOKEN = config.sessionToken;
148
- if (config.profile)
149
- env.AWS_PROFILE = config.profile;
150
- if (config.guardrailId) {
151
- const headers = {
152
- 'x-amzn-bedrock-guardrail-identifier': config.guardrailId,
153
- };
154
- if (config.guardrailVersion) {
155
- headers['x-amzn-bedrock-guardrail-version'] = config.guardrailVersion;
156
- }
157
- env.ANTHROPIC_CUSTOM_HEADERS = JSON.stringify(headers);
158
- }
159
- return env;
160
- }
161
- export function buildDefaultSystemPrompt(colonyName) {
162
- return [
163
- `You are an agent in the "${colonyName}" colony.`,
164
- 'Complete the task described in the prompt.',
165
- 'Be thorough but concise. Focus on the specific task at hand.',
166
- 'If you create or modify files, ensure they compile/pass tests.',
167
- ].join('\n');
168
- }
169
- function resolveOutput(output, result, signal) {
170
- if (!output) {
171
- return [{ type: `${signal.type}:completed`, payload: result }];
172
- }
173
- if (typeof output === 'function') {
174
- const mapped = output(result, signal);
175
- return Array.isArray(mapped) ? mapped : [mapped];
176
- }
177
- return [{
178
- type: output.type,
179
- payload: result,
180
- tags: output.tags,
181
- ttl: output.ttl,
182
- }];
183
- }
184
- //# sourceMappingURL=agent.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"agent.js","sourceRoot":"","sources":["../../../src/providers/agent.ts"],"names":[],"mappings":"AAAA,kFAAkF;AAClF,kFAAkF;AAKlF;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,SAAS,CACvB,MAA8B;IAE9B,MAAM,EACJ,KAAK,GAAG,4BAA4B,EACpC,MAAM,EACN,YAAY,EACZ,YAAY,EACZ,KAAK,EACL,eAAe,EACf,gBAAgB,EAChB,QAAQ,EACR,YAAY,GAAG,GAAG,EAClB,cAAc,GAAG,mBAAmB,EACpC,SAAS,EACT,GAAG,EACH,OAAO,EACP,MAAM,EACN,YAAY,GAAG,IAAI,GACpB,GAAG,MAAM,CAAC;IAEX,mEAAmE;IACnE,MAAM,oBAAoB,GAAG,YAAY,IAAI,KAAK,CAAC;IAEnD,OAAO,KAAK,EAAE,MAAiB,EAAE,GAAkB,EAAE,EAAE;QACrD,wBAAwB;QACxB,MAAM,cAAc,GAAG,OAAO,MAAM,KAAK,UAAU;YACjD,CAAC,CAAC,MAAM,MAAM,CAAC,MAAM,CAAC;YACtB,CAAC,CAAC,MAAM,CAAC;QAEX,+BAA+B;QAC/B,MAAM,GAAG,GAAG,OAAO,gBAAgB,KAAK,UAAU;YAChD,CAAC,CAAC,gBAAgB,CAAC,MAAM,CAAC;YAC1B,CAAC,CAAC,gBAAgB,CAAC;QAEr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