@orboto/mcp 0.181.0 → 0.181.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/server.js
CHANGED
|
@@ -87,7 +87,8 @@ import { setParentToolConfig, makeSetParentHandler } from './tools/set-parent.js
|
|
|
87
87
|
import { applyAgentProfile } from './tools/shared.js';
|
|
88
88
|
import { updateProjectToolConfig, makeUpdateProjectHandler, createProjectToolConfig, makeCreateProjectHandler, archiveProjectToolConfig, makeArchiveProjectHandler, } from './tools/update-project.js';
|
|
89
89
|
import { checkSimilarToolConfig, makeCheckSimilarHandler } from './tools/check-similar.js';
|
|
90
|
-
import { workSessionStartToolConfig, makeWorkSessionStartHandler, workSessionFinishToolConfig, makeWorkSessionFinishHandler, workSessionsToolConfig, makeWorkSessionsHandler, workSessionClaimsAddToolConfig, makeWorkSessionClaimsAddHandler, workSessionClaimsReleaseToolConfig, makeWorkSessionClaimsReleaseHandler, workStartToolConfig, makeWorkStartHandler, workFinishToolConfig, makeWorkFinishHandler,
|
|
90
|
+
import { workSessionStartToolConfig, makeWorkSessionStartHandler, workSessionFinishToolConfig, makeWorkSessionFinishHandler, workSessionsToolConfig, makeWorkSessionsHandler, workSessionClaimsAddToolConfig, makeWorkSessionClaimsAddHandler, workSessionClaimsReleaseToolConfig, makeWorkSessionClaimsReleaseHandler, workStartToolConfig, makeWorkStartHandler, workFinishToolConfig, makeWorkFinishHandler, } from './tools/work-sessions.js';
|
|
91
|
+
import { workNextToolConfig, makeWorkNextHandler } from './tools/work-next.js';
|
|
91
92
|
import { listAdminTranslationsToolConfig, makeListAdminTranslationsHandler, approveTranslationToolConfig, makeApproveTranslationHandler, revertTranslationToolConfig, makeAdminRevertTranslationHandler, } from './tools/admin-translations.js';
|
|
92
93
|
import { listAgentDriftToolConfig, makeListAgentDriftHandler, resolveAgentDriftToolConfig, makeResolveAgentDriftHandler, } from './tools/agent-drift.js';
|
|
93
94
|
/** ORB-1090 - the workspace's configurable working-rules, used as the
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ORB-1613 - `orboto_work_next`, the pull side of low-management dispatch
|
|
3
|
+
* (Wave 3 of ORB-1602), in its own module since ORB-1930 added the peek.
|
|
4
|
+
* The shapes it shares with `orboto_work_start` live in
|
|
5
|
+
* work-sessions-shared.ts.
|
|
6
|
+
*/
|
|
7
|
+
import { z } from 'zod';
|
|
8
|
+
import { mcpInstanceToken } from './shared.js';
|
|
9
|
+
import { GIT_HEALTH_REASON_TEXT, ResourceClaimShape } from './work-sessions-shared.js';
|
|
10
|
+
/** ORB-1799 - rendered identically on every exit (reserved, empty, paused):
|
|
11
|
+
* an agent that just pulled fresh work is exactly the one about to forget
|
|
12
|
+
* the ticket it already finished. Empty array renders nothing. */
|
|
13
|
+
function landedIdleLines(rows) {
|
|
14
|
+
if (!rows || rows.length === 0)
|
|
15
|
+
return [];
|
|
16
|
+
return [
|
|
17
|
+
'',
|
|
18
|
+
'## Landed, idle - finished-looking work of yours awaiting the status move',
|
|
19
|
+
...rows.map((r) => `- ${r.ticketKey ?? r.ticketId} "${r.title}" - ${r.commitCount} commit(s) linked, no activity for ${r.idleWorkingDays} working day(s) (since ${r.lastActivityAt}).`),
|
|
20
|
+
'Verify each is actually finished, then move it into the review lane (orboto_work_finish with targetCategory "in_review", or orboto_move_ticket) - do NOT re-implement it.',
|
|
21
|
+
];
|
|
22
|
+
}
|
|
23
|
+
export const workNextToolConfig = {
|
|
24
|
+
title: 'Pull and reserve the next ready ticket (worker-pool dispatch)',
|
|
25
|
+
description: 'ORB-1613 - the pull side of low-management dispatch, sibling of orboto_work_start on the "I already know which ticket" side. Picks the highest-priority ticket in a project that is READY FOR THE REQUESTED ROLE (default role implementation pulls TODO tickets; `role: "review"` pulls tickets in the in_review status category instead, and NEVER offers a ticket the caller itself implemented - the review lane primitive, ORB-1777), unblocked (every dependency closed), not already leased under the requested role, and not blocked by a conflicting resourceClaim - then reserves it with the EXACT same guarantees as orboto_work_start (atomic lease acquire + the full context bundle: rules ack, primer, ticket, checklists, dependencies, git health, siblings) in the same response. Priority then ticket number, deterministic - never a coin flip on ties. Two workers calling this concurrently never receive the SAME ticket: the underlying reservation is the identical partial-unique-index INSERT orboto_work_start uses, just walked across an ordered candidate list - a collision just advances to the next candidate. Epics are never returned (they are containers, not directly implementable). When nothing is ready, the response is a STRUCTURED result (`reserved: null`) with a `reason` (`none-matching` = no todo tickets at all; `all-blocked` = candidates exist but all have open dependencies; `all-leased` = ready candidates exist but are all currently leased or claim-conflicted; `autonomy_paused` = ORB-1774, this agent identity or the whole workspace has autonomous pulls paused by an operator - idle and wait for an operator/notify wakeup instead of retrying) and, ONLY when derivable from an actual active lease, a `retryAfterSeconds` backoff hint (`earliestFreeAt` null and `retryAfterSeconds` null means no signal exists - never a fabricated constant). This is never an error - a worker pool should back off on the hint rather than poll hot. Prefer this over orboto_work_start whenever the caller does not care WHICH ticket it gets, only that it gets the best available one right now. Every response - reserved, empty or paused - also carries `landedIdle`: YOUR OWN tickets in this project that are still in_progress with a linked commit and no activity for days (ORB-1799). Those are finished-looking work nobody handed to the review lane; move them on instead of re-implementing them.',
|
|
26
|
+
inputSchema: z.object({
|
|
27
|
+
projectKey: z.string().min(1).describe('Project key (e.g. "ACME") or UUID.'),
|
|
28
|
+
agentTag: z.string().min(1).max(64).optional()
|
|
29
|
+
.describe('ORB-1772 - preferred-not-exclusive routing tag: tickets labeled `agent:<tag>` rank first for a matching caller, foreign `agent:*` tags rank last but stay eligible. Lowercased server-side. Set it to this worker\'s routing tag (often the model or fleet lane name).'),
|
|
30
|
+
role: z.enum(['implementation', 'review', 'preflight', 'integration']).optional()
|
|
31
|
+
.describe('Default `implementation`. The dispatcher only reserves a ticket whose (ticket, role) lease is free for THIS role.'),
|
|
32
|
+
leaseSeconds: z.number().int().min(60).max(86_400).optional()
|
|
33
|
+
.describe('How long the lease should hold without renewal. Default 900 (15 min).'),
|
|
34
|
+
startTimer: z.boolean().optional()
|
|
35
|
+
.describe('Defaults to true for `implementation`, false for the attach-only roles.'),
|
|
36
|
+
agentSessionToken: z.string().optional()
|
|
37
|
+
.describe('Stable per-agent-instance token. Omit to use this MCP connection\'s own instance id.'),
|
|
38
|
+
resourceClaims: z.array(z.object(ResourceClaimShape)).max(50).optional()
|
|
39
|
+
.describe('ORB-1610 - resource claims to acquire alongside the reservation, AND to filter candidates: a ticket already held under a conflicting GRANTED write claim elsewhere is skipped even when its (ticket, role) lease is free.'),
|
|
40
|
+
onConflict: z.enum(['reject', 'queue']).optional()
|
|
41
|
+
.describe('Only matters when `resourceClaims` is set on the WINNING candidate. Default `reject`.'),
|
|
42
|
+
peek: z.boolean().optional()
|
|
43
|
+
.describe('ORB-1930 - answer "is there work for me?" WITHOUT reserving anything: the same candidate walk (role pool, lane caps, labels, dependencies, leases), but no lease, no timer, no lane quota consumed. Returns `candidate` (the ticket a real pull would reserve right now) or the usual empty reason. Use it before spending a model turn on self-tasking.'),
|
|
44
|
+
}).shape,
|
|
45
|
+
annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: false },
|
|
46
|
+
};
|
|
47
|
+
export function makeWorkNextHandler(client) {
|
|
48
|
+
// Per-connection rules-hash cache, same pattern as orboto_work_start.
|
|
49
|
+
let lastKnownRulesHash;
|
|
50
|
+
return async (args, extra) => {
|
|
51
|
+
const token = mcpInstanceToken(args.agentSessionToken, extra);
|
|
52
|
+
const res = await client.post('/work-sessions/next', {
|
|
53
|
+
projectKey: args.projectKey,
|
|
54
|
+
...(args.peek ? { peek: true } : {}),
|
|
55
|
+
...(args.agentTag ? { agentTag: args.agentTag } : {}),
|
|
56
|
+
...(args.role ? { role: args.role } : {}),
|
|
57
|
+
...(args.leaseSeconds ? { leaseSeconds: args.leaseSeconds } : {}),
|
|
58
|
+
...(args.startTimer !== undefined ? { startTimer: args.startTimer } : {}),
|
|
59
|
+
...(args.resourceClaims && args.resourceClaims.length > 0 ? { resourceClaims: args.resourceClaims } : {}),
|
|
60
|
+
...(args.onConflict ? { onConflict: args.onConflict } : {}),
|
|
61
|
+
agentSessionToken: token,
|
|
62
|
+
...(lastKnownRulesHash ? { knownRulesHash: lastKnownRulesHash } : {}),
|
|
63
|
+
});
|
|
64
|
+
if (!res.reserved) {
|
|
65
|
+
// ORB-1930 - a peek that found work: name it, reserve nothing.
|
|
66
|
+
if (args.peek && res.candidate) {
|
|
67
|
+
const c = res.candidate;
|
|
68
|
+
return {
|
|
69
|
+
content: [{
|
|
70
|
+
type: 'text',
|
|
71
|
+
text: [
|
|
72
|
+
`Work is ready in "${args.projectKey}": ${c.ticketKey ?? c.ticketId} - ${c.title}${c.priority ? ` (${c.priority})` : ''}.`,
|
|
73
|
+
'Nothing was reserved (peek). Call orboto_work_next without `peek` to take it.',
|
|
74
|
+
...landedIdleLines(res.landedIdle),
|
|
75
|
+
].join('\n'),
|
|
76
|
+
}],
|
|
77
|
+
structuredContent: {
|
|
78
|
+
reserved: null,
|
|
79
|
+
reason: null,
|
|
80
|
+
candidate: c,
|
|
81
|
+
candidatesConsidered: res.candidatesConsidered,
|
|
82
|
+
...(res.landedIdle && res.landedIdle.length > 0 ? { landedIdle: res.landedIdle } : {}),
|
|
83
|
+
},
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
// ORB-1774 - a pause is an operator decision, not a backoff situation:
|
|
87
|
+
// tell the agent to idle, not to poll for a free slot.
|
|
88
|
+
if (res.reason === 'autonomy_paused') {
|
|
89
|
+
return {
|
|
90
|
+
content: [{
|
|
91
|
+
type: 'text',
|
|
92
|
+
text: [
|
|
93
|
+
'Autonomous work is PAUSED for this agent (by an operator, per-bot or workspace-wide). Do not poll for new tickets - idle and wait for an operator instruction or an agent-notify wakeup. Explicitly assigned work via orboto_work_start still runs.',
|
|
94
|
+
...landedIdleLines(res.landedIdle),
|
|
95
|
+
].join('\n'),
|
|
96
|
+
}],
|
|
97
|
+
structuredContent: {
|
|
98
|
+
reserved: null,
|
|
99
|
+
reason: res.reason,
|
|
100
|
+
retryAfterSeconds: null,
|
|
101
|
+
earliestFreeAt: null,
|
|
102
|
+
candidatesConsidered: 0,
|
|
103
|
+
...(res.landedIdle && res.landedIdle.length > 0 ? { landedIdle: res.landedIdle } : {}),
|
|
104
|
+
},
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
const lines = [`No ready ticket in "${args.projectKey}" right now (${res.reason}).`];
|
|
108
|
+
lines.push(res.retryAfterSeconds != null
|
|
109
|
+
? `Retry in ~${res.retryAfterSeconds}s (earliest known free: ${res.earliestFreeAt}).`
|
|
110
|
+
: 'No derivable ETA - poll again later or check the project board.');
|
|
111
|
+
lines.push(`Candidates considered: ${res.candidatesConsidered}.`);
|
|
112
|
+
lines.push(...landedIdleLines(res.landedIdle));
|
|
113
|
+
return {
|
|
114
|
+
content: [{ type: 'text', text: lines.join('\n') }],
|
|
115
|
+
structuredContent: {
|
|
116
|
+
reserved: null,
|
|
117
|
+
reason: res.reason,
|
|
118
|
+
retryAfterSeconds: res.retryAfterSeconds,
|
|
119
|
+
earliestFreeAt: res.earliestFreeAt,
|
|
120
|
+
candidatesConsidered: res.candidatesConsidered,
|
|
121
|
+
...(res.landedIdle && res.landedIdle.length > 0 ? { landedIdle: res.landedIdle } : {}),
|
|
122
|
+
},
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
const r = res.reserved;
|
|
126
|
+
if (r.rulesHash)
|
|
127
|
+
lastKnownRulesHash = r.rulesHash;
|
|
128
|
+
const lines = [
|
|
129
|
+
r.reused
|
|
130
|
+
? `Renewed your existing ${r.session.role} session on ${r.ticket.ticketKey ?? r.session.ticketId}.`
|
|
131
|
+
: `Reserved ${r.ticket.ticketKey ?? r.session.ticketId} - started a ${r.session.role} work session.`,
|
|
132
|
+
`Session id: ${r.session.id} (pass this to orboto_work_session_finish / orboto_work_finish).`,
|
|
133
|
+
`Lease held until ${r.session.leaseUntil}; it renews automatically while you keep calling orboto.`,
|
|
134
|
+
r.session.activeTimerId ? 'Timer running.' : 'No timer started for this role.',
|
|
135
|
+
];
|
|
136
|
+
if (r.queued && r.queued.length > 0) {
|
|
137
|
+
lines.push('Queued (waiting for a conflicting writer to release):', ...r.queued.map((q) => ` - ${q.claim.kind}:${q.claim.value} - position ${q.position}`));
|
|
138
|
+
}
|
|
139
|
+
lines.push('', '## Working rules');
|
|
140
|
+
if (r.rulesUnchanged) {
|
|
141
|
+
lines.push(`Unchanged since your last call on this connection (hash ${r.rulesHash}) - keep following what you already loaded.`);
|
|
142
|
+
}
|
|
143
|
+
else {
|
|
144
|
+
lines.push(r.rules?.trim() || '(no workspace rules configured)');
|
|
145
|
+
}
|
|
146
|
+
lines.push('', '## Project primer');
|
|
147
|
+
lines.push(r.primer.markdown.trim() || '(primer unavailable)');
|
|
148
|
+
lines.push('', `## Ticket: ${r.ticket.ticketKey ?? '?'}`);
|
|
149
|
+
lines.push(r.ticket.title);
|
|
150
|
+
lines.push(`Status: ${r.ticket.statusName ?? r.ticket.status} Priority: ${r.ticket.priority} Type: ${r.ticket.type}`);
|
|
151
|
+
if (r.ticket.description)
|
|
152
|
+
lines.push('', r.ticket.description);
|
|
153
|
+
lines.push('', '## Checklists');
|
|
154
|
+
if (r.checklists.length === 0) {
|
|
155
|
+
lines.push('(none)');
|
|
156
|
+
}
|
|
157
|
+
else {
|
|
158
|
+
for (const cl of r.checklists) {
|
|
159
|
+
lines.push(`${cl.title} (${cl.progress.done}/${cl.progress.total})${cl.triggersDone ? ' - triggers done' : ''}`);
|
|
160
|
+
for (const i of cl.items) {
|
|
161
|
+
const link = i.linkedTicketKey ? ` -> [${i.linkedTicketKey}] (${i.linkedTicketStatusCategory ?? 'unknown'})` : '';
|
|
162
|
+
lines.push(`- [${i.effectiveCompleted ? 'x' : ' '}] ${i.content}${link}`);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
// ORB-1614 - see the comment on the other fmtDeps above.
|
|
167
|
+
const fmtDeps = (edges) => edges.length === 0 ? '(none)' : edges.map((e) => `- [${e.ticketKey ?? '?'}] ${e.title ?? `External dependency (access restricted)${e.resolved ? ' - resolved' : ' - still open'}`}${e.statusName ? ` - ${e.statusName}` : ''}`).join('\n');
|
|
168
|
+
lines.push('', '## Dependencies');
|
|
169
|
+
lines.push('Blocked by:', fmtDeps(r.dependencies.blockedBy), 'Blocks:', fmtDeps(r.dependencies.blocks));
|
|
170
|
+
const unhealthy = r.gitHealth.filter((c) => !c.healthy);
|
|
171
|
+
if (unhealthy.length > 0) {
|
|
172
|
+
lines.push('', '## Git connection health - WARNING');
|
|
173
|
+
for (const c of unhealthy) {
|
|
174
|
+
lines.push(`- "${c.name}" (${c.provider}) - ${GIT_HEALTH_REASON_TEXT[c.reason ?? ''] ?? c.reason ?? 'unknown reason'}`);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
lines.push('', '## Other sessions on this ticket');
|
|
178
|
+
lines.push(r.siblingSessions.length === 0
|
|
179
|
+
? '(none)'
|
|
180
|
+
: r.siblingSessions.map((s) => ` - [${s.role}] ${s.userFullName ?? s.userEmail ?? 'unknown'} - lease until ${s.leaseUntil}`).join('\n'));
|
|
181
|
+
lines.push(...landedIdleLines(res.landedIdle));
|
|
182
|
+
return {
|
|
183
|
+
content: [{ type: 'text', text: lines.join('\n') }],
|
|
184
|
+
structuredContent: {
|
|
185
|
+
reserved: {
|
|
186
|
+
session: r.session,
|
|
187
|
+
reused: r.reused,
|
|
188
|
+
queued: r.queued ?? [],
|
|
189
|
+
rulesHash: r.rulesHash,
|
|
190
|
+
rulesUnchanged: r.rulesUnchanged,
|
|
191
|
+
primer: r.primer,
|
|
192
|
+
ticket: r.ticket,
|
|
193
|
+
checklists: r.checklists,
|
|
194
|
+
dependencies: r.dependencies,
|
|
195
|
+
gitHealth: r.gitHealth,
|
|
196
|
+
siblingSessions: r.siblingSessions,
|
|
197
|
+
},
|
|
198
|
+
reason: null,
|
|
199
|
+
retryAfterSeconds: null,
|
|
200
|
+
earliestFreeAt: null,
|
|
201
|
+
candidatesConsidered: res.candidatesConsidered,
|
|
202
|
+
...(res.landedIdle && res.landedIdle.length > 0 ? { landedIdle: res.landedIdle } : {}),
|
|
203
|
+
},
|
|
204
|
+
};
|
|
205
|
+
};
|
|
206
|
+
}
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
*/
|
|
8
8
|
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
9
9
|
import { OrbotoClient } from '../orboto-client.js';
|
|
10
|
-
import { makeWorkNextHandler } from './work-
|
|
10
|
+
import { makeWorkNextHandler } from './work-next.js';
|
|
11
11
|
beforeEach(() => { vi.restoreAllMocks(); });
|
|
12
12
|
afterEach(() => { vi.restoreAllMocks(); });
|
|
13
13
|
function stub(responses) {
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ORB-1609 / ORB-1613 - the wire shapes the work-session tools share:
|
|
3
|
+
* resource claims, the start bundle `orboto_work_start` and
|
|
4
|
+
* `orboto_work_next` both return, and the git-health reason texts.
|
|
5
|
+
* Extracted so `orboto_work_next` can live in its own module (file-size
|
|
6
|
+
* ratchet, ORB-1863) without a cycle back into work-sessions.ts.
|
|
7
|
+
*/
|
|
8
|
+
import { z } from 'zod';
|
|
9
|
+
export const ResourceClaimShape = {
|
|
10
|
+
kind: z.enum(['path', 'named']),
|
|
11
|
+
value: z.string().min(1).max(500),
|
|
12
|
+
mode: z.enum(['read', 'write']),
|
|
13
|
+
};
|
|
14
|
+
/** Shared 409-body reader: the endpoint's body carries EITHER `holder`
|
|
15
|
+
* (a lease conflict) OR `claimConflicts` (a resource-claim conflict) -
|
|
16
|
+
* never both, since the lease is checked before claims are applied. */
|
|
17
|
+
export const GIT_HEALTH_REASON_TEXT = {
|
|
18
|
+
connection_inactive: 'connection is deactivated',
|
|
19
|
+
app_installation_suspended: 'GitHub App installation is suspended',
|
|
20
|
+
oauth_token_expired: 'OAuth token expired with no refresh path',
|
|
21
|
+
history_backfill_error: 'last history backfill failed',
|
|
22
|
+
};
|
|
@@ -18,14 +18,7 @@
|
|
|
18
18
|
import { z } from 'zod';
|
|
19
19
|
import { OrbotoApiError } from '../orboto-client.js';
|
|
20
20
|
import { mcpInstanceToken, resolveTicketByKey } from './shared.js';
|
|
21
|
-
|
|
22
|
-
kind: z.enum(['path', 'named']),
|
|
23
|
-
value: z.string().min(1).max(500),
|
|
24
|
-
mode: z.enum(['read', 'write']),
|
|
25
|
-
};
|
|
26
|
-
/** Shared 409-body reader: the endpoint's body carries EITHER `holder`
|
|
27
|
-
* (a lease conflict) OR `claimConflicts` (a resource-claim conflict) -
|
|
28
|
-
* never both, since the lease is checked before claims are applied. */
|
|
21
|
+
import { GIT_HEALTH_REASON_TEXT, ResourceClaimShape, } from './work-sessions-shared.js';
|
|
29
22
|
function parseClaimConflicts(err) {
|
|
30
23
|
try {
|
|
31
24
|
return JSON.parse(err.body).claimConflicts;
|
|
@@ -55,12 +48,6 @@ function describe(s) {
|
|
|
55
48
|
// Mirrors apps/mcp/src/tools/session-start.ts's local shapes - kept
|
|
56
49
|
// duplicated rather than imported, same choice that file already made for
|
|
57
50
|
// its own bundle types (no shared MCP-side schema layer for these).
|
|
58
|
-
const GIT_HEALTH_REASON_TEXT = {
|
|
59
|
-
connection_inactive: 'connection is deactivated',
|
|
60
|
-
app_installation_suspended: 'GitHub App installation is suspended',
|
|
61
|
-
oauth_token_expired: 'OAuth token expired with no refresh path',
|
|
62
|
-
history_backfill_error: 'last history backfill failed',
|
|
63
|
-
};
|
|
64
51
|
export const workStartToolConfig = {
|
|
65
52
|
title: 'Start a work session and load the full context bundle',
|
|
66
53
|
description: 'ORB-1611 - the one-call ticket pickup. Acquires the (ticket, role) work lease with the exact same guarantees as orboto_work_session_start (exactly ONE active session per ticket+role workspace-wide, a conflict names the holder, resourceClaims apply atomically with the lease), AND in the SAME response returns the rules-hash ack (same semantics as orboto_session_start), the project primer, the ticket enriched with its description/status/priority, its checklists, its dependencies, that project\'s git connection health, and any other live sessions already on the ticket. This replaces the 8-15 separate calls (orboto_session_start, orboto_get_project_primer, orboto_get_ticket, orboto_get_checklists, orboto_list_ticket_dependencies, ...) a normal ticket pickup used to cost. Prefer this over orboto_work_session_start for picking up a ticket; use the plain tool only when you deliberately do not want the bundle (e.g. a mid-task lease renewal where you already have fresh context). A conflict never leaves a partial session behind - same rollback-on-conflict guarantee as orboto_work_session_start.',
|
|
@@ -423,179 +410,6 @@ export function makeWorkFinishHandler(client) {
|
|
|
423
410
|
};
|
|
424
411
|
};
|
|
425
412
|
}
|
|
426
|
-
/** ORB-1799 - rendered identically on every exit (reserved, empty, paused):
|
|
427
|
-
* an agent that just pulled fresh work is exactly the one about to forget
|
|
428
|
-
* the ticket it already finished. Empty array renders nothing. */
|
|
429
|
-
function landedIdleLines(rows) {
|
|
430
|
-
if (!rows || rows.length === 0)
|
|
431
|
-
return [];
|
|
432
|
-
return [
|
|
433
|
-
'',
|
|
434
|
-
'## Landed, idle - finished-looking work of yours awaiting the status move',
|
|
435
|
-
...rows.map((r) => `- ${r.ticketKey ?? r.ticketId} "${r.title}" - ${r.commitCount} commit(s) linked, no activity for ${r.idleWorkingDays} working day(s) (since ${r.lastActivityAt}).`),
|
|
436
|
-
'Verify each is actually finished, then move it into the review lane (orboto_work_finish with targetCategory "in_review", or orboto_move_ticket) - do NOT re-implement it.',
|
|
437
|
-
];
|
|
438
|
-
}
|
|
439
|
-
export const workNextToolConfig = {
|
|
440
|
-
title: 'Pull and reserve the next ready ticket (worker-pool dispatch)',
|
|
441
|
-
description: 'ORB-1613 - the pull side of low-management dispatch, sibling of orboto_work_start on the "I already know which ticket" side. Picks the highest-priority ticket in a project that is READY FOR THE REQUESTED ROLE (default role implementation pulls TODO tickets; `role: "review"` pulls tickets in the in_review status category instead, and NEVER offers a ticket the caller itself implemented - the review lane primitive, ORB-1777), unblocked (every dependency closed), not already leased under the requested role, and not blocked by a conflicting resourceClaim - then reserves it with the EXACT same guarantees as orboto_work_start (atomic lease acquire + the full context bundle: rules ack, primer, ticket, checklists, dependencies, git health, siblings) in the same response. Priority then ticket number, deterministic - never a coin flip on ties. Two workers calling this concurrently never receive the SAME ticket: the underlying reservation is the identical partial-unique-index INSERT orboto_work_start uses, just walked across an ordered candidate list - a collision just advances to the next candidate. Epics are never returned (they are containers, not directly implementable). When nothing is ready, the response is a STRUCTURED result (`reserved: null`) with a `reason` (`none-matching` = no todo tickets at all; `all-blocked` = candidates exist but all have open dependencies; `all-leased` = ready candidates exist but are all currently leased or claim-conflicted; `autonomy_paused` = ORB-1774, this agent identity or the whole workspace has autonomous pulls paused by an operator - idle and wait for an operator/notify wakeup instead of retrying) and, ONLY when derivable from an actual active lease, a `retryAfterSeconds` backoff hint (`earliestFreeAt` null and `retryAfterSeconds` null means no signal exists - never a fabricated constant). This is never an error - a worker pool should back off on the hint rather than poll hot. Prefer this over orboto_work_start whenever the caller does not care WHICH ticket it gets, only that it gets the best available one right now. Every response - reserved, empty or paused - also carries `landedIdle`: YOUR OWN tickets in this project that are still in_progress with a linked commit and no activity for days (ORB-1799). Those are finished-looking work nobody handed to the review lane; move them on instead of re-implementing them.',
|
|
442
|
-
inputSchema: z.object({
|
|
443
|
-
projectKey: z.string().min(1).describe('Project key (e.g. "ACME") or UUID.'),
|
|
444
|
-
agentTag: z.string().min(1).max(64).optional()
|
|
445
|
-
.describe('ORB-1772 - preferred-not-exclusive routing tag: tickets labeled `agent:<tag>` rank first for a matching caller, foreign `agent:*` tags rank last but stay eligible. Lowercased server-side. Set it to this worker\'s routing tag (often the model or fleet lane name).'),
|
|
446
|
-
role: z.enum(['implementation', 'review', 'preflight', 'integration']).optional()
|
|
447
|
-
.describe('Default `implementation`. The dispatcher only reserves a ticket whose (ticket, role) lease is free for THIS role.'),
|
|
448
|
-
leaseSeconds: z.number().int().min(60).max(86_400).optional()
|
|
449
|
-
.describe('How long the lease should hold without renewal. Default 900 (15 min).'),
|
|
450
|
-
startTimer: z.boolean().optional()
|
|
451
|
-
.describe('Defaults to true for `implementation`, false for the attach-only roles.'),
|
|
452
|
-
agentSessionToken: z.string().optional()
|
|
453
|
-
.describe('Stable per-agent-instance token. Omit to use this MCP connection\'s own instance id.'),
|
|
454
|
-
resourceClaims: z.array(z.object(ResourceClaimShape)).max(50).optional()
|
|
455
|
-
.describe('ORB-1610 - resource claims to acquire alongside the reservation, AND to filter candidates: a ticket already held under a conflicting GRANTED write claim elsewhere is skipped even when its (ticket, role) lease is free.'),
|
|
456
|
-
onConflict: z.enum(['reject', 'queue']).optional()
|
|
457
|
-
.describe('Only matters when `resourceClaims` is set on the WINNING candidate. Default `reject`.'),
|
|
458
|
-
}).shape,
|
|
459
|
-
annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: false },
|
|
460
|
-
};
|
|
461
|
-
export function makeWorkNextHandler(client) {
|
|
462
|
-
// Per-connection rules-hash cache, same pattern as orboto_work_start.
|
|
463
|
-
let lastKnownRulesHash;
|
|
464
|
-
return async (args, extra) => {
|
|
465
|
-
const token = mcpInstanceToken(args.agentSessionToken, extra);
|
|
466
|
-
const res = await client.post('/work-sessions/next', {
|
|
467
|
-
projectKey: args.projectKey,
|
|
468
|
-
...(args.agentTag ? { agentTag: args.agentTag } : {}),
|
|
469
|
-
...(args.role ? { role: args.role } : {}),
|
|
470
|
-
...(args.leaseSeconds ? { leaseSeconds: args.leaseSeconds } : {}),
|
|
471
|
-
...(args.startTimer !== undefined ? { startTimer: args.startTimer } : {}),
|
|
472
|
-
...(args.resourceClaims && args.resourceClaims.length > 0 ? { resourceClaims: args.resourceClaims } : {}),
|
|
473
|
-
...(args.onConflict ? { onConflict: args.onConflict } : {}),
|
|
474
|
-
agentSessionToken: token,
|
|
475
|
-
...(lastKnownRulesHash ? { knownRulesHash: lastKnownRulesHash } : {}),
|
|
476
|
-
});
|
|
477
|
-
if (!res.reserved) {
|
|
478
|
-
// ORB-1774 - a pause is an operator decision, not a backoff situation:
|
|
479
|
-
// tell the agent to idle, not to poll for a free slot.
|
|
480
|
-
if (res.reason === 'autonomy_paused') {
|
|
481
|
-
return {
|
|
482
|
-
content: [{
|
|
483
|
-
type: 'text',
|
|
484
|
-
text: [
|
|
485
|
-
'Autonomous work is PAUSED for this agent (by an operator, per-bot or workspace-wide). Do not poll for new tickets - idle and wait for an operator instruction or an agent-notify wakeup. Explicitly assigned work via orboto_work_start still runs.',
|
|
486
|
-
...landedIdleLines(res.landedIdle),
|
|
487
|
-
].join('\n'),
|
|
488
|
-
}],
|
|
489
|
-
structuredContent: {
|
|
490
|
-
reserved: null,
|
|
491
|
-
reason: res.reason,
|
|
492
|
-
retryAfterSeconds: null,
|
|
493
|
-
earliestFreeAt: null,
|
|
494
|
-
candidatesConsidered: 0,
|
|
495
|
-
...(res.landedIdle && res.landedIdle.length > 0 ? { landedIdle: res.landedIdle } : {}),
|
|
496
|
-
},
|
|
497
|
-
};
|
|
498
|
-
}
|
|
499
|
-
const lines = [`No ready ticket in "${args.projectKey}" right now (${res.reason}).`];
|
|
500
|
-
lines.push(res.retryAfterSeconds != null
|
|
501
|
-
? `Retry in ~${res.retryAfterSeconds}s (earliest known free: ${res.earliestFreeAt}).`
|
|
502
|
-
: 'No derivable ETA - poll again later or check the project board.');
|
|
503
|
-
lines.push(`Candidates considered: ${res.candidatesConsidered}.`);
|
|
504
|
-
lines.push(...landedIdleLines(res.landedIdle));
|
|
505
|
-
return {
|
|
506
|
-
content: [{ type: 'text', text: lines.join('\n') }],
|
|
507
|
-
structuredContent: {
|
|
508
|
-
reserved: null,
|
|
509
|
-
reason: res.reason,
|
|
510
|
-
retryAfterSeconds: res.retryAfterSeconds,
|
|
511
|
-
earliestFreeAt: res.earliestFreeAt,
|
|
512
|
-
candidatesConsidered: res.candidatesConsidered,
|
|
513
|
-
...(res.landedIdle && res.landedIdle.length > 0 ? { landedIdle: res.landedIdle } : {}),
|
|
514
|
-
},
|
|
515
|
-
};
|
|
516
|
-
}
|
|
517
|
-
const r = res.reserved;
|
|
518
|
-
if (r.rulesHash)
|
|
519
|
-
lastKnownRulesHash = r.rulesHash;
|
|
520
|
-
const lines = [
|
|
521
|
-
r.reused
|
|
522
|
-
? `Renewed your existing ${r.session.role} session on ${r.ticket.ticketKey ?? r.session.ticketId}.`
|
|
523
|
-
: `Reserved ${r.ticket.ticketKey ?? r.session.ticketId} - started a ${r.session.role} work session.`,
|
|
524
|
-
`Session id: ${r.session.id} (pass this to orboto_work_session_finish / orboto_work_finish).`,
|
|
525
|
-
`Lease held until ${r.session.leaseUntil}; it renews automatically while you keep calling orboto.`,
|
|
526
|
-
r.session.activeTimerId ? 'Timer running.' : 'No timer started for this role.',
|
|
527
|
-
];
|
|
528
|
-
if (r.queued && r.queued.length > 0) {
|
|
529
|
-
lines.push('Queued (waiting for a conflicting writer to release):', ...r.queued.map((q) => ` - ${q.claim.kind}:${q.claim.value} - position ${q.position}`));
|
|
530
|
-
}
|
|
531
|
-
lines.push('', '## Working rules');
|
|
532
|
-
if (r.rulesUnchanged) {
|
|
533
|
-
lines.push(`Unchanged since your last call on this connection (hash ${r.rulesHash}) - keep following what you already loaded.`);
|
|
534
|
-
}
|
|
535
|
-
else {
|
|
536
|
-
lines.push(r.rules?.trim() || '(no workspace rules configured)');
|
|
537
|
-
}
|
|
538
|
-
lines.push('', '## Project primer');
|
|
539
|
-
lines.push(r.primer.markdown.trim() || '(primer unavailable)');
|
|
540
|
-
lines.push('', `## Ticket: ${r.ticket.ticketKey ?? '?'}`);
|
|
541
|
-
lines.push(r.ticket.title);
|
|
542
|
-
lines.push(`Status: ${r.ticket.statusName ?? r.ticket.status} Priority: ${r.ticket.priority} Type: ${r.ticket.type}`);
|
|
543
|
-
if (r.ticket.description)
|
|
544
|
-
lines.push('', r.ticket.description);
|
|
545
|
-
lines.push('', '## Checklists');
|
|
546
|
-
if (r.checklists.length === 0) {
|
|
547
|
-
lines.push('(none)');
|
|
548
|
-
}
|
|
549
|
-
else {
|
|
550
|
-
for (const cl of r.checklists) {
|
|
551
|
-
lines.push(`${cl.title} (${cl.progress.done}/${cl.progress.total})${cl.triggersDone ? ' - triggers done' : ''}`);
|
|
552
|
-
for (const i of cl.items) {
|
|
553
|
-
const link = i.linkedTicketKey ? ` -> [${i.linkedTicketKey}] (${i.linkedTicketStatusCategory ?? 'unknown'})` : '';
|
|
554
|
-
lines.push(`- [${i.effectiveCompleted ? 'x' : ' '}] ${i.content}${link}`);
|
|
555
|
-
}
|
|
556
|
-
}
|
|
557
|
-
}
|
|
558
|
-
// ORB-1614 - see the comment on the other fmtDeps above.
|
|
559
|
-
const fmtDeps = (edges) => edges.length === 0 ? '(none)' : edges.map((e) => `- [${e.ticketKey ?? '?'}] ${e.title ?? `External dependency (access restricted)${e.resolved ? ' - resolved' : ' - still open'}`}${e.statusName ? ` - ${e.statusName}` : ''}`).join('\n');
|
|
560
|
-
lines.push('', '## Dependencies');
|
|
561
|
-
lines.push('Blocked by:', fmtDeps(r.dependencies.blockedBy), 'Blocks:', fmtDeps(r.dependencies.blocks));
|
|
562
|
-
const unhealthy = r.gitHealth.filter((c) => !c.healthy);
|
|
563
|
-
if (unhealthy.length > 0) {
|
|
564
|
-
lines.push('', '## Git connection health - WARNING');
|
|
565
|
-
for (const c of unhealthy) {
|
|
566
|
-
lines.push(`- "${c.name}" (${c.provider}) - ${GIT_HEALTH_REASON_TEXT[c.reason ?? ''] ?? c.reason ?? 'unknown reason'}`);
|
|
567
|
-
}
|
|
568
|
-
}
|
|
569
|
-
lines.push('', '## Other sessions on this ticket');
|
|
570
|
-
lines.push(r.siblingSessions.length === 0
|
|
571
|
-
? '(none)'
|
|
572
|
-
: r.siblingSessions.map((s) => ` - [${s.role}] ${s.userFullName ?? s.userEmail ?? 'unknown'} - lease until ${s.leaseUntil}`).join('\n'));
|
|
573
|
-
lines.push(...landedIdleLines(res.landedIdle));
|
|
574
|
-
return {
|
|
575
|
-
content: [{ type: 'text', text: lines.join('\n') }],
|
|
576
|
-
structuredContent: {
|
|
577
|
-
reserved: {
|
|
578
|
-
session: r.session,
|
|
579
|
-
reused: r.reused,
|
|
580
|
-
queued: r.queued ?? [],
|
|
581
|
-
rulesHash: r.rulesHash,
|
|
582
|
-
rulesUnchanged: r.rulesUnchanged,
|
|
583
|
-
primer: r.primer,
|
|
584
|
-
ticket: r.ticket,
|
|
585
|
-
checklists: r.checklists,
|
|
586
|
-
dependencies: r.dependencies,
|
|
587
|
-
gitHealth: r.gitHealth,
|
|
588
|
-
siblingSessions: r.siblingSessions,
|
|
589
|
-
},
|
|
590
|
-
reason: null,
|
|
591
|
-
retryAfterSeconds: null,
|
|
592
|
-
earliestFreeAt: null,
|
|
593
|
-
candidatesConsidered: res.candidatesConsidered,
|
|
594
|
-
...(res.landedIdle && res.landedIdle.length > 0 ? { landedIdle: res.landedIdle } : {}),
|
|
595
|
-
},
|
|
596
|
-
};
|
|
597
|
-
};
|
|
598
|
-
}
|
|
599
413
|
// ---------------------------------------------------------------------------
|
|
600
414
|
// orboto_work_sessions
|
|
601
415
|
// ---------------------------------------------------------------------------
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@orboto/mcp",
|
|
3
|
-
"version": "0.181.
|
|
3
|
+
"version": "0.181.1",
|
|
4
4
|
"description": "Model Context Protocol server for orboto - exposes tickets, projects, milestones, time, docs, primer-facts, alerts and absences as MCP tools for Claude Desktop / Cursor / Copilot Chat / any MCP-aware AI client.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|