@idea1/cli 1.10.3 → 1.11.0
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/README.md +43 -16
- package/dist/commands/help.d.ts.map +1 -1
- package/dist/commands/help.js +19 -2
- package/dist/commands/help.js.map +1 -1
- package/dist/commands/index.d.ts +3 -1
- package/dist/commands/index.d.ts.map +1 -1
- package/dist/commands/index.js +5 -1
- package/dist/commands/index.js.map +1 -1
- package/dist/commands/login.d.ts +3 -0
- package/dist/commands/login.d.ts.map +1 -0
- package/dist/commands/login.js +15 -0
- package/dist/commands/login.js.map +1 -0
- package/dist/commands/logout.d.ts +3 -0
- package/dist/commands/logout.d.ts.map +1 -0
- package/dist/commands/logout.js +17 -0
- package/dist/commands/logout.js.map +1 -0
- package/dist/commands/release.d.ts +15 -9
- package/dist/commands/release.d.ts.map +1 -1
- package/dist/commands/release.js +60 -31
- package/dist/commands/release.js.map +1 -1
- package/dist/lib/project-item-url.d.ts +6 -0
- package/dist/lib/project-item-url.d.ts.map +1 -1
- package/dist/lib/project-item-url.js +11 -0
- package/dist/lib/project-item-url.js.map +1 -1
- package/dist/lib/settings.d.ts +15 -4
- package/dist/lib/settings.d.ts.map +1 -1
- package/dist/lib/settings.js +17 -2
- package/dist/lib/settings.js.map +1 -1
- package/dist/lib/shell.d.ts.map +1 -1
- package/dist/lib/shell.js +4 -0
- package/dist/lib/shell.js.map +1 -1
- package/dist/prompts/platform-prompts.d.ts +5 -30
- package/dist/prompts/platform-prompts.d.ts.map +1 -1
- package/dist/prompts/platform-prompts.js +5 -44
- package/dist/prompts/platform-prompts.js.map +1 -1
- package/dist/services/github.d.ts +15 -3
- package/dist/services/github.d.ts.map +1 -1
- package/dist/services/github.js +20 -1
- package/dist/services/github.js.map +1 -1
- package/dist/services/platform-auth.d.ts +43 -0
- package/dist/services/platform-auth.d.ts.map +1 -0
- package/dist/services/platform-auth.js +380 -0
- package/dist/services/platform-auth.js.map +1 -0
- package/dist/services/platform.d.ts +23 -16
- package/dist/services/platform.d.ts.map +1 -1
- package/dist/services/platform.js +188 -190
- package/dist/services/platform.js.map +1 -1
- package/dist/services/setup.d.ts.map +1 -1
- package/dist/services/setup.js +4 -1
- package/dist/services/setup.js.map +1 -1
- package/dist/types/index.d.ts +18 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js +1 -1
- package/dist/types/index.js.map +1 -1
- package/dist/workflow/data/team-member.d.ts +9 -2
- package/dist/workflow/data/team-member.d.ts.map +1 -1
- package/dist/workflow/data/team-member.js +8 -1
- package/dist/workflow/data/team-member.js.map +1 -1
- package/dist/workflow/engine/approval-flow.d.ts +3 -3
- package/dist/workflow/engine/approval-flow.d.ts.map +1 -1
- package/dist/workflow/engine/approval-flow.js +5 -5
- package/dist/workflow/engine/approval-flow.js.map +1 -1
- package/dist/workflow/engine/branch-setup.d.ts +1 -1
- package/dist/workflow/engine/branch-setup.js +1 -1
- package/dist/workflow/engine/handlers/approve-pr.d.ts +1 -1
- package/dist/workflow/engine/handlers/approve-pr.js +1 -1
- package/dist/workflow/engine/handlers/ready-for-approval.d.ts +1 -1
- package/dist/workflow/engine/handlers/ready-for-approval.js +1 -1
- package/dist/workflow/engine/release-engine.d.ts +41 -24
- package/dist/workflow/engine/release-engine.d.ts.map +1 -1
- package/dist/workflow/engine/release-engine.js +151 -80
- package/dist/workflow/engine/release-engine.js.map +1 -1
- package/package.json +2 -1
|
@@ -6,30 +6,33 @@ import type { ClaudeRunOptions } from './claude.js';
|
|
|
6
6
|
* The CLI's access to the Idea1 cloud platform (app.idea1.ai / api.idea1.ai): reading a project
|
|
7
7
|
* item's summary (by item or by branch), recording the item's workflow context, setting its workflow
|
|
8
8
|
* status (with the teammate it is assigned to), creating items, listing the team's Projects and
|
|
9
|
-
* members, deriving a branch name from an item
|
|
10
|
-
* nothing about the transport.
|
|
9
|
+
* members, deriving a branch name from an item, and reading who is signed in. Callers use
|
|
10
|
+
* `platform.someFunction()` and know nothing about the transport.
|
|
11
11
|
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
* `src/prompts/platform-prompts.ts`; this module owns the output schemas their answers are read with.
|
|
12
|
+
* The transport is the platform's REST API, authorized with the user's OAuth credential or
|
|
13
|
+
* `IDEA1_TOKEN` (see `platform-auth.ts`), on the team that credential is bound to. Responses are the
|
|
14
|
+
* platform's `ApiDataResponse` envelope; a refused request surfaces as an Error carrying the
|
|
15
|
+
* platform's status and message. Claude is used only to name branches, on PLATFORM_CALL_RUN_OPTIONS.
|
|
17
16
|
*/
|
|
18
17
|
/**
|
|
19
|
-
* Model and effort for
|
|
20
|
-
*
|
|
18
|
+
* Model and effort for the Claude run that names a branch: a small, fast model at medium effort is
|
|
19
|
+
* all a one-line answer from a description needs, and pinning it keeps the run consistent and cheap.
|
|
21
20
|
*/
|
|
22
21
|
export declare const PLATFORM_CALL_RUN_OPTIONS: Required<ClaudeRunOptions>;
|
|
22
|
+
/**
|
|
23
|
+
* Who the platform credential signs in as: the user's email address and the team its calls work on.
|
|
24
|
+
*/
|
|
25
|
+
export interface SignedInUser {
|
|
26
|
+
emailAddress: string;
|
|
27
|
+
teamName: string;
|
|
28
|
+
}
|
|
23
29
|
/**
|
|
24
30
|
* Record workflow context updates on an idea1.ai project item directly, with no side effects on the
|
|
25
31
|
* platform: the CLI has already run the transition's work locally. The item must be under workflow
|
|
26
32
|
* management (have a workflow context); the workflow engine is the only caller, as the persist step
|
|
27
33
|
* of a transition. `assignedToEmail` names the team member the item is assigned to along with the
|
|
28
|
-
* status; null leaves the assignment as it is.
|
|
29
|
-
*
|
|
30
|
-
* TODO: Direct workflow-context updates move from the update_item MCP tool to an authenticated
|
|
31
|
-
* platform API call; the CLI will authenticate a user and call the API for direct integrations
|
|
32
|
-
* like this, and MCP tools will be only operations that agents should run.
|
|
34
|
+
* status; null leaves the assignment as it is. Returns false, with a warning, when the platform did
|
|
35
|
+
* not record it.
|
|
33
36
|
*/
|
|
34
37
|
export declare function setWorkflowStatus(itemUrl: string, status: string, pullRequestUrl: string | null, assignedToEmail: string | null): Promise<boolean>;
|
|
35
38
|
/**
|
|
@@ -67,7 +70,7 @@ export interface UpsertProjectItemWorkflowContextInput {
|
|
|
67
70
|
*/
|
|
68
71
|
export declare function upsertProjectItemWorkflowContext(input: UpsertProjectItemWorkflowContextInput): Promise<ProjectItemSummary>;
|
|
69
72
|
/**
|
|
70
|
-
* Generate a branch name from a project item description
|
|
73
|
+
* Generate a branch name from a project item's description.
|
|
71
74
|
*/
|
|
72
75
|
export declare function generateBranchName(itemUrl: string): Promise<string>;
|
|
73
76
|
/**
|
|
@@ -86,9 +89,13 @@ export declare function listTeamMembers(): Promise<TeamMember[]>;
|
|
|
86
89
|
*/
|
|
87
90
|
export declare function resolveTeammate(identity: string): Promise<TeamMember>;
|
|
88
91
|
/**
|
|
89
|
-
* Create a new idea1 project item with the given title in the named Project.
|
|
92
|
+
* Create a new idea1 project item with the given title in the named live Project.
|
|
90
93
|
* The item is created with description `# <title>`.
|
|
91
94
|
* Returns the created item's URL.
|
|
92
95
|
*/
|
|
93
96
|
export declare function createProjectItem(title: string, projectName: string): Promise<string>;
|
|
97
|
+
/**
|
|
98
|
+
* The user the platform credential signs in as, and the team its calls work on.
|
|
99
|
+
*/
|
|
100
|
+
export declare function getSignedInUser(): Promise<SignedInUser>;
|
|
94
101
|
//# sourceMappingURL=platform.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"platform.d.ts","sourceRoot":"","sources":["../../src/services/platform.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,
|
|
1
|
+
{"version":3,"file":"platform.d.ts","sourceRoot":"","sources":["../../src/services/platform.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAmB,MAAM,sCAAsC,CAAC;AAC7F,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,kCAAkC,CAAC;AAC3E,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAKlE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAGpD;;;;;;;;;;;GAWG;AAEH;;;GAGG;AACH,eAAO,MAAM,yBAAyB,EAAE,QAAQ,CAAC,gBAAgB,CAAyC,CAAC;AA4D3G;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,YAAY,EAAE,MAAM,CAAC;IACrB,QAAQ,EAAE,MAAM,CAAC;CAClB;AAqID;;;;;;;GAOG;AACH,wBAAsB,iBAAiB,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,GAAG,IAAI,EAAE,eAAe,EAAE,MAAM,GAAG,IAAI,GAAG,OAAO,CAAC,OAAO,CAAC,CAaxJ;AAED;;;GAGG;AACH,wBAAsB,8BAA8B,CAAC,KAAK,EAAE;IAAE,kBAAkB,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,MAAM,CAAA;CAAE,GAAG,OAAO,CAAC,kBAAkB,GAAG,IAAI,CAAC,CASlJ;AAED;;;GAGG;AACH,wBAAsB,qBAAqB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAIxF;AAED;;GAEG;AACH,MAAM,WAAW,qCAAqC;IACpD,cAAc,EAAE,MAAM,CAAC;IACvB,kBAAkB,EAAE,MAAM,CAAC;IAC3B,UAAU,EAAE,MAAM,CAAC;IACnB,yEAAyE;IACzE,UAAU,EAAE,MAAM,CAAC;IACnB,eAAe,EAAE,eAAe,CAAC;IACjC,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,iBAAiB,EAAE,MAAM,GAAG,IAAI,CAAC;CAClC;AAED;;;;;;GAMG;AACH,wBAAsB,gCAAgC,CAAC,KAAK,EAAE,qCAAqC,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAehI;AAED;;GAEG;AACH,wBAAsB,kBAAkB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAWzE;AAUD;;GAEG;AACH,wBAAsB,YAAY,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC,CAItD;AAID;;;GAGG;AACH,wBAAgB,eAAe,IAAI,OAAO,CAAC,UAAU,EAAE,CAAC,CAQvD;AAcD;;;;GAIG;AACH,wBAAsB,eAAe,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC,CAQ3E;AAED;;;;GAIG;AACH,wBAAsB,iBAAiB,CAAC,KAAK,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAY3F;AAED;;GAEG;AACH,wBAAsB,eAAe,IAAI,OAAO,CAAC,YAAY,CAAC,CAG7D"}
|
|
@@ -1,68 +1,182 @@
|
|
|
1
1
|
import { logger } from '../lib/logger.js';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { createProjectItemPrompt, generateBranchNamePrompt, getProjectItemSummaryForBranchPrompt, getProjectItemSummaryPrompt, listProjectsPrompt, listTeamMembersPrompt, setWorkflowStatusPrompt, upsertProjectItemWorkflowContextPrompt } from '../prompts/platform-prompts.js';
|
|
2
|
+
import { projectItemExternalId } from '../lib/project-item-url.js';
|
|
3
|
+
import { generateBranchNamePrompt } from '../prompts/platform-prompts.js';
|
|
5
4
|
import * as claude from './claude.js';
|
|
5
|
+
import { apiBaseUrl, authorizedFetch } from './platform-auth.js';
|
|
6
6
|
/**
|
|
7
7
|
* The CLI's access to the Idea1 cloud platform (app.idea1.ai / api.idea1.ai): reading a project
|
|
8
8
|
* item's summary (by item or by branch), recording the item's workflow context, setting its workflow
|
|
9
9
|
* status (with the teammate it is assigned to), creating items, listing the team's Projects and
|
|
10
|
-
* members, deriving a branch name from an item
|
|
11
|
-
* nothing about the transport.
|
|
10
|
+
* members, deriving a branch name from an item, and reading who is signed in. Callers use
|
|
11
|
+
* `platform.someFunction()` and know nothing about the transport.
|
|
12
12
|
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
* `src/prompts/platform-prompts.ts`; this module owns the output schemas their answers are read with.
|
|
13
|
+
* The transport is the platform's REST API, authorized with the user's OAuth credential or
|
|
14
|
+
* `IDEA1_TOKEN` (see `platform-auth.ts`), on the team that credential is bound to. Responses are the
|
|
15
|
+
* platform's `ApiDataResponse` envelope; a refused request surfaces as an Error carrying the
|
|
16
|
+
* platform's status and message. Claude is used only to name branches, on PLATFORM_CALL_RUN_OPTIONS.
|
|
18
17
|
*/
|
|
19
18
|
/**
|
|
20
|
-
* Model and effort for
|
|
21
|
-
*
|
|
19
|
+
* Model and effort for the Claude run that names a branch: a small, fast model at medium effort is
|
|
20
|
+
* all a one-line answer from a description needs, and pinning it keeps the run consistent and cheap.
|
|
22
21
|
*/
|
|
23
22
|
export const PLATFORM_CALL_RUN_OPTIONS = { model: 'sonnet', effort: 'medium' };
|
|
24
23
|
/**
|
|
25
|
-
*
|
|
24
|
+
* The platform's `ApiResultType`, the `result` of every response envelope.
|
|
26
25
|
*/
|
|
27
|
-
|
|
28
|
-
|
|
26
|
+
var ApiResultType;
|
|
27
|
+
(function (ApiResultType) {
|
|
28
|
+
ApiResultType[ApiResultType["Ok"] = 0] = "Ok";
|
|
29
|
+
ApiResultType[ApiResultType["Failed"] = 1] = "Failed";
|
|
30
|
+
ApiResultType[ApiResultType["NotFound"] = 2] = "NotFound";
|
|
31
|
+
ApiResultType[ApiResultType["Unauthorized"] = 3] = "Unauthorized";
|
|
32
|
+
ApiResultType[ApiResultType["InvalidRequest"] = 4] = "InvalidRequest";
|
|
33
|
+
ApiResultType[ApiResultType["QuotaLimit"] = 5] = "QuotaLimit";
|
|
34
|
+
})(ApiResultType || (ApiResultType = {}));
|
|
35
|
+
/**
|
|
36
|
+
* The platform's `ProjectStatus`.
|
|
37
|
+
*/
|
|
38
|
+
var ProjectStatus;
|
|
39
|
+
(function (ProjectStatus) {
|
|
40
|
+
ProjectStatus[ProjectStatus["Live"] = 0] = "Live";
|
|
41
|
+
ProjectStatus[ProjectStatus["Completed"] = 1] = "Completed";
|
|
42
|
+
ProjectStatus[ProjectStatus["Cancelled"] = 2] = "Cancelled";
|
|
43
|
+
})(ProjectStatus || (ProjectStatus = {}));
|
|
44
|
+
/**
|
|
45
|
+
* Send a request to the platform's API, at `path` relative to the API base URL.
|
|
46
|
+
*/
|
|
47
|
+
function send(method, path, body) {
|
|
48
|
+
return authorizedFetch(`${apiBaseUrl()}/${path}`, {
|
|
49
|
+
method,
|
|
50
|
+
headers: body === null ? { Accept: 'application/json' } : { Accept: 'application/json', 'Content-Type': 'application/json' },
|
|
51
|
+
body: body === null ? undefined : JSON.stringify(body)
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* The `data` of a successful response; anything else throws an Error naming the request, the
|
|
56
|
+
* status and the platform's message.
|
|
57
|
+
*/
|
|
58
|
+
async function readData(method, path, response) {
|
|
59
|
+
const text = await response.text();
|
|
60
|
+
if (!response.ok) {
|
|
61
|
+
const message = serverMessage(text);
|
|
62
|
+
throw new Error(`idea1.ai refused ${method} /${path} (${response.status} ${response.statusText})${message.length > 0 ? `: ${message}` : ''}`);
|
|
63
|
+
}
|
|
64
|
+
const envelope = JSON.parse(text);
|
|
65
|
+
if (envelope.result !== ApiResultType.Ok) {
|
|
66
|
+
throw new Error(`idea1.ai could not complete ${method} /${path}: ${ApiResultType[envelope.result]}`);
|
|
67
|
+
}
|
|
68
|
+
return envelope.data;
|
|
69
|
+
}
|
|
70
|
+
async function call(method, path, body) {
|
|
71
|
+
return readData(method, path, await send(method, path, body));
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* A branch name the platform returned, checked before it reaches git: the CLI passes branch names
|
|
75
|
+
* to git as arguments, so a name that is not a plain ref (one starting with `-` would read as an
|
|
76
|
+
* option) is refused.
|
|
77
|
+
*/
|
|
78
|
+
const SAFE_BRANCH_NAME = /^(?!-)(?!.*\.\.)[A-Za-z0-9._\/-]+$/;
|
|
79
|
+
function checkedBranchName(name) {
|
|
80
|
+
if (!SAFE_BRANCH_NAME.test(name)) {
|
|
81
|
+
throw new Error(`idea1.ai returned an invalid branch name: ${JSON.stringify(name)}`);
|
|
82
|
+
}
|
|
83
|
+
return name;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* A project item URL the platform returned, checked before it is stored in git config: it must be a
|
|
87
|
+
* plain idea1.ai project item URL.
|
|
88
|
+
*/
|
|
89
|
+
const SAFE_PROJECT_ITEM_URL = /^https?:\/\/(app\.idea1\.ai|localhost(:\d+)?)\/project\/items\/\d+\/?$/i;
|
|
90
|
+
function checkedProjectItemUrl(url) {
|
|
91
|
+
if (!SAFE_PROJECT_ITEM_URL.test(url)) {
|
|
92
|
+
throw new Error(`idea1.ai returned an invalid project item URL: ${JSON.stringify(url)}`);
|
|
93
|
+
}
|
|
94
|
+
return url;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* A workflow context the platform returned, with its branch names checked. Each field is copied by
|
|
98
|
+
* name, so nothing the platform sent reaches git without passing the check.
|
|
99
|
+
*/
|
|
100
|
+
function checkedContext(context) {
|
|
101
|
+
return {
|
|
102
|
+
workflowStatus: context.workflowStatus,
|
|
103
|
+
codingAgentUrl: context.codingAgentUrl,
|
|
104
|
+
pullRequestUrl: context.pullRequestUrl,
|
|
105
|
+
repositoryFullName: context.repositoryFullName,
|
|
106
|
+
branchName: checkedBranchName(context.branchName),
|
|
107
|
+
baseBranch: checkedBranchName(context.baseBranch),
|
|
108
|
+
devWorkflowType: context.devWorkflowType,
|
|
109
|
+
stackBranch: context.stackBranch === null ? null : checkedBranchName(context.stackBranch),
|
|
110
|
+
integrationBranch: context.integrationBranch === null ? null : checkedBranchName(context.integrationBranch),
|
|
111
|
+
branchState: context.branchState
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
/** A project item summary the platform returned, with its URL and the branch names of its workflow context checked. */
|
|
115
|
+
function checkedSummary(summary) {
|
|
116
|
+
return {
|
|
117
|
+
url: checkedProjectItemUrl(summary.url),
|
|
118
|
+
externalId: summary.externalId,
|
|
119
|
+
title: summary.title,
|
|
120
|
+
epicId: summary.epicId,
|
|
121
|
+
completionDate: summary.completionDate,
|
|
122
|
+
legacyWorkflowStatus: summary.legacyWorkflowStatus,
|
|
123
|
+
projectId: summary.projectId,
|
|
124
|
+
assignedToUserId: summary.assignedToUserId,
|
|
125
|
+
workflowContext: summary.workflowContext === null ? null : checkedContext(summary.workflowContext)
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
async function callForSummary(method, path, body) {
|
|
129
|
+
return checkedSummary(await call(method, path, body));
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* The message an error response carries: the `message` (or OAuth `error_description`) of a JSON
|
|
133
|
+
* body, a JSON string, or the body's text; empty for an empty body.
|
|
134
|
+
*/
|
|
135
|
+
function serverMessage(text) {
|
|
136
|
+
const trimmed = text.trim();
|
|
137
|
+
try {
|
|
138
|
+
const body = JSON.parse(trimmed);
|
|
139
|
+
if (typeof body === 'string') {
|
|
140
|
+
return body;
|
|
141
|
+
}
|
|
142
|
+
if (typeof body === 'object' && body !== null) {
|
|
143
|
+
const fields = body;
|
|
144
|
+
const message = [fields.message, fields.error_description, fields.error, fields.detail, fields.title].find(value => typeof value === 'string');
|
|
145
|
+
if (typeof message === 'string') {
|
|
146
|
+
return message;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
catch {
|
|
151
|
+
// Not JSON: the text is the message.
|
|
152
|
+
}
|
|
153
|
+
return trimmed.slice(0, 500);
|
|
29
154
|
}
|
|
30
155
|
/**
|
|
31
|
-
*
|
|
156
|
+
* The path of a project item by its URL's external id.
|
|
32
157
|
*/
|
|
33
|
-
|
|
34
|
-
return
|
|
158
|
+
function projectItemPath(itemUrl) {
|
|
159
|
+
return `v1/teams/active/project-items/by-external-id/${projectItemExternalId(itemUrl)}`;
|
|
35
160
|
}
|
|
36
161
|
/**
|
|
37
162
|
* Record workflow context updates on an idea1.ai project item directly, with no side effects on the
|
|
38
163
|
* platform: the CLI has already run the transition's work locally. The item must be under workflow
|
|
39
164
|
* management (have a workflow context); the workflow engine is the only caller, as the persist step
|
|
40
165
|
* of a transition. `assignedToEmail` names the team member the item is assigned to along with the
|
|
41
|
-
* status; null leaves the assignment as it is.
|
|
42
|
-
*
|
|
43
|
-
* TODO: Direct workflow-context updates move from the update_item MCP tool to an authenticated
|
|
44
|
-
* platform API call; the CLI will authenticate a user and call the API for direct integrations
|
|
45
|
-
* like this, and MCP tools will be only operations that agents should run.
|
|
166
|
+
* status; null leaves the assignment as it is. Returns false, with a warning, when the platform did
|
|
167
|
+
* not record it.
|
|
46
168
|
*/
|
|
47
169
|
export async function setWorkflowStatus(itemUrl, status, pullRequestUrl, assignedToEmail) {
|
|
48
|
-
const hasClaude = await claude.ensureClaudeCli();
|
|
49
|
-
if (!hasClaude) {
|
|
50
|
-
logger.warning('Claude CLI not available, skipping workflow status update');
|
|
51
|
-
return false;
|
|
52
|
-
}
|
|
53
170
|
logger.step(assignedToEmail === null
|
|
54
171
|
? `Setting workflow status to "${status}"...`
|
|
55
172
|
: `Setting workflow status to "${status}", assigned to ${assignedToEmail}...`);
|
|
56
173
|
try {
|
|
57
|
-
await
|
|
174
|
+
await call('PUT', `${projectItemPath(itemUrl)}/workflow-status`, { workflowStatus: status, pullRequestUrl, assignedToEmail });
|
|
58
175
|
logger.success(`Workflow status updated to "${status}"`);
|
|
59
176
|
return true;
|
|
60
177
|
}
|
|
61
178
|
catch (error) {
|
|
62
|
-
|
|
63
|
-
? `Model could not update workflow status: ${error.message}`
|
|
64
|
-
: `Could not update workflow status: ${error.message}`;
|
|
65
|
-
logger.warning(message);
|
|
179
|
+
logger.warning(`Could not update workflow status: ${error.message}`);
|
|
66
180
|
return false;
|
|
67
181
|
}
|
|
68
182
|
}
|
|
@@ -71,30 +185,21 @@ export async function setWorkflowStatus(itemUrl, status, pullRequestUrl, assigne
|
|
|
71
185
|
* management. The repository is always named; nothing defaults it.
|
|
72
186
|
*/
|
|
73
187
|
export async function getProjectItemSummaryForBranch(query) {
|
|
74
|
-
const hasClaude = await claude.ensureClaudeCli();
|
|
75
|
-
if (!hasClaude) {
|
|
76
|
-
throw new Error('Claude CLI is required to read the project item of a branch from idea1.ai');
|
|
77
|
-
}
|
|
78
188
|
logger.step(`Reading the project item of ${query.branchName} from idea1.ai...`);
|
|
79
|
-
const
|
|
80
|
-
|
|
189
|
+
const path = `v1/teams/active/project-items/for-branch?${new URLSearchParams(query).toString()}`;
|
|
190
|
+
const response = await send('GET', path, null);
|
|
191
|
+
if (response.status === 404) {
|
|
192
|
+
return null;
|
|
193
|
+
}
|
|
194
|
+
return checkedSummary(await readData('GET', path, response));
|
|
81
195
|
}
|
|
82
196
|
/**
|
|
83
197
|
* The summary of a project item: its `workflowContext` is null while the item is outside workflow
|
|
84
198
|
* management.
|
|
85
199
|
*/
|
|
86
200
|
export async function getProjectItemSummary(itemUrl) {
|
|
87
|
-
const hasClaude = await claude.ensureClaudeCli();
|
|
88
|
-
if (!hasClaude) {
|
|
89
|
-
throw new Error('Claude CLI is required to read a project item from idea1.ai');
|
|
90
|
-
}
|
|
91
201
|
logger.step(`Reading ${itemUrl} from idea1.ai...`);
|
|
92
|
-
|
|
93
|
-
const summary = readProjectItemSummaryOutput(output, () => false);
|
|
94
|
-
if (!summary) {
|
|
95
|
-
throw new Error(`idea1.ai returned no project item for ${itemUrl}`);
|
|
96
|
-
}
|
|
97
|
-
return summary;
|
|
202
|
+
return callForSummary('GET', `${projectItemPath(itemUrl)}/summary`, null);
|
|
98
203
|
}
|
|
99
204
|
/**
|
|
100
205
|
* Record a branch in a project item's workflow context as the one implementing the item, putting
|
|
@@ -104,120 +209,46 @@ export async function getProjectItemSummary(itemUrl) {
|
|
|
104
209
|
* refused by the platform, which surfaces here as an error.
|
|
105
210
|
*/
|
|
106
211
|
export async function upsertProjectItemWorkflowContext(input) {
|
|
107
|
-
const hasClaude = await claude.ensureClaudeCli();
|
|
108
|
-
if (!hasClaude) {
|
|
109
|
-
throw new Error('Claude CLI is required to record the workflow context on idea1.ai');
|
|
110
|
-
}
|
|
111
212
|
logger.step(`Recording ${input.branchName} as the branch of ${input.projectItemUrl} on idea1.ai...`);
|
|
112
|
-
const
|
|
113
|
-
|
|
114
|
-
|
|
213
|
+
const summary = await callForSummary('PUT', `${projectItemPath(input.projectItemUrl)}/workflow-context`, {
|
|
214
|
+
repositoryFullName: input.repositoryFullName,
|
|
215
|
+
branchName: input.branchName,
|
|
216
|
+
baseBranch: input.baseBranch,
|
|
217
|
+
devWorkflowType: input.devWorkflowType,
|
|
218
|
+
stackBranch: input.stackBranch,
|
|
219
|
+
integrationBranch: input.integrationBranch
|
|
220
|
+
});
|
|
221
|
+
if (summary.workflowContext === null) {
|
|
115
222
|
throw new Error('The platform returned no workflow context after recording the branch');
|
|
116
223
|
}
|
|
117
224
|
return summary;
|
|
118
225
|
}
|
|
119
226
|
/**
|
|
120
|
-
*
|
|
121
|
-
* item" yields null; any other error is thrown.
|
|
122
|
-
*/
|
|
123
|
-
function readProjectItemSummaryOutput(output, isAbsence) {
|
|
124
|
-
if (typeof output.error === 'string' && output.error.trim().length > 0) {
|
|
125
|
-
if (isAbsence(output.error)) {
|
|
126
|
-
return null;
|
|
127
|
-
}
|
|
128
|
-
throw new Error(`idea1.ai: ${output.error.trim()}`);
|
|
129
|
-
}
|
|
130
|
-
const summary = output.projectItemSummary;
|
|
131
|
-
if (!summary || typeof summary.url !== 'string' || !isProjectItemUrl(summary.url)) {
|
|
132
|
-
throw new Error(`Claude did not return a valid project item summary: ${JSON.stringify(output.projectItemSummary)}`);
|
|
133
|
-
}
|
|
134
|
-
return summary;
|
|
135
|
-
}
|
|
136
|
-
/**
|
|
137
|
-
* JSON schema for the project-item-summary structured output (`ProjectItemSummary` or an error).
|
|
138
|
-
*/
|
|
139
|
-
const projectItemSummaryOutputSchema = {
|
|
140
|
-
type: 'object',
|
|
141
|
-
properties: {
|
|
142
|
-
projectItemSummary: {
|
|
143
|
-
type: ['object', 'null'],
|
|
144
|
-
description: 'The project item summary the tool returned, or null when it returned an error',
|
|
145
|
-
properties: {
|
|
146
|
-
url: { type: 'string' },
|
|
147
|
-
externalId: { type: 'integer' },
|
|
148
|
-
title: { type: 'string' },
|
|
149
|
-
epicId: { type: ['string', 'null'] },
|
|
150
|
-
completionDate: { type: ['string', 'null'] },
|
|
151
|
-
legacyWorkflowStatus: { type: 'string' },
|
|
152
|
-
projectId: { type: ['string', 'null'], description: 'The Project the item is planned in; null when it is out of scope' },
|
|
153
|
-
assignedToUserId: { type: ['string', 'null'], description: 'The team member the item is assigned to; null when unassigned' },
|
|
154
|
-
workflowContext: {
|
|
155
|
-
type: ['object', 'null'],
|
|
156
|
-
properties: {
|
|
157
|
-
workflowStatus: { type: 'string' },
|
|
158
|
-
codingAgentUrl: { type: 'string' },
|
|
159
|
-
pullRequestUrl: { type: 'string' },
|
|
160
|
-
repositoryFullName: { type: 'string' },
|
|
161
|
-
branchName: { type: 'string' },
|
|
162
|
-
baseBranch: { type: 'string' },
|
|
163
|
-
devWorkflowType: { type: 'string', enum: ['independent', 'integration'] },
|
|
164
|
-
stackBranch: { type: ['string', 'null'] },
|
|
165
|
-
integrationBranch: { type: ['string', 'null'] },
|
|
166
|
-
branchState: { type: 'integer', enum: [0, 1, 2], description: '0 Live, 1 Merged, 2 Deleted' }
|
|
167
|
-
},
|
|
168
|
-
required: ['workflowStatus', 'codingAgentUrl', 'pullRequestUrl', 'repositoryFullName', 'branchName', 'baseBranch', 'devWorkflowType', 'stackBranch', 'integrationBranch', 'branchState'],
|
|
169
|
-
additionalProperties: false
|
|
170
|
-
}
|
|
171
|
-
},
|
|
172
|
-
required: ['url', 'externalId', 'title', 'epicId', 'completionDate', 'legacyWorkflowStatus', 'projectId', 'assignedToUserId', 'workflowContext'],
|
|
173
|
-
additionalProperties: false
|
|
174
|
-
},
|
|
175
|
-
error: { type: ['string', 'null'], description: 'The error the tool returned, verbatim, or null on success' }
|
|
176
|
-
},
|
|
177
|
-
required: ['projectItemSummary', 'error'],
|
|
178
|
-
additionalProperties: false
|
|
179
|
-
};
|
|
180
|
-
/**
|
|
181
|
-
* Generate a branch name from a project item description
|
|
227
|
+
* Generate a branch name from a project item's description.
|
|
182
228
|
*/
|
|
183
229
|
export async function generateBranchName(itemUrl) {
|
|
184
|
-
const hasClaude = await claude.ensureClaudeCli();
|
|
185
|
-
if (!hasClaude) {
|
|
186
|
-
throw new Error('Claude CLI is required to generate branch names');
|
|
187
|
-
}
|
|
188
230
|
logger.step('Generating branch name from item description...');
|
|
189
|
-
const
|
|
231
|
+
const item = await call('GET', projectItemPath(itemUrl), null);
|
|
232
|
+
const branchName = await claude.runWithPrompt(generateBranchNamePrompt({ description: item.description }), PLATFORM_CALL_RUN_OPTIONS);
|
|
190
233
|
// Clean up any extra whitespace/newlines
|
|
191
234
|
const cleanedName = branchName.replace(/\n/g, '').trim();
|
|
192
235
|
logger.dim(`Generated branch name: ${cleanedName}`);
|
|
193
236
|
return cleanedName;
|
|
194
237
|
}
|
|
238
|
+
/**
|
|
239
|
+
* The team's live Projects, most recently created first.
|
|
240
|
+
*/
|
|
241
|
+
async function readLiveProjects() {
|
|
242
|
+
const projects = await call('GET', 'v1/teams/active/projects', null);
|
|
243
|
+
return projects.filter(project => project.status === ProjectStatus.Live);
|
|
244
|
+
}
|
|
195
245
|
/**
|
|
196
246
|
* The names of the team's live Projects, most recently created first.
|
|
197
247
|
*/
|
|
198
248
|
export async function listProjects() {
|
|
199
249
|
logger.step('Reading the team\'s projects from idea1.ai...');
|
|
200
|
-
|
|
201
|
-
const projects = Array.isArray(output.projects)
|
|
202
|
-
? output.projects.filter((name) => typeof name === 'string' && name.trim().length > 0).map(name => name.trim())
|
|
203
|
-
: [];
|
|
204
|
-
return projects;
|
|
250
|
+
return (await readLiveProjects()).map(project => project.name);
|
|
205
251
|
}
|
|
206
|
-
/**
|
|
207
|
-
* JSON schema for the list-projects structured output.
|
|
208
|
-
*/
|
|
209
|
-
const listProjectsSchema = {
|
|
210
|
-
type: 'object',
|
|
211
|
-
properties: {
|
|
212
|
-
projects: {
|
|
213
|
-
type: 'array',
|
|
214
|
-
description: 'The names of the live Idea1 projects, most recently created first',
|
|
215
|
-
items: { type: 'string' }
|
|
216
|
-
}
|
|
217
|
-
},
|
|
218
|
-
required: ['projects'],
|
|
219
|
-
additionalProperties: false
|
|
220
|
-
};
|
|
221
252
|
let teamMembers = null;
|
|
222
253
|
/**
|
|
223
254
|
* The members of the team, read once per process: the teammates a project item can be assigned
|
|
@@ -234,11 +265,8 @@ export function listTeamMembers() {
|
|
|
234
265
|
}
|
|
235
266
|
async function readTeamMembers() {
|
|
236
267
|
logger.step('Reading the team\'s members from idea1.ai...');
|
|
237
|
-
const
|
|
238
|
-
|
|
239
|
-
throw new Error(`Claude did not return the team's members: ${JSON.stringify(output.members)}`);
|
|
240
|
-
}
|
|
241
|
-
return output.members.map(member => ({
|
|
268
|
+
const members = await call('GET', 'v1/teams/active/members', null);
|
|
269
|
+
return members.map(member => ({
|
|
242
270
|
userId: member.userId,
|
|
243
271
|
email: member.email.trim(),
|
|
244
272
|
role: member.role,
|
|
@@ -260,55 +288,25 @@ export async function resolveTeammate(identity) {
|
|
|
260
288
|
return teammate;
|
|
261
289
|
}
|
|
262
290
|
/**
|
|
263
|
-
*
|
|
264
|
-
*/
|
|
265
|
-
const listTeamMembersSchema = {
|
|
266
|
-
type: 'object',
|
|
267
|
-
properties: {
|
|
268
|
-
members: {
|
|
269
|
-
type: 'array',
|
|
270
|
-
description: 'The team\'s members, in the order returned',
|
|
271
|
-
items: {
|
|
272
|
-
type: 'object',
|
|
273
|
-
properties: {
|
|
274
|
-
userId: { type: 'string' },
|
|
275
|
-
email: { type: 'string' },
|
|
276
|
-
role: { type: 'string' },
|
|
277
|
-
gitHubUsername: { type: ['string', 'null'], description: 'The member\'s linked GitHub login, or null when none is linked' }
|
|
278
|
-
},
|
|
279
|
-
required: ['userId', 'email', 'role', 'gitHubUsername'],
|
|
280
|
-
additionalProperties: false
|
|
281
|
-
}
|
|
282
|
-
}
|
|
283
|
-
},
|
|
284
|
-
required: ['members'],
|
|
285
|
-
additionalProperties: false
|
|
286
|
-
};
|
|
287
|
-
/**
|
|
288
|
-
* Create a new idea1 project item with the given title in the named Project.
|
|
291
|
+
* Create a new idea1 project item with the given title in the named live Project.
|
|
289
292
|
* The item is created with description `# <title>`.
|
|
290
293
|
* Returns the created item's URL.
|
|
291
294
|
*/
|
|
292
295
|
export async function createProjectItem(title, projectName) {
|
|
293
296
|
logger.step(`Creating project item "${title}" in project "${projectName}"...`);
|
|
294
|
-
const
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
throw new Error(`Claude did not return a valid project item URL: ${JSON.stringify(output.projectItemUrl)}`);
|
|
297
|
+
const project = (await readLiveProjects()).find(candidate => candidate.name.trim().toLowerCase() === projectName.trim().toLowerCase());
|
|
298
|
+
if (!project) {
|
|
299
|
+
throw new Error(`The team has no live project named "${projectName}".`);
|
|
298
300
|
}
|
|
299
|
-
|
|
300
|
-
|
|
301
|
+
const summary = await callForSummary('POST', `v1/teams/active/projects/${project.projectId}/project-items`, { description: `# ${title}` });
|
|
302
|
+
logger.success(`Created project item: ${summary.url}`);
|
|
303
|
+
return summary.url;
|
|
301
304
|
}
|
|
302
305
|
/**
|
|
303
|
-
*
|
|
306
|
+
* The user the platform credential signs in as, and the team its calls work on.
|
|
304
307
|
*/
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
error: { type: ['string', 'null'], description: 'The error returned by create_item, or null when the item was created' }
|
|
310
|
-
},
|
|
311
|
-
required: ['projectItemUrl', 'error'],
|
|
312
|
-
additionalProperties: false
|
|
313
|
-
};
|
|
308
|
+
export async function getSignedInUser() {
|
|
309
|
+
const context = await call('GET', 'v1/user/core-application-context', null);
|
|
310
|
+
return { emailAddress: context.userContext.emailAddress, teamName: context.activeTeam.teamName };
|
|
311
|
+
}
|
|
314
312
|
//# sourceMappingURL=platform.js.map
|