@lincyaw/kernel 1.0.0-rc.44 → 1.0.0-rc.46
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/package.json +1 -1
- package/src/contracts/projects.ts +4 -1
- package/src/contracts/workspace-review.ts +39 -0
- package/src/contracts/workspace-source.ts +38 -0
- package/src/contracts.ts +2 -0
- package/src/node/index.ts +2 -0
- package/src/node/workspace-review.ts +9 -0
- package/src/node/workspace-source.ts +10 -0
package/package.json
CHANGED
|
@@ -10,6 +10,8 @@ export type ProjectOperation = DocumentOperation | { op: 'retitle', dir: string,
|
|
|
10
10
|
export interface ProjectCaller { member: Member, origin: 'editor' | 'agent', boundDocument?: string }
|
|
11
11
|
export interface ProjectObservation { snapshot?: string, configuration: string }
|
|
12
12
|
export interface ProjectCapabilities {
|
|
13
|
+
templates?: string[]
|
|
14
|
+
nextTemplatesOffset?: number
|
|
13
15
|
available: boolean
|
|
14
16
|
actions: Record<ProjectOperation['op'], { available: boolean, reasons: string[] }>
|
|
15
17
|
reasons: string[]
|
|
@@ -45,7 +47,7 @@ export interface ProjectApplied extends OperationAnswer {
|
|
|
45
47
|
}
|
|
46
48
|
/** Directory management borrows the Web writer; metadata retitle borrows canonical document CAS. */
|
|
47
49
|
export interface ProjectAuthoring {
|
|
48
|
-
capabilities(caller: ProjectCaller): Promise<ProjectCapabilities>
|
|
50
|
+
capabilities(caller: ProjectCaller, query?: { templatesOffset?: number }): Promise<ProjectCapabilities>
|
|
49
51
|
plan(request: ProjectPlanRequest, caller: ProjectCaller): Promise<ProjectPlan>
|
|
50
52
|
readPlan(request: ProjectApply, caller: ProjectCaller): Promise<ProjectPlan>
|
|
51
53
|
apply(request: ProjectApply, caller: ProjectCaller, signal?: AbortSignal): Promise<ProjectApplied>
|
|
@@ -57,3 +59,4 @@ export const PROJECT_PLAN_SCHEMA = { type: 'object', additionalProperties: false
|
|
|
57
59
|
id: text, operation: { oneOf: [operation('create', { title: text, template: text }, []), operation('copy', { to: text, title: text }, ['to']), operation('rename', { to: text }, ['to']), operation('delete', {}, []), operation('retitle', { title: text }, ['title'])] },
|
|
58
60
|
} } as const
|
|
59
61
|
export const PROJECT_APPLY_SCHEMA = { type: 'object', additionalProperties: false, required: ['planId', 'digest'], properties: { planId: text, digest: { type: 'string', pattern: '^[a-f0-9]{64}$' }, confirmDeletion: { const: true } } } as const
|
|
62
|
+
export const PROJECT_CAPABILITIES_SCHEMA = { type: 'object', additionalProperties: false, properties: { templatesOffset: { type: 'integer', minimum: 0 } } } as const
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { Member } from './server.ts'
|
|
2
|
+
import type { ReviewChange, ReviewStep } from './workspace.ts'
|
|
3
|
+
|
|
4
|
+
export const WORKSPACE_REVIEW_MAX_REQUEST_CHARS = 8192
|
|
5
|
+
export const WORKSPACE_REVIEW_MAX_RESPONSE_CHARS = 7168
|
|
6
|
+
export const WORKSPACE_REVIEW_FRAGMENT_CHARS = 4000
|
|
7
|
+
export interface WorkspaceReviewQuery { part?: 'summary' | 'files' | 'steps' | 'diff', path?: string, step?: string, offset?: number, snapshot?: string }
|
|
8
|
+
export interface WorkspaceReviewSummary { id: string, document: string, running: boolean, mode: 'required' | 'auto', files: number, steps: number }
|
|
9
|
+
export interface WorkspaceReviewAnswer {
|
|
10
|
+
review: WorkspaceReviewSummary | null
|
|
11
|
+
snapshot?: string
|
|
12
|
+
files?: Omit<ReviewChange, 'diff'>[]
|
|
13
|
+
steps?: (Omit<ReviewStep, 'changes'> & { files: number })[]
|
|
14
|
+
nextOffset?: number
|
|
15
|
+
diff?: { path: string, step?: string, text: string, offset: number, totalChars: number, sha256: string }
|
|
16
|
+
}
|
|
17
|
+
export type WorkspaceReviewChange =
|
|
18
|
+
| { action: 'accept', snapshot: string, reject?: string[], message?: string }
|
|
19
|
+
| { action: 'reject', snapshot: string, paths?: string[], confirm: true }
|
|
20
|
+
| { action: 'restore', snapshot: string, step: string, confirm: true }
|
|
21
|
+
export interface WorkspaceReviewChanged { outcome: 'accepted' | 'rejected' | 'restored' | 'updated' | 'empty', revision?: string, files?: number, remainingFiles?: number }
|
|
22
|
+
/** Workspace publication authority; document-scoped agent credentials must never receive this service. */
|
|
23
|
+
export interface WorkspaceReview {
|
|
24
|
+
read(query: WorkspaceReviewQuery, member: Member): Promise<WorkspaceReviewAnswer>
|
|
25
|
+
check(change: WorkspaceReviewChange, member: Member): Promise<void>
|
|
26
|
+
change(change: WorkspaceReviewChange, member: Member, signal?: AbortSignal): Promise<WorkspaceReviewChanged>
|
|
27
|
+
}
|
|
28
|
+
const path = { type: 'string', minLength: 1, maxLength: 500 } as const
|
|
29
|
+
const snapshot = { type: 'string', pattern: '^[a-f0-9]{64}$' } as const
|
|
30
|
+
const step = { type: 'string', minLength: 1, maxLength: 100 } as const
|
|
31
|
+
const paths = { type: 'array', minItems: 1, maxItems: 200, uniqueItems: true, items: path } as const
|
|
32
|
+
export const WORKSPACE_REVIEW_QUERY_SCHEMA = { type: 'object', additionalProperties: false, properties: {
|
|
33
|
+
part: { enum: ['summary', 'files', 'steps', 'diff'] }, path, step, offset: { type: 'integer', minimum: 0 }, snapshot,
|
|
34
|
+
} } as const
|
|
35
|
+
export const WORKSPACE_REVIEW_CHANGE_SCHEMA = { oneOf: [
|
|
36
|
+
{ type: 'object', additionalProperties: false, required: ['action', 'snapshot'], properties: { action: { const: 'accept' }, snapshot, reject: paths, message: { type: 'string', minLength: 1, maxLength: 4000 } } },
|
|
37
|
+
{ type: 'object', additionalProperties: false, required: ['action', 'snapshot', 'confirm'], properties: { action: { const: 'reject' }, snapshot, paths, confirm: { const: true } } },
|
|
38
|
+
{ type: 'object', additionalProperties: false, required: ['action', 'snapshot', 'step', 'confirm'], properties: { action: { const: 'restore' }, snapshot, step, confirm: { const: true } } },
|
|
39
|
+
] } as const
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { Member } from './server.ts'
|
|
2
|
+
import type { SourceFile } from './workspace.ts'
|
|
3
|
+
|
|
4
|
+
export const SOURCE_MAX_BYTES = 2 << 20
|
|
5
|
+
export const SOURCE_MAX_FILES = 16
|
|
6
|
+
export const SOURCE_MAX_REQUEST_CHARS = SOURCE_MAX_BYTES * 3 + 8192
|
|
7
|
+
export const SOURCE_MAX_RESPONSE_CHARS = 7168
|
|
8
|
+
export const SOURCE_FRAGMENT_CHARS = 4000
|
|
9
|
+
/** Supplied by an adapter, never accepted as model arguments. */
|
|
10
|
+
export interface SourceCaller { member: Member, boundDocument?: string, confirmed?: boolean, origin: 'editor' | 'agent' }
|
|
11
|
+
export interface SourceListQuery { document?: string, query?: string, offset?: number, snapshot?: string }
|
|
12
|
+
export interface SourceListAnswer { files: SourceFile[], snapshot: string, nextOffset?: number, truncated?: true }
|
|
13
|
+
export interface SourceReadQuery { document?: string, path: string, offset?: number, version?: string }
|
|
14
|
+
export interface SourceReadAnswer { path: string, version: string, text: string, offset: number, totalChars: number, nextOffset?: number }
|
|
15
|
+
export type SourceEditFile = { path: string, version?: string } & ({ content: string, create?: true } | { find: string, replace: string })
|
|
16
|
+
export type SourceEdit = ({ document?: string } & SourceEditFile) | { document?: string, edits: SourceEditFile[] }
|
|
17
|
+
export interface SourceSaved { saved: true, changed: boolean, path?: string, files?: number, revision?: string, current?: false }
|
|
18
|
+
export interface PreparedSourceEdit { change(signal?: AbortSignal): Promise<SourceSaved> }
|
|
19
|
+
/** Current source editor scope and transaction owner; invalid IR is readable and repairable. */
|
|
20
|
+
export interface WorkspaceSource {
|
|
21
|
+
list(query: SourceListQuery, caller: SourceCaller): Promise<SourceListAnswer>
|
|
22
|
+
read(query: SourceReadQuery, caller: SourceCaller): Promise<SourceReadAnswer>
|
|
23
|
+
prepare(edit: SourceEdit, caller: SourceCaller): Promise<PreparedSourceEdit>
|
|
24
|
+
}
|
|
25
|
+
const document = { type: 'string', maxLength: 500 } as const
|
|
26
|
+
const path = { type: 'string', minLength: 1, maxLength: 500 } as const
|
|
27
|
+
const version = { type: 'string', pattern: '^[a-f0-9]{20}$' } as const
|
|
28
|
+
const offset = { type: 'integer', minimum: 0 } as const
|
|
29
|
+
export const SOURCE_LIST_SCHEMA = { type: 'object', additionalProperties: false, properties: { document, query: { type: 'string', maxLength: 200 }, offset, snapshot: { type: 'string', pattern: '^[a-f0-9]{64}$' } } } as const
|
|
30
|
+
export const SOURCE_READ_SCHEMA = { type: 'object', additionalProperties: false, required: ['path'], properties: { document, path, offset, version } } as const
|
|
31
|
+
const fileSchema = { oneOf: [
|
|
32
|
+
{ type: 'object', additionalProperties: false, required: ['path', 'content'], properties: { path, version, content: { type: 'string', maxLength: SOURCE_MAX_BYTES }, create: { const: true } } },
|
|
33
|
+
{ type: 'object', additionalProperties: false, required: ['path', 'find', 'replace'], properties: { path, version, find: { type: 'string', minLength: 1, maxLength: SOURCE_MAX_BYTES }, replace: { type: 'string', maxLength: SOURCE_MAX_BYTES } } },
|
|
34
|
+
] } as const
|
|
35
|
+
export const SOURCE_EDIT_SCHEMA = { oneOf: [
|
|
36
|
+
...fileSchema.oneOf.map(schema => ({ ...schema, properties: { document, ...schema.properties } })),
|
|
37
|
+
{ type: 'object', additionalProperties: false, required: ['edits'], properties: { document, edits: { type: 'array', minItems: 1, maxItems: SOURCE_MAX_FILES, items: fileSchema } } },
|
|
38
|
+
] } as const
|
package/src/contracts.ts
CHANGED
|
@@ -23,6 +23,8 @@ export * from './contracts/server.ts'
|
|
|
23
23
|
export * from './contracts/service.ts'
|
|
24
24
|
export * from './contracts/speech.ts'
|
|
25
25
|
export * from './contracts/speech-settings.ts'
|
|
26
|
+
export * from './contracts/workspace-review.ts'
|
|
27
|
+
export * from './contracts/workspace-source.ts'
|
|
26
28
|
export * from './contracts/transcription.ts'
|
|
27
29
|
export * from './contracts/transcription-adoption.ts'
|
|
28
30
|
export * from './contracts/voice.ts'
|
package/src/node/index.ts
CHANGED
|
@@ -29,3 +29,5 @@ export { systemLocale } from './locale.ts'
|
|
|
29
29
|
export { OperatorSpeechSettings, operatorSpeechSecrets, SpeechSettingsError, validateSpeechSettingsChange } from './operator-speech.ts'
|
|
30
30
|
export { devStateFile, readServiceState, removeServiceState, serveStateDir } from './service-state.ts'
|
|
31
31
|
export type { ServiceState } from './service-state.ts'
|
|
32
|
+
export { validateWorkspaceReviewQuery, validateWorkspaceReviewChange } from './workspace-review.ts'
|
|
33
|
+
export { validateSourceList, validateSourceRead, validateSourceEdit } from './workspace-source.ts'
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Validator } from '@cfworker/json-schema'
|
|
2
|
+
import type { Schema } from '@cfworker/json-schema'
|
|
3
|
+
import { WORKSPACE_REVIEW_CHANGE_SCHEMA, WORKSPACE_REVIEW_QUERY_SCHEMA } from '../contracts/workspace-review.ts'
|
|
4
|
+
import type { WorkspaceReviewChange, WorkspaceReviewQuery } from '../contracts/workspace-review.ts'
|
|
5
|
+
|
|
6
|
+
const query = new Validator(WORKSPACE_REVIEW_QUERY_SCHEMA as unknown as Schema)
|
|
7
|
+
const change = new Validator(WORKSPACE_REVIEW_CHANGE_SCHEMA as unknown as Schema)
|
|
8
|
+
export const validateWorkspaceReviewQuery = (value: unknown): value is WorkspaceReviewQuery => query.validate(value).valid
|
|
9
|
+
export const validateWorkspaceReviewChange = (value: unknown): value is WorkspaceReviewChange => change.validate(value).valid
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Validator } from '@cfworker/json-schema'
|
|
2
|
+
import type { Schema } from '@cfworker/json-schema'
|
|
3
|
+
import { SOURCE_EDIT_SCHEMA, SOURCE_LIST_SCHEMA, SOURCE_READ_SCHEMA } from '../contracts/workspace-source.ts'
|
|
4
|
+
import type { SourceEdit, SourceListQuery, SourceReadQuery } from '../contracts/workspace-source.ts'
|
|
5
|
+
const list = new Validator(SOURCE_LIST_SCHEMA as unknown as Schema)
|
|
6
|
+
const read = new Validator(SOURCE_READ_SCHEMA as unknown as Schema)
|
|
7
|
+
const edit = new Validator(SOURCE_EDIT_SCHEMA as unknown as Schema)
|
|
8
|
+
export const validateSourceList = (value: unknown): value is SourceListQuery => list.validate(value).valid
|
|
9
|
+
export const validateSourceRead = (value: unknown): value is SourceReadQuery => read.validate(value).valid
|
|
10
|
+
export const validateSourceEdit = (value: unknown): value is SourceEdit => edit.validate(value).valid
|