@ycodium-ai/plugin-team 0.2.5280 → 0.2.5304
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/index.js +441 -49
- package/package.json +4 -4
package/dist/index.js
CHANGED
|
@@ -8,7 +8,7 @@ var __export = (target, all3) => {
|
|
|
8
8
|
import { definePlugin } from "@ycodium-ai/plugin-api";
|
|
9
9
|
|
|
10
10
|
// ../../packages/plugin-api/src/version.ts
|
|
11
|
-
var PLUGIN_API_VERSION =
|
|
11
|
+
var PLUGIN_API_VERSION = 161;
|
|
12
12
|
|
|
13
13
|
// ../../node_modules/.pnpm/effect@4.0.0-beta.103_patch_hash=2379c0b6f6365efdc960ef467ae589e40827f36fbfe7992e14580cecfa87fd2b/node_modules/effect/dist/Pipeable.js
|
|
14
14
|
var pipeArguments = (self, args2) => {
|
|
@@ -3030,6 +3030,15 @@ var runSyncExitWith = (context2) => {
|
|
|
3030
3030
|
};
|
|
3031
3031
|
};
|
|
3032
3032
|
var runSyncExit = /* @__PURE__ */ runSyncExitWith(/* @__PURE__ */ empty());
|
|
3033
|
+
var runSyncWith = (context2) => {
|
|
3034
|
+
const runSyncExit3 = runSyncExitWith(context2);
|
|
3035
|
+
return (effect) => {
|
|
3036
|
+
const exit3 = runSyncExit3(effect);
|
|
3037
|
+
if (exit3._tag === "Failure") throw causeSquash(exit3.cause);
|
|
3038
|
+
return exit3.value;
|
|
3039
|
+
};
|
|
3040
|
+
};
|
|
3041
|
+
var runSync = /* @__PURE__ */ runSyncWith(/* @__PURE__ */ empty());
|
|
3033
3042
|
var ClockRef = /* @__PURE__ */ Reference("effect/Clock", {
|
|
3034
3043
|
defaultValue: () => new ClockImpl()
|
|
3035
3044
|
});
|
|
@@ -3350,6 +3359,7 @@ var exit2 = exit;
|
|
|
3350
3359
|
var map5 = map3;
|
|
3351
3360
|
var catchCause2 = catchCause;
|
|
3352
3361
|
var runPromise2 = runPromise;
|
|
3362
|
+
var runSync2 = runSync;
|
|
3353
3363
|
var runSyncExit2 = runSyncExit;
|
|
3354
3364
|
var mapEager2 = mapEager;
|
|
3355
3365
|
var mapErrorEager2 = mapErrorEager;
|
|
@@ -6253,11 +6263,11 @@ function fromASTs(asts) {
|
|
|
6253
6263
|
return id;
|
|
6254
6264
|
}
|
|
6255
6265
|
function getIdentityKey(ast) {
|
|
6256
|
-
let
|
|
6266
|
+
let identity3 = ast._tag;
|
|
6257
6267
|
for (const [key, value] of Object.entries(ast)) {
|
|
6258
|
-
if (key !== "_tag" && key !== "context")
|
|
6268
|
+
if (key !== "_tag" && key !== "context") identity3 += `:${getValueId(value)}`;
|
|
6259
6269
|
}
|
|
6260
|
-
return
|
|
6270
|
+
return identity3;
|
|
6261
6271
|
}
|
|
6262
6272
|
function getCanonicalAST(ast) {
|
|
6263
6273
|
const key = getIdentityKey(ast);
|
|
@@ -7646,9 +7656,9 @@ function goalExecution(goal) {
|
|
|
7646
7656
|
members: goal === null ? [] : [...goal.threads, ...goal.remoteMembers ?? []]
|
|
7647
7657
|
};
|
|
7648
7658
|
}
|
|
7649
|
-
function findGoalMember(members,
|
|
7659
|
+
function findGoalMember(members, identity3) {
|
|
7650
7660
|
return members.find(
|
|
7651
|
-
(member) => "threadId" in
|
|
7661
|
+
(member) => "threadId" in identity3 ? "threadId" in member && member.threadId === identity3.threadId : "principalId" in member && member.principalId === identity3.principalId
|
|
7652
7662
|
);
|
|
7653
7663
|
}
|
|
7654
7664
|
|
|
@@ -10919,7 +10929,7 @@ function createMemberWriter(ctx, rosters, queue = createSerial()) {
|
|
|
10919
10929
|
const input = decoded.value;
|
|
10920
10930
|
if (input.avatar !== void 0 && input.clearAvatar === true)
|
|
10921
10931
|
return rejectMember("updateMember", "invalid-payload");
|
|
10922
|
-
let
|
|
10932
|
+
let identity3;
|
|
10923
10933
|
if (input.bindToMe !== void 0) {
|
|
10924
10934
|
const me = await meOf("updateMember", invocation);
|
|
10925
10935
|
if ("code" in me) return me;
|
|
@@ -10928,7 +10938,7 @@ function createMemberWriter(ctx, rosters, queue = createSerial()) {
|
|
|
10928
10938
|
const held = personOfMember(member);
|
|
10929
10939
|
if (held !== null && !samePerson(held, me))
|
|
10930
10940
|
return rejectMember("updateMember", "bound-to-other");
|
|
10931
|
-
|
|
10941
|
+
identity3 = input.bindToMe ? { kind: "human", principal: me } : null;
|
|
10932
10942
|
}
|
|
10933
10943
|
const result2 = await refused(
|
|
10934
10944
|
"updateMember",
|
|
@@ -10943,7 +10953,7 @@ function createMemberWriter(ctx, rosters, queue = createSerial()) {
|
|
|
10943
10953
|
...input.clearAvatar === true ? { avatar: null } : input.avatar === void 0 ? {} : { avatar: input.avatar },
|
|
10944
10954
|
...input.workInstructions === void 0 ? {} : { workInstructions: input.workInstructions },
|
|
10945
10955
|
...input.agent === void 0 ? {} : { agent: toEngineAgent(input.agent) },
|
|
10946
|
-
...
|
|
10956
|
+
...identity3 === void 0 ? {} : { identity: identity3 }
|
|
10947
10957
|
})
|
|
10948
10958
|
);
|
|
10949
10959
|
return "code" in result2 ? result2 : written(result2);
|
|
@@ -11398,14 +11408,14 @@ function pruneReviews(previous, state) {
|
|
|
11398
11408
|
return next;
|
|
11399
11409
|
}
|
|
11400
11410
|
function reviewFacts(project2, queues, lead) {
|
|
11401
|
-
const { busy, waiting } = queues;
|
|
11411
|
+
const { busy, waiting: waiting2 } = queues;
|
|
11402
11412
|
const team = scopeOfThread(project2, lead)?.threads ?? project2.threads;
|
|
11403
11413
|
return {
|
|
11404
11414
|
idle: team.filter(
|
|
11405
|
-
(threadId) => !isLeadThread(project2, threadId) && !busy.has(threadId) && (
|
|
11415
|
+
(threadId) => !isLeadThread(project2, threadId) && !busy.has(threadId) && (waiting2.get(threadId) ?? []).length === 0
|
|
11406
11416
|
),
|
|
11407
11417
|
queued: [...busy].filter((threadId) => team.includes(threadId)).flatMap(
|
|
11408
|
-
(threadId) => [...
|
|
11418
|
+
(threadId) => [...waiting2.get(threadId) ?? []].sort(compareWakeItems).map(({ workItemId, sequenceId }) => ({ workItemId, sequenceId, threadId }))
|
|
11409
11419
|
)
|
|
11410
11420
|
};
|
|
11411
11421
|
}
|
|
@@ -11452,7 +11462,7 @@ var needsMemberSlot = (wake) => wake.kind === "item" && wake.lead !== true;
|
|
|
11452
11462
|
function memberQueues(projectId, project2, woken = new Set(project2.woken), onlyThreadId) {
|
|
11453
11463
|
const isMemberThread = memberLookup(project2);
|
|
11454
11464
|
const busy = /* @__PURE__ */ new Set();
|
|
11455
|
-
const
|
|
11465
|
+
const waiting2 = /* @__PURE__ */ new Map();
|
|
11456
11466
|
for (const [workItemId, item] of Object.entries(project2.items)) {
|
|
11457
11467
|
if (onlyThreadId !== void 0 && !item.assigneeThreads.includes(onlyThreadId)) continue;
|
|
11458
11468
|
if (!isWorkable(project2, workItemId)) continue;
|
|
@@ -11470,17 +11480,17 @@ function memberQueues(projectId, project2, woken = new Set(project2.woken), only
|
|
|
11470
11480
|
isMemberThread
|
|
11471
11481
|
);
|
|
11472
11482
|
if (candidate === null || !needsMemberSlot(candidate)) continue;
|
|
11473
|
-
const queue =
|
|
11474
|
-
if (queue === void 0)
|
|
11483
|
+
const queue = waiting2.get(threadId);
|
|
11484
|
+
if (queue === void 0) waiting2.set(threadId, [candidate]);
|
|
11475
11485
|
else queue.push(candidate);
|
|
11476
11486
|
}
|
|
11477
11487
|
}
|
|
11478
|
-
return { busy, waiting };
|
|
11488
|
+
return { busy, waiting: waiting2 };
|
|
11479
11489
|
}
|
|
11480
11490
|
function memberItemSlots(projectId, project2, woken, onlyThreadId) {
|
|
11481
|
-
const { busy, waiting } = memberQueues(projectId, project2, woken, onlyThreadId);
|
|
11491
|
+
const { busy, waiting: waiting2 } = memberQueues(projectId, project2, woken, onlyThreadId);
|
|
11482
11492
|
const slots = /* @__PURE__ */ new Map();
|
|
11483
|
-
for (const [threadId, candidates] of
|
|
11493
|
+
for (const [threadId, candidates] of waiting2)
|
|
11484
11494
|
if (!busy.has(threadId))
|
|
11485
11495
|
slots.set(
|
|
11486
11496
|
threadId,
|
|
@@ -11719,7 +11729,7 @@ async function leadAddressOf(ctx, goal) {
|
|
|
11719
11729
|
return person === null ? null : { kind: "person", person, aboutThreadId: room };
|
|
11720
11730
|
}
|
|
11721
11731
|
var leadAddressKey = (address) => address.kind === "thread" ? address.threadId : address.kind === "remote" ? `${address.principalId}:${address.memberId}` : personKey(address.person);
|
|
11722
|
-
async function
|
|
11732
|
+
async function sendLeadNotice(ctx, projectId, address, note) {
|
|
11723
11733
|
if (address.kind === "thread" || address.kind === "remote") {
|
|
11724
11734
|
const wake = () => deliverWake(ctx, {
|
|
11725
11735
|
projectId,
|
|
@@ -11729,22 +11739,30 @@ async function tellLeadAt(ctx, projectId, address, note) {
|
|
|
11729
11739
|
wake: { reason: "notice" },
|
|
11730
11740
|
text: note.text
|
|
11731
11741
|
});
|
|
11732
|
-
return
|
|
11733
|
-
if (isRejection(error)) return false;
|
|
11734
|
-
throw error;
|
|
11735
|
-
});
|
|
11742
|
+
return wake();
|
|
11736
11743
|
}
|
|
11744
|
+
await ctx.communication.records.send({
|
|
11745
|
+
projectId,
|
|
11746
|
+
requestId: note.requestId,
|
|
11747
|
+
to: { person: address.person },
|
|
11748
|
+
aboutThreadId: address.aboutThreadId,
|
|
11749
|
+
text: note.text
|
|
11750
|
+
});
|
|
11751
|
+
return true;
|
|
11752
|
+
}
|
|
11753
|
+
async function tellLeadAt(ctx, projectId, address, note) {
|
|
11737
11754
|
try {
|
|
11738
|
-
await ctx
|
|
11739
|
-
|
|
11740
|
-
|
|
11741
|
-
|
|
11742
|
-
|
|
11743
|
-
|
|
11744
|
-
|
|
11745
|
-
|
|
11755
|
+
return await sendLeadNotice(ctx, projectId, address, note);
|
|
11756
|
+
} catch (error) {
|
|
11757
|
+
if (address.kind !== "thread" && isRejection(error)) return false;
|
|
11758
|
+
throw error;
|
|
11759
|
+
}
|
|
11760
|
+
}
|
|
11761
|
+
async function tellLeadForWait(ctx, projectId, address, note) {
|
|
11762
|
+
try {
|
|
11763
|
+
return await sendLeadNotice(ctx, projectId, address, note) ? "sent" : "unavailable";
|
|
11746
11764
|
} catch (error) {
|
|
11747
|
-
if (isRejection(error)) return
|
|
11765
|
+
if (isRejection(error)) return "rejected";
|
|
11748
11766
|
throw error;
|
|
11749
11767
|
}
|
|
11750
11768
|
}
|
|
@@ -13259,7 +13277,7 @@ function startWakeRuntime(ctx, goals, options = {}) {
|
|
|
13259
13277
|
};
|
|
13260
13278
|
})()
|
|
13261
13279
|
});
|
|
13262
|
-
const
|
|
13280
|
+
const waiting2 = team === void 0 || !("threadId" in wake) || team.scope.leadThreads?.includes(wake.threadId) !== true || options.teamWaiting === void 0 ? null : await (async () => {
|
|
13263
13281
|
const members = (await goals.read(wake.projectId, { forThread: wake.threadId }))?.members ?? [];
|
|
13264
13282
|
return options.teamWaiting(
|
|
13265
13283
|
team.scope.threads.filter((id) => id !== wake.threadId),
|
|
@@ -13270,7 +13288,7 @@ function startWakeRuntime(ctx, goals, options = {}) {
|
|
|
13270
13288
|
digest,
|
|
13271
13289
|
text: async () => {
|
|
13272
13290
|
const body = await baseText(wake, state);
|
|
13273
|
-
return [digest?.body, body,
|
|
13291
|
+
return [digest?.body, body, waiting2].filter((part2) => part2 != null).join("\n\n");
|
|
13274
13292
|
}
|
|
13275
13293
|
};
|
|
13276
13294
|
};
|
|
@@ -13724,9 +13742,9 @@ function createCapacityLedger() {
|
|
|
13724
13742
|
const waits = /* @__PURE__ */ new Map();
|
|
13725
13743
|
return {
|
|
13726
13744
|
/** 这一刻会话是否在排队等名额;同一刻重复采样不要紧。 */
|
|
13727
|
-
observe(threadId,
|
|
13745
|
+
observe(threadId, waiting2, at) {
|
|
13728
13746
|
const known = waits.get(threadId) ?? { open: null, closed: [] };
|
|
13729
|
-
if (
|
|
13747
|
+
if (waiting2) {
|
|
13730
13748
|
if (known.open === null) waits.set(threadId, { ...known, open: at });
|
|
13731
13749
|
return;
|
|
13732
13750
|
}
|
|
@@ -13937,14 +13955,14 @@ function startProgressCheckinRuntime(ctx, goals, wakes, now3 = factTime) {
|
|
|
13937
13955
|
let mountedAt = 0;
|
|
13938
13956
|
const ask = async (item, who, memberId, clock, at) => {
|
|
13939
13957
|
const target = "threadId" in who ? void 0 : who.memberId ?? memberId;
|
|
13940
|
-
const
|
|
13958
|
+
const identity3 = askKey(who, target);
|
|
13941
13959
|
const machine = recipientKey(who);
|
|
13942
|
-
const sharedAsks =
|
|
13960
|
+
const sharedAsks = identity3 === machine ? [] : item.asks[machine] ?? [];
|
|
13943
13961
|
const since = later(
|
|
13944
|
-
later(clock.since, item.acted[
|
|
13945
|
-
|
|
13962
|
+
later(clock.since, item.acted[identity3]),
|
|
13963
|
+
identity3 === machine ? void 0 : item.acted[machine]
|
|
13946
13964
|
);
|
|
13947
|
-
const asked = [...item.asks[
|
|
13965
|
+
const asked = [...item.asks[identity3] ?? [], ...sharedAsks].filter((time) => Date.parse(time) > Date.parse(since)).toSorted();
|
|
13948
13966
|
if (asked.length >= PROGRESS_CHECKIN_LIMIT) return;
|
|
13949
13967
|
const from = Date.parse(asked.at(-1) ?? since);
|
|
13950
13968
|
const counted = Math.max(from, mountedAt);
|
|
@@ -13955,7 +13973,7 @@ function startProgressCheckinRuntime(ctx, goals, wakes, now3 = factTime) {
|
|
|
13955
13973
|
const key = stableHash(
|
|
13956
13974
|
`${item.projectId}
|
|
13957
13975
|
${item.workItemId}
|
|
13958
|
-
${
|
|
13976
|
+
${identity3}
|
|
13959
13977
|
${since}
|
|
13960
13978
|
${asked.length}`
|
|
13961
13979
|
);
|
|
@@ -14033,6 +14051,379 @@ ${asked.length}`
|
|
|
14033
14051
|
ctx.interval({ name: "team-progress-checkin", everyMs: TICK_MS, handle: tick });
|
|
14034
14052
|
}
|
|
14035
14053
|
|
|
14054
|
+
// src/runtime/memberWaitingNotice.ts
|
|
14055
|
+
import { projectOrNull as projectOrNull3 } from "@ycodium-ai/plugin-api";
|
|
14056
|
+
|
|
14057
|
+
// src/runtime/memberWaitTarget.ts
|
|
14058
|
+
async function goalForWaitingMember(ctx, projectId, row, goals) {
|
|
14059
|
+
if (row.environmentId === ctx.environment.id)
|
|
14060
|
+
return goals.find(
|
|
14061
|
+
(goal) => goal.projectId === projectId && goal.threads.some(
|
|
14062
|
+
(thread) => thread.threadId === row.threadId && thread.memberId === row.memberId
|
|
14063
|
+
)
|
|
14064
|
+
) ?? null;
|
|
14065
|
+
if (row.workItemId === void 0) return null;
|
|
14066
|
+
const result2 = await ctx.work.items.get({
|
|
14067
|
+
projectId,
|
|
14068
|
+
workItemIds: [row.workItemId],
|
|
14069
|
+
textLimit: 2
|
|
14070
|
+
});
|
|
14071
|
+
const item = result2.items.find(
|
|
14072
|
+
(item2) => item2.projectId === projectId && item2.workItemId === row.workItemId
|
|
14073
|
+
);
|
|
14074
|
+
if (item?.workLineId === void 0) return null;
|
|
14075
|
+
return goals.find(
|
|
14076
|
+
(goal) => goal.projectId === projectId && goal.workLineId === item.workLineId && goal.remoteMembers?.some((member) => member.memberId === row.memberId)
|
|
14077
|
+
) ?? null;
|
|
14078
|
+
}
|
|
14079
|
+
|
|
14080
|
+
// src/runtime/memberWaitingNotice.ts
|
|
14081
|
+
var waiting = (row) => row.waitId !== void 0 && row.online && row.stale !== true && ["needs-approval", "needs-input", "plan-ready"].includes(row.status);
|
|
14082
|
+
var identity2 = (projectId, row) => `member-wait:${stableHash(JSON.stringify([projectId, row.memberId, row.threadId, row.waitId]))}`;
|
|
14083
|
+
var backoff = (failures) => Math.min(6e4, 1e3 * 2 ** Math.min(failures - 1, 6));
|
|
14084
|
+
var object = (value) => typeof value === "object" && value !== null ? value : null;
|
|
14085
|
+
var permanent = (error) => {
|
|
14086
|
+
const value = object(error);
|
|
14087
|
+
return value?._tag === "EnvironmentAuthorizationError" || value?._tag === "MemberReadError" && value.reason === "project-not-found";
|
|
14088
|
+
};
|
|
14089
|
+
function startMemberWaitingNotice(ctx, goals, options = {}) {
|
|
14090
|
+
const now3 = options.now ?? (() => runSync2(currentTimeMillis2));
|
|
14091
|
+
const watches = /* @__PURE__ */ new Map();
|
|
14092
|
+
const forbidden2 = /* @__PURE__ */ new Map();
|
|
14093
|
+
const finished = /* @__PURE__ */ new Set();
|
|
14094
|
+
const finish = (key) => {
|
|
14095
|
+
finished.add(key);
|
|
14096
|
+
if (finished.size > 1e4) finished.delete(finished.values().next().value);
|
|
14097
|
+
};
|
|
14098
|
+
const reconcileQueue = createSerial("member-waiting-closed");
|
|
14099
|
+
let disposed = false;
|
|
14100
|
+
let nextReconcile = 0;
|
|
14101
|
+
const alive = (watch) => !disposed && !watch.closed && watches.get(watch.projectId) === watch;
|
|
14102
|
+
const enqueue = (watch, execute) => {
|
|
14103
|
+
const result2 = watch.pending.then(async () => {
|
|
14104
|
+
if (alive(watch)) await execute();
|
|
14105
|
+
});
|
|
14106
|
+
watch.pending = result2.catch(
|
|
14107
|
+
(error) => ctx.log.warn("member waiting callback failed", { error })
|
|
14108
|
+
);
|
|
14109
|
+
return watch.pending;
|
|
14110
|
+
};
|
|
14111
|
+
const sendDue = async (watch) => {
|
|
14112
|
+
if (!alive(watch) || !watch.eligible) return;
|
|
14113
|
+
for (const [key, job] of watch.jobs) {
|
|
14114
|
+
if (job.parked || job.due > now3() || finished.has(key)) continue;
|
|
14115
|
+
try {
|
|
14116
|
+
const goal = await goalForWaitingMember(ctx, watch.projectId, job.row, watch.goals);
|
|
14117
|
+
if (!alive(watch) || !watch.eligible) return;
|
|
14118
|
+
if (goal === null || goal.leadMemberId === job.row.memberId) {
|
|
14119
|
+
job.parked = true;
|
|
14120
|
+
continue;
|
|
14121
|
+
}
|
|
14122
|
+
job.workLineId = goal.workLineId;
|
|
14123
|
+
job.goalId = goal.goalId;
|
|
14124
|
+
job.leadMemberId = goal.leadMemberId;
|
|
14125
|
+
const address = await leadAddressOf(ctx, goal);
|
|
14126
|
+
if (!alive(watch) || !watch.eligible) return;
|
|
14127
|
+
if (address === null) {
|
|
14128
|
+
job.parked = true;
|
|
14129
|
+
continue;
|
|
14130
|
+
}
|
|
14131
|
+
job.address = address;
|
|
14132
|
+
const result2 = await tellLeadForWait(ctx, watch.projectId, address, {
|
|
14133
|
+
requestId: key,
|
|
14134
|
+
text: `Member ${job.row.memberId} is waiting for a person (${job.row.status}) in conversation ${job.row.threadId}.${job.row.requestSummary ? ` ${job.row.requestSummary}` : ""}`
|
|
14135
|
+
});
|
|
14136
|
+
if (result2 === "unavailable") job.parked = true;
|
|
14137
|
+
else {
|
|
14138
|
+
finish(key);
|
|
14139
|
+
watch.jobs.delete(key);
|
|
14140
|
+
}
|
|
14141
|
+
} catch (error) {
|
|
14142
|
+
job.due = now3() + backoff(++job.failures);
|
|
14143
|
+
if (job.failures === 1)
|
|
14144
|
+
ctx.log.warn("member waiting notice will retry", { projectId: watch.projectId, error });
|
|
14145
|
+
}
|
|
14146
|
+
}
|
|
14147
|
+
};
|
|
14148
|
+
const receive = (watch, rows) => enqueue(watch, async () => {
|
|
14149
|
+
watch.rows = rows;
|
|
14150
|
+
if (!watch.eligible) return;
|
|
14151
|
+
const current = /* @__PURE__ */ new Set();
|
|
14152
|
+
for (const row of rows) {
|
|
14153
|
+
if (!waiting(row)) continue;
|
|
14154
|
+
const key = identity2(watch.projectId, row);
|
|
14155
|
+
current.add(key);
|
|
14156
|
+
if (finished.has(key)) continue;
|
|
14157
|
+
const known = watch.jobs.get(key);
|
|
14158
|
+
if (known) known.row = row;
|
|
14159
|
+
else watch.jobs.set(key, { row, due: 0, failures: 0, parked: false });
|
|
14160
|
+
}
|
|
14161
|
+
for (const key of watch.jobs.keys()) if (!current.has(key)) watch.jobs.delete(key);
|
|
14162
|
+
await sendDue(watch);
|
|
14163
|
+
});
|
|
14164
|
+
const connect = (watch) => {
|
|
14165
|
+
if (!alive(watch) || !watch.eligible || watch.connected || watch.reconnectAt > now3()) return;
|
|
14166
|
+
watch.connected = true;
|
|
14167
|
+
watch.stream = ctx.members.runtime.subscribe(
|
|
14168
|
+
{ projectId: watch.projectId },
|
|
14169
|
+
async (frame) => {
|
|
14170
|
+
if (frame._tag === "snapshot" && alive(watch)) {
|
|
14171
|
+
watch.streamFailures = 0;
|
|
14172
|
+
await receive(watch, frame.value.items);
|
|
14173
|
+
}
|
|
14174
|
+
},
|
|
14175
|
+
watch.controller.signal
|
|
14176
|
+
).then(
|
|
14177
|
+
() => {
|
|
14178
|
+
if (alive(watch)) watch.reconnectAt = now3() + backoff(++watch.streamFailures);
|
|
14179
|
+
},
|
|
14180
|
+
(error) => {
|
|
14181
|
+
if (!alive(watch)) return;
|
|
14182
|
+
if (permanent(error)) {
|
|
14183
|
+
forbidden2.set(
|
|
14184
|
+
watch.projectId,
|
|
14185
|
+
object(error)?._tag === "EnvironmentAuthorizationError" ? "authorization" : "project"
|
|
14186
|
+
);
|
|
14187
|
+
watch.eligible = false;
|
|
14188
|
+
watch.closed = true;
|
|
14189
|
+
watch.controller.abort();
|
|
14190
|
+
watch.jobs.clear();
|
|
14191
|
+
} else watch.reconnectAt = now3() + backoff(++watch.streamFailures);
|
|
14192
|
+
}
|
|
14193
|
+
).finally(() => {
|
|
14194
|
+
watch.connected = false;
|
|
14195
|
+
});
|
|
14196
|
+
};
|
|
14197
|
+
const close = async (watch) => {
|
|
14198
|
+
watch.closed = true;
|
|
14199
|
+
watch.controller.abort();
|
|
14200
|
+
await watch.stream;
|
|
14201
|
+
await watch.pending;
|
|
14202
|
+
if (watches.get(watch.projectId) === watch) watches.delete(watch.projectId);
|
|
14203
|
+
};
|
|
14204
|
+
const activeGoals = async (projectId, candidates) => {
|
|
14205
|
+
const active = [];
|
|
14206
|
+
for (const goal of candidates) {
|
|
14207
|
+
if (goal.workLineId !== void 0) {
|
|
14208
|
+
try {
|
|
14209
|
+
const { line } = await ctx.work.lines.get({ projectId, workLineId: goal.workLineId });
|
|
14210
|
+
if (line.archivedAt !== null) continue;
|
|
14211
|
+
} catch (error) {
|
|
14212
|
+
const failure = object(error);
|
|
14213
|
+
if (failure?._tag === "WorkReadError" && failure.reason === "work-line-not-found")
|
|
14214
|
+
continue;
|
|
14215
|
+
throw error;
|
|
14216
|
+
}
|
|
14217
|
+
} else {
|
|
14218
|
+
const result2 = await ctx.work.items.get({
|
|
14219
|
+
projectId,
|
|
14220
|
+
workItemIds: [teamGoalItemId(projectId, goal.goalId)],
|
|
14221
|
+
textLimit: 2
|
|
14222
|
+
});
|
|
14223
|
+
const item = result2.items[0];
|
|
14224
|
+
if (item && (item.archivedAt !== null || ["completed", "cancelled"].includes(item.state.group)))
|
|
14225
|
+
continue;
|
|
14226
|
+
}
|
|
14227
|
+
active.push(goal);
|
|
14228
|
+
}
|
|
14229
|
+
return active;
|
|
14230
|
+
};
|
|
14231
|
+
const reconcile = () => reconcileQueue.run(async () => {
|
|
14232
|
+
if (disposed) return;
|
|
14233
|
+
nextReconcile = now3() + 6e4;
|
|
14234
|
+
let all3;
|
|
14235
|
+
try {
|
|
14236
|
+
all3 = await goals.everyGoal();
|
|
14237
|
+
} catch (error) {
|
|
14238
|
+
for (const watch of watches.values()) watch.eligible = false;
|
|
14239
|
+
nextReconcile = now3() + 1e3;
|
|
14240
|
+
throw error;
|
|
14241
|
+
}
|
|
14242
|
+
const projects = new Set(all3.map((goal) => goal.projectId));
|
|
14243
|
+
for (const watch of watches.values()) if (!projects.has(watch.projectId)) await close(watch);
|
|
14244
|
+
for (const projectId of projects) {
|
|
14245
|
+
if (disposed || forbidden2.has(projectId)) continue;
|
|
14246
|
+
const existing = watches.get(projectId);
|
|
14247
|
+
if (existing) existing.eligible = false;
|
|
14248
|
+
let selected;
|
|
14249
|
+
try {
|
|
14250
|
+
const project2 = await projectOrNull3(ctx.projects, projectId);
|
|
14251
|
+
if (disposed) return;
|
|
14252
|
+
if (project2 === null || project2.archivedAt !== null || project2.homeEnvironmentId != null && project2.homeEnvironmentId !== ctx.environment.id) {
|
|
14253
|
+
const watch2 = watches.get(projectId);
|
|
14254
|
+
if (watch2) await close(watch2);
|
|
14255
|
+
continue;
|
|
14256
|
+
}
|
|
14257
|
+
selected = await activeGoals(
|
|
14258
|
+
projectId,
|
|
14259
|
+
all3.filter((goal) => goal.projectId === projectId)
|
|
14260
|
+
);
|
|
14261
|
+
} catch {
|
|
14262
|
+
const watch2 = watches.get(projectId);
|
|
14263
|
+
if (watch2) watch2.eligible = false;
|
|
14264
|
+
nextReconcile = Math.min(nextReconcile, now3() + 1e3);
|
|
14265
|
+
continue;
|
|
14266
|
+
}
|
|
14267
|
+
if (disposed) return;
|
|
14268
|
+
let watch = watches.get(projectId);
|
|
14269
|
+
if (selected.length === 0) {
|
|
14270
|
+
if (watch) await close(watch);
|
|
14271
|
+
continue;
|
|
14272
|
+
}
|
|
14273
|
+
if (watch?.closed) {
|
|
14274
|
+
await close(watch);
|
|
14275
|
+
watch = void 0;
|
|
14276
|
+
}
|
|
14277
|
+
if (!watch) {
|
|
14278
|
+
watch = {
|
|
14279
|
+
projectId,
|
|
14280
|
+
goals: selected,
|
|
14281
|
+
eligible: true,
|
|
14282
|
+
closed: false,
|
|
14283
|
+
controller: new AbortController(),
|
|
14284
|
+
stream: Promise.resolve(),
|
|
14285
|
+
pending: Promise.resolve(),
|
|
14286
|
+
jobs: /* @__PURE__ */ new Map(),
|
|
14287
|
+
reconnectAt: 0,
|
|
14288
|
+
streamFailures: 0,
|
|
14289
|
+
connected: false
|
|
14290
|
+
};
|
|
14291
|
+
watches.set(projectId, watch);
|
|
14292
|
+
} else {
|
|
14293
|
+
if (JSON.stringify(watch.goals) !== JSON.stringify(selected)) {
|
|
14294
|
+
for (const job of watch.jobs.values()) {
|
|
14295
|
+
if (job.parked && job.address === void 0) {
|
|
14296
|
+
job.parked = false;
|
|
14297
|
+
job.due = 0;
|
|
14298
|
+
}
|
|
14299
|
+
}
|
|
14300
|
+
}
|
|
14301
|
+
watch.goals = selected;
|
|
14302
|
+
watch.eligible = true;
|
|
14303
|
+
}
|
|
14304
|
+
connect(watch);
|
|
14305
|
+
if (watch.rows) await receive(watch, watch.rows);
|
|
14306
|
+
else await enqueue(watch, () => sendDue(watch));
|
|
14307
|
+
}
|
|
14308
|
+
});
|
|
14309
|
+
const invalidate = async (event) => {
|
|
14310
|
+
const payload = object(event.payload);
|
|
14311
|
+
for (const watch of watches.values()) {
|
|
14312
|
+
if (payload?.projectId !== void 0 && payload.projectId !== watch.projectId) continue;
|
|
14313
|
+
await enqueue(watch, async () => {
|
|
14314
|
+
const invalid2 = (row) => event.type === "member.removed" ? row.memberId === payload?.memberId : row.threadId === payload?.threadId;
|
|
14315
|
+
if (watch.rows)
|
|
14316
|
+
watch.rows = watch.rows.filter((row) => {
|
|
14317
|
+
if (!invalid2(row)) return true;
|
|
14318
|
+
finish(identity2(watch.projectId, row));
|
|
14319
|
+
return false;
|
|
14320
|
+
});
|
|
14321
|
+
for (const [key, job] of watch.jobs) if (invalid2(job.row)) watch.jobs.delete(key);
|
|
14322
|
+
});
|
|
14323
|
+
}
|
|
14324
|
+
};
|
|
14325
|
+
const recover = (event) => {
|
|
14326
|
+
if (event.type === "member.removed" || event.type === "thread.deleted")
|
|
14327
|
+
return invalidate(event);
|
|
14328
|
+
const payload = object(event.payload);
|
|
14329
|
+
const projectId = typeof payload?.projectId === "string" ? payload.projectId : event.aggregateKind === "project" ? event.aggregateId : void 0;
|
|
14330
|
+
const threadId = typeof payload?.threadId === "string" ? payload.threadId : void 0;
|
|
14331
|
+
const workItemId = typeof payload?.workItemId === "string" ? payload.workItemId : void 0;
|
|
14332
|
+
const workLineId = typeof payload?.workLineId === "string" ? payload.workLineId : void 0;
|
|
14333
|
+
const memberId = typeof payload?.memberId === "string" ? payload.memberId : void 0;
|
|
14334
|
+
const fact = object(payload?.data);
|
|
14335
|
+
const factGoal = object(fact?.goal);
|
|
14336
|
+
const goalId = typeof fact?.goalId === "string" ? fact.goalId : typeof factGoal?.goalId === "string" ? factGoal.goalId : void 0;
|
|
14337
|
+
if (event.type === "plugin.event-appended" && (payload?.pluginId !== "team" || !["team/goal-started", "team/member-bound", "team/roster-set"].includes(
|
|
14338
|
+
String(payload.name)
|
|
14339
|
+
)))
|
|
14340
|
+
return Promise.resolve();
|
|
14341
|
+
if (event.type === "thread.session-set" && ![...watches.values()].some(
|
|
14342
|
+
(watch) => [...watch.jobs.values()].some(
|
|
14343
|
+
(job) => job.parked && job.address?.kind === "thread" && job.address.threadId === threadId
|
|
14344
|
+
)
|
|
14345
|
+
))
|
|
14346
|
+
return Promise.resolve();
|
|
14347
|
+
if (event.type === "work.item-updated" && ![...watches.values()].some(
|
|
14348
|
+
(watch) => [...watch.jobs.values()].some((job) => job.row.workItemId === workItemId) || watch.goals.some(
|
|
14349
|
+
(goal) => goal.workLineId === void 0 && teamGoalItemId(goal.projectId, goal.goalId) === workItemId
|
|
14350
|
+
)
|
|
14351
|
+
))
|
|
14352
|
+
return Promise.resolve();
|
|
14353
|
+
for (const watch of watches.values()) {
|
|
14354
|
+
if (projectId !== void 0 && projectId !== watch.projectId) continue;
|
|
14355
|
+
for (const job of watch.jobs.values()) {
|
|
14356
|
+
const changedWork = event.type === "work.item-updated" && job.row.workItemId === workItemId;
|
|
14357
|
+
if (event.type === "work.item-updated" && !changedWork && workItemId !== teamGoalItemId(watch.projectId, job.goalId ?? ""))
|
|
14358
|
+
continue;
|
|
14359
|
+
if (!changedWork && workLineId !== void 0 && job.workLineId !== workLineId) continue;
|
|
14360
|
+
if (goalId !== void 0 && job.goalId !== goalId) continue;
|
|
14361
|
+
if (memberId !== void 0 && job.row.memberId !== memberId && job.leadMemberId !== memberId)
|
|
14362
|
+
continue;
|
|
14363
|
+
const matches = threadId !== void 0 ? job.address?.kind === "thread" && job.address.threadId === threadId : projectId === watch.projectId;
|
|
14364
|
+
if (matches) {
|
|
14365
|
+
job.parked = false;
|
|
14366
|
+
job.due = 0;
|
|
14367
|
+
}
|
|
14368
|
+
}
|
|
14369
|
+
}
|
|
14370
|
+
if (projectId !== void 0 && forbidden2.get(projectId) !== "authorization" && (["project.created", "project.unarchived"].includes(event.type) || event.type === "project.meta-updated" && payload !== null && Object.hasOwn(payload, "homeEnvironmentId")))
|
|
14371
|
+
forbidden2.delete(projectId);
|
|
14372
|
+
return reconcile();
|
|
14373
|
+
};
|
|
14374
|
+
const stopEvents = ctx.reactor({
|
|
14375
|
+
name: "team-member-waiting",
|
|
14376
|
+
events: [
|
|
14377
|
+
"project.created",
|
|
14378
|
+
"project.meta-updated",
|
|
14379
|
+
"project.deleted",
|
|
14380
|
+
"project.archived",
|
|
14381
|
+
"project.unarchived",
|
|
14382
|
+
"work.line-updated",
|
|
14383
|
+
"work.line-restored",
|
|
14384
|
+
"work.line-archived",
|
|
14385
|
+
"work.line-deleted",
|
|
14386
|
+
"work.item-updated",
|
|
14387
|
+
"member.updated",
|
|
14388
|
+
"member.restored",
|
|
14389
|
+
"member.removed",
|
|
14390
|
+
"thread.deleted",
|
|
14391
|
+
"thread.unarchived",
|
|
14392
|
+
"thread.session-set",
|
|
14393
|
+
"plugin.event-appended"
|
|
14394
|
+
],
|
|
14395
|
+
handle: recover
|
|
14396
|
+
});
|
|
14397
|
+
const stopTick = ctx.interval({
|
|
14398
|
+
name: "team-member-waiting-retry",
|
|
14399
|
+
everyMs: 1e3,
|
|
14400
|
+
handle: async () => {
|
|
14401
|
+
if (disposed) return;
|
|
14402
|
+
if (now3() >= nextReconcile) await reconcile();
|
|
14403
|
+
for (const watch of watches.values()) {
|
|
14404
|
+
connect(watch);
|
|
14405
|
+
await enqueue(watch, () => sendDue(watch));
|
|
14406
|
+
}
|
|
14407
|
+
}
|
|
14408
|
+
});
|
|
14409
|
+
ctx.onDispose(async () => {
|
|
14410
|
+
disposed = true;
|
|
14411
|
+
stopEvents();
|
|
14412
|
+
stopTick();
|
|
14413
|
+
for (const watch of watches.values()) {
|
|
14414
|
+
watch.closed = true;
|
|
14415
|
+
watch.controller.abort();
|
|
14416
|
+
}
|
|
14417
|
+
await reconcileQueue.close();
|
|
14418
|
+
await Promise.all([...watches.values()].map(close));
|
|
14419
|
+
});
|
|
14420
|
+
const ready = reconcile();
|
|
14421
|
+
void ready.catch(
|
|
14422
|
+
(error) => ctx.log.warn("member waiting subscription catch-up failed", { error })
|
|
14423
|
+
);
|
|
14424
|
+
return { ready };
|
|
14425
|
+
}
|
|
14426
|
+
|
|
14036
14427
|
// src/handbook/content.ts
|
|
14037
14428
|
async function releaseRefs(memory, projectId, release) {
|
|
14038
14429
|
return release === 0 ? [] : (await memory.handbook.releases.get({ projectId, release })).pages;
|
|
@@ -16685,8 +17076,8 @@ async function teamWaitingList(ctx, memberThreads, nameOf2) {
|
|
|
16685
17076
|
return parts.length === 0 ? [] : [`${nameOf2(threadId)}: ${parts.join(", ")}`];
|
|
16686
17077
|
})
|
|
16687
17078
|
);
|
|
16688
|
-
const
|
|
16689
|
-
return
|
|
17079
|
+
const waiting2 = rows.flat();
|
|
17080
|
+
return waiting2.length === 0 ? null : `${count(waiting2.length, "member is", "members are")} waiting on the person: ${waiting2.join("; ")}. These appear in this conversation for the person to answer; you cannot answer them and should not wait for them. Hand out work to members who are not blocked.`;
|
|
16690
17081
|
}
|
|
16691
17082
|
|
|
16692
17083
|
// src/team/groupDigest.ts
|
|
@@ -18014,12 +18405,12 @@ function waitingWording(machine) {
|
|
|
18014
18405
|
machine: machine.name
|
|
18015
18406
|
};
|
|
18016
18407
|
}
|
|
18017
|
-
async function tellWaiting(env,
|
|
18408
|
+
async function tellWaiting(env, waiting2, ledger, runnable) {
|
|
18018
18409
|
for (const fact of ledger.unrecorded.values())
|
|
18019
18410
|
if (await runnable(fact.projectId)) await recordTold(env, ledger, fact);
|
|
18020
18411
|
const { settled } = ledger;
|
|
18021
18412
|
const groups = /* @__PURE__ */ new Map();
|
|
18022
|
-
for (const row of
|
|
18413
|
+
for (const row of waiting2) {
|
|
18023
18414
|
const { record: record2 } = row;
|
|
18024
18415
|
const { environmentId } = record2.spec;
|
|
18025
18416
|
for (const leadThreadId of await openLeadThreads(env, record2)) {
|
|
@@ -18324,16 +18715,16 @@ function startTrialRuntime(ctx, deps, options = {}) {
|
|
|
18324
18715
|
[...pendingTrials(snapshot), ...runningTrials(snapshot)].map(trialIdOfRecord)
|
|
18325
18716
|
);
|
|
18326
18717
|
for (const id of stuck.keys()) if (!open.has(id) || ensured.has(id)) stuck.delete(id);
|
|
18327
|
-
const
|
|
18718
|
+
const waiting2 = [];
|
|
18328
18719
|
for (const record2 of runningTrials(snapshot)) {
|
|
18329
18720
|
const since = ensured.get(trialIdOfRecord(record2));
|
|
18330
18721
|
if (record2.route !== "remote" || record2.phase !== "dispatched" || since === void 0)
|
|
18331
18722
|
continue;
|
|
18332
18723
|
if (!await runnable(record2.projectId)) continue;
|
|
18333
18724
|
if (at - since >= waitingNotice)
|
|
18334
|
-
|
|
18725
|
+
waiting2.push({ record: record2, minutes: Math.floor((at - since) / 6e4) });
|
|
18335
18726
|
}
|
|
18336
|
-
await tellWaiting(env,
|
|
18727
|
+
await tellWaiting(env, waiting2, waitingSettled, runnable).catch(guard("waiting notice"));
|
|
18337
18728
|
};
|
|
18338
18729
|
const flush = () => serial(execute);
|
|
18339
18730
|
const failOnSessionError = (event) => serial(async () => {
|
|
@@ -18515,6 +18906,7 @@ var index_default = definePlugin({
|
|
|
18515
18906
|
registerGoalCommands(ctx, goals);
|
|
18516
18907
|
registerCoordinator(ctx, startCoordinatorRuntime(ctx, { goals, rosters, queue: memberQueue }));
|
|
18517
18908
|
const readiness = readinessReader(trialState);
|
|
18909
|
+
startMemberWaitingNotice(ctx, goals);
|
|
18518
18910
|
const groupDigest = createGroupDigest(ctx, ctx.derivedState(groupDigestStateDefinition));
|
|
18519
18911
|
const wakes = startWakeRuntime(ctx, goals, {
|
|
18520
18912
|
readiness,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ycodium-ai/plugin-team",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.5304",
|
|
4
4
|
"description": "A project team roster with members, a lead, and goals.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"teams",
|
|
@@ -34,10 +34,10 @@
|
|
|
34
34
|
"tailwindcss": "^4.0.0",
|
|
35
35
|
"typescript": "~6.0.3",
|
|
36
36
|
"vite-plus": "0.2.2",
|
|
37
|
-
"@ycodium-ai/plugin-api": "0.2.
|
|
37
|
+
"@ycodium-ai/plugin-api": "0.2.5304",
|
|
38
38
|
"ycodium-full-access-mode": "0.0.0",
|
|
39
|
-
"ycodium-
|
|
40
|
-
"ycodium-
|
|
39
|
+
"ycodium-system-text": "0.0.0",
|
|
40
|
+
"ycodium-react-test-harness": "0.0.0"
|
|
41
41
|
},
|
|
42
42
|
"ycodium": {
|
|
43
43
|
"plugin": "./dist/index.js",
|