@unson/brainbase-mcp 0.51.9 → 0.51.11
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/canonical-task-comment-tools.d.ts +78 -0
- package/dist/canonical-task-comment-tools.js +177 -0
- package/dist/canonical-task-list-tools.d.ts +44 -0
- package/dist/canonical-task-list-tools.js +130 -0
- package/dist/organization-graph-web.js +17 -1
- package/dist/world-extension.d.ts +90 -4
- package/dist/world-extension.js +80 -8
- package/package.json +10 -2
- package/ui/world/world-canvas-ui.css +24 -0
- package/ui/world/world-canvas-ui.js +52 -2
- package/ui/world/world-view.css +57 -0
- package/ui/world/world-view.js +306 -19
- package/ui/world/world-work-rail.js +272 -2
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import type { Tool } from '@modelcontextprotocol/sdk/types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Canonical Task comment MCP contract.
|
|
4
|
+
*
|
|
5
|
+
* The host owns authentication, tenant binding and the HTTP client. This
|
|
6
|
+
* module owns the tool schema, the request it maps to, and the check of the
|
|
7
|
+
* answer, so hosts handle comment requests consistently.
|
|
8
|
+
*/
|
|
9
|
+
export declare const ADD_TASK_COMMENT_TOOL_NAME = "add_task_comment";
|
|
10
|
+
export declare const LIST_TASK_COMMENTS_TOOL_NAME = "list_task_comments";
|
|
11
|
+
export declare const LIST_TASK_COMMENTS_DEFAULT_LIMIT = 100;
|
|
12
|
+
export declare const LIST_TASK_COMMENTS_MAX_LIMIT = 200;
|
|
13
|
+
export declare const listTaskCommentsTool: Tool;
|
|
14
|
+
export declare const addTaskCommentTool: Tool;
|
|
15
|
+
export type TaskComment = {
|
|
16
|
+
id: string;
|
|
17
|
+
body: string;
|
|
18
|
+
reply_to: string | null;
|
|
19
|
+
author: string | null;
|
|
20
|
+
created_at: string | null;
|
|
21
|
+
edited_at: string | null;
|
|
22
|
+
version: number;
|
|
23
|
+
};
|
|
24
|
+
export type TaskCommentPage = {
|
|
25
|
+
task_id: string;
|
|
26
|
+
comments: TaskComment[];
|
|
27
|
+
total_count: number;
|
|
28
|
+
truncated: boolean;
|
|
29
|
+
};
|
|
30
|
+
export type TaskCommentToolError = {
|
|
31
|
+
code: string;
|
|
32
|
+
message: string;
|
|
33
|
+
http_status?: number;
|
|
34
|
+
};
|
|
35
|
+
export type ListTaskCommentsResult = {
|
|
36
|
+
status: 'ok';
|
|
37
|
+
page: TaskCommentPage;
|
|
38
|
+
} | {
|
|
39
|
+
status: 'error';
|
|
40
|
+
error: TaskCommentToolError;
|
|
41
|
+
};
|
|
42
|
+
export declare class TaskCommentArgumentError extends Error {
|
|
43
|
+
readonly code = "invalid_arguments";
|
|
44
|
+
}
|
|
45
|
+
export declare function addTaskCommentRequest(args: unknown): {
|
|
46
|
+
method: 'POST';
|
|
47
|
+
path: string;
|
|
48
|
+
taskId: string;
|
|
49
|
+
body: {
|
|
50
|
+
body: string;
|
|
51
|
+
idempotency_key: string;
|
|
52
|
+
reply_to?: string;
|
|
53
|
+
};
|
|
54
|
+
};
|
|
55
|
+
/** The HTTP request a host sends for `list_task_comments`. Throws TaskCommentArgumentError on bad input. */
|
|
56
|
+
export declare function listTaskCommentsRequest(args: unknown): {
|
|
57
|
+
method: 'GET';
|
|
58
|
+
path: string;
|
|
59
|
+
taskId: string;
|
|
60
|
+
};
|
|
61
|
+
/**
|
|
62
|
+
* Checks the API answer for the requested Task. An error answer keeps only its
|
|
63
|
+
* code; any other body detail is dropped so a store message cannot reach the agent.
|
|
64
|
+
*/
|
|
65
|
+
export declare function readListTaskCommentsResponse(taskId: string, httpStatus: number, body: unknown): ListTaskCommentsResult;
|
|
66
|
+
export type AddTaskCommentResult = {
|
|
67
|
+
status: 'ok';
|
|
68
|
+
comment: TaskComment;
|
|
69
|
+
replayed: boolean;
|
|
70
|
+
notification: {
|
|
71
|
+
status: 'not_delivered';
|
|
72
|
+
reason: 'notification_delivery_not_configured';
|
|
73
|
+
};
|
|
74
|
+
} | {
|
|
75
|
+
status: 'error';
|
|
76
|
+
error: TaskCommentToolError;
|
|
77
|
+
};
|
|
78
|
+
export declare function readAddTaskCommentResponse(httpStatus: number, body: unknown): AddTaskCommentResult;
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Canonical Task comment MCP contract.
|
|
3
|
+
*
|
|
4
|
+
* The host owns authentication, tenant binding and the HTTP client. This
|
|
5
|
+
* module owns the tool schema, the request it maps to, and the check of the
|
|
6
|
+
* answer, so hosts handle comment requests consistently.
|
|
7
|
+
*/
|
|
8
|
+
export const ADD_TASK_COMMENT_TOOL_NAME = 'add_task_comment';
|
|
9
|
+
export const LIST_TASK_COMMENTS_TOOL_NAME = 'list_task_comments';
|
|
10
|
+
export const LIST_TASK_COMMENTS_DEFAULT_LIMIT = 100;
|
|
11
|
+
export const LIST_TASK_COMMENTS_MAX_LIMIT = 200;
|
|
12
|
+
const TASK_ID_MAX_LENGTH = 200;
|
|
13
|
+
const MAX_COMMENT_BODY_LENGTH = 20000;
|
|
14
|
+
const BODY_CONTROL = /[\u0000-\u0008\u000b\u000c\u000e-\u001f\u007f]/u;
|
|
15
|
+
const CONTROL = /[\u0000-\u001f\u007f]/u;
|
|
16
|
+
export const listTaskCommentsTool = {
|
|
17
|
+
name: LIST_TASK_COMMENTS_TOOL_NAME,
|
|
18
|
+
description: 'Read the comments on one Canonical Task, oldest first, with edits applied. '
|
|
19
|
+
+ 'Returns only what the caller\'s verified project scope can see; a Task outside it is task_not_found. '
|
|
20
|
+
+ 'This read never writes and does not notify anyone.',
|
|
21
|
+
inputSchema: {
|
|
22
|
+
type: 'object',
|
|
23
|
+
properties: {
|
|
24
|
+
task_id: { type: 'string', minLength: 1, maxLength: TASK_ID_MAX_LENGTH, description: 'Canonical Task ID (ct1....).' },
|
|
25
|
+
limit: {
|
|
26
|
+
type: 'integer',
|
|
27
|
+
minimum: 1,
|
|
28
|
+
maximum: LIST_TASK_COMMENTS_MAX_LIMIT,
|
|
29
|
+
description: `Newest comments to return, at most ${LIST_TASK_COMMENTS_MAX_LIMIT} (default ${LIST_TASK_COMMENTS_DEFAULT_LIMIT}).`,
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
required: ['task_id'],
|
|
33
|
+
additionalProperties: false,
|
|
34
|
+
},
|
|
35
|
+
annotations: { readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: false },
|
|
36
|
+
};
|
|
37
|
+
export const addTaskCommentTool = {
|
|
38
|
+
name: ADD_TASK_COMMENT_TOOL_NAME,
|
|
39
|
+
description: 'Post a comment on a Canonical Task. Reuse the same idempotency key when retrying.',
|
|
40
|
+
inputSchema: {
|
|
41
|
+
type: 'object',
|
|
42
|
+
properties: {
|
|
43
|
+
task_id: { type: 'string', minLength: 1, maxLength: TASK_ID_MAX_LENGTH },
|
|
44
|
+
body: { type: 'string', minLength: 1, maxLength: MAX_COMMENT_BODY_LENGTH },
|
|
45
|
+
reply_to: { type: 'string', minLength: 1, maxLength: TASK_ID_MAX_LENGTH },
|
|
46
|
+
idempotency_key: { type: 'string', minLength: 1, maxLength: TASK_ID_MAX_LENGTH },
|
|
47
|
+
},
|
|
48
|
+
required: ['task_id', 'body', 'idempotency_key'],
|
|
49
|
+
additionalProperties: false,
|
|
50
|
+
},
|
|
51
|
+
annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: true, openWorldHint: false },
|
|
52
|
+
};
|
|
53
|
+
export class TaskCommentArgumentError extends Error {
|
|
54
|
+
code = 'invalid_arguments';
|
|
55
|
+
}
|
|
56
|
+
function record(value) {
|
|
57
|
+
return value && typeof value === 'object' && !Array.isArray(value) ? value : null;
|
|
58
|
+
}
|
|
59
|
+
function requiredIdentifier(value, field) {
|
|
60
|
+
const trimmed = typeof value === 'string' ? value.trim() : '';
|
|
61
|
+
if (typeof value !== 'string' || !trimmed || value.length > TASK_ID_MAX_LENGTH || CONTROL.test(value)) {
|
|
62
|
+
throw new TaskCommentArgumentError(`${field} is invalid`);
|
|
63
|
+
}
|
|
64
|
+
return trimmed;
|
|
65
|
+
}
|
|
66
|
+
export function addTaskCommentRequest(args) {
|
|
67
|
+
const input = record(args);
|
|
68
|
+
if (!input)
|
|
69
|
+
throw new TaskCommentArgumentError('arguments must be an object');
|
|
70
|
+
const unsupported = Object.keys(input).filter(key => !['task_id', 'body', 'reply_to', 'idempotency_key'].includes(key));
|
|
71
|
+
if (unsupported.length)
|
|
72
|
+
throw new TaskCommentArgumentError(`unsupported argument: ${unsupported.join(', ')}`);
|
|
73
|
+
const taskId = requiredIdentifier(input.task_id, 'task_id');
|
|
74
|
+
if (taskId === '.' || taskId === '..')
|
|
75
|
+
throw new TaskCommentArgumentError('task_id is invalid');
|
|
76
|
+
if (typeof input.body !== 'string' || !input.body.trim()
|
|
77
|
+
|| input.body.length > MAX_COMMENT_BODY_LENGTH || BODY_CONTROL.test(input.body)) {
|
|
78
|
+
throw new TaskCommentArgumentError('body is invalid');
|
|
79
|
+
}
|
|
80
|
+
const idempotencyKey = requiredIdentifier(input.idempotency_key, 'idempotency_key');
|
|
81
|
+
return {
|
|
82
|
+
method: 'POST',
|
|
83
|
+
path: `/api/companion/tasks/${encodeURIComponent(taskId)}/comments`,
|
|
84
|
+
taskId,
|
|
85
|
+
body: {
|
|
86
|
+
body: input.body,
|
|
87
|
+
idempotency_key: idempotencyKey,
|
|
88
|
+
...(input.reply_to === undefined ? {} : { reply_to: requiredIdentifier(input.reply_to, 'reply_to') }),
|
|
89
|
+
},
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
/** The HTTP request a host sends for `list_task_comments`. Throws TaskCommentArgumentError on bad input. */
|
|
93
|
+
export function listTaskCommentsRequest(args) {
|
|
94
|
+
const input = record(args);
|
|
95
|
+
if (!input)
|
|
96
|
+
throw new TaskCommentArgumentError('arguments must be an object');
|
|
97
|
+
const unknown = Object.keys(input).filter((key) => key !== 'task_id' && key !== 'limit');
|
|
98
|
+
if (unknown.length)
|
|
99
|
+
throw new TaskCommentArgumentError(`unsupported argument: ${unknown.join(', ')}`);
|
|
100
|
+
const raw = typeof input.task_id === 'string' ? input.task_id : '';
|
|
101
|
+
const taskId = raw.trim();
|
|
102
|
+
if (!taskId || taskId.length > TASK_ID_MAX_LENGTH || CONTROL.test(raw))
|
|
103
|
+
throw new TaskCommentArgumentError('task_id is required');
|
|
104
|
+
let query = '';
|
|
105
|
+
if (input.limit !== undefined) {
|
|
106
|
+
const limit = input.limit;
|
|
107
|
+
if (typeof limit !== 'number' || !Number.isSafeInteger(limit) || limit < 1 || limit > LIST_TASK_COMMENTS_MAX_LIMIT) {
|
|
108
|
+
throw new TaskCommentArgumentError(`limit must be an integer from 1 to ${LIST_TASK_COMMENTS_MAX_LIMIT}`);
|
|
109
|
+
}
|
|
110
|
+
query = `?limit=${limit}`;
|
|
111
|
+
}
|
|
112
|
+
return { method: 'GET', path: `/api/companion/tasks/${encodeURIComponent(taskId)}/comments${query}`, taskId };
|
|
113
|
+
}
|
|
114
|
+
function comment(value) {
|
|
115
|
+
const item = record(value);
|
|
116
|
+
if (!item)
|
|
117
|
+
return null;
|
|
118
|
+
const optionalText = (key) => item[key] === null || typeof item[key] === 'string';
|
|
119
|
+
if (typeof item.id !== 'string' || !item.id || typeof item.body !== 'string'
|
|
120
|
+
|| !optionalText('reply_to') || !optionalText('author') || !optionalText('created_at') || !optionalText('edited_at')
|
|
121
|
+
|| typeof item.version !== 'number' || !Number.isSafeInteger(item.version) || item.version < 0)
|
|
122
|
+
return null;
|
|
123
|
+
return {
|
|
124
|
+
id: item.id,
|
|
125
|
+
body: item.body,
|
|
126
|
+
reply_to: item.reply_to,
|
|
127
|
+
author: item.author,
|
|
128
|
+
created_at: item.created_at,
|
|
129
|
+
edited_at: item.edited_at,
|
|
130
|
+
version: item.version,
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
function responseErrorCode(payload) {
|
|
134
|
+
const nested = record(payload?.error);
|
|
135
|
+
return typeof payload?.code === 'string' ? payload.code
|
|
136
|
+
: typeof nested?.code === 'string' ? nested.code : 'task_comments_unavailable';
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Checks the API answer for the requested Task. An error answer keeps only its
|
|
140
|
+
* code; any other body detail is dropped so a store message cannot reach the agent.
|
|
141
|
+
*/
|
|
142
|
+
export function readListTaskCommentsResponse(taskId, httpStatus, body) {
|
|
143
|
+
const payload = record(body);
|
|
144
|
+
if (httpStatus < 200 || httpStatus >= 300) {
|
|
145
|
+
const code = responseErrorCode(payload);
|
|
146
|
+
return { status: 'error', error: { code, message: `Task comments could not be read (${code})`, http_status: httpStatus } };
|
|
147
|
+
}
|
|
148
|
+
const comments = Array.isArray(payload?.comments) ? payload.comments.map(comment) : null;
|
|
149
|
+
if (!payload || payload.task_id !== taskId || !comments || comments.some((item) => item === null)
|
|
150
|
+
|| typeof payload.total_count !== 'number' || !Number.isSafeInteger(payload.total_count) || payload.total_count < comments.length
|
|
151
|
+
|| typeof payload.truncated !== 'boolean') {
|
|
152
|
+
return { status: 'error', error: { code: 'task_contract_error', message: 'Task comment response does not match the requested Task' } };
|
|
153
|
+
}
|
|
154
|
+
return {
|
|
155
|
+
status: 'ok',
|
|
156
|
+
page: { task_id: taskId, comments: comments, total_count: payload.total_count, truncated: payload.truncated },
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
export function readAddTaskCommentResponse(httpStatus, body) {
|
|
160
|
+
const payload = record(body);
|
|
161
|
+
if (httpStatus < 200 || httpStatus >= 300) {
|
|
162
|
+
const code = responseErrorCode(payload);
|
|
163
|
+
return { status: 'error', error: { code, message: `Task comment could not be posted (${code})`, http_status: httpStatus } };
|
|
164
|
+
}
|
|
165
|
+
const saved = comment(payload?.comment);
|
|
166
|
+
const notification = record(payload?.notification);
|
|
167
|
+
if (!payload || !saved || (httpStatus !== 200 && httpStatus !== 201) || payload?.replayed !== (httpStatus === 200)
|
|
168
|
+
|| notification?.status !== 'not_delivered' || notification.reason !== 'notification_delivery_not_configured') {
|
|
169
|
+
return { status: 'error', error: { code: 'task_contract_error', message: 'Task comment response is invalid' } };
|
|
170
|
+
}
|
|
171
|
+
return {
|
|
172
|
+
status: 'ok',
|
|
173
|
+
comment: saved,
|
|
174
|
+
replayed: payload.replayed,
|
|
175
|
+
notification: { status: notification.status, reason: notification.reason },
|
|
176
|
+
};
|
|
177
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { Tool } from '@modelcontextprotocol/sdk/types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Canonical Task `list_tasks` MCP contract.
|
|
4
|
+
*
|
|
5
|
+
* The host owns authentication, tenant binding, the HTTP client and the
|
|
6
|
+
* handling of non-2xx answers. This module owns the tool schema, the request
|
|
7
|
+
* it maps to on the companion task API, and the check of a page answer, so
|
|
8
|
+
* every host lists Tasks the same way instead of keeping its own copy.
|
|
9
|
+
*
|
|
10
|
+
* Archived Tasks are left out unless the caller passes include_archived: true.
|
|
11
|
+
* Only then is a single `include_archived=true` forwarded to the list or search
|
|
12
|
+
* endpoint; false or omitted sends the same request as before archiving existed.
|
|
13
|
+
*/
|
|
14
|
+
export declare const LIST_TASKS_TOOL_NAME = "list_tasks";
|
|
15
|
+
/** The task kernel caps list pages at 50 and full-text search pages at 20. */
|
|
16
|
+
export declare const LIST_TASKS_MAX_LIMIT = 50;
|
|
17
|
+
export declare const SEARCH_TASKS_MAX_LIMIT = 20;
|
|
18
|
+
export declare const listTasksTool: Tool;
|
|
19
|
+
export declare class TaskListArgumentError extends Error {
|
|
20
|
+
readonly code = "invalid_arguments";
|
|
21
|
+
}
|
|
22
|
+
export type ListTasksResult = {
|
|
23
|
+
status: 'ok';
|
|
24
|
+
page: Record<string, unknown>;
|
|
25
|
+
} | {
|
|
26
|
+
status: 'error';
|
|
27
|
+
error: {
|
|
28
|
+
code: 'task_contract_error';
|
|
29
|
+
message: string;
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* The HTTP request a host sends for `list_tasks`, relative to the companion
|
|
34
|
+
* task API base URL. Throws TaskListArgumentError before any request is made.
|
|
35
|
+
*/
|
|
36
|
+
export declare function listTasksRequest(args: unknown): {
|
|
37
|
+
method: 'GET';
|
|
38
|
+
path: string;
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* Checks a 2xx answer is a Task page and passes it through unchanged (archived_at and
|
|
42
|
+
* archive_reason included). Non-2xx answers stay with the host's common Task error mapping.
|
|
43
|
+
*/
|
|
44
|
+
export declare function readListTasksResponse(body: unknown): ListTasksResult;
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Canonical Task `list_tasks` MCP contract.
|
|
3
|
+
*
|
|
4
|
+
* The host owns authentication, tenant binding, the HTTP client and the
|
|
5
|
+
* handling of non-2xx answers. This module owns the tool schema, the request
|
|
6
|
+
* it maps to on the companion task API, and the check of a page answer, so
|
|
7
|
+
* every host lists Tasks the same way instead of keeping its own copy.
|
|
8
|
+
*
|
|
9
|
+
* Archived Tasks are left out unless the caller passes include_archived: true.
|
|
10
|
+
* Only then is a single `include_archived=true` forwarded to the list or search
|
|
11
|
+
* endpoint; false or omitted sends the same request as before archiving existed.
|
|
12
|
+
*/
|
|
13
|
+
export const LIST_TASKS_TOOL_NAME = 'list_tasks';
|
|
14
|
+
/** The task kernel caps list pages at 50 and full-text search pages at 20. */
|
|
15
|
+
export const LIST_TASKS_MAX_LIMIT = 50;
|
|
16
|
+
export const SEARCH_TASKS_MAX_LIMIT = 20;
|
|
17
|
+
const TASK_STATUSES = ['pending', 'in_progress', 'waiting', 'completed', 'cancelled'];
|
|
18
|
+
const TASK_PRIORITIES = ['low', 'medium', 'high', 'urgent'];
|
|
19
|
+
export const listTasksTool = {
|
|
20
|
+
name: LIST_TASKS_TOOL_NAME,
|
|
21
|
+
description: `List Canonical Tasks page by page (at most ${LIST_TASKS_MAX_LIMIT} per page, ${SEARCH_TASKS_MAX_LIMIT} when query is set). `
|
|
22
|
+
+ 'Follow nextCursor until it is null; totalCount and countStatus report whether the total is exact. '
|
|
23
|
+
+ 'Passing query switches to full-text search. '
|
|
24
|
+
+ 'Archived Tasks are left out unless include_archived is true; keep the same value while following nextCursor.',
|
|
25
|
+
inputSchema: {
|
|
26
|
+
type: 'object',
|
|
27
|
+
properties: {
|
|
28
|
+
query: { type: 'string', description: 'Optional full-text search query.' },
|
|
29
|
+
statuses: { type: 'array', items: { type: 'string', enum: [...TASK_STATUSES] } },
|
|
30
|
+
priorities: { type: 'array', items: { type: 'string', enum: [...TASK_PRIORITIES] } },
|
|
31
|
+
project_codes: { type: 'array', items: { type: 'string' } },
|
|
32
|
+
assignee_person_id: { type: 'string' },
|
|
33
|
+
due_after: { type: 'string', description: 'ISO 8601 date-time lower bound.' },
|
|
34
|
+
due_before: { type: 'string', description: 'ISO 8601 date-time upper bound.' },
|
|
35
|
+
limit: { type: 'integer', minimum: 1, maximum: LIST_TASKS_MAX_LIMIT },
|
|
36
|
+
cursor: { type: 'string' },
|
|
37
|
+
include_archived: {
|
|
38
|
+
type: 'boolean',
|
|
39
|
+
description: 'true also returns archived Tasks within the same scope, filters and paging. Omit or false for active Tasks only.',
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
// Only readOnlyHint, so a host that merges its own annotations lists the same tool as before.
|
|
44
|
+
annotations: { readOnlyHint: true },
|
|
45
|
+
};
|
|
46
|
+
export class TaskListArgumentError extends Error {
|
|
47
|
+
code = 'invalid_arguments';
|
|
48
|
+
}
|
|
49
|
+
function record(value) {
|
|
50
|
+
return value && typeof value === 'object' && !Array.isArray(value) ? value : null;
|
|
51
|
+
}
|
|
52
|
+
function optionalString(args, key) {
|
|
53
|
+
const value = args[key];
|
|
54
|
+
if (value === undefined || value === null || value === '')
|
|
55
|
+
return null;
|
|
56
|
+
if (typeof value !== 'string' || !value.trim())
|
|
57
|
+
throw new TaskListArgumentError(`${key} must be a non-empty string`);
|
|
58
|
+
return value.trim();
|
|
59
|
+
}
|
|
60
|
+
function optionalStringList(args, key) {
|
|
61
|
+
const value = args[key];
|
|
62
|
+
if (value === undefined || value === null)
|
|
63
|
+
return null;
|
|
64
|
+
if (!Array.isArray(value) || value.some((item) => typeof item !== 'string' || !item.trim())) {
|
|
65
|
+
throw new TaskListArgumentError(`${key} must be an array of non-empty strings`);
|
|
66
|
+
}
|
|
67
|
+
return value.length ? value.map((item) => item.trim()) : null;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* The HTTP request a host sends for `list_tasks`, relative to the companion
|
|
71
|
+
* task API base URL. Throws TaskListArgumentError before any request is made.
|
|
72
|
+
*/
|
|
73
|
+
export function listTasksRequest(args) {
|
|
74
|
+
const input = record(args);
|
|
75
|
+
if (!input)
|
|
76
|
+
throw new TaskListArgumentError('arguments must be an object');
|
|
77
|
+
const query = new URLSearchParams();
|
|
78
|
+
const text = optionalString(input, 'query');
|
|
79
|
+
if (text !== null)
|
|
80
|
+
query.set('q', text);
|
|
81
|
+
const lists = [
|
|
82
|
+
['statuses', 'statuses'], ['priorities', 'priorities'], ['project_codes', 'projectCodes'],
|
|
83
|
+
];
|
|
84
|
+
for (const [key, parameter] of lists) {
|
|
85
|
+
const values = optionalStringList(input, key);
|
|
86
|
+
if (values)
|
|
87
|
+
query.set(parameter, values.join(','));
|
|
88
|
+
}
|
|
89
|
+
const scalars = [
|
|
90
|
+
['assignee_person_id', 'assigneePersonId'], ['due_after', 'dueAfter'], ['due_before', 'dueBefore'], ['cursor', 'cursor'],
|
|
91
|
+
];
|
|
92
|
+
for (const [key, parameter] of scalars) {
|
|
93
|
+
const value = optionalString(input, key);
|
|
94
|
+
if (value !== null)
|
|
95
|
+
query.set(parameter, value);
|
|
96
|
+
}
|
|
97
|
+
if (input.limit !== undefined && input.limit !== null) {
|
|
98
|
+
const maxLimit = text !== null ? SEARCH_TASKS_MAX_LIMIT : LIST_TASKS_MAX_LIMIT;
|
|
99
|
+
if (typeof input.limit !== 'number' || !Number.isInteger(input.limit) || input.limit < 1 || input.limit > maxLimit) {
|
|
100
|
+
throw new TaskListArgumentError(`limit must be an integer from 1 to ${maxLimit}`);
|
|
101
|
+
}
|
|
102
|
+
query.set('limit', String(input.limit));
|
|
103
|
+
}
|
|
104
|
+
if (input.include_archived !== undefined && input.include_archived !== null) {
|
|
105
|
+
if (typeof input.include_archived !== 'boolean')
|
|
106
|
+
throw new TaskListArgumentError('include_archived must be a boolean');
|
|
107
|
+
// The task API includes archived Tasks only for exactly one include_archived=true.
|
|
108
|
+
if (input.include_archived)
|
|
109
|
+
query.set('include_archived', 'true');
|
|
110
|
+
}
|
|
111
|
+
const suffix = query.toString();
|
|
112
|
+
return {
|
|
113
|
+
method: 'GET',
|
|
114
|
+
path: `/api/companion/tasks${text !== null ? '/search' : ''}${suffix ? `?${suffix}` : ''}`,
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Checks a 2xx answer is a Task page and passes it through unchanged (archived_at and
|
|
119
|
+
* archive_reason included). Non-2xx answers stay with the host's common Task error mapping.
|
|
120
|
+
*/
|
|
121
|
+
export function readListTasksResponse(body) {
|
|
122
|
+
const page = record(body);
|
|
123
|
+
if (!page) {
|
|
124
|
+
return { status: 'error', error: { code: 'task_contract_error', message: 'Expected a Canonical Task object response' } };
|
|
125
|
+
}
|
|
126
|
+
if (!Array.isArray(page.items)) {
|
|
127
|
+
return { status: 'error', error: { code: 'task_contract_error', message: 'Expected a Canonical Task page response' } };
|
|
128
|
+
}
|
|
129
|
+
return { status: 'ok', page };
|
|
130
|
+
}
|
|
@@ -63,6 +63,21 @@ export function projectVocabularyTerms(records) {
|
|
|
63
63
|
}
|
|
64
64
|
return terms.sort((a, b) => a.id.localeCompare(b.id));
|
|
65
65
|
}
|
|
66
|
+
/**
|
|
67
|
+
* What the world's display filter reads from a project record (story-world-agents-step1-v1): both status
|
|
68
|
+
* fields as recorded (the entity's `status` keeps only one of them), a test mark and a hidden mark.
|
|
69
|
+
*/
|
|
70
|
+
function projectWorldFlags(payload) {
|
|
71
|
+
const operational = text(payload.operational_status);
|
|
72
|
+
const recorded = text(payload.status);
|
|
73
|
+
const visibility = text(payload.world_visibility);
|
|
74
|
+
return {
|
|
75
|
+
...(operational ? { operational_status: operational } : {}),
|
|
76
|
+
...(recorded ? { record_status: recorded } : {}),
|
|
77
|
+
...(payload.is_test === true ? { is_test: true } : {}),
|
|
78
|
+
...(visibility ? { world_visibility: visibility } : {})
|
|
79
|
+
};
|
|
80
|
+
}
|
|
66
81
|
/** A project's code, parent and repositories as the organization Graph states them. */
|
|
67
82
|
function projectPlacement(record, payload, catalogByCode) {
|
|
68
83
|
const scope = text(record.project_code);
|
|
@@ -125,7 +140,8 @@ export function projectOrganizationGraph(records, owner) {
|
|
|
125
140
|
...(type === 'project' && status ? { status } : {}),
|
|
126
141
|
...(type === 'project' && text(payload.kind) ? { kind: text(payload.kind) } : {}),
|
|
127
142
|
...(type === 'decision' && text(payload.decided_at) ? { decided_at: text(payload.decided_at) } : {}),
|
|
128
|
-
...(type === 'project' ? projectPlacement(record, payload, catalogByCode) : {})
|
|
143
|
+
...(type === 'project' ? projectPlacement(record, payload, catalogByCode) : {}),
|
|
144
|
+
...(type === 'project' ? projectWorldFlags(payload) : {})
|
|
129
145
|
}
|
|
130
146
|
});
|
|
131
147
|
ids.set(record.id, type);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { JudgmentValueProofJournalCache } from './judgment-value-proof-review.js';
|
|
2
2
|
import { type GraphVocabularyTerm, type LocalWebExtension, type LocalWebModuleContext } from './local-web-host.js';
|
|
3
|
-
import type { GraphFileV2 } from './types.js';
|
|
3
|
+
import type { CanonicalEntity, GraphFileV2 } from './types.js';
|
|
4
4
|
export * from './world-work.js';
|
|
5
5
|
/**
|
|
6
6
|
* World view (ledger P17, adopted 2026-10-04): the home's upper layer.
|
|
@@ -104,7 +104,36 @@ export interface WorldBusinessProjection {
|
|
|
104
104
|
readonly excluded: {
|
|
105
105
|
readonly inactive: number;
|
|
106
106
|
};
|
|
107
|
+
/**
|
|
108
|
+
* Projects kept off the map by the display filter (story-world-agents-step1-v1 AC-01/02): archived or
|
|
109
|
+
* finished businesses, projects marked as tests or hidden, and projects named like test leftovers.
|
|
110
|
+
* The Graph is never changed; only how many were kept off is said (P9: never dropped silently).
|
|
111
|
+
* Optional on this public type so consumers that build the earlier three-field shape keep compiling;
|
|
112
|
+
* `projectWorldFromGraph` and the businesses API always emit it. Read it as `filtered_out_count ?? 0`.
|
|
113
|
+
*/
|
|
114
|
+
readonly filtered_out_count?: number;
|
|
107
115
|
}
|
|
116
|
+
/** What `projectWorldFromGraph` returns: the projection with the display filter's count always present. */
|
|
117
|
+
export type WorldBusinessProjectionResult = WorldBusinessProjection & {
|
|
118
|
+
readonly filtered_out_count: number;
|
|
119
|
+
};
|
|
120
|
+
/** Options for the world's display filter; `includeTest` draws the filtered projects too (for checking only). */
|
|
121
|
+
export interface WorldProjectionOptions {
|
|
122
|
+
readonly includeTest?: boolean;
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Names of the probes and acceptance runs that were left in Graphs as active projects. A project whose
|
|
126
|
+
* code or name matches one is kept off the map by default (layer 2; layer 1 is the record's own flags).
|
|
127
|
+
*/
|
|
128
|
+
export declare const WORLD_TEST_PROJECT_PATTERNS: readonly RegExp[];
|
|
129
|
+
/**
|
|
130
|
+
* Why a project is kept off the world by default, or null when it is drawn. `top` is true for a
|
|
131
|
+
* business (a city): a finished business is kept off, while a finished engagement inside a city stays
|
|
132
|
+
* as its empty lot (story-world-size-and-activity-v1).
|
|
133
|
+
*/
|
|
134
|
+
export declare function worldProjectFilterReason(entity: Pick<CanonicalEntity, 'name' | 'metadata'>, { top }?: {
|
|
135
|
+
readonly top?: boolean;
|
|
136
|
+
}): 'lifecycle' | 'archived' | 'test_flag' | 'hidden' | 'test_name' | null;
|
|
108
137
|
export type WorldSource = {
|
|
109
138
|
readonly authority: 'organization_graph';
|
|
110
139
|
readonly server: string;
|
|
@@ -123,6 +152,63 @@ export type WorldBusinessesResponse = ({
|
|
|
123
152
|
readonly version: typeof WORLD_EXTENSION_VERSION;
|
|
124
153
|
readonly reason: string;
|
|
125
154
|
};
|
|
155
|
+
/**
|
|
156
|
+
* The AI agents a host projects onto the world (story-world-agents-step1-v1, design item #707 §1.3).
|
|
157
|
+
* It is an execution-state projection (for example Orca run receipts), never Brainbase's judgment record:
|
|
158
|
+
* the plaza (判断) is not touched by it, and the world says where it came from. This package only draws
|
|
159
|
+
* it; the host computes the states on its server, with its own organization and member boundaries.
|
|
160
|
+
*/
|
|
161
|
+
export declare const WORLD_AGENTS_CONTRACT_VERSION: "world-agents.v1";
|
|
162
|
+
/** Where an agent stands: the common headquarters (cross-business work) or a business it serves. */
|
|
163
|
+
export type WorldAgentZone = 'hq' | 'business';
|
|
164
|
+
/** What the agent is doing, decided by the host; `unconfirmed` when it could not be confirmed (never idle). */
|
|
165
|
+
export type WorldAgentState = 'idle' | 'working' | 'needs_you' | 'blocked' | 'unconfirmed';
|
|
166
|
+
/** How recent the observation is, against the host's `stale_threshold_sec`. */
|
|
167
|
+
export type WorldAgentFreshness = 'fresh' | 'stale' | 'unconfirmed';
|
|
168
|
+
export interface WorldAgent {
|
|
169
|
+
readonly agent_id: string;
|
|
170
|
+
readonly slug: string;
|
|
171
|
+
readonly display_name: string;
|
|
172
|
+
/** One line on what the agent is for. */
|
|
173
|
+
readonly role_summary: string | null;
|
|
174
|
+
readonly zone: WorldAgentZone;
|
|
175
|
+
/** The business code the agent belongs to (its city), or the organization's own code for `hq`. */
|
|
176
|
+
readonly home_project_code: string | null;
|
|
177
|
+
/** Where the agent works now (Step 2); null while only the home is known. */
|
|
178
|
+
readonly current_project_code: string | null;
|
|
179
|
+
readonly state: WorldAgentState;
|
|
180
|
+
readonly freshness: WorldAgentFreshness;
|
|
181
|
+
/** When the state was observed (ISO 8601), or null when never observed. */
|
|
182
|
+
readonly observed_at: string | null;
|
|
183
|
+
readonly age_sec: number | null;
|
|
184
|
+
/** A non-confidential line the host composes from fixed phrases (no item titles, no chat text). */
|
|
185
|
+
readonly summary_line: string | null;
|
|
186
|
+
readonly blocker_code: string | null;
|
|
187
|
+
readonly metrics: {
|
|
188
|
+
readonly active_workers: number | null;
|
|
189
|
+
readonly needs_you_count: number | null;
|
|
190
|
+
readonly open_items_count: number | null;
|
|
191
|
+
};
|
|
192
|
+
/** The one way down; `href` only when `available`, else why there is none (story-world-clickable-honesty-v1 AC-03). */
|
|
193
|
+
readonly drilldown: {
|
|
194
|
+
readonly available: boolean;
|
|
195
|
+
readonly href: string | null;
|
|
196
|
+
readonly unavailable_reason: string | null;
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
export interface WorldAgentsResponse {
|
|
200
|
+
readonly contract_version: typeof WORLD_AGENTS_CONTRACT_VERSION;
|
|
201
|
+
readonly organization_id: string;
|
|
202
|
+
readonly viewer_scope: 'owner' | 'member';
|
|
203
|
+
readonly source: string;
|
|
204
|
+
/** Always false: the projection is not Brainbase's judgment record. */
|
|
205
|
+
readonly is_canonical_judgment: false;
|
|
206
|
+
readonly snapshot_interval_sec: number;
|
|
207
|
+
readonly stale_threshold_sec: number;
|
|
208
|
+
readonly read_state: 'confirmed' | 'partial' | 'unavailable';
|
|
209
|
+
readonly checked_at: string;
|
|
210
|
+
readonly agents: readonly WorldAgent[];
|
|
211
|
+
}
|
|
126
212
|
/**
|
|
127
213
|
* The projects of a Graph v2 → cities (top-level projects) and their districts
|
|
128
214
|
* (projects whose `metadata.parent_project_id` names another project). A
|
|
@@ -133,7 +219,7 @@ export type WorldBusinessesResponse = ({
|
|
|
133
219
|
*/
|
|
134
220
|
export declare function projectWorldFromGraph(graph: Pick<GraphFileV2, 'entities'> & {
|
|
135
221
|
readonly edges?: GraphFileV2['edges'];
|
|
136
|
-
}, now?: Date):
|
|
222
|
+
}, now?: Date, options?: WorldProjectionOptions): WorldBusinessProjectionResult;
|
|
137
223
|
/**
|
|
138
224
|
* The vocabulary the world draws with: the host's kinds in their order, then
|
|
139
225
|
* kinds the Graph uses that the host did not name (under their own value),
|
|
@@ -151,7 +237,7 @@ export declare function readWorldVocabulary(path: string): Promise<WorldVocabula
|
|
|
151
237
|
export declare function readWorldBusinesses(context: Pick<LocalWebModuleContext, 'dataDir'>, options?: {
|
|
152
238
|
readonly vocabulary?: WorldVocabularyConfig;
|
|
153
239
|
readonly now?: () => Date;
|
|
154
|
-
}): Promise<WorldBusinessesResponse>;
|
|
240
|
+
} & WorldProjectionOptions): Promise<WorldBusinessesResponse>;
|
|
155
241
|
/**
|
|
156
242
|
* The world of an organization from the project and glossary-term records its Graph API returns, for an
|
|
157
243
|
* organization web that hosts the same world screen (P16). Pure: the caller reads the records with the
|
|
@@ -165,7 +251,7 @@ export declare function projectOrganizationWorld(records: {
|
|
|
165
251
|
readonly server: string;
|
|
166
252
|
readonly vocabulary?: WorldVocabularyConfig;
|
|
167
253
|
readonly now?: Date;
|
|
168
|
-
}): WorldBusinessesResponse;
|
|
254
|
+
} & WorldProjectionOptions): WorldBusinessesResponse;
|
|
169
255
|
export interface WorldJudgmentPlace {
|
|
170
256
|
readonly decision_attempt_id: string;
|
|
171
257
|
/** Repository the judgment Host recorded for the turn (`turn-input.json` project_code); null when unrecorded. */
|