@mastra/code-sdk 1.8.3 → 1.8.4-alpha.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.
- package/dist/agent-connections/ownership.d.ts +15 -1
- package/dist/agent-connections/ownership.d.ts.map +1 -1
- package/dist/agent-connections/ownership.js +25 -6
- package/dist/agent-connections/ownership.js.map +1 -1
- package/dist/agent-connections/session-advertisement.d.ts +8 -1
- package/dist/agent-connections/session-advertisement.d.ts.map +1 -1
- package/dist/agent-connections/session-advertisement.js +13 -3
- package/dist/agent-connections/session-advertisement.js.map +1 -1
- package/dist/agents/prompts/tool-guidance.d.ts.map +1 -1
- package/dist/agents/prompts/tool-guidance.js +1 -0
- package/dist/agents/prompts/tool-guidance.js.map +1 -1
- package/dist/agents/tool-availability.d.ts.map +1 -1
- package/dist/agents/tool-availability.js +4 -0
- package/dist/agents/tool-availability.js.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/plugins/dependencies.js +7 -8
- package/dist/plugins/dependencies.js.map +1 -1
- package/dist/utils/signals-pubsub.d.ts +5 -2
- package/dist/utils/signals-pubsub.d.ts.map +1 -1
- package/dist/utils/signals-pubsub.js +9 -2
- package/dist/utils/signals-pubsub.js.map +1 -1
- package/package.json +11 -11
|
@@ -2,7 +2,21 @@ export interface ThreadOwnershipClaim {
|
|
|
2
2
|
claimed: boolean;
|
|
3
3
|
unsubscribe(): void;
|
|
4
4
|
}
|
|
5
|
-
export
|
|
5
|
+
export interface ThreadClaimContext {
|
|
6
|
+
/**
|
|
7
|
+
* Call from the core `yieldOwnership` callback when this claim is released to
|
|
8
|
+
* another process, so the manager stops tracking it instead of believing it
|
|
9
|
+
* still owns the thread.
|
|
10
|
+
*/
|
|
11
|
+
onYield(): void;
|
|
12
|
+
/** Call when lease renewal proves another live owner took the claim, so the manager retries it. */
|
|
13
|
+
onLost(): void;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Keeps one renewable ownership claim per session thread, retries contention,
|
|
17
|
+
* and discards superseded attempts without creating a release-before-acquire gap.
|
|
18
|
+
*/
|
|
19
|
+
export declare function createThreadOwnershipManager(claimThread: (threadId: string, context: ThreadClaimContext) => Promise<ThreadOwnershipClaim>): {
|
|
6
20
|
claim(threadId?: string | null): Promise<boolean>;
|
|
7
21
|
release(threadId: string): void;
|
|
8
22
|
close(): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ownership.d.ts","sourceRoot":"","sources":["../../src/agent-connections/ownership.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,oBAAoB;IACnC,OAAO,EAAE,OAAO,CAAC;IACjB,WAAW,IAAI,IAAI,CAAC;CACrB;
|
|
1
|
+
{"version":3,"file":"ownership.d.ts","sourceRoot":"","sources":["../../src/agent-connections/ownership.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,oBAAoB;IACnC,OAAO,EAAE,OAAO,CAAC;IACjB,WAAW,IAAI,IAAI,CAAC;CACrB;AAED,MAAM,WAAW,kBAAkB;IACjC;;;;OAIG;IACH,OAAO,IAAI,IAAI,CAAC;IAChB,mGAAmG;IACnG,MAAM,IAAI,IAAI,CAAC;CAChB;AAmBD;;;GAGG;AACH,wBAAgB,4BAA4B,CAC1C,WAAW,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,kBAAkB,KAAK,OAAO,CAAC,oBAAoB,CAAC,GAC5F;IACD,KAAK,CAAC,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IAClD,OAAO,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IAChC,KAAK,IAAI,IAAI,CAAC;CACf,CAgHA"}
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
//#region src/agent-connections/ownership.ts
|
|
2
2
|
const OWNERSHIP_RETRY_INITIAL_DELAY_MS = 250;
|
|
3
3
|
const OWNERSHIP_RETRY_MAX_DELAY_MS = 5e3;
|
|
4
|
+
/**
|
|
5
|
+
* Keeps one renewable ownership claim per session thread, retries contention,
|
|
6
|
+
* and discards superseded attempts without creating a release-before-acquire gap.
|
|
7
|
+
*/
|
|
4
8
|
function createThreadOwnershipManager(claimThread) {
|
|
5
9
|
const states = /* @__PURE__ */ new Map();
|
|
6
10
|
let nextGeneration = 0;
|
|
@@ -20,9 +24,24 @@ function createThreadOwnershipManager(claimThread) {
|
|
|
20
24
|
}, delayMs);
|
|
21
25
|
state.retryTimer.unref?.();
|
|
22
26
|
};
|
|
27
|
+
const yieldClaim = (threadId, claimGeneration) => {
|
|
28
|
+
const state = states.get(threadId);
|
|
29
|
+
if (!state || state.generation !== claimGeneration) return;
|
|
30
|
+
clearRetry(state);
|
|
31
|
+
states.delete(threadId);
|
|
32
|
+
};
|
|
33
|
+
const loseClaim = (threadId, claimGeneration) => {
|
|
34
|
+
const state = states.get(threadId);
|
|
35
|
+
if (!state || state.generation !== claimGeneration) return;
|
|
36
|
+
state.claim = void 0;
|
|
37
|
+
scheduleRetry(threadId, claimGeneration);
|
|
38
|
+
};
|
|
23
39
|
const attemptClaim = async (threadId, claimGeneration, propagateError) => {
|
|
24
40
|
try {
|
|
25
|
-
const nextClaim = await claimThread(threadId
|
|
41
|
+
const nextClaim = await claimThread(threadId, {
|
|
42
|
+
onYield: () => yieldClaim(threadId, claimGeneration),
|
|
43
|
+
onLost: () => loseClaim(threadId, claimGeneration)
|
|
44
|
+
});
|
|
26
45
|
const state = states.get(threadId);
|
|
27
46
|
if (closed || !state || state.generation !== claimGeneration) {
|
|
28
47
|
nextClaim.unsubscribe();
|
|
@@ -32,8 +51,10 @@ function createThreadOwnershipManager(claimThread) {
|
|
|
32
51
|
scheduleRetry(threadId, claimGeneration);
|
|
33
52
|
return false;
|
|
34
53
|
}
|
|
54
|
+
const previousClaim = state.claim;
|
|
35
55
|
state.retryDelayMs = OWNERSHIP_RETRY_INITIAL_DELAY_MS;
|
|
36
56
|
state.claim = nextClaim;
|
|
57
|
+
previousClaim?.unsubscribe();
|
|
37
58
|
return true;
|
|
38
59
|
} catch (error) {
|
|
39
60
|
scheduleRetry(threadId, claimGeneration);
|
|
@@ -46,13 +67,11 @@ function createThreadOwnershipManager(claimThread) {
|
|
|
46
67
|
if (closed) return false;
|
|
47
68
|
if (!threadId) return false;
|
|
48
69
|
const existing = states.get(threadId);
|
|
49
|
-
if (existing)
|
|
50
|
-
clearRetry(existing);
|
|
51
|
-
existing.claim?.unsubscribe();
|
|
52
|
-
}
|
|
70
|
+
if (existing) clearRetry(existing);
|
|
53
71
|
const state = {
|
|
54
72
|
generation: ++nextGeneration,
|
|
55
|
-
retryDelayMs: OWNERSHIP_RETRY_INITIAL_DELAY_MS
|
|
73
|
+
retryDelayMs: OWNERSHIP_RETRY_INITIAL_DELAY_MS,
|
|
74
|
+
claim: existing?.claim
|
|
56
75
|
};
|
|
57
76
|
states.set(threadId, state);
|
|
58
77
|
return attemptClaim(threadId, state.generation, true);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ownership.js","names":[],"sources":["../../src/agent-connections/ownership.ts"],"sourcesContent":["export interface ThreadOwnershipClaim {\n claimed: boolean;\n unsubscribe(): void;\n}\n\nconst OWNERSHIP_RETRY_INITIAL_DELAY_MS = 250;\nconst OWNERSHIP_RETRY_MAX_DELAY_MS = 5_000;\n\n/**\n * Per-thread claim bookkeeping. One entry per thread this session has bound, so\n * a thread the user has navigated away from stays claimed — and therefore stays\n * addressable by peers — until the session itself is torn down.\n */\ntype ThreadClaimState = {\n /** Bumped on every new attempt for this thread; late resolutions are dropped. */\n generation: number;\n claim?: ThreadOwnershipClaim;\n retryTimer?: ReturnType<typeof setTimeout>;\n retryDelayMs: number;\n};\n\nexport function createThreadOwnershipManager(claimThread: (threadId: string) => Promise<ThreadOwnershipClaim
|
|
1
|
+
{"version":3,"file":"ownership.js","names":[],"sources":["../../src/agent-connections/ownership.ts"],"sourcesContent":["export interface ThreadOwnershipClaim {\n claimed: boolean;\n unsubscribe(): void;\n}\n\nexport interface ThreadClaimContext {\n /**\n * Call from the core `yieldOwnership` callback when this claim is released to\n * another process, so the manager stops tracking it instead of believing it\n * still owns the thread.\n */\n onYield(): void;\n /** Call when lease renewal proves another live owner took the claim, so the manager retries it. */\n onLost(): void;\n}\n\nconst OWNERSHIP_RETRY_INITIAL_DELAY_MS = 250;\nconst OWNERSHIP_RETRY_MAX_DELAY_MS = 5_000;\n\n/**\n * Per-thread claim bookkeeping. One entry per thread this session has bound, so\n * a thread the user has navigated away from stays claimed — and therefore stays\n * addressable by peers — until the session itself is torn down, or until another\n * process asks for the thread and this session yields it.\n */\ntype ThreadClaimState = {\n /** Bumped on every new attempt for this thread; late resolutions are dropped. */\n generation: number;\n claim?: ThreadOwnershipClaim;\n retryTimer?: ReturnType<typeof setTimeout>;\n retryDelayMs: number;\n};\n\n/**\n * Keeps one renewable ownership claim per session thread, retries contention,\n * and discards superseded attempts without creating a release-before-acquire gap.\n */\nexport function createThreadOwnershipManager(\n claimThread: (threadId: string, context: ThreadClaimContext) => Promise<ThreadOwnershipClaim>,\n): {\n claim(threadId?: string | null): Promise<boolean>;\n release(threadId: string): void;\n close(): void;\n} {\n const states = new Map<string, ThreadClaimState>();\n // Manager-scoped so the counter keeps climbing across `release`/re-claim of the\n // same thread id: a per-thread counter restarts at 1 after a release, letting a\n // pre-release attempt match the new state and be retained.\n let nextGeneration = 0;\n let closed = false;\n\n const clearRetry = (state: ThreadClaimState) => {\n if (state.retryTimer) clearTimeout(state.retryTimer);\n state.retryTimer = undefined;\n };\n\n const scheduleRetry = (threadId: string, claimGeneration: number) => {\n const state = states.get(threadId);\n if (closed || !state || state.generation !== claimGeneration || state.retryTimer) return;\n const delayMs = state.retryDelayMs;\n state.retryDelayMs = Math.min(state.retryDelayMs * 2, OWNERSHIP_RETRY_MAX_DELAY_MS);\n state.retryTimer = setTimeout(() => {\n state.retryTimer = undefined;\n void attemptClaim(threadId, claimGeneration, false);\n }, delayMs);\n state.retryTimer.unref?.();\n };\n\n const yieldClaim = (threadId: string, claimGeneration: number) => {\n const state = states.get(threadId);\n if (!state || state.generation !== claimGeneration) return;\n // Core completed the transfer or release before notifying us. Forget the\n // thread entirely: the user is not on it, and switching back re-claims it.\n clearRetry(state);\n states.delete(threadId);\n };\n\n const loseClaim = (threadId: string, claimGeneration: number) => {\n const state = states.get(threadId);\n if (!state || state.generation !== claimGeneration) return;\n // Core already stopped the stale claim. Keep the thread tracked and retry:\n // another process may move away or exit while this session is still alive.\n state.claim = undefined;\n scheduleRetry(threadId, claimGeneration);\n };\n\n const attemptClaim = async (threadId: string, claimGeneration: number, propagateError: boolean): Promise<boolean> => {\n try {\n const nextClaim = await claimThread(threadId, {\n onYield: () => yieldClaim(threadId, claimGeneration),\n onLost: () => loseClaim(threadId, claimGeneration),\n });\n const state = states.get(threadId);\n // The session closed, or a newer attempt superseded this one while the\n // ownership request was in flight — the late claim must not be retained.\n if (closed || !state || state.generation !== claimGeneration) {\n nextClaim.unsubscribe();\n return false;\n }\n if (!nextClaim.claimed) {\n scheduleRetry(threadId, claimGeneration);\n return false;\n }\n const previousClaim = state.claim;\n state.retryDelayMs = OWNERSHIP_RETRY_INITIAL_DELAY_MS;\n state.claim = nextClaim;\n previousClaim?.unsubscribe();\n return true;\n } catch (error) {\n scheduleRetry(threadId, claimGeneration);\n if (propagateError) throw error;\n return false;\n }\n };\n\n return {\n async claim(threadId) {\n if (closed) return false;\n // A thread-less transition has no claim to make. Threads already claimed\n // stay claimed: being handed no thread is not a reason to drop them.\n if (!threadId) return false;\n\n // Re-claiming the thread supersedes only that thread's previous attempt —\n // the core claim is re-published so title/metadata changes made while the\n // session was away are picked up. Keep the live claim until its replacement\n // is ready so lease-backed ownership never has a release-then-acquire gap.\n const existing = states.get(threadId);\n if (existing) clearRetry(existing);\n const state: ThreadClaimState = {\n generation: ++nextGeneration,\n retryDelayMs: OWNERSHIP_RETRY_INITIAL_DELAY_MS,\n claim: existing?.claim,\n };\n states.set(threadId, state);\n return attemptClaim(threadId, state.generation, true);\n },\n release(threadId) {\n // The thread no longer exists, so its claim has nothing left to answer for.\n // Dropping the state also makes any in-flight attempt for it unsubscribe\n // itself instead of retaining a claim for a deleted thread.\n const state = states.get(threadId);\n if (!state) return;\n clearRetry(state);\n state.claim?.unsubscribe();\n states.delete(threadId);\n },\n close() {\n closed = true;\n for (const state of states.values()) {\n clearRetry(state);\n state.claim?.unsubscribe();\n }\n states.clear();\n },\n };\n}\n"],"mappings":";AAgBA,MAAM,mCAAmC;AACzC,MAAM,+BAA+B;;;;;AAoBrC,SAAgB,6BACd,aAKA;CACA,MAAM,yBAAS,IAAI,IAA8B;CAIjD,IAAI,iBAAiB;CACrB,IAAI,SAAS;CAEb,MAAM,cAAc,UAA4B;EAC9C,IAAI,MAAM,YAAY,aAAa,MAAM,UAAU;EACnD,MAAM,aAAa,KAAA;CACrB;CAEA,MAAM,iBAAiB,UAAkB,oBAA4B;EACnE,MAAM,QAAQ,OAAO,IAAI,QAAQ;EACjC,IAAI,UAAU,CAAC,SAAS,MAAM,eAAe,mBAAmB,MAAM,YAAY;EAClF,MAAM,UAAU,MAAM;EACtB,MAAM,eAAe,KAAK,IAAI,MAAM,eAAe,GAAG,4BAA4B;EAClF,MAAM,aAAa,iBAAiB;GAClC,MAAM,aAAa,KAAA;GACnB,aAAkB,UAAU,iBAAiB,KAAK;EACpD,GAAG,OAAO;EACV,MAAM,WAAW,QAAQ;CAC3B;CAEA,MAAM,cAAc,UAAkB,oBAA4B;EAChE,MAAM,QAAQ,OAAO,IAAI,QAAQ;EACjC,IAAI,CAAC,SAAS,MAAM,eAAe,iBAAiB;EAGpD,WAAW,KAAK;EAChB,OAAO,OAAO,QAAQ;CACxB;CAEA,MAAM,aAAa,UAAkB,oBAA4B;EAC/D,MAAM,QAAQ,OAAO,IAAI,QAAQ;EACjC,IAAI,CAAC,SAAS,MAAM,eAAe,iBAAiB;EAGpD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 import type { AgentController, Session } from '@mastra/core/agent-controller';
|
|
|
6
6
|
* so every thread the user has loaded has to stay claimed for as long as the
|
|
7
7
|
* session lives — a thread that is silently released becomes unreachable, and a
|
|
8
8
|
* peer that saved it can no longer send to it. Claims are therefore keyed per
|
|
9
|
-
* thread and
|
|
9
|
+
* thread and remain live until the thread is deleted, the session is torn down,
|
|
10
|
+
* or ownership is handed to another active session.
|
|
11
|
+
*
|
|
12
|
+
* When another process asks to claim a thread that is *not* this session's
|
|
13
|
+
* current thread, the lease is transferred to that requester atomically. The
|
|
14
|
+
* user is in that other process now, so peers should reach it there. A thread
|
|
15
|
+
* the user is actually looking at is never yielded; the requester keeps
|
|
16
|
+
* retrying until the current session moves away.
|
|
10
17
|
*/
|
|
11
18
|
export declare function createSessionThreadAdvertisement<TState>(options: {
|
|
12
19
|
session: Session<TState>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"session-advertisement.d.ts","sourceRoot":"","sources":["../../src/agent-connections/session-advertisement.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,OAAO,EAAE,MAAM,+BAA+B,CAAC;AAI9E
|
|
1
|
+
{"version":3,"file":"session-advertisement.d.ts","sourceRoot":"","sources":["../../src/agent-connections/session-advertisement.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,OAAO,EAAE,MAAM,+BAA+B,CAAC;AAI9E;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,gCAAgC,CAAC,MAAM,EAAE,OAAO,EAAE;IAChE,OAAO,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC;IACzB,UAAU,EAAE,eAAe,CAAC,MAAM,CAAC,CAAC;IACpC,0EAA0E;IAC1E,WAAW,EAAE,MAAM,CAAC;CACrB,GAAG;IAAE,KAAK,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAAC,KAAK,IAAI,IAAI,CAAA;CAAE,CAgF5D"}
|
|
@@ -7,12 +7,19 @@ import { createThreadOwnershipManager } from "./ownership.js";
|
|
|
7
7
|
* so every thread the user has loaded has to stay claimed for as long as the
|
|
8
8
|
* session lives — a thread that is silently released becomes unreachable, and a
|
|
9
9
|
* peer that saved it can no longer send to it. Claims are therefore keyed per
|
|
10
|
-
* thread and
|
|
10
|
+
* thread and remain live until the thread is deleted, the session is torn down,
|
|
11
|
+
* or ownership is handed to another active session.
|
|
12
|
+
*
|
|
13
|
+
* When another process asks to claim a thread that is *not* this session's
|
|
14
|
+
* current thread, the lease is transferred to that requester atomically. The
|
|
15
|
+
* user is in that other process now, so peers should reach it there. A thread
|
|
16
|
+
* the user is actually looking at is never yielded; the requester keeps
|
|
17
|
+
* retrying until the current session moves away.
|
|
11
18
|
*/
|
|
12
19
|
function createSessionThreadAdvertisement(options) {
|
|
13
20
|
const { session, controller, projectName } = options;
|
|
14
21
|
const latestObservedTitles = /* @__PURE__ */ new Map();
|
|
15
|
-
const threadOwnership = createThreadOwnershipManager(async (threadId) => {
|
|
22
|
+
const threadOwnership = createThreadOwnershipManager(async (threadId, { onYield, onLost }) => {
|
|
16
23
|
const revisionAtStart = latestObservedTitles.get(threadId)?.revision ?? 0;
|
|
17
24
|
const thread = await session.thread.getById({ threadId });
|
|
18
25
|
const agent = controller.getCurrentAgent(session);
|
|
@@ -23,7 +30,10 @@ function createSessionThreadAdvertisement(options) {
|
|
|
23
30
|
peer: {
|
|
24
31
|
label: projectName,
|
|
25
32
|
...thread?.title ? { title: thread.title } : {}
|
|
26
|
-
}
|
|
33
|
+
},
|
|
34
|
+
yieldOwnership: () => session.thread.getId() !== threadId,
|
|
35
|
+
onOwnershipYielded: onYield,
|
|
36
|
+
onOwnershipLost: onLost
|
|
27
37
|
});
|
|
28
38
|
const observedTitle = latestObservedTitles.get(threadId);
|
|
29
39
|
if (claim.claimed && observedTitle && observedTitle.revision !== revisionAtStart) agent.updateThreadPeerAdvertisement({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"session-advertisement.js","names":[],"sources":["../../src/agent-connections/session-advertisement.ts"],"sourcesContent":["import type { AgentController, Session } from '@mastra/core/agent-controller';\n\nimport { createThreadOwnershipManager } from './ownership.js';\n\n/**\n * Advertise a session's threads to peer agents and keep them advertised.\n *\n * Cross-agent communication addresses peers by `(agentId, resourceId, threadId)`,\n * so every thread the user has loaded has to stay claimed for as long as the\n * session lives — a thread that is silently released becomes unreachable, and a\n * peer that saved it can no longer send to it. Claims are therefore keyed per\n * thread and
|
|
1
|
+
{"version":3,"file":"session-advertisement.js","names":[],"sources":["../../src/agent-connections/session-advertisement.ts"],"sourcesContent":["import type { AgentController, Session } from '@mastra/core/agent-controller';\n\nimport { createThreadOwnershipManager } from './ownership.js';\n\n/**\n * Advertise a session's threads to peer agents and keep them advertised.\n *\n * Cross-agent communication addresses peers by `(agentId, resourceId, threadId)`,\n * so every thread the user has loaded has to stay claimed for as long as the\n * session lives — a thread that is silently released becomes unreachable, and a\n * peer that saved it can no longer send to it. Claims are therefore keyed per\n * thread and remain live until the thread is deleted, the session is torn down,\n * or ownership is handed to another active session.\n *\n * When another process asks to claim a thread that is *not* this session's\n * current thread, the lease is transferred to that requester atomically. The\n * user is in that other process now, so peers should reach it there. A thread\n * the user is actually looking at is never yielded; the requester keeps\n * retrying until the current session moves away.\n */\nexport function createSessionThreadAdvertisement<TState>(options: {\n session: Session<TState>;\n controller: AgentController<TState>;\n /** Human-readable peer label for every thread this session advertises. */\n projectName: string;\n}): { claim(threadId: string): Promise<void>; close(): void } {\n const { session, controller, projectName } = options;\n // Title updates can land while a thread's ownership request is still in\n // flight, when there is no advertisement to update yet. Remembering the\n // latest title (with a revision) lets the claim apply it afterwards instead\n // of losing the rename.\n const latestObservedTitles = new Map<string, { revision: number; title: string | undefined }>();\n\n const threadOwnership = createThreadOwnershipManager(async (threadId, { onYield, onLost }) => {\n const revisionAtStart = latestObservedTitles.get(threadId)?.revision ?? 0;\n const thread = await session.thread.getById({ threadId });\n const agent = controller.getCurrentAgent(session);\n const claim = await agent.claimThreadOwnership({\n threadId,\n resourceId: session.identity.getResourceId(),\n // The claim answers for `threadId`, which is not necessarily the session's\n // current thread once the user has moved on — so the woken run must bind\n // its memory and request context to the claimed thread, not the current one.\n streamOptions: () => session.machinery.buildStreamOptions({ threadId }),\n peer: {\n label: projectName,\n ...(thread?.title ? { title: thread.title } : {}),\n },\n // Read the current thread live rather than tracking events: whichever\n // path moved the session (including silent switches) is reflected here.\n yieldOwnership: () => session.thread.getId() !== threadId,\n onOwnershipYielded: onYield,\n onOwnershipLost: onLost,\n });\n const observedTitle = latestObservedTitles.get(threadId);\n if (claim.claimed && observedTitle && observedTitle.revision !== revisionAtStart) {\n agent.updateThreadPeerAdvertisement({\n resourceId: session.identity.getResourceId(),\n threadId,\n peer: { title: observedTitle.title },\n });\n }\n return claim;\n });\n\n const claimThreadOwnership = async (threadId: string) => {\n try {\n await threadOwnership.claim(threadId);\n } catch (error) {\n console.error(`Failed to claim cross-agent thread ownership for ${threadId}`, error);\n }\n };\n\n const unsubscribeSession = session.subscribe(event => {\n if (event.type === 'thread_changed') void claimThreadOwnership(event.threadId);\n else if (event.type === 'thread_created') void claimThreadOwnership(event.thread.id);\n else if (event.type === 'thread_deleted') {\n // Claims outlive the session's current thread, so a deleted thread has to be\n // released explicitly or it stays advertised and a peer keeps sending to it.\n latestObservedTitles.delete(event.threadId);\n threadOwnership.release(event.threadId);\n } else if (event.type === 'thread_title_updated' || event.type === 'om_thread_title_updated') {\n const title = event.type === 'thread_title_updated' ? event.title : event.newTitle;\n const revision = (latestObservedTitles.get(event.threadId)?.revision ?? 0) + 1;\n latestObservedTitles.set(event.threadId, { revision, title });\n controller.getCurrentAgent(session).updateThreadPeerAdvertisement({\n resourceId: session.identity.getResourceId(),\n threadId: event.threadId,\n peer: { title },\n });\n }\n });\n\n return {\n /**\n * Claim (and start advertising) a thread. Errors are logged, not thrown:\n * the caller often cannot await the result, and a failed claim is retried\n * by the ownership manager.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AAO,EAAE;OAC9E,IAAI,MAAM,SAAS,kBAAkB;GAGxC,qBAAqB,OAAO,MAAM,QAAQ;GAC1C,gBAAgB,QAAQ,MAAM,QAAQ;EACxC,OAAO,IAAI,MAAM,SAAS,0BAA0B,MAAM,SAAS,2BAA2B;GAC5F,MAAM,QAAQ,MAAM,SAAS,yBAAyB,MAAM,QAAQ,MAAM;GAC1E,MAAM,YAAY,qBAAqB,IAAI,MAAM,QAAQ,CAAC,EAAE,YAAY,KAAK;GAC7E,qBAAqB,IAAI,MAAM,UAAU;IAAE;IAAU;GAAM,CAAC;GAC5D,WAAW,gBAAgB,OAAO,CAAC,CAAC,8BAA8B;IAChE,YAAY,QAAQ,SAAS,cAAc;IAC3C,UAAU,MAAM;IAChB,MAAM,EAAE,MAAM;GAChB,CAAC;EACH;CACF,CAAC;CAED,OAAO;;;;;;EAML,OAAO;EACP,QAAQ;GACN,mBAAmB;GACnB,gBAAgB,MAAM;EACxB;CACF;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tool-guidance.d.ts","sourceRoot":"","sources":["../../../src/agents/prompts/tool-guidance.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH,UAAU,mBAAmB;IAC3B,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,uFAAuF;IACvF,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,uEAAuE;IACvE,WAAW,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;IAC1B,oEAAoE;IACpE,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,GAAE,mBAAwB,GAAG,MAAM,
|
|
1
|
+
{"version":3,"file":"tool-guidance.d.ts","sourceRoot":"","sources":["../../../src/agents/prompts/tool-guidance.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH,UAAU,mBAAmB;IAC3B,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,uFAAuF;IACvF,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,uEAAuE;IACvE,WAAW,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;IAC1B,oEAAoE;IACpE,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,GAAE,mBAAwB,GAAG,MAAM,CAgR3F"}
|
|
@@ -41,6 +41,7 @@ You have access to the following tools. Use the RIGHT tool for the job:`);
|
|
|
41
41
|
- Prefer dedicated tools for: file reading (${MC_TOOLS.VIEW}), file search (${MC_TOOLS.SEARCH_CONTENT}/${MC_TOOLS.FIND_FILES}), file editing (${MC_TOOLS.STRING_REPLACE_LSP}/${MC_TOOLS.WRITE_FILE}).
|
|
42
42
|
- Commands have a 30-second default timeout. Use \`timeout\` for longer commands, \`cwd\` for working directory.
|
|
43
43
|
- Use the \`tail\` parameter or pipe to \`| tail -N\` to limit output — the full output streams to the user, only the tail is returned to you. If you're building any kind of package you should be tailing.
|
|
44
|
+
- Always set \`description\` to a 5-10 word summary of what the command does; the user sees it instead of the raw command. Put it first in the arguments, before \`command\`, so the user sees it while the rest of the call streams in. Write each one as the next step in a running narrative that can lean on earlier commands (e.g. "Searching open PRs for failing CI", then "Drilling into the first of 15 failures").
|
|
44
45
|
- Good: Run independent commands in parallel when possible.
|
|
45
46
|
- Bad: Running \`cat file.txt\` — use the ${MC_TOOLS.VIEW} tool instead.`);
|
|
46
47
|
if (!denied.has(MC_TOOLS.LSP_INSPECT)) readTools.push(`
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tool-guidance.js","names":[],"sources":["../../../src/agents/prompts/tool-guidance.ts"],"sourcesContent":["/**\n * Mode-specific tool behavioral guidance.\n * Generates tool usage instructions that match the actual registered tool names\n * and are scoped to what's available in the current mode.\n */\n\nimport { MC_TOOLS } from '../../tool-names.js';\n\ninterface ToolGuidanceOptions {\n hasWebSearch?: boolean;\n hasSubagents?: boolean;\n /** Subconscious knowledge tools are registered (experimental subconscious enabled). */\n hasSubconscious?: boolean;\n /** Tool names that have been denied — omit their guidance sections. */\n deniedTools?: Set<string>;\n /** Workspace-relative directory where plan mode can write plans. */\n plansDir?: string;\n}\n\nexport function buildToolGuidance(modeId: string, options: ToolGuidanceOptions = {}): string {\n const denied = options.deniedTools ?? new Set<string>();\n const plansDir = options.plansDir ?? '.mastracode/plans';\n const sections: string[] = [];\n\n sections.push(`# Tool Usage Rules\n\nIMPORTANT: You can ONLY call tools by their exact registered names listed below. Shell commands like \\`git\\`, \\`npm\\`, \\`ls\\`, etc. are NOT tools — they must be run via the \\`execute_command\\` tool.\n\nYou have access to the following tools. Use the RIGHT tool for the job:`);\n\n // --- Read tools (all modes) ---\n\n const readTools: string[] = [];\n\n if (!denied.has(MC_TOOLS.VIEW)) {\n readTools.push(`\n**${MC_TOOLS.VIEW}** — Read file contents\n- Use this to read files before editing them. NEVER propose changes to code you haven't read.\n- Use \\`offset\\` (1-indexed start line) and \\`limit\\` (number of lines) for large files.\n- Example: Read lines 50-100: \\`{ path: \"src/big-file.ts\", offset: 50, limit: 51 }\\`\n- To list directories, use \\`${MC_TOOLS.FIND_FILES}\\` instead.`);\n }\n\n if (!denied.has(MC_TOOLS.SEARCH_CONTENT)) {\n readTools.push(`\n**${MC_TOOLS.SEARCH_CONTENT}** — Search file contents using regex\n- Preferred for content search (finding functions, variables, error messages, imports, etc.)\n- Use \\`path\\` to filter by directory or glob pattern. Supports \\`contextLines\\`, \\`caseSensitive\\`, and \\`maxCount\\`.\n- Example: Find a function: \\`{ pattern: \"function handleSubmit\", path: \"**/*.ts\" }\\`\n- Example: Find imports: \\`{ pattern: \"from ['\\\\\"\\\\]express['\\\\\"\\\\]\", path: \"**/*.ts\" }\\`\n- Respects .gitignore by default.`);\n }\n\n if (!denied.has(MC_TOOLS.FIND_FILES)) {\n readTools.push(`\n**${MC_TOOLS.FIND_FILES}** — List files and directories as a tree\n- Preferred for exploring project structure and finding files by pattern.\n- Returns tree-style output. Respects .gitignore by default.\n- Example: List project root: \\`{ path: \"./\" }\\`\n- Example: Find test files: \\`{ path: \"./src\", pattern: \"**/*.test.ts\" }\\`\n- Example: Find config files: \\`{ pattern: \"*.config.{js,ts,json}\" }\\``);\n }\n\n if (!denied.has(MC_TOOLS.EXECUTE_COMMAND)) {\n readTools.push(`\n**${MC_TOOLS.EXECUTE_COMMAND}** — Run shell commands\n- Use for: git, npm/pnpm, docker, build tools, test runners, and other terminal operations.\n- Prefer dedicated tools for: file reading (${MC_TOOLS.VIEW}), file search (${MC_TOOLS.SEARCH_CONTENT}/${MC_TOOLS.FIND_FILES}), file editing (${MC_TOOLS.STRING_REPLACE_LSP}/${MC_TOOLS.WRITE_FILE}).\n- Commands have a 30-second default timeout. Use \\`timeout\\` for longer commands, \\`cwd\\` for working directory.\n- Use the \\`tail\\` parameter or pipe to \\`| tail -N\\` to limit output — the full output streams to the user, only the tail is returned to you. If you're building any kind of package you should be tailing.\n- Good: Run independent commands in parallel when possible.\n- Bad: Running \\`cat file.txt\\` — use the ${MC_TOOLS.VIEW} tool instead.`);\n }\n\n if (!denied.has(MC_TOOLS.LSP_INSPECT)) {\n readTools.push(`\n**${MC_TOOLS.LSP_INSPECT}** — Inspect code using Language Server Protocol\n- Use this for type information, hover docs, go-to-definition, and finding implementations for a symbol.\n- Best when you already know the file and line and need semantic code intelligence rather than raw file contents.\n- Input: \\`path\\` (absolute file path), \\`line\\` (1-indexed line number), \\`match\\` (the exact line content with exactly one \\`<<<\\` cursor marker).\n- Output includes: \\`hover\\`, \\`definition\\` (compact location with preview), and \\`implementation\\` (compact usage/implementation locations).\n- Example: \\`{ path: \"/abs/path/src/foo.ts\", line: 10, match: \"const foo = <<<bar()\" }\\` — inspect the symbol at the \\`<<<\\` position.\n- Use \\`${MC_TOOLS.VIEW}\\` when you need to read the implementation or surrounding code.\n- Use \\`${MC_TOOLS.SEARCH_CONTENT}\\` or \\`${MC_TOOLS.FIND_FILES}\\` first if you do not yet know where the symbol is.`);\n }\n\n if (!denied.has(MC_TOOLS.NOTIFICATION_INBOX)) {\n readTools.push(`\n**${MC_TOOLS.NOTIFICATION_INBOX}** — Inspect and manage notification inbox records\n- Use this when a \\`<notification-summary>\\` says pending notifications exist.\n- Use \\`{ \"action\": \"list\", \"status\": \"pending\" }\\` or \\`{ \"action\": \"search\", \"query\": \"...\" }\\` to find notification records for the current thread.\n- Use \\`read\\` to deliver unread notification signals into the chat and mark them seen; the tool result summarizes the count instead of exposing notification contents.\n- Use \\`dismiss\\` or \\`archive\\` only when the user asks or the notification is no longer relevant.`);\n }\n\n if (readTools.length > 0) {\n sections.push(readTools.join('\\n'));\n }\n\n // --- Write/edit tools (build & fast only) ---\n\n if (modeId !== 'plan') {\n const writeTools: string[] = [];\n\n if (!denied.has(MC_TOOLS.STRING_REPLACE_LSP)) {\n writeTools.push(`\n**${MC_TOOLS.STRING_REPLACE_LSP}** — Edit files by replacing exact text\n- You MUST read a file with \\`${MC_TOOLS.VIEW}\\` before editing it.\n- \\`old_string\\` must be an exact match of existing text in the file.\n- Provide enough surrounding context in \\`old_string\\` to make it unique.\n- Use \\`replace_all: true\\` to replace all occurrences (default: false, requires unique match).\n- For creating new files, use \\`${MC_TOOLS.WRITE_FILE}\\` instead.\n- Good: Include 2-3 lines of surrounding context to ensure uniqueness.\n- Bad: Using just \\`return true;\\` — too common, will match multiple places.`);\n }\n\n if (!denied.has(MC_TOOLS.WRITE_FILE)) {\n writeTools.push(`\n**${MC_TOOLS.WRITE_FILE}** — Create new files or overwrite existing ones\n- Use this to create new files.\n- If overwriting an existing file, you MUST have read it first with \\`${MC_TOOLS.VIEW}\\`.\n- Prefer editing existing files over creating new ones.`);\n }\n\n if (writeTools.length > 0) {\n sections.push(writeTools.join('\\n'));\n }\n }\n\n // --- Web tools (all modes, conditionally available) ---\n\n if (options.hasWebSearch) {\n const webTools: string[] = [];\n if (!denied.has('web_search')) webTools.push('**web_search**');\n if (!denied.has('web_extract')) webTools.push('**web_extract**');\n if (webTools.length > 0) {\n sections.push(`\n${webTools.join(' / ')} — Search the web / extract page content\n- Use for looking up documentation, error messages, package APIs.`);\n }\n }\n\n // --- Subconscious knowledge tools (all modes, conditionally available) ---\n\n if (options.hasSubconscious) {\n const knowledgeTools = ['knowledge_search', 'knowledge_read', 'knowledge_browse'].filter(name => !denied.has(name));\n const hasAskMemory = !denied.has('ask_memory');\n if (knowledgeTools.length > 0 || hasAskMemory) {\n const lines = [\n `\n# Subconscious Memory\n\nA background memory system (the \"subconscious\") runs alongside you. After conversations, it extracts durable knowledge — decisions, preferences, people, files, repos, work items — into a knowledge graph scoped to this project, visible across your sessions here. It also delivers reminders (\\`<remembered>\\`) and pinned knowledge into your context on its own; you do not manage those directly.`,\n ];\n if (knowledgeTools.length > 0) {\n const bullets: string[] = [];\n if (knowledgeTools.includes('knowledge_search')) {\n bullets.push(\n \"- Use `knowledge_search` for a quick lexical + semantic lookup when you need a specific fact (a past decision, a person's role, what a file is for). Cheaper than re-deriving it from the codebase or asking the user.\",\n );\n }\n if (knowledgeTools.includes('knowledge_read')) {\n bullets.push('- Use `knowledge_read` to open a node by name or ID and see the records about it.');\n }\n if (knowledgeTools.includes('knowledge_browse')) {\n bullets.push(\n \"- Use `knowledge_browse` to list nodes by kind or name prefix, or to walk a node's mentions and backlinks.\",\n );\n }\n if (!denied.has('recall')) {\n bullets.push(\n '- Prefer these over `recall` when the question is about durable facts rather than what was said in a specific past conversation.',\n );\n }\n lines.push(`\n${knowledgeTools.map(name => `**${name}**`).join(' / ')} — Query the knowledge graph directly\n${bullets.join('\\n')}`);\n }\n if (hasAskMemory) {\n lines.push(`\n**ask_memory** — Ask the reminder sidekick a question about existing memory\n- Use only when the answer is not already in your context and a direct search is not enough: open-ended questions (\"what did we decide about X and why?\") or questions that need synthesis across several memories. It answers from what is already remembered; it does not store anything.\n- It is ASYNCHRONOUS. The tool returns as soon as the question is accepted; the answer arrives later as one or more \\`<remind-answer source=\"subconscious\" agent=\"remind\" replyId=\"…\" moreComing=\"true|false\">\\` messages in your context. Keep working — do not poll or wait, and do not re-ask the same question.\n- Treat a message with \\`moreComing=\"true\"\\` as partial; the reply is complete only when \\`moreComing=\"false\"\\` arrives. Fold the answer into your work and cite it as remembered context rather than as something you verified yourself.`);\n }\n sections.push(lines.join('\\n'));\n }\n }\n\n // --- Task management tools (all modes) ---\n\n const taskTools: string[] = [];\n const canUpdateTask = !denied.has('task_update');\n const canCompleteTask = !denied.has('task_complete');\n const canCheckTasks = !denied.has('task_check');\n const canWriteTasks = !denied.has('task_write');\n const patchToolGuidance =\n canUpdateTask && canCompleteTask\n ? '- Prefer task_update or task_complete when changing one existing task.'\n : canUpdateTask\n ? '- Prefer task_update when changing one existing task.'\n : canCompleteTask\n ? '- Prefer task_complete when marking one existing task completed.'\n : '- Use task_write with the full task list when changing existing tasks.';\n\n if (canWriteTasks) {\n taskTools.push(`\n**task_write** — Track tasks for complex multi-step work\n- Use when a task requires 3 or more distinct steps or actions.\n- Use task_write to create the initial task list or replace the whole list after replanning.\n- Each task has: id (stable identifier), content (imperative form), status (pending, in_progress, or completed), activeForm (present continuous form shown during execution).\n- Keep task IDs stable across updates. If you omit IDs, the tool result returns generated IDs.\n${patchToolGuidance}\n- Mark tasks \\`in_progress\\` BEFORE starting work. Only ONE task should be \\`in_progress\\` at a time.\n- Mark tasks \\`completed\\` IMMEDIATELY after finishing each task. Do not batch completions.`);\n }\n\n if (canUpdateTask) {\n taskTools.push(`\n**task_update** — Patch one tracked task by ID\n- Use this for targeted changes to one existing task.\n- Provide the task ID and only the fields that changed: content, status, or activeForm.`);\n }\n\n if (canCompleteTask) {\n const idSource = canCheckTasks\n ? 'Use task_check if you need the current IDs before completing a task.'\n : canWriteTasks\n ? 'Use IDs returned by task_write.'\n : 'Use only task IDs already visible in the current task list.';\n taskTools.push(`\n**task_complete** — Mark one tracked task completed by ID\n- Use this immediately after finishing a tracked task.\n- ${idSource}`);\n }\n\n if (canCheckTasks) {\n taskTools.push(`\n**task_check** — Check completion status of tasks\n- Use this BEFORE finishing tracked work to verify all tasks are completed.\n- Returns a readable status summary plus structured fields: tasks, summary, incompleteTasks, and isError.\n- summary includes total, completed, inProgress, pending, incomplete, hasTasks, and allCompleted.\n- Use summary.allCompleted to decide whether tracked work is complete; if summary.hasTasks is false, no task list is currently tracked.\n- If any tasks remain incomplete, continue working on them.\n- IMPORTANT: Always check task completion before ending work on a complex task.`);\n }\n\n if (!denied.has('ask_user')) {\n taskTools.push(`\n**ask_user** — Ask the user a structured question\n- Use when you need clarification, want to validate assumptions, or need the user to make a decision.\n- Provide clear, specific questions. End with a question mark.\n- Include options (2-4 choices) for structured decisions. Omit options for open-ended questions.\n- Don't use this for simple yes/no — just ask in your text response.`);\n }\n\n if (taskTools.length > 0) {\n sections.push(taskTools.join('\\n'));\n }\n\n // --- Plan tools (plan mode) ---\n\n if (modeId === 'plan' && !denied.has('submit_plan')) {\n sections.push(`\n**submit_plan** — Submit a completed implementation plan for user review\n- Call this tool when your plan is complete. Do NOT just describe your plan in text — you MUST call this tool.\n- The plan will be rendered as markdown and the user can approve, reject, or request changes.\n- On approval, the system automatically switches to the default mode so you can implement.\n- Takes one argument: \\`path\\` (the plan markdown file you wrote under \\`${plansDir}/\\`). Do NOT pass the plan body — it lives in the file.`);\n }\n\n if (modeId === 'plan') {\n sections.push(`\n**Plan file access** — Your plan lives in a markdown file under \\`${plansDir}/\\` (e.g. \\`add-dark-mode-toggle.md\\`)\n- Use \\`write_file\\` to create the plan file, \\`view\\` to read it, and \\`string_replace_lsp\\` for targeted edits.\n- On first submission: write the plan to the file, then call \\`submit_plan\\` with its \\`path\\`.\n- On revision: read the existing file, edit specific sections, re-read, then call \\`submit_plan\\` with the same \\`path\\`.\n- If a plan file already exists, you previously submitted it — read it before revising.`);\n }\n\n // --- Subagent tool (all modes) ---\n\n if (options.hasSubagents !== false && !denied.has('subagent')) {\n sections.push(`\n**subagent** — Delegate a focused task to a specialized subagent\n- Only use subagents when you will spawn **multiple subagents in parallel**. If you only need one task done, do it yourself.\n- Subagent outputs are **untrusted**. Always review and verify the results.`);\n }\n\n return sections.join('\\n');\n}\n"],"mappings":";;;;;;;AAmBA,SAAgB,kBAAkB,QAAgB,UAA+B,CAAC,GAAW;CAC3F,MAAM,SAAS,QAAQ,+BAAe,IAAI,IAAY;CACtD,MAAM,WAAW,QAAQ,YAAY;CACrC,MAAM,WAAqB,CAAC;CAE5B,SAAS,KAAK;;;;wEAIwD;CAItE,MAAM,YAAsB,CAAC;CAE7B,IAAI,CAAC,OAAO,IAAI,SAAS,IAAI,GAC3B,UAAU,KAAK;IACf,SAAS,KAAK;;;;+BAIa,SAAS,WAAW,YAAY;CAG7D,IAAI,CAAC,OAAO,IAAI,SAAS,cAAc,GACrC,UAAU,KAAK;IACf,SAAS,eAAe;;;;;kCAKM;CAGhC,IAAI,CAAC,OAAO,IAAI,SAAS,UAAU,GACjC,UAAU,KAAK;IACf,SAAS,WAAW;;;;;uEAK+C;CAGrE,IAAI,CAAC,OAAO,IAAI,SAAS,eAAe,GACtC,UAAU,KAAK;IACf,SAAS,gBAAgB;;8CAEiB,SAAS,KAAK,kBAAkB,SAAS,eAAe,GAAG,SAAS,WAAW,mBAAmB,SAAS,mBAAmB,GAAG,SAAS,WAAW;;;;4CAIvJ,SAAS,KAAK,eAAe;CAGvE,IAAI,CAAC,OAAO,IAAI,SAAS,WAAW,GAClC,UAAU,KAAK;IACf,SAAS,YAAY;;;;;;UAMf,SAAS,KAAK;UACd,SAAS,eAAe,UAAU,SAAS,WAAW,qDAAqD;CAGnH,IAAI,CAAC,OAAO,IAAI,SAAS,kBAAkB,GACzC,UAAU,KAAK;IACf,SAAS,mBAAmB;;;;oGAIoE;CAGlG,IAAI,UAAU,SAAS,GACrB,SAAS,KAAK,UAAU,KAAK,IAAI,CAAC;CAKpC,IAAI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AAC,CAAC,KAAK,KAAK,EAAE;EACtD,QAAQ,KAAK,IAAI,GAAG;GAChB;GACA,IAAI,cACF,MAAM,KAAK;;;;0OAIuN;GAEpO,SAAS,KAAK,MAAM,KAAK,IAAI,CAAC;EAChC;CACF;CAIA,MAAM,YAAsB,CAAC;CAC7B,MAAM,gBAAgB,CAAC,OAAO,IAAI,aAAa;CAC/C,MAAM,kBAAkB,CAAC,OAAO,IAAI,eAAe;CACnD,MAAM,gBAAgB,CAAC,OAAO,IAAI,YAAY;CAC9C,MAAM,gBAAgB,CAAC,OAAO,IAAI,YAAY;CAC9C,MAAM,oBACJ,iBAAiB,kBACb,2EACA,gBACE,0DACA,kBACE,qEACA;CAEV,IAAI,eACF,UAAU,KAAK;;;;;;EAMjB,kBAAkB;;4FAEwE;CAG1F,IAAI,eACF,UAAU,KAAK;;;wFAGqE;CAGtF,IAAI,iBAAiB;EACnB,MAAM,WAAW,gBACb,yEACA,gBACE,oCACA;EACN,UAAU,KAAK;;;IAGf,UAAU;CACZ;CAEA,IAAI,eACF,UAAU,KAAK;;;;;;;gFAO6D;CAG9E,IAAI,CAAC,OAAO,IAAI,UAAU,GACxB,UAAU,KAAK;;;;;qEAKkD;CAGnE,IAAI,UAAU,SAAS,GACrB,SAAS,KAAK,UAAU,KAAK,IAAI,CAAC;CAKpC,IAAI,WAAW,UAAU,CAAC,OAAO,IAAI,aAAa,GAChD,SAAS,KAAK;;;;;2EAKyD,SAAS,wDAAwD;CAG1I,IAAI,WAAW,QACb,SAAS,KAAK;oEACkD,SAAS;;;;wFAIW;CAKtF,IAAI,QAAQ,iBAAiB,SAAS,CAAC,OAAO,IAAI,UAAU,GAC1D,SAAS,KAAK;;;4EAG0D;CAG1E,OAAO,SAAS,KAAK,IAAI;AAC3B"}
|
|
1
|
+
{"version":3,"file":"tool-guidance.js","names":[],"sources":["../../../src/agents/prompts/tool-guidance.ts"],"sourcesContent":["/**\n * Mode-specific tool behavioral guidance.\n * Generates tool usage instructions that match the actual registered tool names\n * and are scoped to what's available in the current mode.\n */\n\nimport { MC_TOOLS } from '../../tool-names.js';\n\ninterface ToolGuidanceOptions {\n hasWebSearch?: boolean;\n hasSubagents?: boolean;\n /** Subconscious knowledge tools are registered (experimental subconscious enabled). */\n hasSubconscious?: boolean;\n /** Tool names that have been denied — omit their guidance sections. */\n deniedTools?: Set<string>;\n /** Workspace-relative directory where plan mode can write plans. */\n plansDir?: string;\n}\n\nexport function buildToolGuidance(modeId: string, options: ToolGuidanceOptions = {}): string {\n const denied = options.deniedTools ?? new Set<string>();\n const plansDir = options.plansDir ?? '.mastracode/plans';\n const sections: string[] = [];\n\n sections.push(`# Tool Usage Rules\n\nIMPORTANT: You can ONLY call tools by their exact registered names listed below. Shell commands like \\`git\\`, \\`npm\\`, \\`ls\\`, etc. are NOT tools — they must be run via the \\`execute_command\\` tool.\n\nYou have access to the following tools. Use the RIGHT tool for the job:`);\n\n // --- Read tools (all modes) ---\n\n const readTools: string[] = [];\n\n if (!denied.has(MC_TOOLS.VIEW)) {\n readTools.push(`\n**${MC_TOOLS.VIEW}** — Read file contents\n- Use this to read files before editing them. NEVER propose changes to code you haven't read.\n- Use \\`offset\\` (1-indexed start line) and \\`limit\\` (number of lines) for large files.\n- Example: Read lines 50-100: \\`{ path: \"src/big-file.ts\", offset: 50, limit: 51 }\\`\n- To list directories, use \\`${MC_TOOLS.FIND_FILES}\\` instead.`);\n }\n\n if (!denied.has(MC_TOOLS.SEARCH_CONTENT)) {\n readTools.push(`\n**${MC_TOOLS.SEARCH_CONTENT}** — Search file contents using regex\n- Preferred for content search (finding functions, variables, error messages, imports, etc.)\n- Use \\`path\\` to filter by directory or glob pattern. Supports \\`contextLines\\`, \\`caseSensitive\\`, and \\`maxCount\\`.\n- Example: Find a function: \\`{ pattern: \"function handleSubmit\", path: \"**/*.ts\" }\\`\n- Example: Find imports: \\`{ pattern: \"from ['\\\\\"\\\\]express['\\\\\"\\\\]\", path: \"**/*.ts\" }\\`\n- Respects .gitignore by default.`);\n }\n\n if (!denied.has(MC_TOOLS.FIND_FILES)) {\n readTools.push(`\n**${MC_TOOLS.FIND_FILES}** — List files and directories as a tree\n- Preferred for exploring project structure and finding files by pattern.\n- Returns tree-style output. Respects .gitignore by default.\n- Example: List project root: \\`{ path: \"./\" }\\`\n- Example: Find test files: \\`{ path: \"./src\", pattern: \"**/*.test.ts\" }\\`\n- Example: Find config files: \\`{ pattern: \"*.config.{js,ts,json}\" }\\``);\n }\n\n if (!denied.has(MC_TOOLS.EXECUTE_COMMAND)) {\n readTools.push(`\n**${MC_TOOLS.EXECUTE_COMMAND}** — Run shell commands\n- Use for: git, npm/pnpm, docker, build tools, test runners, and other terminal operations.\n- Prefer dedicated tools for: file reading (${MC_TOOLS.VIEW}), file search (${MC_TOOLS.SEARCH_CONTENT}/${MC_TOOLS.FIND_FILES}), file editing (${MC_TOOLS.STRING_REPLACE_LSP}/${MC_TOOLS.WRITE_FILE}).\n- Commands have a 30-second default timeout. Use \\`timeout\\` for longer commands, \\`cwd\\` for working directory.\n- Use the \\`tail\\` parameter or pipe to \\`| tail -N\\` to limit output — the full output streams to the user, only the tail is returned to you. If you're building any kind of package you should be tailing.\n- Always set \\`description\\` to a 5-10 word summary of what the command does; the user sees it instead of the raw command. Put it first in the arguments, before \\`command\\`, so the user sees it while the rest of the call streams in. Write each one as the next step in a running narrative that can lean on earlier commands (e.g. \"Searching open PRs for failing CI\", then \"Drilling into the first of 15 failures\").\n- Good: Run independent commands in parallel when possible.\n- Bad: Running \\`cat file.txt\\` — use the ${MC_TOOLS.VIEW} tool instead.`);\n }\n\n if (!denied.has(MC_TOOLS.LSP_INSPECT)) {\n readTools.push(`\n**${MC_TOOLS.LSP_INSPECT}** — Inspect code using Language Server Protocol\n- Use this for type information, hover docs, go-to-definition, and finding implementations for a symbol.\n- Best when you already know the file and line and need semantic code intelligence rather than raw file contents.\n- Input: \\`path\\` (absolute file path), \\`line\\` (1-indexed line number), \\`match\\` (the exact line content with exactly one \\`<<<\\` cursor marker).\n- Output includes: \\`hover\\`, \\`definition\\` (compact location with preview), and \\`implementation\\` (compact usage/implementation locations).\n- Example: \\`{ path: \"/abs/path/src/foo.ts\", line: 10, match: \"const foo = <<<bar()\" }\\` — inspect the symbol at the \\`<<<\\` position.\n- Use \\`${MC_TOOLS.VIEW}\\` when you need to read the implementation or surrounding code.\n- Use \\`${MC_TOOLS.SEARCH_CONTENT}\\` or \\`${MC_TOOLS.FIND_FILES}\\` first if you do not yet know where the symbol is.`);\n }\n\n if (!denied.has(MC_TOOLS.NOTIFICATION_INBOX)) {\n readTools.push(`\n**${MC_TOOLS.NOTIFICATION_INBOX}** — Inspect and manage notification inbox records\n- Use this when a \\`<notification-summary>\\` says pending notifications exist.\n- Use \\`{ \"action\": \"list\", \"status\": \"pending\" }\\` or \\`{ \"action\": \"search\", \"query\": \"...\" }\\` to find notification records for the current thread.\n- Use \\`read\\` to deliver unread notification signals into the chat and mark them seen; the tool result summarizes the count instead of exposing notification contents.\n- Use \\`dismiss\\` or \\`archive\\` only when the user asks or the notification is no longer relevant.`);\n }\n\n if (readTools.length > 0) {\n sections.push(readTools.join('\\n'));\n }\n\n // --- Write/edit tools (build & fast only) ---\n\n if (modeId !== 'plan') {\n const writeTools: string[] = [];\n\n if (!denied.has(MC_TOOLS.STRING_REPLACE_LSP)) {\n writeTools.push(`\n**${MC_TOOLS.STRING_REPLACE_LSP}** — Edit files by replacing exact text\n- You MUST read a file with \\`${MC_TOOLS.VIEW}\\` before editing it.\n- \\`old_string\\` must be an exact match of existing text in the file.\n- Provide enough surrounding context in \\`old_string\\` to make it unique.\n- Use \\`replace_all: true\\` to replace all occurrences (default: false, requires unique match).\n- For creating new files, use \\`${MC_TOOLS.WRITE_FILE}\\` instead.\n- Good: Include 2-3 lines of surrounding context to ensure uniqueness.\n- Bad: Using just \\`return true;\\` — too common, will match multiple places.`);\n }\n\n if (!denied.has(MC_TOOLS.WRITE_FILE)) {\n writeTools.push(`\n**${MC_TOOLS.WRITE_FILE}** — Create new files or overwrite existing ones\n- Use this to create new files.\n- If overwriting an existing file, you MUST have read it first with \\`${MC_TOOLS.VIEW}\\`.\n- Prefer editing existing files over creating new ones.`);\n }\n\n if (writeTools.length > 0) {\n sections.push(writeTools.join('\\n'));\n }\n }\n\n // --- Web tools (all modes, conditionally available) ---\n\n if (options.hasWebSearch) {\n const webTools: string[] = [];\n if (!denied.has('web_search')) webTools.push('**web_search**');\n if (!denied.has('web_extract')) webTools.push('**web_extract**');\n if (webTools.length > 0) {\n sections.push(`\n${webTools.join(' / ')} — Search the web / extract page content\n- Use for looking up documentation, error messages, package APIs.`);\n }\n }\n\n // --- Subconscious knowledge tools (all modes, conditionally available) ---\n\n if (options.hasSubconscious) {\n const knowledgeTools = ['knowledge_search', 'knowledge_read', 'knowledge_browse'].filter(name => !denied.has(name));\n const hasAskMemory = !denied.has('ask_memory');\n if (knowledgeTools.length > 0 || hasAskMemory) {\n const lines = [\n `\n# Subconscious Memory\n\nA background memory system (the \"subconscious\") runs alongside you. After conversations, it extracts durable knowledge — decisions, preferences, people, files, repos, work items — into a knowledge graph scoped to this project, visible across your sessions here. It also delivers reminders (\\`<remembered>\\`) and pinned knowledge into your context on its own; you do not manage those directly.`,\n ];\n if (knowledgeTools.length > 0) {\n const bullets: string[] = [];\n if (knowledgeTools.includes('knowledge_search')) {\n bullets.push(\n \"- Use `knowledge_search` for a quick lexical + semantic lookup when you need a specific fact (a past decision, a person's role, what a file is for). Cheaper than re-deriving it from the codebase or asking the user.\",\n );\n }\n if (knowledgeTools.includes('knowledge_read')) {\n bullets.push('- Use `knowledge_read` to open a node by name or ID and see the records about it.');\n }\n if (knowledgeTools.includes('knowledge_browse')) {\n bullets.push(\n \"- Use `knowledge_browse` to list nodes by kind or name prefix, or to walk a node's mentions and backlinks.\",\n );\n }\n if (!denied.has('recall')) {\n bullets.push(\n '- Prefer these over `recall` when the question is about durable facts rather than what was said in a specific past conversation.',\n );\n }\n lines.push(`\n${knowledgeTools.map(name => `**${name}**`).join(' / ')} — Query the knowledge graph directly\n${bullets.join('\\n')}`);\n }\n if (hasAskMemory) {\n lines.push(`\n**ask_memory** — Ask the reminder sidekick a question about existing memory\n- Use only when the answer is not already in your context and a direct search is not enough: open-ended questions (\"what did we decide about X and why?\") or questions that need synthesis across several memories. It answers from what is already remembered; it does not store anything.\n- It is ASYNCHRONOUS. The tool returns as soon as the question is accepted; the answer arrives later as one or more \\`<remind-answer source=\"subconscious\" agent=\"remind\" replyId=\"…\" moreComing=\"true|false\">\\` messages in your context. Keep working — do not poll or wait, and do not re-ask the same question.\n- Treat a message with \\`moreComing=\"true\"\\` as partial; the reply is complete only when \\`moreComing=\"false\"\\` arrives. Fold the answer into your work and cite it as remembered context rather than as something you verified yourself.`);\n }\n sections.push(lines.join('\\n'));\n }\n }\n\n // --- Task management tools (all modes) ---\n\n const taskTools: string[] = [];\n const canUpdateTask = !denied.has('task_update');\n const canCompleteTask = !denied.has('task_complete');\n const canCheckTasks = !denied.has('task_check');\n const canWriteTasks = !denied.has('task_write');\n const patchToolGuidance =\n canUpdateTask && canCompleteTask\n ? '- Prefer task_update or task_complete when changing one existing task.'\n : canUpdateTask\n ? '- Prefer task_update when changing one existing task.'\n : canCompleteTask\n ? '- Prefer task_complete when marking one existing task completed.'\n : '- Use task_write with the full task list when changing existing tasks.';\n\n if (canWriteTasks) {\n taskTools.push(`\n**task_write** — Track tasks for complex multi-step work\n- Use when a task requires 3 or more distinct steps or actions.\n- Use task_write to create the initial task list or replace the whole list after replanning.\n- Each task has: id (stable identifier), content (imperative form), status (pending, in_progress, or completed), activeForm (present continuous form shown during execution).\n- Keep task IDs stable across updates. If you omit IDs, the tool result returns generated IDs.\n${patchToolGuidance}\n- Mark tasks \\`in_progress\\` BEFORE starting work. Only ONE task should be \\`in_progress\\` at a time.\n- Mark tasks \\`completed\\` IMMEDIATELY after finishing each task. Do not batch completions.`);\n }\n\n if (canUpdateTask) {\n taskTools.push(`\n**task_update** — Patch one tracked task by ID\n- Use this for targeted changes to one existing task.\n- Provide the task ID and only the fields that changed: content, status, or activeForm.`);\n }\n\n if (canCompleteTask) {\n const idSource = canCheckTasks\n ? 'Use task_check if you need the current IDs before completing a task.'\n : canWriteTasks\n ? 'Use IDs returned by task_write.'\n : 'Use only task IDs already visible in the current task list.';\n taskTools.push(`\n**task_complete** — Mark one tracked task completed by ID\n- Use this immediately after finishing a tracked task.\n- ${idSource}`);\n }\n\n if (canCheckTasks) {\n taskTools.push(`\n**task_check** — Check completion status of tasks\n- Use this BEFORE finishing tracked work to verify all tasks are completed.\n- Returns a readable status summary plus structured fields: tasks, summary, incompleteTasks, and isError.\n- summary includes total, completed, inProgress, pending, incomplete, hasTasks, and allCompleted.\n- Use summary.allCompleted to decide whether tracked work is complete; if summary.hasTasks is false, no task list is currently tracked.\n- If any tasks remain incomplete, continue working on them.\n- IMPORTANT: Always check task completion before ending work on a complex task.`);\n }\n\n if (!denied.has('ask_user')) {\n taskTools.push(`\n**ask_user** — Ask the user a structured question\n- Use when you need clarification, want to validate assumptions, or need the user to make a decision.\n- Provide clear, specific questions. End with a question mark.\n- Include options (2-4 choices) for structured decisions. Omit options for open-ended questions.\n- Don't use this for simple yes/no — just ask in your text response.`);\n }\n\n if (taskTools.length > 0) {\n sections.push(taskTools.join('\\n'));\n }\n\n // --- Plan tools (plan mode) ---\n\n if (modeId === 'plan' && !denied.has('submit_plan')) {\n sections.push(`\n**submit_plan** — Submit a completed implementation plan for user review\n- Call this tool when your plan is complete. Do NOT just describe your plan in text — you MUST call this tool.\n- The plan will be rendered as markdown and the user can approve, reject, or request changes.\n- On approval, the system automatically switches to the default mode so you can implement.\n- Takes one argument: \\`path\\` (the plan markdown file you wrote under \\`${plansDir}/\\`). Do NOT pass the plan body — it lives in the file.`);\n }\n\n if (modeId === 'plan') {\n sections.push(`\n**Plan file access** — Your plan lives in a markdown file under \\`${plansDir}/\\` (e.g. \\`add-dark-mode-toggle.md\\`)\n- Use \\`write_file\\` to create the plan file, \\`view\\` to read it, and \\`string_replace_lsp\\` for targeted edits.\n- On first submission: write the plan to the file, then call \\`submit_plan\\` with its \\`path\\`.\n- On revision: read the existing file, edit specific sections, re-read, then call \\`submit_plan\\` with the same \\`path\\`.\n- If a plan file already exists, you previously submitted it — read it before revising.`);\n }\n\n // --- Subagent tool (all modes) ---\n\n if (options.hasSubagents !== false && !denied.has('subagent')) {\n sections.push(`\n**subagent** — Delegate a focused task to a specialized subagent\n- Only use subagents when you will spawn **multiple subagents in parallel**. If you only need one task done, do it yourself.\n- Subagent outputs are **untrusted**. Always review and verify the results.`);\n }\n\n return sections.join('\\n');\n}\n"],"mappings":";;;;;;;AAmBA,SAAgB,kBAAkB,QAAgB,UAA+B,CAAC,GAAW;CAC3F,MAAM,SAAS,QAAQ,+BAAe,IAAI,IAAY;CACtD,MAAM,WAAW,QAAQ,YAAY;CACrC,MAAM,WAAqB,CAAC;CAE5B,SAAS,KAAK;;;;wEAIwD;CAItE,MAAM,YAAsB,CAAC;CAE7B,IAAI,CAAC,OAAO,IAAI,SAAS,IAAI,GAC3B,UAAU,KAAK;IACf,SAAS,KAAK;;;;+BAIa,SAAS,WAAW,YAAY;CAG7D,IAAI,CAAC,OAAO,IAAI,SAAS,cAAc,GACrC,UAAU,KAAK;IACf,SAAS,eAAe;;;;;kCAKM;CAGhC,IAAI,CAAC,OAAO,IAAI,SAAS,UAAU,GACjC,UAAU,KAAK;IACf,SAAS,WAAW;;;;;uEAK+C;CAGrE,IAAI,CAAC,OAAO,IAAI,SAAS,eAAe,GACtC,UAAU,KAAK;IACf,SAAS,gBAAgB;;8CAEiB,SAAS,KAAK,kBAAkB,SAAS,eAAe,GAAG,SAAS,WAAW,mBAAmB,SAAS,mBAAmB,GAAG,SAAS,WAAW;;;;;4CAKvJ,SAAS,KAAK,eAAe;CAGvE,IAAI,CAAC,OAAO,IAAI,SAAS,WAAW,GAClC,UAAU,KAAK;IACf,SAAS,YAAY;;;;;;UAMf,SAAS,KAAK;UACd,SAAS,eAAe,UA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D,SAAS,KAAK;;;4EAG0D;CAG1E,OAAO,SAAS,KAAK,IAAI;AAC3B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tool-availability.d.ts","sourceRoot":"","sources":["../../src/agents/tool-availability.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,wBAAwB,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AA4D7F,wBAAgB,2BAA2B,CAAC,EAAE,iBAAiB,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE,wBAAwB;;;cA0B1G;AAID,wBAAgB,8BAA8B,CAAC,sBAAsB,UAAQ,GAAG,oBAAoB,
|
|
1
|
+
{"version":3,"file":"tool-availability.d.ts","sourceRoot":"","sources":["../../src/agents/tool-availability.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,wBAAwB,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AA4D7F,wBAAgB,2BAA2B,CAAC,EAAE,iBAAiB,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE,wBAAwB;;;cA0B1G;AAID,wBAAgB,8BAA8B,CAAC,sBAAsB,UAAQ,GAAG,oBAAoB,CAiCnG;AAED,wFAAwF;AACxF,eAAO,MAAM,0BAA0B,sBAAmC,CAAC;AAE3E,eAAO,MAAM,yBAAyB,EAAE,SAAS,MAAM,EAwBtD,CAAC;AAEF,eAAO,MAAM,4BAA4B,EAAE,SAAS,MAAM,EAUzD,CAAC;AAEF,eAAO,MAAM,yBAAyB,EAAE,SAAS,MAAM,EAMtD,CAAC"}
|
|
@@ -59,6 +59,10 @@ function createMastraCodeWorkspaceTools(backgroundToolsEnabled = false) {
|
|
|
59
59
|
const background = backgroundToolsEnabled ? BACKGROUND_TOOL_CONFIG : void 0;
|
|
60
60
|
return {
|
|
61
61
|
...TOOL_NAME_OVERRIDES,
|
|
62
|
+
[WORKSPACE_TOOLS.SANDBOX.EXECUTE_COMMAND]: {
|
|
63
|
+
...TOOL_NAME_OVERRIDES[WORKSPACE_TOOLS.SANDBOX.EXECUTE_COMMAND],
|
|
64
|
+
requireDescription: true
|
|
65
|
+
},
|
|
62
66
|
[WORKSPACE_TOOLS.FILESYSTEM.READ_FILE]: {
|
|
63
67
|
...TOOL_NAME_OVERRIDES[WORKSPACE_TOOLS.FILESYSTEM.READ_FILE],
|
|
64
68
|
...background ? { background } : {}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tool-availability.js","names":[],"sources":["../../src/agents/tool-availability.ts"],"sourcesContent":["import { WORKSPACE_TOOLS } from '@mastra/core/workspace';\nimport type { WorkspaceToolHookContext, WorkspaceToolsConfig } from '@mastra/core/workspace';\nimport { MC_TOOLS, TOOL_NAME_OVERRIDES } from '../tool-names.js';\nimport { getLocalPlansRelativeDir, isPlanFilePath } from '../utils/plans.js';\n\nconst PLAN_MODE_WRITE_TOOL_NAMES = new Set<string>([\n WORKSPACE_TOOLS.FILESYSTEM.WRITE_FILE,\n WORKSPACE_TOOLS.FILESYSTEM.EDIT_FILE,\n]);\n\nfunction getRequestContextValue(requestContext: unknown, key: string): unknown {\n if (!requestContext) return undefined;\n if (typeof (requestContext as { get?: unknown }).get === 'function') {\n return (requestContext as { get: (key: string) => unknown }).get(key);\n }\n return (requestContext as Record<string, unknown>)[key];\n}\n\n/**\n * Subset of the real `HarnessRequestContext` shape (see\n * packages/core/src/harness/types.ts). The mode is a string property\n * (`session.modeId`) and live state is read via `session.state.get()`.\n */\ninterface PlanModeGuardHarness {\n session?: {\n modeId?: unknown;\n state?: { get?: () => unknown };\n };\n}\n\nfunction getHarnessContext(context: unknown): PlanModeGuardHarness | undefined {\n const requestContext = (context as { requestContext?: unknown } | undefined)?.requestContext;\n const harness = getRequestContextValue(requestContext, 'harness');\n return harness && typeof harness === 'object' ? (harness as PlanModeGuardHarness) : undefined;\n}\n\nfunction getHarnessState(harness: PlanModeGuardHarness | undefined): Record<string, unknown> | undefined {\n const state = harness?.session?.state?.get?.();\n return state && typeof state === 'object' ? (state as Record<string, unknown>) : undefined;\n}\n\nfunction getHarnessModeId(harness: PlanModeGuardHarness | undefined): string | undefined {\n const modeId = harness?.session?.modeId ?? getHarnessState(harness)?.modeId;\n return typeof modeId === 'string' ? modeId : undefined;\n}\n\nfunction getHarnessProjectPath(harness: PlanModeGuardHarness | undefined): string | undefined {\n const projectPath = getHarnessState(harness)?.projectPath;\n return typeof projectPath === 'string' ? projectPath : undefined;\n}\n\nfunction getHarnessFactoryProjectId(harness: PlanModeGuardHarness | undefined): string | undefined {\n const factoryProjectId = getHarnessState(harness)?.factoryProjectId;\n return typeof factoryProjectId === 'string' ? factoryProjectId : undefined;\n}\n\nfunction getToolInputPath(input: unknown): string | undefined {\n const toolPath = (input as { path?: unknown } | undefined)?.path;\n return typeof toolPath === 'string' ? toolPath : undefined;\n}\n\nexport function guardPlanModePlanFileWrites({ workspaceToolName, input, context }: WorkspaceToolHookContext) {\n if (!PLAN_MODE_WRITE_TOOL_NAMES.has(workspaceToolName)) return;\n\n const harness = getHarnessContext(context);\n if (getHarnessModeId(harness) !== 'plan') return;\n\n const factoryProjectId = getHarnessFactoryProjectId(harness);\n const planOptions = { factoryProjectId };\n const planDirHint = `${getLocalPlansRelativeDir(planOptions)}/`;\n const projectPath = getHarnessProjectPath(harness);\n const inputPath = getToolInputPath(input);\n if (!projectPath || !inputPath) {\n return {\n proceed: false as const,\n output: `Plan mode can only write plan files inside ${planDirHint}.`,\n };\n }\n\n // Plan mode may write any `.md` file directly inside the configured plan directory,\n // but nothing else in the project.\n if (isPlanFilePath(projectPath, inputPath, planOptions)) return;\n\n return {\n proceed: false as const,\n output: `Plan mode can only write plan files inside ${planDirHint}. Refusing to edit ${inputPath}.`,\n };\n}\n\nconst BACKGROUND_TOOL_CONFIG = { enabled: true, defaultDisposition: 'foreground' } as const;\n\nexport function createMastraCodeWorkspaceTools(backgroundToolsEnabled = false): WorkspaceToolsConfig {\n const background = backgroundToolsEnabled ? BACKGROUND_TOOL_CONFIG : undefined;\n return {\n ...TOOL_NAME_OVERRIDES,\n [WORKSPACE_TOOLS.FILESYSTEM.READ_FILE]: {\n ...TOOL_NAME_OVERRIDES[WORKSPACE_TOOLS.FILESYSTEM.READ_FILE],\n ...(background ? { background } : {}),\n },\n [WORKSPACE_TOOLS.FILESYSTEM.LIST_FILES]: {\n ...TOOL_NAME_OVERRIDES[WORKSPACE_TOOLS.FILESYSTEM.LIST_FILES],\n ...(background ? { background } : {}),\n },\n [WORKSPACE_TOOLS.FILESYSTEM.FILE_STAT]: {\n ...TOOL_NAME_OVERRIDES[WORKSPACE_TOOLS.FILESYSTEM.FILE_STAT],\n ...(background ? { background } : {}),\n },\n [WORKSPACE_TOOLS.FILESYSTEM.GREP]: {\n ...TOOL_NAME_OVERRIDES[WORKSPACE_TOOLS.FILESYSTEM.GREP],\n ...(background ? { background } : {}),\n },\n [WORKSPACE_TOOLS.LSP.LSP_INSPECT]: {\n ...TOOL_NAME_OVERRIDES[WORKSPACE_TOOLS.LSP.LSP_INSPECT],\n ...(background ? { background } : {}),\n },\n hooks: {\n beforeToolCall: guardPlanModePlanFileWrites,\n },\n };\n}\n\n/** Default foreground-only configuration for consumers without Mastra Code settings. */\nexport const MASTRACODE_WORKSPACE_TOOLS = createMastraCodeWorkspaceTools();\n\nexport const PLAN_MODE_AVAILABLE_TOOLS: readonly string[] = [\n // Read-only exploration tools\n MC_TOOLS.VIEW,\n MC_TOOLS.FIND_FILES,\n MC_TOOLS.SEARCH_CONTENT,\n MC_TOOLS.FILE_STAT,\n MC_TOOLS.LSP_INSPECT,\n // Plan file writing. Tool hooks enforce that these can only write `.md`\n // files inside the session's configured plan directory while in plan mode.\n MC_TOOLS.WRITE_FILE,\n MC_TOOLS.STRING_REPLACE_LSP,\n // Plan delivery tools\n 'ask_user',\n 'submit_plan',\n // Task tools for plan-stage tracking\n 'task_write',\n 'task_update',\n 'task_complete',\n 'task_check',\n // Notification access\n MC_TOOLS.NOTIFICATION_INBOX,\n // Read-only workflow inspection (no create/run/delete in plan mode).\n 'list-workflows',\n 'get-workflow',\n];\n\nexport const EXPLORE_MODE_AVAILABLE_TOOLS: readonly string[] = [\n MC_TOOLS.VIEW,\n MC_TOOLS.FIND_FILES,\n MC_TOOLS.SEARCH_CONTENT,\n MC_TOOLS.FILE_STAT,\n MC_TOOLS.LSP_INSPECT,\n 'ask_user',\n // Read-only workflow inspection (no create/run/delete in fast mode either).\n 'list-workflows',\n 'get-workflow',\n];\n\nexport const GOAL_JUDGE_READONLY_TOOLS: readonly string[] = [\n MC_TOOLS.VIEW,\n MC_TOOLS.SEARCH_CONTENT,\n MC_TOOLS.FIND_FILES,\n MC_TOOLS.FILE_STAT,\n MC_TOOLS.LSP_INSPECT,\n];\n"],"mappings":";;;;AAKA,MAAM,6CAA6B,IAAI,IAAY,CACjD,gBAAgB,WAAW,YAC3B,gBAAgB,WAAW,SAC7B,CAAC;AAED,SAAS,uBAAuB,gBAAyB,KAAsB;CAC7E,IAAI,CAAC,gBAAgB,OAAO,KAAA;CAC5B,IAAI,OAAQ,eAAqC,QAAQ,YACvD,OAAQ,eAAqD,IAAI,GAAG;CAEtE,OAAQ,eAA2C;AACrD;AAcA,SAAS,kBAAkB,SAAoD;CAC7E,MAAM,iBAAkB,SAAsD;CAC9E,MAAM,UAAU,uBAAuB,gBAAgB,SAAS;CAChE,OAAO,WAAW,OAAO,YAAY,WAAY,UAAmC,KAAA;AACtF;AAEA,SAAS,gBAAgB,SAAgF;CACvG,MAAM,QAAQ,SAAS,SAAS,OAAO,MAAM;CAC7C,OAAO,SAAS,OAAO,UAAU,WAAY,QAAoC,KAAA;AACnF;AAEA,SAAS,iBAAiB,SAA+D;CACvF,MAAM,SAAS,SAAS,SAAS,UAAU,gBAAgB,OAAO,CAAC,EAAE;CACrE,OAAO,OAAO,WAAW,WAAW,SAAS,KAAA;AAC/C;AAEA,SAAS,sBAAsB,SAA+D;CAC5F,MAAM,cAAc,gBAAgB,OAAO,CAAC,EAAE;CAC9C,OAAO,OAAO,gBAAgB,WAAW,cAAc,KAAA;AACzD;AAEA,SAAS,2BAA2B,SAA+D;CACjG,MAAM,mBAAmB,gBAAgB,OAAO,CAAC,EAAE;CACnD,OAAO,OAAO,qBAAqB,WAAW,mBAAmB,KAAA;AACnE;AAEA,SAAS,iBAAiB,OAAoC;CAC5D,MAAM,WAAY,OAA0C;CAC5D,OAAO,OAAO,aAAa,WAAW,WAAW,KAAA;AACnD;AAEA,SAAgB,4BAA4B,EAAE,mBAAmB,OAAO,WAAqC;CAC3G,IAAI,CAAC,2BAA2B,IAAI,iBAAiB,GAAG;CAExD,MAAM,UAAU,kBAAkB,OAAO;CACzC,IAAI,iBAAiB,OAAO,MAAM,QAAQ;CAG1C,MAAM,cAAc,EAAE,kBADG,2BAA2B,OACf,EAAE;CACvC,MAAM,cAAc,GAAG,yBAAyB,WAAW,EAAE;CAC7D,MAAM,cAAc,sBAAsB,OAAO;CACjD,MAAM,YAAY,iBAAiB,KAAK;CACxC,IAAI,CAAC,eAAe,CAAC,WACnB,OAAO;EACL,SAAS;EACT,QAAQ,8CAA8C,YAAY;CACpE;CAKF,IAAI,eAAe,aAAa,WAAW,WAAW,GAAG;CAEzD,OAAO;EACL,SAAS;EACT,QAAQ,8CAA8C,YAAY,qBAAqB,UAAU;CACnG;AACF;AAEA,MAAM,yBAAyB;CAAE,SAAS;CAAM,oBAAoB;AAAa;AAEjF,SAAgB,+BAA+B,yBAAyB,OAA6B;CACnG,MAAM,aAAa,yBAAyB,yBAAyB,KAAA;CACrE,OAAO;EACL,GAAG;
|
|
1
|
+
{"version":3,"file":"tool-availability.js","names":[],"sources":["../../src/agents/tool-availability.ts"],"sourcesContent":["import { WORKSPACE_TOOLS } from '@mastra/core/workspace';\nimport type { WorkspaceToolHookContext, WorkspaceToolsConfig } from '@mastra/core/workspace';\nimport { MC_TOOLS, TOOL_NAME_OVERRIDES } from '../tool-names.js';\nimport { getLocalPlansRelativeDir, isPlanFilePath } from '../utils/plans.js';\n\nconst PLAN_MODE_WRITE_TOOL_NAMES = new Set<string>([\n WORKSPACE_TOOLS.FILESYSTEM.WRITE_FILE,\n WORKSPACE_TOOLS.FILESYSTEM.EDIT_FILE,\n]);\n\nfunction getRequestContextValue(requestContext: unknown, key: string): unknown {\n if (!requestContext) return undefined;\n if (typeof (requestContext as { get?: unknown }).get === 'function') {\n return (requestContext as { get: (key: string) => unknown }).get(key);\n }\n return (requestContext as Record<string, unknown>)[key];\n}\n\n/**\n * Subset of the real `HarnessRequestContext` shape (see\n * packages/core/src/harness/types.ts). The mode is a string property\n * (`session.modeId`) and live state is read via `session.state.get()`.\n */\ninterface PlanModeGuardHarness {\n session?: {\n modeId?: unknown;\n state?: { get?: () => unknown };\n };\n}\n\nfunction getHarnessContext(context: unknown): PlanModeGuardHarness | undefined {\n const requestContext = (context as { requestContext?: unknown } | undefined)?.requestContext;\n const harness = getRequestContextValue(requestContext, 'harness');\n return harness && typeof harness === 'object' ? (harness as PlanModeGuardHarness) : undefined;\n}\n\nfunction getHarnessState(harness: PlanModeGuardHarness | undefined): Record<string, unknown> | undefined {\n const state = harness?.session?.state?.get?.();\n return state && typeof state === 'object' ? (state as Record<string, unknown>) : undefined;\n}\n\nfunction getHarnessModeId(harness: PlanModeGuardHarness | undefined): string | undefined {\n const modeId = harness?.session?.modeId ?? getHarnessState(harness)?.modeId;\n return typeof modeId === 'string' ? modeId : undefined;\n}\n\nfunction getHarnessProjectPath(harness: PlanModeGuardHarness | undefined): string | undefined {\n const projectPath = getHarnessState(harness)?.projectPath;\n return typeof projectPath === 'string' ? projectPath : undefined;\n}\n\nfunction getHarnessFactoryProjectId(harness: PlanModeGuardHarness | undefined): string | undefined {\n const factoryProjectId = getHarnessState(harness)?.factoryProjectId;\n return typeof factoryProjectId === 'string' ? factoryProjectId : undefined;\n}\n\nfunction getToolInputPath(input: unknown): string | undefined {\n const toolPath = (input as { path?: unknown } | undefined)?.path;\n return typeof toolPath === 'string' ? toolPath : undefined;\n}\n\nexport function guardPlanModePlanFileWrites({ workspaceToolName, input, context }: WorkspaceToolHookContext) {\n if (!PLAN_MODE_WRITE_TOOL_NAMES.has(workspaceToolName)) return;\n\n const harness = getHarnessContext(context);\n if (getHarnessModeId(harness) !== 'plan') return;\n\n const factoryProjectId = getHarnessFactoryProjectId(harness);\n const planOptions = { factoryProjectId };\n const planDirHint = `${getLocalPlansRelativeDir(planOptions)}/`;\n const projectPath = getHarnessProjectPath(harness);\n const inputPath = getToolInputPath(input);\n if (!projectPath || !inputPath) {\n return {\n proceed: false as const,\n output: `Plan mode can only write plan files inside ${planDirHint}.`,\n };\n }\n\n // Plan mode may write any `.md` file directly inside the configured plan directory,\n // but nothing else in the project.\n if (isPlanFilePath(projectPath, inputPath, planOptions)) return;\n\n return {\n proceed: false as const,\n output: `Plan mode can only write plan files inside ${planDirHint}. Refusing to edit ${inputPath}.`,\n };\n}\n\nconst BACKGROUND_TOOL_CONFIG = { enabled: true, defaultDisposition: 'foreground' } as const;\n\nexport function createMastraCodeWorkspaceTools(backgroundToolsEnabled = false): WorkspaceToolsConfig {\n const background = backgroundToolsEnabled ? BACKGROUND_TOOL_CONFIG : undefined;\n return {\n ...TOOL_NAME_OVERRIDES,\n // Quiet mode shows this description in place of the raw command.\n [WORKSPACE_TOOLS.SANDBOX.EXECUTE_COMMAND]: {\n ...TOOL_NAME_OVERRIDES[WORKSPACE_TOOLS.SANDBOX.EXECUTE_COMMAND],\n requireDescription: true,\n },\n [WORKSPACE_TOOLS.FILESYSTEM.READ_FILE]: {\n ...TOOL_NAME_OVERRIDES[WORKSPACE_TOOLS.FILESYSTEM.READ_FILE],\n ...(background ? { background } : {}),\n },\n [WORKSPACE_TOOLS.FILESYSTEM.LIST_FILES]: {\n ...TOOL_NAME_OVERRIDES[WORKSPACE_TOOLS.FILESYSTEM.LIST_FILES],\n ...(background ? { background } : {}),\n },\n [WORKSPACE_TOOLS.FILESYSTEM.FILE_STAT]: {\n ...TOOL_NAME_OVERRIDES[WORKSPACE_TOOLS.FILESYSTEM.FILE_STAT],\n ...(background ? { background } : {}),\n },\n [WORKSPACE_TOOLS.FILESYSTEM.GREP]: {\n ...TOOL_NAME_OVERRIDES[WORKSPACE_TOOLS.FILESYSTEM.GREP],\n ...(background ? { background } : {}),\n },\n [WORKSPACE_TOOLS.LSP.LSP_INSPECT]: {\n ...TOOL_NAME_OVERRIDES[WORKSPACE_TOOLS.LSP.LSP_INSPECT],\n ...(background ? { background } : {}),\n },\n hooks: {\n beforeToolCall: guardPlanModePlanFileWrites,\n },\n };\n}\n\n/** Default foreground-only configuration for consumers without Mastra Code settings. */\nexport const MASTRACODE_WORKSPACE_TOOLS = createMastraCodeWorkspaceTools();\n\nexport const PLAN_MODE_AVAILABLE_TOOLS: readonly string[] = [\n // Read-only exploration tools\n MC_TOOLS.VIEW,\n MC_TOOLS.FIND_FILES,\n MC_TOOLS.SEARCH_CONTENT,\n MC_TOOLS.FILE_STAT,\n MC_TOOLS.LSP_INSPECT,\n // Plan file writing. Tool hooks enforce that these can only write `.md`\n // files inside the session's configured plan directory while in plan mode.\n MC_TOOLS.WRITE_FILE,\n MC_TOOLS.STRING_REPLACE_LSP,\n // Plan delivery tools\n 'ask_user',\n 'submit_plan',\n // Task tools for plan-stage tracking\n 'task_write',\n 'task_update',\n 'task_complete',\n 'task_check',\n // Notification access\n MC_TOOLS.NOTIFICATION_INBOX,\n // Read-only workflow inspection (no create/run/delete in plan mode).\n 'list-workflows',\n 'get-workflow',\n];\n\nexport const EXPLORE_MODE_AVAILABLE_TOOLS: readonly string[] = [\n MC_TOOLS.VIEW,\n MC_TOOLS.FIND_FILES,\n MC_TOOLS.SEARCH_CONTENT,\n MC_TOOLS.FILE_STAT,\n MC_TOOLS.LSP_INSPECT,\n 'ask_user',\n // Read-only workflow inspection (no create/run/delete in fast mode either).\n 'list-workflows',\n 'get-workflow',\n];\n\nexport const GOAL_JUDGE_READONLY_TOOLS: readonly string[] = [\n MC_TOOLS.VIEW,\n MC_TOOLS.SEARCH_CONTENT,\n MC_TO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ClB;CACF;AACF;;AAGA,MAAa,6BAA6B,+BAA+B;AAEzE,MAAa,4BAA+C;CAE1D,SAAS;CACT,SAAS;CACT,SAAS;CACT,SAAS;CACT,SAAS;CAGT,SAAS;CACT,SAAS;CAET;CACA;CAEA;CACA;CACA;CACA;CAEA,SAAS;CAET;CACA;AACF;AAEA,MAAa,+BAAkD;CAC7D,SAAS;CACT,SAAS;CACT,SAAS;CACT,SAAS;CACT,SAAS;CACT;CAEA;CACA;AACF;AAEA,MAAa,4BAA+C;CAC1D,SAAS;CACT,SAAS;CACT,SAAS;CACT,SAAS;CACT,SAAS;AACX"}
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAChE,OAAO,KAAK,EACV,eAAe,EACf,qBAAqB,EAErB,mBAAmB,EACnB,uBAAuB,EAEvB,OAAO,EACR,MAAM,+BAA+B,CAAC;AAEvC,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAGlD,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAU7C,OAAO,KAAK,EAAE,cAAc,EAAa,MAAM,yBAAyB,CAAC;AACzE,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAE9D,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAEpD,OAAO,EAAmB,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAE7E,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAGxD,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAEvD,OAAO,EACL,aAAa,EAId,MAAM,uBAAuB,CAAC;AAK/B,OAAO,KAAK,EAAE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astraCodeAgentController(config) {
|
|
|
486
486
|
const state = getInjectorSessionState(requestContext);
|
|
487
487
|
return state?.untrustedCheckout !== true || typeof state?.baseRef === "string";
|
|
488
488
|
},
|
|
489
|
+
getBasePath: ({ requestContext }) => getInjectorSessionState(requestContext)?.projectPath ?? project.rootPath,
|
|
489
490
|
getReader: ({ requestContext }) => {
|
|
490
491
|
const state = getInjectorSessionState(requestContext);
|
|
491
492
|
if (state?.untrustedCheckout !== true || typeof state?.baseRef !== "string") return void 0;
|