@longtable/cli 0.1.32 → 0.1.34

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.
@@ -0,0 +1,22 @@
1
+ import type { FirstResearchShape, LongTableQuestionObligation, QuestionRecord, ResearchState } from "@longtable/core";
2
+ export declare function pendingQuestionObligations(state: ResearchState): LongTableQuestionObligation[];
3
+ export declare function createRequiredQuestionObligation(question: QuestionRecord): LongTableQuestionObligation;
4
+ export declare function createFirstResearchShapeObligation(shape: FirstResearchShape, options: {
5
+ prompt: string;
6
+ reason: string;
7
+ questionId?: string;
8
+ }): LongTableQuestionObligation;
9
+ export declare function upsertQuestionObligation(state: ResearchState, obligation: LongTableQuestionObligation): ResearchState;
10
+ export declare function ensureRequiredQuestionObligation(state: ResearchState, question: QuestionRecord): ResearchState;
11
+ export declare function ensureFirstResearchShapeObligation(state: ResearchState, shape: FirstResearchShape, options: {
12
+ prompt: string;
13
+ reason: string;
14
+ questionId?: string;
15
+ }): ResearchState;
16
+ export declare function resolveQuestionObligationByQuestionId(state: ResearchState, questionId: string, decisionId?: string, status?: "satisfied" | "cleared"): ResearchState;
17
+ export declare function resolveFirstResearchShapeObligation(state: ResearchState, options: {
18
+ sourceHookId?: string;
19
+ questionId?: string;
20
+ decisionId?: string;
21
+ status?: "satisfied" | "cleared";
22
+ }): ResearchState;
@@ -0,0 +1,112 @@
1
+ function nowIso() {
2
+ return new Date().toISOString();
3
+ }
4
+ function createId(prefix) {
5
+ return `${prefix}_${Date.now().toString(36)}_${Math.random().toString(36).slice(2, 8)}`;
6
+ }
7
+ export function pendingQuestionObligations(state) {
8
+ return (state.questionObligations ?? []).filter((obligation) => obligation.status === "pending");
9
+ }
10
+ export function createRequiredQuestionObligation(question) {
11
+ const timestamp = question.createdAt || nowIso();
12
+ return {
13
+ id: createId("question_obligation"),
14
+ kind: "required_question",
15
+ status: "pending",
16
+ createdAt: timestamp,
17
+ updatedAt: timestamp,
18
+ prompt: question.prompt.question,
19
+ reason: question.prompt.displayReason ?? "A required LongTable checkpoint is pending.",
20
+ questionId: question.id
21
+ };
22
+ }
23
+ export function createFirstResearchShapeObligation(shape, options) {
24
+ const timestamp = nowIso();
25
+ return {
26
+ id: createId("question_obligation"),
27
+ kind: "first_research_shape_confirmation",
28
+ status: "pending",
29
+ createdAt: timestamp,
30
+ updatedAt: timestamp,
31
+ prompt: options.prompt,
32
+ reason: options.reason,
33
+ ...(shape.sourceHookId ? { sourceHookId: shape.sourceHookId } : {}),
34
+ ...(options.questionId ? { questionId: options.questionId } : {})
35
+ };
36
+ }
37
+ export function upsertQuestionObligation(state, obligation) {
38
+ const current = state.questionObligations ?? [];
39
+ const next = current.some((entry) => entry.id === obligation.id)
40
+ ? current.map((entry) => entry.id === obligation.id ? obligation : entry)
41
+ : [...current, obligation];
42
+ return {
43
+ ...state,
44
+ questionObligations: next
45
+ };
46
+ }
47
+ export function ensureRequiredQuestionObligation(state, question) {
48
+ if (!question.prompt.required) {
49
+ return state;
50
+ }
51
+ const existing = (state.questionObligations ?? []).find((obligation) => obligation.kind === "required_question" &&
52
+ obligation.questionId === question.id &&
53
+ obligation.status === "pending");
54
+ if (existing) {
55
+ return state;
56
+ }
57
+ return upsertQuestionObligation(state, createRequiredQuestionObligation(question));
58
+ }
59
+ export function ensureFirstResearchShapeObligation(state, shape, options) {
60
+ const current = state.questionObligations ?? [];
61
+ const existing = current.find((obligation) => obligation.kind === "first_research_shape_confirmation" &&
62
+ obligation.status === "pending" &&
63
+ obligation.sourceHookId === shape.sourceHookId);
64
+ if (!existing) {
65
+ return upsertQuestionObligation(state, createFirstResearchShapeObligation(shape, options));
66
+ }
67
+ const updated = {
68
+ ...existing,
69
+ updatedAt: nowIso(),
70
+ prompt: options.prompt,
71
+ reason: options.reason,
72
+ ...(shape.sourceHookId ? { sourceHookId: shape.sourceHookId } : {}),
73
+ ...(options.questionId ? { questionId: options.questionId } : {}),
74
+ ...(existing.decisionId ? { decisionId: existing.decisionId } : {})
75
+ };
76
+ return upsertQuestionObligation(state, updated);
77
+ }
78
+ export function resolveQuestionObligationByQuestionId(state, questionId, decisionId, status = "satisfied") {
79
+ return {
80
+ ...state,
81
+ questionObligations: (state.questionObligations ?? []).map((obligation) => {
82
+ if (obligation.questionId !== questionId || obligation.status !== "pending") {
83
+ return obligation;
84
+ }
85
+ return {
86
+ ...obligation,
87
+ status,
88
+ updatedAt: nowIso(),
89
+ ...(decisionId ? { decisionId } : obligation.decisionId ? { decisionId: obligation.decisionId } : {})
90
+ };
91
+ })
92
+ };
93
+ }
94
+ export function resolveFirstResearchShapeObligation(state, options) {
95
+ return {
96
+ ...state,
97
+ questionObligations: (state.questionObligations ?? []).map((obligation) => {
98
+ const matches = obligation.kind === "first_research_shape_confirmation" && ((options.sourceHookId && obligation.sourceHookId === options.sourceHookId) ||
99
+ (options.questionId && obligation.questionId === options.questionId));
100
+ if (!matches || obligation.status !== "pending") {
101
+ return obligation;
102
+ }
103
+ return {
104
+ ...obligation,
105
+ status: options.status ?? "satisfied",
106
+ updatedAt: nowIso(),
107
+ ...(options.questionId ? { questionId: options.questionId } : obligation.questionId ? { questionId: obligation.questionId } : {}),
108
+ ...(options.decisionId ? { decisionId: options.decisionId } : obligation.decisionId ? { decisionId: obligation.decisionId } : {})
109
+ };
110
+ })
111
+ };
112
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@longtable/cli",
3
- "version": "0.1.32",
3
+ "version": "0.1.34",
4
4
  "private": false,
5
5
  "description": "Researcher-facing LongTable CLI",
6
6
  "type": "module",
@@ -29,12 +29,12 @@
29
29
  },
30
30
  "dependencies": {
31
31
  "@clack/prompts": "^1.2.0",
32
- "@longtable/checkpoints": "0.1.32",
33
- "@longtable/core": "0.1.32",
34
- "@longtable/memory": "0.1.32",
35
- "@longtable/provider-claude": "0.1.32",
36
- "@longtable/provider-codex": "0.1.32",
37
- "@longtable/setup": "0.1.32"
32
+ "@longtable/checkpoints": "0.1.34",
33
+ "@longtable/core": "0.1.34",
34
+ "@longtable/memory": "0.1.34",
35
+ "@longtable/provider-claude": "0.1.34",
36
+ "@longtable/provider-codex": "0.1.34",
37
+ "@longtable/setup": "0.1.34"
38
38
  },
39
39
  "devDependencies": {
40
40
  "@types/node": "^22.10.1",