@primusclaw/personal-agent-runtime 0.10.3 → 0.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/dist/index.js +113 -1
- package/dist/sqlite/schema.sql +4 -0
- package/dist/types/sqlite/github-repository.d.ts +22 -2
- package/dist/worker.js +8 -0
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -3359,7 +3359,8 @@ var SqliteFeedbackRepository = class {
|
|
|
3359
3359
|
|
|
3360
3360
|
// packages/runtime/src/sqlite/github-repository.ts
|
|
3361
3361
|
import {
|
|
3362
|
-
ACTING_SESSION_KEEP_SECONDS
|
|
3362
|
+
ACTING_SESSION_KEEP_SECONDS,
|
|
3363
|
+
REVIEW_ONBOARDING_KEEP_SECONDS
|
|
3363
3364
|
} from "@primusclaw/personal-agent";
|
|
3364
3365
|
var CONFIRMATION_COLUMNS = "confirmation_id, session_id, actor_aad, requester_aad, repo, pr, reference_json, expires_at, state, created_at, kind, event";
|
|
3365
3366
|
function confirmation(row) {
|
|
@@ -3378,6 +3379,23 @@ function confirmation(row) {
|
|
|
3378
3379
|
event: col.str(row, "event")
|
|
3379
3380
|
};
|
|
3380
3381
|
}
|
|
3382
|
+
var ONBOARDING_DONE = 1;
|
|
3383
|
+
var ONBOARDING_DECLINED = 2;
|
|
3384
|
+
var ONBOARDING_DECLINED_TELLING = 3;
|
|
3385
|
+
var ONBOARDING_COLUMNS = "onboarding_id, actor_aad, requester_aad, pulls, request_json, told_rank, done, created_at";
|
|
3386
|
+
function onboarding(row) {
|
|
3387
|
+
return {
|
|
3388
|
+
onboardingId: col.str(row, "onboarding_id"),
|
|
3389
|
+
actorId: col.str(row, "actor_aad"),
|
|
3390
|
+
requesterId: col.str(row, "requester_aad"),
|
|
3391
|
+
pulls: col.str(row, "pulls"),
|
|
3392
|
+
request: storedObject(col.str(row, "request_json")) ?? {},
|
|
3393
|
+
toldRank: col.num(row, "told_rank"),
|
|
3394
|
+
done: col.num(row, "done") === ONBOARDING_DONE,
|
|
3395
|
+
declined: col.num(row, "done") >= ONBOARDING_DECLINED,
|
|
3396
|
+
createdAt: col.num(row, "created_at")
|
|
3397
|
+
};
|
|
3398
|
+
}
|
|
3381
3399
|
var SqliteGithubConfirmationRepository = class {
|
|
3382
3400
|
constructor(ctx) {
|
|
3383
3401
|
this.ctx = ctx;
|
|
@@ -3508,6 +3526,100 @@ var SqliteReviewDelegationRepository = class {
|
|
|
3508
3526
|
releaseGithubNotice(userId, kind) {
|
|
3509
3527
|
this.ctx.db.run("DELETE FROM github_notices WHERE aad_id = ? AND kind = ?", userId, kind);
|
|
3510
3528
|
}
|
|
3529
|
+
saveReviewOnboarding(o) {
|
|
3530
|
+
const { db } = this.ctx;
|
|
3531
|
+
const now = this.ctx.now();
|
|
3532
|
+
db.run("DELETE FROM review_onboarding WHERE created_at < ?", now - REVIEW_ONBOARDING_KEEP_SECONDS);
|
|
3533
|
+
db.run(
|
|
3534
|
+
"INSERT INTO review_onboarding (onboarding_id, actor_aad, requester_aad, pulls, request_json, told_rank, created_at) VALUES (?, ?, ?, ?, ?, ?, ?) ON CONFLICT (actor_aad, requester_aad, pulls) DO UPDATE SET onboarding_id = excluded.onboarding_id, request_json = excluded.request_json, told_rank = excluded.told_rank, done = 0, created_at = excluded.created_at",
|
|
3535
|
+
o.onboardingId,
|
|
3536
|
+
o.actorId,
|
|
3537
|
+
o.requesterId,
|
|
3538
|
+
o.pulls,
|
|
3539
|
+
pyJsonDumps(o.request),
|
|
3540
|
+
o.toldRank,
|
|
3541
|
+
now
|
|
3542
|
+
);
|
|
3543
|
+
const row = db.get(
|
|
3544
|
+
`SELECT ${ONBOARDING_COLUMNS} FROM review_onboarding WHERE actor_aad = ? AND requester_aad = ? AND pulls = ?`,
|
|
3545
|
+
o.actorId,
|
|
3546
|
+
o.requesterId,
|
|
3547
|
+
o.pulls
|
|
3548
|
+
);
|
|
3549
|
+
if (row === void 0) throw new Error("the review onboarding row was not kept");
|
|
3550
|
+
return onboarding(row);
|
|
3551
|
+
}
|
|
3552
|
+
getReviewOnboarding(onboardingId) {
|
|
3553
|
+
const row = this.ctx.db.get(
|
|
3554
|
+
`SELECT ${ONBOARDING_COLUMNS} FROM review_onboarding WHERE onboarding_id = ? AND created_at >= ?`,
|
|
3555
|
+
onboardingId,
|
|
3556
|
+
this.ctx.now() - REVIEW_ONBOARDING_KEEP_SECONDS
|
|
3557
|
+
);
|
|
3558
|
+
return row ? onboarding(row) : null;
|
|
3559
|
+
}
|
|
3560
|
+
openReviewOnboardings(actorId) {
|
|
3561
|
+
return this.ctx.db.all(
|
|
3562
|
+
`SELECT ${ONBOARDING_COLUMNS} FROM review_onboarding WHERE actor_aad = ? AND done = 0 AND created_at >= ? ORDER BY created_at, rowid`,
|
|
3563
|
+
actorId,
|
|
3564
|
+
this.ctx.now() - REVIEW_ONBOARDING_KEEP_SECONDS
|
|
3565
|
+
).map(onboarding);
|
|
3566
|
+
}
|
|
3567
|
+
onboardingReviewers() {
|
|
3568
|
+
return this.ctx.db.all(
|
|
3569
|
+
"SELECT DISTINCT actor_aad FROM review_onboarding WHERE done = 0 AND created_at >= ? ORDER BY actor_aad",
|
|
3570
|
+
this.ctx.now() - REVIEW_ONBOARDING_KEEP_SECONDS
|
|
3571
|
+
).map((r) => col.str(r, "actor_aad"));
|
|
3572
|
+
}
|
|
3573
|
+
claimOnboardingStep(actorId, rank) {
|
|
3574
|
+
return this.ctx.db.run(
|
|
3575
|
+
"UPDATE review_onboarding SET told_rank = ? WHERE actor_aad = ? AND done = 0 AND told_rank < ? AND created_at >= ?",
|
|
3576
|
+
rank,
|
|
3577
|
+
actorId,
|
|
3578
|
+
rank,
|
|
3579
|
+
this.ctx.now() - REVIEW_ONBOARDING_KEEP_SECONDS
|
|
3580
|
+
) > 0;
|
|
3581
|
+
}
|
|
3582
|
+
releaseOnboardingStep(onboardingId, from, to) {
|
|
3583
|
+
this.ctx.db.run(
|
|
3584
|
+
"UPDATE review_onboarding SET told_rank = ? WHERE onboarding_id = ? AND told_rank = ? AND done = 0",
|
|
3585
|
+
to,
|
|
3586
|
+
onboardingId,
|
|
3587
|
+
from
|
|
3588
|
+
);
|
|
3589
|
+
}
|
|
3590
|
+
finishReviewOnboarding(onboardingId) {
|
|
3591
|
+
return this.ctx.db.run("UPDATE review_onboarding SET done = 1 WHERE onboarding_id = ? AND done = 0", onboardingId) === 1;
|
|
3592
|
+
}
|
|
3593
|
+
dropReviewOnboarding(onboardingId) {
|
|
3594
|
+
this.ctx.db.run("DELETE FROM review_onboarding WHERE onboarding_id = ?", onboardingId);
|
|
3595
|
+
}
|
|
3596
|
+
declineReviewOnboarding(onboardingId) {
|
|
3597
|
+
return this.moveOnboarding(onboardingId, 0, ONBOARDING_DECLINED);
|
|
3598
|
+
}
|
|
3599
|
+
declinedReviewOnboardings(actorId) {
|
|
3600
|
+
const since = this.ctx.now() - REVIEW_ONBOARDING_KEEP_SECONDS;
|
|
3601
|
+
const where = actorId === void 0 ? "" : " AND actor_aad = ?";
|
|
3602
|
+
return this.ctx.db.all(
|
|
3603
|
+
`SELECT ${ONBOARDING_COLUMNS} FROM review_onboarding WHERE done = ? AND created_at >= ?${where} ORDER BY created_at, rowid`,
|
|
3604
|
+
ONBOARDING_DECLINED,
|
|
3605
|
+
since,
|
|
3606
|
+
...actorId === void 0 ? [] : [actorId]
|
|
3607
|
+
).map(onboarding);
|
|
3608
|
+
}
|
|
3609
|
+
claimDeclinedOnboarding(onboardingId) {
|
|
3610
|
+
return this.moveOnboarding(onboardingId, ONBOARDING_DECLINED, ONBOARDING_DECLINED_TELLING);
|
|
3611
|
+
}
|
|
3612
|
+
releaseDeclinedOnboarding(onboardingId) {
|
|
3613
|
+
this.moveOnboarding(onboardingId, ONBOARDING_DECLINED_TELLING, ONBOARDING_DECLINED);
|
|
3614
|
+
}
|
|
3615
|
+
moveOnboarding(onboardingId, from, to) {
|
|
3616
|
+
return this.ctx.db.run(
|
|
3617
|
+
"UPDATE review_onboarding SET done = ? WHERE onboarding_id = ? AND done = ?",
|
|
3618
|
+
to,
|
|
3619
|
+
onboardingId,
|
|
3620
|
+
from
|
|
3621
|
+
) === 1;
|
|
3622
|
+
}
|
|
3511
3623
|
};
|
|
3512
3624
|
|
|
3513
3625
|
// packages/runtime/src/sqlite/idempotency-repository.ts
|
package/dist/sqlite/schema.sql
CHANGED
|
@@ -129,3 +129,7 @@ CREATE TABLE IF NOT EXISTS group_language (
|
|
|
129
129
|
conversation_id TEXT PRIMARY KEY, lang TEXT NOT NULL, updated_at REAL NOT NULL);
|
|
130
130
|
CREATE TABLE IF NOT EXISTS bound_users (
|
|
131
131
|
aad_id TEXT PRIMARY KEY, claw_user_id TEXT NOT NULL, token_hash TEXT NOT NULL, updated_at REAL NOT NULL);
|
|
132
|
+
CREATE TABLE IF NOT EXISTS review_onboarding (
|
|
133
|
+
onboarding_id TEXT PRIMARY KEY, actor_aad TEXT NOT NULL, requester_aad TEXT NOT NULL, pulls TEXT NOT NULL,
|
|
134
|
+
request_json TEXT NOT NULL, told_rank INTEGER NOT NULL DEFAULT 0, done INTEGER NOT NULL DEFAULT 0, created_at REAL NOT NULL,
|
|
135
|
+
UNIQUE (actor_aad, requester_aad, pulls));
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/** GitHub review delegation on SQLite (tables `github_confirmations`, `acting_sessions`, `review_notices`,
|
|
2
|
-
* `asker_follows`, `github_notices`). */
|
|
3
|
-
import { type AskerFollow, type ConfirmationState, type GithubConfirmation, type GithubConfirmationRepository, type JsonObject, type NewGithubConfirmation, type ReviewDelegationRepository, type ReviewNotice } from "@primusclaw/personal-agent";
|
|
2
|
+
* `asker_follows`, `github_notices`, `review_onboarding`). */
|
|
3
|
+
import { type AskerFollow, type ConfirmationState, type GithubConfirmation, type GithubConfirmationRepository, type JsonObject, type NewGithubConfirmation, type ReviewDelegationRepository, type ReviewNotice, type ReviewOnboarding } from "@primusclaw/personal-agent";
|
|
4
4
|
import type { StoreContext } from "./context.js";
|
|
5
5
|
export declare class SqliteGithubConfirmationRepository implements GithubConfirmationRepository {
|
|
6
6
|
private readonly ctx;
|
|
@@ -33,4 +33,24 @@ export declare class SqliteReviewDelegationRepository implements ReviewDelegatio
|
|
|
33
33
|
dropAskerFollow(itemId: string): void;
|
|
34
34
|
claimGithubNotice(userId: string, kind: string, interval: number): boolean;
|
|
35
35
|
releaseGithubNotice(userId: string, kind: string): void;
|
|
36
|
+
saveReviewOnboarding(o: {
|
|
37
|
+
readonly onboardingId: string;
|
|
38
|
+
readonly actorId: string;
|
|
39
|
+
readonly requesterId: string;
|
|
40
|
+
readonly pulls: string;
|
|
41
|
+
readonly request: JsonObject;
|
|
42
|
+
readonly toldRank: number;
|
|
43
|
+
}): ReviewOnboarding;
|
|
44
|
+
getReviewOnboarding(onboardingId: string): ReviewOnboarding | null;
|
|
45
|
+
openReviewOnboardings(actorId: string): ReviewOnboarding[];
|
|
46
|
+
onboardingReviewers(): string[];
|
|
47
|
+
claimOnboardingStep(actorId: string, rank: number): boolean;
|
|
48
|
+
releaseOnboardingStep(onboardingId: string, from: number, to: number): void;
|
|
49
|
+
finishReviewOnboarding(onboardingId: string): boolean;
|
|
50
|
+
dropReviewOnboarding(onboardingId: string): void;
|
|
51
|
+
declineReviewOnboarding(onboardingId: string): boolean;
|
|
52
|
+
declinedReviewOnboardings(actorId?: string): ReviewOnboarding[];
|
|
53
|
+
claimDeclinedOnboarding(onboardingId: string): boolean;
|
|
54
|
+
releaseDeclinedOnboarding(onboardingId: string): void;
|
|
55
|
+
private moveOnboarding;
|
|
36
56
|
}
|
package/dist/worker.js
CHANGED
|
@@ -55,6 +55,7 @@ import {
|
|
|
55
55
|
Router,
|
|
56
56
|
reviewStop,
|
|
57
57
|
REVIEW_HANDOFF,
|
|
58
|
+
ONBOARDING_SWEEP_MS,
|
|
58
59
|
pendingOf,
|
|
59
60
|
UPGRADE_RETRY_SECONDS,
|
|
60
61
|
noModelRefusalPolicy,
|
|
@@ -1136,6 +1137,13 @@ function featureTimers(base, built) {
|
|
|
1136
1137
|
runAtStart: true,
|
|
1137
1138
|
run: () => sweepOnce(review)
|
|
1138
1139
|
});
|
|
1140
|
+
timers.push({
|
|
1141
|
+
name: "review_onboarding",
|
|
1142
|
+
// (a reviewer who confirmed at the identity service is sent the next step)
|
|
1143
|
+
everyMs: ONBOARDING_SWEEP_MS,
|
|
1144
|
+
runAtStart: false,
|
|
1145
|
+
run: () => review.sweepOnboarding()
|
|
1146
|
+
});
|
|
1139
1147
|
}
|
|
1140
1148
|
return timers;
|
|
1141
1149
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@primusclaw/personal-agent-runtime",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.11.0",
|
|
4
4
|
"description": "Node adapters for the personal agent's ports (clock, randomness, logging, storage, Claw, metrics, HTTP), and, at @primusclaw/personal-agent-runtime/worker, the worker process on any chat surface.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"access": "public"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@primusclaw/personal-agent": "0.
|
|
36
|
+
"@primusclaw/personal-agent": "0.11.0",
|
|
37
37
|
"fastify": "^5.12.8",
|
|
38
38
|
"zod": "^4.6.7"
|
|
39
39
|
}
|