@namzu/sdk 71.1.0 → 72.0.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/CHANGELOG.md +32 -0
- package/dist/agents/QueryAgent.d.ts.map +1 -1
- package/dist/agents/QueryAgent.js +1 -0
- package/dist/agents/QueryAgent.js.map +1 -1
- package/dist/compaction/index.d.ts +1 -1
- package/dist/compaction/index.d.ts.map +1 -1
- package/dist/compaction/index.js +1 -1
- package/dist/compaction/index.js.map +1 -1
- package/dist/compaction/manual.d.ts +8 -0
- package/dist/compaction/manual.d.ts.map +1 -1
- package/dist/compaction/manual.js +18 -14
- package/dist/compaction/manual.js.map +1 -1
- package/dist/compaction/model-summary.d.ts +24 -6
- package/dist/compaction/model-summary.d.ts.map +1 -1
- package/dist/compaction/model-summary.js +108 -23
- package/dist/compaction/model-summary.js.map +1 -1
- package/dist/compaction/restore.d.ts +23 -0
- package/dist/compaction/restore.d.ts.map +1 -1
- package/dist/compaction/restore.js +59 -1
- package/dist/compaction/restore.js.map +1 -1
- package/dist/compaction/summary.d.ts +37 -2
- package/dist/compaction/summary.d.ts.map +1 -1
- package/dist/compaction/summary.js +46 -6
- package/dist/compaction/summary.js.map +1 -1
- package/dist/config/runtime.js +3 -3
- package/dist/config/runtime.js.map +1 -1
- package/dist/connector/index.d.ts +2 -2
- package/dist/connector/index.d.ts.map +1 -1
- package/dist/connector/index.js +1 -1
- package/dist/connector/index.js.map +1 -1
- package/dist/connector/mcp/client.d.ts +26 -6
- package/dist/connector/mcp/client.d.ts.map +1 -1
- package/dist/connector/mcp/client.js +49 -7
- package/dist/connector/mcp/client.js.map +1 -1
- package/dist/connector/mcp/index.d.ts +2 -0
- package/dist/connector/mcp/index.d.ts.map +1 -1
- package/dist/connector/mcp/index.js +1 -0
- package/dist/connector/mcp/index.js.map +1 -1
- package/dist/connector/mcp/sandbox-stdio.d.ts +67 -0
- package/dist/connector/mcp/sandbox-stdio.d.ts.map +1 -0
- package/dist/connector/mcp/sandbox-stdio.js +178 -0
- package/dist/connector/mcp/sandbox-stdio.js.map +1 -0
- package/dist/connector/mcp/stdio-program.d.ts +34 -0
- package/dist/connector/mcp/stdio-program.d.ts.map +1 -0
- package/dist/connector/mcp/stdio-program.js +47 -0
- package/dist/connector/mcp/stdio-program.js.map +1 -0
- package/dist/connector/mcp/stdio.d.ts.map +1 -1
- package/dist/connector/mcp/stdio.js +5 -2
- package/dist/connector/mcp/stdio.js.map +1 -1
- package/dist/connector/web/guarded-fetch.d.ts +51 -2
- package/dist/connector/web/guarded-fetch.d.ts.map +1 -1
- package/dist/connector/web/guarded-fetch.js +140 -19
- package/dist/connector/web/guarded-fetch.js.map +1 -1
- package/dist/connector/web/index.d.ts +2 -2
- package/dist/connector/web/index.d.ts.map +1 -1
- package/dist/connector/web/index.js +1 -1
- package/dist/connector/web/index.js.map +1 -1
- package/dist/manager/agent/lifecycle.js +1 -1
- package/dist/manager/agent/lifecycle.js.map +1 -1
- package/dist/plugin/hook-module/capabilities.d.ts.map +1 -1
- package/dist/plugin/hook-module/capabilities.js +24 -13
- package/dist/plugin/hook-module/capabilities.js.map +1 -1
- package/dist/plugin/hook-module/host.d.ts +31 -0
- package/dist/plugin/hook-module/host.d.ts.map +1 -1
- package/dist/plugin/hook-module/host.js +56 -13
- package/dist/plugin/hook-module/host.js.map +1 -1
- package/dist/plugin/hook-module/index.d.ts +3 -2
- package/dist/plugin/hook-module/index.d.ts.map +1 -1
- package/dist/plugin/hook-module/index.js +2 -1
- package/dist/plugin/hook-module/index.js.map +1 -1
- package/dist/plugin/index.d.ts +1 -0
- package/dist/plugin/index.d.ts.map +1 -1
- package/dist/plugin/index.js +1 -0
- package/dist/plugin/index.js.map +1 -1
- package/dist/plugin/shell-hook-execute.d.ts +55 -0
- package/dist/plugin/shell-hook-execute.d.ts.map +1 -0
- package/dist/plugin/shell-hook-execute.js +73 -0
- package/dist/plugin/shell-hook-execute.js.map +1 -0
- package/dist/plugin/shell-hook-restrict.d.ts +31 -0
- package/dist/plugin/shell-hook-restrict.d.ts.map +1 -0
- package/dist/plugin/shell-hook-restrict.js +69 -0
- package/dist/plugin/shell-hook-restrict.js.map +1 -0
- package/dist/plugin/shell-hook.d.ts +29 -2
- package/dist/plugin/shell-hook.d.ts.map +1 -1
- package/dist/plugin/shell-hook.js +44 -12
- package/dist/plugin/shell-hook.js.map +1 -1
- package/dist/public-runtime.d.ts +7 -5
- package/dist/public-runtime.d.ts.map +1 -1
- package/dist/public-runtime.js +5 -4
- package/dist/public-runtime.js.map +1 -1
- package/dist/public-types.d.ts +2 -0
- package/dist/public-types.d.ts.map +1 -1
- package/dist/runtime/jobs/websocket-source.d.ts +2 -22
- package/dist/runtime/jobs/websocket-source.d.ts.map +1 -1
- package/dist/runtime/jobs/websocket-source.js +2 -33
- package/dist/runtime/jobs/websocket-source.js.map +1 -1
- package/dist/runtime/query/compact-session.d.ts.map +1 -1
- package/dist/runtime/query/compact-session.js +5 -0
- package/dist/runtime/query/compact-session.js.map +1 -1
- package/dist/runtime/query/events.d.ts +7 -0
- package/dist/runtime/query/events.d.ts.map +1 -1
- package/dist/runtime/query/events.js +29 -11
- package/dist/runtime/query/events.js.map +1 -1
- package/dist/runtime/query/executor/tool-call-admission.d.ts.map +1 -1
- package/dist/runtime/query/executor/tool-call-admission.js +51 -10
- package/dist/runtime/query/executor/tool-call-admission.js.map +1 -1
- package/dist/runtime/query/index.d.ts +6 -0
- package/dist/runtime/query/index.d.ts.map +1 -1
- package/dist/runtime/query/index.js +3 -0
- package/dist/runtime/query/index.js.map +1 -1
- package/dist/runtime/query/iteration/phases/compaction.d.ts.map +1 -1
- package/dist/runtime/query/iteration/phases/compaction.js +21 -3
- package/dist/runtime/query/iteration/phases/compaction.js.map +1 -1
- package/dist/runtime/query/iteration/phases/context.d.ts +4 -0
- package/dist/runtime/query/iteration/phases/context.d.ts.map +1 -1
- package/dist/runtime/query/iteration/phases/context.js.map +1 -1
- package/dist/scheduler/completion-inbox.d.ts.map +1 -1
- package/dist/scheduler/completion-inbox.js +15 -0
- package/dist/scheduler/completion-inbox.js.map +1 -1
- package/dist/store/session-index/index.d.ts +13 -0
- package/dist/store/session-index/index.d.ts.map +1 -1
- package/dist/store/session-index/index.js +1 -0
- package/dist/store/session-index/index.js.map +1 -1
- package/dist/store/session-index/rebuild.d.ts +12 -0
- package/dist/store/session-index/rebuild.d.ts.map +1 -1
- package/dist/store/session-index/rebuild.js +20 -4
- package/dist/store/session-index/rebuild.js.map +1 -1
- package/dist/store/session-index/sqlite.d.ts +20 -0
- package/dist/store/session-index/sqlite.d.ts.map +1 -1
- package/dist/store/session-index/sqlite.js +50 -12
- package/dist/store/session-index/sqlite.js.map +1 -1
- package/dist/tools/admit-facts.d.ts.map +1 -1
- package/dist/tools/admit-facts.js +59 -0
- package/dist/tools/admit-facts.js.map +1 -1
- package/dist/tools/coordinator/ask-user-question.d.ts.map +1 -1
- package/dist/tools/coordinator/ask-user-question.js +67 -3
- package/dist/tools/coordinator/ask-user-question.js.map +1 -1
- package/dist/turn/memory-promoter.d.ts.map +1 -1
- package/dist/turn/memory-promoter.js +20 -4
- package/dist/turn/memory-promoter.js.map +1 -1
- package/dist/types/agent/base.d.ts +6 -0
- package/dist/types/agent/base.d.ts.map +1 -1
- package/dist/types/agent/task.d.ts +5 -0
- package/dist/types/agent/task.d.ts.map +1 -1
- package/dist/types/agent/task.js.map +1 -1
- package/dist/types/hitl/index.d.ts +8 -0
- package/dist/types/hitl/index.d.ts.map +1 -1
- package/dist/types/hitl/index.js.map +1 -1
- package/dist/types/message/index.d.ts +7 -0
- package/dist/types/message/index.d.ts.map +1 -1
- package/dist/types/message/index.js.map +1 -1
- package/dist/types/tool/presentation.d.ts +21 -0
- package/dist/types/tool/presentation.d.ts.map +1 -1
- package/package.json +6 -6
- package/src/agents/QueryAgent.ts +1 -0
- package/src/compaction/index.ts +1 -0
- package/src/compaction/manual.ts +48 -12
- package/src/compaction/model-summary.ts +118 -23
- package/src/compaction/restore.ts +74 -1
- package/src/compaction/summary.ts +69 -3
- package/src/config/runtime.ts +3 -3
- package/src/connector/index.ts +3 -0
- package/src/connector/mcp/client.ts +49 -7
- package/src/connector/mcp/index.ts +5 -0
- package/src/connector/mcp/sandbox-stdio.ts +214 -0
- package/src/connector/mcp/stdio-program.ts +68 -0
- package/src/connector/mcp/stdio.ts +5 -2
- package/src/connector/web/guarded-fetch.ts +197 -30
- package/src/connector/web/index.ts +4 -1
- package/src/manager/agent/lifecycle.ts +1 -1
- package/src/plugin/hook-module/capabilities.ts +36 -14
- package/src/plugin/hook-module/host.ts +86 -13
- package/src/plugin/hook-module/index.ts +3 -0
- package/src/plugin/index.ts +1 -0
- package/src/plugin/shell-hook-execute.ts +126 -0
- package/src/plugin/shell-hook-restrict.ts +66 -0
- package/src/plugin/shell-hook.ts +78 -10
- package/src/public-runtime.ts +14 -0
- package/src/public-types.ts +13 -0
- package/src/runtime/jobs/websocket-source.ts +2 -46
- package/src/runtime/query/compact-session.ts +5 -0
- package/src/runtime/query/events.ts +29 -11
- package/src/runtime/query/executor/tool-call-admission.ts +62 -17
- package/src/runtime/query/index.ts +10 -0
- package/src/runtime/query/iteration/phases/compaction.ts +26 -2
- package/src/runtime/query/iteration/phases/context.ts +6 -0
- package/src/scheduler/completion-inbox.ts +14 -0
- package/src/store/session-index/index.ts +14 -0
- package/src/store/session-index/rebuild.ts +22 -4
- package/src/store/session-index/sqlite.ts +63 -14
- package/src/tools/admit-facts.ts +64 -0
- package/src/tools/coordinator/ask-user-question.ts +88 -4
- package/src/turn/memory-promoter.ts +24 -3
- package/src/types/agent/base.ts +7 -0
- package/src/types/agent/task.ts +5 -0
- package/src/types/hitl/index.ts +8 -0
- package/src/types/message/index.ts +7 -0
- package/src/types/tool/presentation.ts +22 -0
|
@@ -477,6 +477,13 @@ export interface SqliteSessionIndexOptions {
|
|
|
477
477
|
* longer waits on a home with thousands of logs.
|
|
478
478
|
*/
|
|
479
479
|
readonly syncInBackground?: boolean
|
|
480
|
+
/**
|
|
481
|
+
* Return once the index is open and current in version, and read the logs
|
|
482
|
+
* only when something first asks for a list, a search or a lookup. Opening
|
|
483
|
+
* does no session work; that first read waits for the catch-up, later reads
|
|
484
|
+
* find it done, and a write never starts it.
|
|
485
|
+
*/
|
|
486
|
+
readonly syncOnDemand?: boolean
|
|
480
487
|
}
|
|
481
488
|
|
|
482
489
|
export interface RebuildSqliteSessionIndexOptions extends SqliteSessionIndexOptions {
|
|
@@ -485,6 +492,8 @@ export interface RebuildSqliteSessionIndexOptions extends SqliteSessionIndexOpti
|
|
|
485
492
|
* index already in place (another process finished first) discards its own.
|
|
486
493
|
*/
|
|
487
494
|
readonly force?: boolean
|
|
495
|
+
/** Build the schema only and index no log; a later sync fills it. Opening on demand uses it. */
|
|
496
|
+
readonly empty?: boolean
|
|
488
497
|
}
|
|
489
498
|
|
|
490
499
|
/**
|
|
@@ -520,17 +529,52 @@ export class SqliteSessionIndex extends SessionIndexBase {
|
|
|
520
529
|
readonly #sink: IndexSink
|
|
521
530
|
readonly #statements = new Map<string, StatementSync>()
|
|
522
531
|
#open = true
|
|
523
|
-
/** The catch-up started by `syncInBackground`; reads wait on it. */
|
|
532
|
+
/** The catch-up started by `syncInBackground`, or on the first read under `syncOnDemand`; reads wait on it. */
|
|
524
533
|
#catchUp: Promise<void> | undefined
|
|
534
|
+
/** The home a first read catches up with, kept only while the catch-up has not started. */
|
|
535
|
+
#pendingHome: string | undefined
|
|
536
|
+
|
|
537
|
+
/** True while opening promised a catch-up that no read has started yet. */
|
|
538
|
+
get syncPending(): boolean {
|
|
539
|
+
return this.#pendingHome !== undefined
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
/** True while a catch-up is reading the logs. */
|
|
543
|
+
get syncing(): boolean {
|
|
544
|
+
return this.#catchUp !== undefined && !this.#caughtUp
|
|
545
|
+
}
|
|
546
|
+
#caughtUp = false
|
|
525
547
|
|
|
526
548
|
#startBackgroundSync(home: string): void {
|
|
527
|
-
this.#
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
549
|
+
this.#pendingHome = undefined
|
|
550
|
+
this.#catchUp = this.syncNow(home)
|
|
551
|
+
.catch(() => {
|
|
552
|
+
// A failed catch-up (the index closed, a log vanished mid-read) leaves the
|
|
553
|
+
// rows the last sync wrote; the next open syncs again.
|
|
554
|
+
})
|
|
555
|
+
.then(() => {
|
|
556
|
+
this.#caughtUp = true
|
|
557
|
+
})
|
|
531
558
|
}
|
|
532
559
|
|
|
533
560
|
protected override async settled(): Promise<void> {
|
|
561
|
+
if (this.#pendingHome !== undefined) this.#startBackgroundSync(this.#pendingHome)
|
|
562
|
+
await this.#catchUp
|
|
563
|
+
}
|
|
564
|
+
|
|
565
|
+
/**
|
|
566
|
+
* A read about one session before any catch-up has started: bring that session's
|
|
567
|
+
* rows current from its own log and leave the other logs unread. A session with
|
|
568
|
+
* no row yet has no known log, so that read waits for the whole catch-up.
|
|
569
|
+
*/
|
|
570
|
+
protected override async settledFor(sessionId: SessionId | undefined): Promise<void> {
|
|
571
|
+
if (this.#pendingHome === undefined || sessionId === undefined) return this.settled()
|
|
572
|
+
const row = this.readSession(sessionId)
|
|
573
|
+
if (row === undefined) return this.settled()
|
|
574
|
+
await this.refreshNow({ sessionId, slug: row.slug, logPath: row.logPath })
|
|
575
|
+
}
|
|
576
|
+
|
|
577
|
+
protected override async settledForWrite(): Promise<void> {
|
|
534
578
|
await this.#catchUp
|
|
535
579
|
}
|
|
536
580
|
|
|
@@ -740,7 +784,9 @@ export class SqliteSessionIndex extends SessionIndexBase {
|
|
|
740
784
|
try {
|
|
741
785
|
configure(db)
|
|
742
786
|
db.exec(`BEGIN IMMEDIATE; ${SCHEMA} COMMIT;`)
|
|
743
|
-
|
|
787
|
+
if (options.empty !== true) {
|
|
788
|
+
for (const log of await discoverSessionLogs(options.home)) await index.refresh(log)
|
|
789
|
+
}
|
|
744
790
|
} finally {
|
|
745
791
|
index.close()
|
|
746
792
|
}
|
|
@@ -764,7 +810,9 @@ export class SqliteSessionIndex extends SessionIndexBase {
|
|
|
764
810
|
if (indexVersion(options.path) !== SESSION_INDEX_VERSION) {
|
|
765
811
|
// Not forced: if another process renames a current index into place
|
|
766
812
|
// first, this one discards its own and opens that one.
|
|
767
|
-
await SqliteSessionIndex.rebuild(
|
|
813
|
+
await SqliteSessionIndex.rebuild(
|
|
814
|
+
options.syncOnDemand === true ? { ...options, empty: true } : options,
|
|
815
|
+
)
|
|
768
816
|
} else {
|
|
769
817
|
await sweepAbandonedRebuilds(options.path)
|
|
770
818
|
}
|
|
@@ -780,7 +828,8 @@ export class SqliteSessionIndex extends SessionIndexBase {
|
|
|
780
828
|
throw error
|
|
781
829
|
}
|
|
782
830
|
const index = new SqliteSessionIndex(db, options.path)
|
|
783
|
-
if (options.
|
|
831
|
+
if (options.syncOnDemand === true) index.#pendingHome = options.home
|
|
832
|
+
else if (options.syncInBackground === true) index.#startBackgroundSync(options.home)
|
|
784
833
|
else await index.sync(options.home)
|
|
785
834
|
return index
|
|
786
835
|
}
|
|
@@ -885,7 +934,7 @@ export class SqliteSessionIndex extends SessionIndexBase {
|
|
|
885
934
|
}
|
|
886
935
|
|
|
887
936
|
async listTurns(sessionId: SessionId): Promise<IndexedTurn[]> {
|
|
888
|
-
await this.
|
|
937
|
+
await this.settledFor(sessionId)
|
|
889
938
|
return this.#all(
|
|
890
939
|
'SELECT * FROM turns WHERE session_id = ? ORDER BY started_at, id',
|
|
891
940
|
sessionId,
|
|
@@ -893,7 +942,7 @@ export class SqliteSessionIndex extends SessionIndexBase {
|
|
|
893
942
|
}
|
|
894
943
|
|
|
895
944
|
async listChildren(sessionId: SessionId): Promise<ChildSessionSummary[]> {
|
|
896
|
-
await this.
|
|
945
|
+
await this.settledFor(sessionId)
|
|
897
946
|
return this.#all(
|
|
898
947
|
'SELECT * FROM children WHERE session_id = ? ORDER BY spawned_at, child_id',
|
|
899
948
|
sessionId,
|
|
@@ -906,7 +955,7 @@ export class SqliteSessionIndex extends SessionIndexBase {
|
|
|
906
955
|
async listPendingDecisions(
|
|
907
956
|
options: { sessionId?: SessionId } = {},
|
|
908
957
|
): Promise<IndexedPendingDecision[]> {
|
|
909
|
-
await this.
|
|
958
|
+
await this.settledFor(options.sessionId)
|
|
910
959
|
const rows =
|
|
911
960
|
options.sessionId === undefined
|
|
912
961
|
? this.#all('SELECT * FROM pending_decisions ORDER BY session_id, decision_id')
|
|
@@ -934,7 +983,7 @@ export class SqliteSessionIndex extends SessionIndexBase {
|
|
|
934
983
|
}
|
|
935
984
|
|
|
936
985
|
async listExternalRefs(sessionId: SessionId): Promise<ExternalRefTarget[]> {
|
|
937
|
-
await this.
|
|
986
|
+
await this.settledFor(sessionId)
|
|
938
987
|
return this.#all(
|
|
939
988
|
'SELECT * FROM external_refs WHERE session_id = ? ORDER BY protocol, kind, external_id',
|
|
940
989
|
sessionId,
|
|
@@ -942,7 +991,7 @@ export class SqliteSessionIndex extends SessionIndexBase {
|
|
|
942
991
|
}
|
|
943
992
|
|
|
944
993
|
async batches(options: { sessionId?: SessionId } = {}): Promise<IndexedBatch[]> {
|
|
945
|
-
await this.
|
|
994
|
+
await this.settledFor(options.sessionId)
|
|
946
995
|
const rows =
|
|
947
996
|
options.sessionId === undefined
|
|
948
997
|
? this.#all('SELECT * FROM batches ORDER BY session_id, batch_id')
|
|
@@ -954,7 +1003,7 @@ export class SqliteSessionIndex extends SessionIndexBase {
|
|
|
954
1003
|
}
|
|
955
1004
|
|
|
956
1005
|
async searchEvidence(options: EvidenceSearchOptions): Promise<EvidenceHit[]> {
|
|
957
|
-
await this.
|
|
1006
|
+
await this.settledFor(options.sessionId)
|
|
958
1007
|
const match = evidenceMatcher(options)
|
|
959
1008
|
const narrowing = ftsMatchExpression(options)
|
|
960
1009
|
const limit = options.limit ?? 100
|
package/src/tools/admit-facts.ts
CHANGED
|
@@ -44,6 +44,34 @@ function flag(value: unknown): true | undefined {
|
|
|
44
44
|
return value === true ? true : undefined
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
+
/** The person's own words are kept whole well past an ordinary field's bound. */
|
|
48
|
+
const MAX_ANSWER_TEXT = 20_000
|
|
49
|
+
|
|
50
|
+
function answerText(value: unknown): string | undefined {
|
|
51
|
+
return typeof value === 'string' && value.length <= MAX_ANSWER_TEXT ? value : undefined
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* The person's own words, cut rather than dropped past the bound: a dropped
|
|
56
|
+
* field would leave an answered row with nothing after its arrow. The model
|
|
57
|
+
* already has the whole text in the tool result; this is what is drawn.
|
|
58
|
+
*/
|
|
59
|
+
function ownWords(value: unknown): string | undefined {
|
|
60
|
+
if (typeof value !== 'string') return undefined
|
|
61
|
+
return value.length <= MAX_ANSWER_TEXT ? value : `${value.slice(0, MAX_ANSWER_TEXT - 1)}…`
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function labels(value: unknown): readonly string[] | undefined {
|
|
65
|
+
if (!Array.isArray(value) || value.length > 50) return undefined
|
|
66
|
+
const out: string[] = []
|
|
67
|
+
for (const item of value) {
|
|
68
|
+
const label = answerText(item)
|
|
69
|
+
if (label === undefined) return undefined
|
|
70
|
+
out.push(label)
|
|
71
|
+
}
|
|
72
|
+
return out
|
|
73
|
+
}
|
|
74
|
+
|
|
47
75
|
function pick<T extends object>(entries: Record<string, unknown>): T {
|
|
48
76
|
const out: Record<string, unknown> = {}
|
|
49
77
|
for (const [key, value] of Object.entries(entries)) if (value !== undefined) out[key] = value
|
|
@@ -210,6 +238,42 @@ export function admitToolFacts(value: unknown): ToolFacts | undefined {
|
|
|
210
238
|
generatedImage: generated === undefined ? undefined : { prompt: generated },
|
|
211
239
|
})
|
|
212
240
|
}
|
|
241
|
+
case 'questions': {
|
|
242
|
+
const outcome =
|
|
243
|
+
value.outcome === 'discussed'
|
|
244
|
+
? 'discussed'
|
|
245
|
+
: value.outcome === 'answered'
|
|
246
|
+
? 'answered'
|
|
247
|
+
: undefined
|
|
248
|
+
if (outcome === undefined || !Array.isArray(value.questions)) return undefined
|
|
249
|
+
if (value.questions.length === 0 || value.questions.length > 8) return undefined
|
|
250
|
+
const questions: {
|
|
251
|
+
question: string
|
|
252
|
+
header?: string
|
|
253
|
+
options?: readonly string[]
|
|
254
|
+
picked?: readonly string[]
|
|
255
|
+
freeText?: string
|
|
256
|
+
answered: boolean
|
|
257
|
+
}[] = []
|
|
258
|
+
for (const entry of value.questions) {
|
|
259
|
+
if (!isRecord(entry)) return undefined
|
|
260
|
+
const question = answerText(entry.question)
|
|
261
|
+
if (question === undefined || typeof entry.answered !== 'boolean') return undefined
|
|
262
|
+
const header = answerText(entry.header)
|
|
263
|
+
const options = labels(entry.options)
|
|
264
|
+
const picked = labels(entry.picked)
|
|
265
|
+
const freeText = ownWords(entry.freeText)
|
|
266
|
+
questions.push({
|
|
267
|
+
question,
|
|
268
|
+
...(header === undefined ? {} : { header }),
|
|
269
|
+
...(options === undefined ? {} : { options }),
|
|
270
|
+
...(picked === undefined ? {} : { picked }),
|
|
271
|
+
...(freeText === undefined ? {} : { freeText }),
|
|
272
|
+
answered: entry.answered,
|
|
273
|
+
})
|
|
274
|
+
}
|
|
275
|
+
return { kind: 'questions', outcome, questions }
|
|
276
|
+
}
|
|
213
277
|
case 'failure': {
|
|
214
278
|
const reason = FAILURE_REASONS.find((candidate) => candidate === value.reason)
|
|
215
279
|
if (reason === undefined) return undefined
|
|
@@ -20,7 +20,7 @@ import type {
|
|
|
20
20
|
UserQuestionOption,
|
|
21
21
|
} from '../../types/hitl/index.js'
|
|
22
22
|
import type { SessionId, TurnId } from '../../types/ids/index.js'
|
|
23
|
-
import type { ToolDefinition } from '../../types/tool/index.js'
|
|
23
|
+
import type { ToolDefinition, ToolFacts } from '../../types/tool/index.js'
|
|
24
24
|
import { generateCheckpointId } from '../../utils/id.js'
|
|
25
25
|
import { defineTool } from '../defineTool.js'
|
|
26
26
|
import { questionOptions } from './question-options.js'
|
|
@@ -246,6 +246,23 @@ export interface AskUserQuestionToolOptions {
|
|
|
246
246
|
const NO_ANSWER_TEXT =
|
|
247
247
|
'The user did not answer this question. Do not assume a choice or consent; proceed on your best judgment or continue without this information.'
|
|
248
248
|
|
|
249
|
+
const DISCUSS_TEXT =
|
|
250
|
+
"The user doesn't want to answer yet: they want to talk the question over first. Do not assume a choice or consent, and do not ask again. Reply briefly, ask what is unclear, and follow what they say next."
|
|
251
|
+
|
|
252
|
+
const DISCUSS_BATCH_TEXT =
|
|
253
|
+
"The user doesn't want to answer yet: they want to talk these questions over first. Do not assume a choice or consent, and do not ask again. Reply briefly, ask what is unclear, and follow what they say next."
|
|
254
|
+
|
|
255
|
+
/** The questions a talk-it-over left open, each with its options and the fact that nothing was answered. */
|
|
256
|
+
function discussQuestions(items: readonly UserQuestionItem[]): string {
|
|
257
|
+
return items
|
|
258
|
+
.map((i) => {
|
|
259
|
+
const options =
|
|
260
|
+
i.options.length > 0 ? `\n Options: ${i.options.map((o) => o.label).join(' / ')}` : ''
|
|
261
|
+
return `- "${i.question}"${options}\n (No answer provided)`
|
|
262
|
+
})
|
|
263
|
+
.join('\n')
|
|
264
|
+
}
|
|
265
|
+
|
|
249
266
|
const NO_ANSWER_BATCH_TEXT =
|
|
250
267
|
'The user did not answer these questions. Do not assume a choice or consent; proceed on your best judgment or continue without this information.'
|
|
251
268
|
|
|
@@ -255,6 +272,7 @@ interface ReadAnswer {
|
|
|
255
272
|
readonly selected: readonly {
|
|
256
273
|
id: string
|
|
257
274
|
label: string
|
|
275
|
+
description?: string
|
|
258
276
|
recommended?: true
|
|
259
277
|
}[]
|
|
260
278
|
readonly freeText: string
|
|
@@ -299,15 +317,53 @@ function readAnswers(
|
|
|
299
317
|
const selected = (item.multiSelect ? chosen : chosen.slice(0, 1)).map((opt) => ({
|
|
300
318
|
id: opt.id,
|
|
301
319
|
label: opt.label,
|
|
320
|
+
...(opt.description ? { description: opt.description } : {}),
|
|
302
321
|
...(opt.recommended === true ? { recommended: true as const } : {}),
|
|
303
322
|
}))
|
|
304
323
|
return { item, selected, freeText: entry?.freeText?.trim() ?? '' }
|
|
305
324
|
})
|
|
306
325
|
}
|
|
307
326
|
|
|
327
|
+
/**
|
|
328
|
+
* What each picked option means, in the context of the question it answers:
|
|
329
|
+
* the option's description, which the model wrote and the person read when
|
|
330
|
+
* choosing. Nothing for an option that carried none, and nothing broader
|
|
331
|
+
* than the options that were actually picked.
|
|
332
|
+
*/
|
|
333
|
+
function pickedMeanings(answers: readonly ReadAnswer[], batch: boolean): string {
|
|
334
|
+
const lines = answers.flatMap(({ item, selected }) =>
|
|
335
|
+
selected.flatMap((s) =>
|
|
336
|
+
s.description
|
|
337
|
+
? [`- "${s.label}"${batch ? ` (${labelOf(item)})` : ''}: ${s.description}`]
|
|
338
|
+
: [],
|
|
339
|
+
),
|
|
340
|
+
)
|
|
341
|
+
return lines.length > 0 ? `\nWhat the picked options mean:\n${lines.join('\n')}` : ''
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
/** What the person answered, as typed fields: the host draws its block from these, not from the receipt text. */
|
|
345
|
+
function questionFacts(
|
|
346
|
+
outcome: 'answered' | 'discussed',
|
|
347
|
+
answers: readonly ReadAnswer[],
|
|
348
|
+
): ToolFacts {
|
|
349
|
+
return {
|
|
350
|
+
kind: 'questions',
|
|
351
|
+
outcome,
|
|
352
|
+
questions: answers.map(({ item, selected, freeText }) => ({
|
|
353
|
+
question: item.question,
|
|
354
|
+
...(item.header !== undefined ? { header: item.header } : {}),
|
|
355
|
+
options: item.options.map((o) => o.label),
|
|
356
|
+
...(selected.length > 0 ? { picked: selected.map((s) => s.label) } : {}),
|
|
357
|
+
...(freeText ? { freeText } : {}),
|
|
358
|
+
answered: outcome === 'answered' && isAnswered({ item, selected, freeText }),
|
|
359
|
+
})),
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
|
|
308
363
|
function describeSingle(answer: ReadAnswer): {
|
|
309
364
|
output: string
|
|
310
365
|
data: Record<string, unknown>
|
|
366
|
+
facts: ToolFacts
|
|
311
367
|
} {
|
|
312
368
|
const { item, selected, freeText } = answer
|
|
313
369
|
let output: string
|
|
@@ -318,8 +374,10 @@ function describeSingle(answer: ReadAnswer): {
|
|
|
318
374
|
} else {
|
|
319
375
|
output = `User answered "${item.question}" in their own words: "${freeText}"`
|
|
320
376
|
}
|
|
377
|
+
output += pickedMeanings([answer], false)
|
|
321
378
|
return {
|
|
322
379
|
output,
|
|
380
|
+
facts: questionFacts('answered', [answer]),
|
|
323
381
|
data: {
|
|
324
382
|
question: item.question,
|
|
325
383
|
selected,
|
|
@@ -334,6 +392,7 @@ const labelOf = (item: UserQuestionItem): string => item.header ?? item.question
|
|
|
334
392
|
function describeBatch(answers: readonly ReadAnswer[]): {
|
|
335
393
|
output: string
|
|
336
394
|
data: Record<string, unknown>
|
|
395
|
+
facts: ToolFacts
|
|
337
396
|
} {
|
|
338
397
|
const lines = answers.map((answer) => {
|
|
339
398
|
const { item, selected, freeText } = answer
|
|
@@ -346,7 +405,8 @@ function describeBatch(answers: readonly ReadAnswer[]): {
|
|
|
346
405
|
})
|
|
347
406
|
const answered = answers.filter(isAnswered).length
|
|
348
407
|
return {
|
|
349
|
-
output: `The user answered ${answered} of ${answers.length} questions:\n${lines.join('\n')}`,
|
|
408
|
+
output: `The user answered ${answered} of ${answers.length} questions:\n${lines.join('\n')}${pickedMeanings(answers, true)}`,
|
|
409
|
+
facts: questionFacts('answered', answers),
|
|
350
410
|
data: {
|
|
351
411
|
questions: answers.map(({ item }) => ({
|
|
352
412
|
questionId: item.id,
|
|
@@ -377,7 +437,7 @@ export function buildAskUserQuestionTool(config: AskUserQuestionToolOptions): To
|
|
|
377
437
|
description:
|
|
378
438
|
'Ask the user when you are blocked on a decision that is genuinely theirs to make: one you cannot resolve from their request, your tools, the files you can read, or sensible defaults. The question must be the one undecidable thing in this task. Look up anything a tool can discover (what you can read, list or search) and reuse what the conversation already answered, because asking for it wastes the user\'s time. Leave out questions like "Shall I proceed?"; plan ratification goes through ' +
|
|
379
439
|
planApproval +
|
|
380
|
-
'. Provide 2-4 genuinely distinct options derived from the actual context, with concrete paths rather than generic placeholders (for example, asked to prepare a presentation, ask who the audience is, with an option for each plausible audience). Give each option a short label (1-5 words) and a one-line description of what practically changes if it is chosen; put qualifiers in the description, since a label with a trailing note reads as two choices. To recommend an option, put it first and set recommended: true on it: the host marks it for the user, so the label stays plain. Set multiSelect: true only when several options can apply at once. An option may carry a preview (plain text or markdown) that the host shows beside the list while it is focused; use it only when seeing the thing helps the choice. A free-text "
|
|
440
|
+
'. Provide 2-4 genuinely distinct options derived from the actual context, with concrete paths rather than generic placeholders (for example, asked to prepare a presentation, ask who the audience is, with an option for each plausible audience). Give each option a short label (1-5 words) and a one-line description of what practically changes if it is chosen; put qualifiers in the description, since a label with a trailing note reads as two choices. To recommend an option, put it first and set recommended: true on it: the host marks it for the user, so the label stays plain. Set multiSelect: true only when several options can apply at once. An option may carry a preview (plain text or markdown) that the host shows beside the list while it is focused; use it only when seeing the thing helps the choice. A free-text "Other" choice is always shown by the host, so the options cover only the real alternatives. Put the questions in the questions array: one entry for a single decision. Put several entries in the same call only when they are related decisions that all block your next step and the user can answer them together (for example which account, for what purpose, which environment before a credentialed step), at most 4, each with a short unique header; the user answers them all in one card and you get one answer per question. Ask questions that depend on one another\'s answers one at a time, since the first answer changes the second. Most work needs at most 2-3 questions in all, so prefer proceeding on stated defaults over interrogating the user. Answers come only from the user, because a made-up answer or synthetic content would pass for their decision (unless they explicitly asked for a random/test scenario). The answers arrive as this tool\'s result; a question the result says was not answered stays open, and if the result says the user did not answer at all, do not ask again: proceed on your best judgment without assuming consent. Example call: {"questions":[{"header":"Scope","question":"Which part of the project should the change cover?","options":[{"label":"One module","description":"Only the module you named","recommended":true},{"label":"Whole project","description":"Every module that uses it"}]}]}.',
|
|
381
441
|
inputSchema,
|
|
382
442
|
modelInputSchema: structuredClone(askUserQuestionModelInputSchema),
|
|
383
443
|
enforceModelInput: true,
|
|
@@ -500,6 +560,25 @@ export function buildAskUserQuestionTool(config: AskUserQuestionToolOptions): To
|
|
|
500
560
|
}
|
|
501
561
|
|
|
502
562
|
if (decision.action !== 'answer_question') return noAnswer
|
|
563
|
+
if (decision.discuss === true) {
|
|
564
|
+
if (decision.questionId !== undefined && decision.questionId !== toolUseId) return noAnswer
|
|
565
|
+
// An error result, not a success: nothing was answered, and the
|
|
566
|
+
// model must not read the call as having gone through.
|
|
567
|
+
return {
|
|
568
|
+
success: false,
|
|
569
|
+
output: `${batch ? DISCUSS_BATCH_TEXT : DISCUSS_TEXT}\n\nQuestions asked:\n${discussQuestions(items)}`,
|
|
570
|
+
facts: questionFacts(
|
|
571
|
+
'discussed',
|
|
572
|
+
items.map((item) => ({ item, selected: [], freeText: '' })),
|
|
573
|
+
),
|
|
574
|
+
data: {
|
|
575
|
+
question: first.question,
|
|
576
|
+
...(batch ? { questions: items.map((i) => i.question) } : {}),
|
|
577
|
+
answered: false,
|
|
578
|
+
discuss: true,
|
|
579
|
+
},
|
|
580
|
+
}
|
|
581
|
+
}
|
|
503
582
|
if (decision.questionId !== undefined && decision.questionId !== toolUseId) {
|
|
504
583
|
// Misdirection guard: this answer was meant for a different
|
|
505
584
|
// question parked under the same turn (stale client). Never
|
|
@@ -511,7 +590,12 @@ export function buildAskUserQuestionTool(config: AskUserQuestionToolOptions): To
|
|
|
511
590
|
if (!answers.some(isAnswered)) return noAnswer
|
|
512
591
|
|
|
513
592
|
const described = batch ? describeBatch(answers) : describeSingle(answers[0] as ReadAnswer)
|
|
514
|
-
return {
|
|
593
|
+
return {
|
|
594
|
+
success: true,
|
|
595
|
+
output: described.output,
|
|
596
|
+
data: described.data,
|
|
597
|
+
facts: described.facts,
|
|
598
|
+
}
|
|
515
599
|
},
|
|
516
600
|
})
|
|
517
601
|
}
|
|
@@ -88,6 +88,25 @@ function knowledge(
|
|
|
88
88
|
return out
|
|
89
89
|
}
|
|
90
90
|
|
|
91
|
+
const TITLE_MAX = 80
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* A record's title from what it holds: its first claim, in the order the
|
|
95
|
+
* sections are rendered. The turn's task is the session's first message and
|
|
96
|
+
* is the same for every record the session writes, so it names none of them.
|
|
97
|
+
* A candidate with no usable claim falls back to the turn id.
|
|
98
|
+
*/
|
|
99
|
+
function titleOf(
|
|
100
|
+
candidate: SessionMemoryCandidate,
|
|
101
|
+
sections: readonly (readonly [string, readonly string[]])[],
|
|
102
|
+
): string {
|
|
103
|
+
const first = sections[0]?.[1][0]?.replace(/\s+/g, ' ').trim()
|
|
104
|
+
if (!first) return `Turn ${candidate.turnId}`
|
|
105
|
+
return first.length <= TITLE_MAX
|
|
106
|
+
? first
|
|
107
|
+
: `${first.slice(0, TITLE_MAX - 1).replace(/[\uD800-\uDBFF]$/, '')}…`
|
|
108
|
+
}
|
|
109
|
+
|
|
91
110
|
/** Carry actual claims into search results, with their category attribution. */
|
|
92
111
|
function summarize(sections: readonly (readonly [string, readonly string[]])[]): string {
|
|
93
112
|
const text = sections.map(([heading, items]) => `${heading}: ${items[0]}`).join('; ')
|
|
@@ -96,6 +115,7 @@ function summarize(sections: readonly (readonly [string, readonly string[]])[]):
|
|
|
96
115
|
|
|
97
116
|
function render(
|
|
98
117
|
candidate: SessionMemoryCandidate,
|
|
118
|
+
title: string,
|
|
99
119
|
sections: readonly (readonly [string, readonly string[]])[],
|
|
100
120
|
): string {
|
|
101
121
|
const body = sections.map(
|
|
@@ -116,7 +136,7 @@ function render(
|
|
|
116
136
|
if (candidate.files.length > 0) {
|
|
117
137
|
body.push(`## Files touched\n\n${candidate.files.map((f) => `- ${f}`).join('\n')}`)
|
|
118
138
|
}
|
|
119
|
-
return `# ${
|
|
139
|
+
return `# ${title}\n\n${body.join('\n\n')}\n`
|
|
120
140
|
}
|
|
121
141
|
|
|
122
142
|
/**
|
|
@@ -155,10 +175,11 @@ export function createMemoryPromoter(options: MemoryPromoterOptions): PromoteMem
|
|
|
155
175
|
)
|
|
156
176
|
return
|
|
157
177
|
|
|
178
|
+
const title = titleOf(candidate, sections)
|
|
158
179
|
await options.store.create({
|
|
159
|
-
title
|
|
180
|
+
title,
|
|
160
181
|
summary: summarize(sections),
|
|
161
|
-
content: render(candidate, sections),
|
|
182
|
+
content: render(candidate, title, sections),
|
|
162
183
|
tags: [...tags, knowledgeTag],
|
|
163
184
|
type: 'project',
|
|
164
185
|
format: 'markdown',
|
package/src/types/agent/base.ts
CHANGED
|
@@ -134,6 +134,13 @@ export interface BaseAgentConfig {
|
|
|
134
134
|
*/
|
|
135
135
|
compactionSummaryRoute?: CompactionSummaryRouter
|
|
136
136
|
|
|
137
|
+
/**
|
|
138
|
+
* Close a compaction summary with the wording that lets the model ask when
|
|
139
|
+
* something is unclear. Absent or false, it tells the model to continue
|
|
140
|
+
* directly.
|
|
141
|
+
*/
|
|
142
|
+
compactionAskWhenUnclear?: boolean
|
|
143
|
+
|
|
137
144
|
allowedTools?: readonly string[]
|
|
138
145
|
|
|
139
146
|
/**
|
package/src/types/agent/task.ts
CHANGED
|
@@ -26,6 +26,11 @@ export type ChildWorkspaceRequest =
|
|
|
26
26
|
readonly mode: 'isolated'
|
|
27
27
|
readonly backend: 'git-worktree'
|
|
28
28
|
readonly baseRef?: string
|
|
29
|
+
/**
|
|
30
|
+
* Name of the checkout below the managed worktree folder, and so of its branch
|
|
31
|
+
* (`<branch prefix>/<label>`). Absent, the child's sub-session id names both.
|
|
32
|
+
*/
|
|
33
|
+
readonly label?: string
|
|
29
34
|
/** Relative directory within the checkout where this child starts. */
|
|
30
35
|
readonly subdirectory?: string
|
|
31
36
|
/**
|
package/src/types/hitl/index.ts
CHANGED
|
@@ -123,6 +123,14 @@ export type HITLResumeDecision =
|
|
|
123
123
|
* question.
|
|
124
124
|
*/
|
|
125
125
|
questionId?: string
|
|
126
|
+
/**
|
|
127
|
+
* The person chose to talk the question over instead of answering
|
|
128
|
+
* it. Nothing is picked (send `[]`); the tool returns an error
|
|
129
|
+
* result telling the model the person wants to talk the questions
|
|
130
|
+
* over first, lists them with no answer, and says not to assume a
|
|
131
|
+
* choice and to take the person's next message as the way forward.
|
|
132
|
+
*/
|
|
133
|
+
discuss?: true
|
|
126
134
|
}
|
|
127
135
|
| { action: 'pause'; reason: string }
|
|
128
136
|
| { action: 'abort'; reason: string }
|
|
@@ -311,6 +311,13 @@ export interface SystemMessage extends BaseMessage {
|
|
|
311
311
|
* what an earlier one did.
|
|
312
312
|
*/
|
|
313
313
|
revealedTools?: readonly ToolRevealReceipt[]
|
|
314
|
+
/**
|
|
315
|
+
* On a compaction summary: the names of the tools the conversation called
|
|
316
|
+
* before the pass cut the calls. Written only by the summary renderer, from
|
|
317
|
+
* the calls themselves, and read back from here and never from the summary's
|
|
318
|
+
* text, so words in a summary cannot add a name. Cumulative across passes.
|
|
319
|
+
*/
|
|
320
|
+
toolsUsed?: readonly string[]
|
|
314
321
|
}
|
|
315
322
|
|
|
316
323
|
/**
|
|
@@ -233,6 +233,28 @@ export type ToolFacts =
|
|
|
233
233
|
/** The one file is an image the agent made: the prompt it was made from. A host draws the picture itself. */
|
|
234
234
|
readonly generatedImage?: { readonly prompt: string }
|
|
235
235
|
}
|
|
236
|
+
| {
|
|
237
|
+
/**
|
|
238
|
+
* What the person answered to an `ask_user_question` call, one entry per
|
|
239
|
+
* question, as they gave it. A host draws its block from these and never
|
|
240
|
+
* reads the person's words back out of the model's receipt.
|
|
241
|
+
*/
|
|
242
|
+
readonly kind: 'questions'
|
|
243
|
+
/** `discussed`: the person set the questions aside to talk them over; nothing was answered. */
|
|
244
|
+
readonly outcome: 'answered' | 'discussed'
|
|
245
|
+
readonly questions: readonly {
|
|
246
|
+
readonly question: string
|
|
247
|
+
/** The short label a batch answer is keyed by. */
|
|
248
|
+
readonly header?: string
|
|
249
|
+
/** The options offered, in order (what a talk-it-over lists). */
|
|
250
|
+
readonly options?: readonly string[]
|
|
251
|
+
/** The labels the person picked. */
|
|
252
|
+
readonly picked?: readonly string[]
|
|
253
|
+
/** What the person typed: their own words when nothing was picked, or a note beside the pick. */
|
|
254
|
+
readonly freeText?: string
|
|
255
|
+
readonly answered: boolean
|
|
256
|
+
}[]
|
|
257
|
+
}
|
|
236
258
|
| {
|
|
237
259
|
readonly kind: 'failure'
|
|
238
260
|
readonly reason: ToolFailureReason
|