@openship/protocol 0.0.1

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.
Files changed (35) hide show
  1. package/README.md +12 -0
  2. package/bin/openship.mjs +96 -0
  3. package/dist/package-meta.json +7 -0
  4. package/dist/skill/SKILL.md +18 -0
  5. package/dist/skill/references/examples/invalid/changes-submission.json +9 -0
  6. package/dist/skill/references/examples/invalid/changes-violation.json +7 -0
  7. package/dist/skill/references/examples/invalid/discovery.json +13 -0
  8. package/dist/skill/references/examples/invalid/sources-manifest.json +11 -0
  9. package/dist/skill/references/examples/invalid/systems-ownership.json +29 -0
  10. package/dist/skill/references/examples/invalid/systems.json +34 -0
  11. package/dist/skill/references/examples/valid/changes-accepted.json +13 -0
  12. package/dist/skill/references/examples/valid/changes-policy.json +12 -0
  13. package/dist/skill/references/examples/valid/changes-status.json +12 -0
  14. package/dist/skill/references/examples/valid/changes-submission.json +11 -0
  15. package/dist/skill/references/examples/valid/changes-violation.json +16 -0
  16. package/dist/skill/references/examples/valid/discovery.json +20 -0
  17. package/dist/skill/references/examples/valid/sources-bundle.json +10 -0
  18. package/dist/skill/references/examples/valid/sources-manifest.json +27 -0
  19. package/dist/skill/references/examples/valid/systems.json +55 -0
  20. package/dist/skill/references/openship-changes.md +135 -0
  21. package/dist/skill/references/openship-sources.md +143 -0
  22. package/dist/skill/references/openship-systems.md +165 -0
  23. package/dist/skill/references/openship.md +125 -0
  24. package/dist/skill/references/schemas/changes-accepted.schema.json +17 -0
  25. package/dist/skill/references/schemas/changes-policy.schema.json +44 -0
  26. package/dist/skill/references/schemas/changes-status.schema.json +22 -0
  27. package/dist/skill/references/schemas/changes-submission.schema.json +34 -0
  28. package/dist/skill/references/schemas/changes-violation.schema.json +32 -0
  29. package/dist/skill/references/schemas/discovery.schema.json +61 -0
  30. package/dist/skill/references/schemas/sources-bundle.schema.json +27 -0
  31. package/dist/skill/references/schemas/sources-manifest.schema.json +79 -0
  32. package/dist/skill/references/schemas/systems.schema.json +121 -0
  33. package/package.json +52 -0
  34. package/src/index.d.ts +36 -0
  35. package/src/index.js +454 -0
@@ -0,0 +1,27 @@
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "$id": "https://openship.dev/schemas/sources-bundle.schema.json",
4
+ "title": "OpenShip Sources v1 bundle",
5
+ "type": "object",
6
+ "required": ["openship", "capability", "digest", "files"],
7
+ "properties": {
8
+ "openship": { "const": "1.0" },
9
+ "capability": { "const": "sources" },
10
+ "generatedAt": { "type": "string", "format": "date-time" },
11
+ "digest": { "type": "string", "pattern": "^sha256:[0-9a-f]{64}$" },
12
+ "files": {
13
+ "type": "object",
14
+ "propertyNames": { "type": "string", "minLength": 1, "maxLength": 512, "pattern": "^(?!/)(?!.*\\\\)(?!.*(?:^|/)\\.{1,2}(?:/|$))(?!.*//)[^\\u0000]+$" },
15
+ "additionalProperties": {
16
+ "type": "object",
17
+ "required": ["encoding", "content"],
18
+ "properties": {
19
+ "encoding": { "enum": ["utf-8", "base64"] },
20
+ "content": { "type": "string" }
21
+ },
22
+ "additionalProperties": true
23
+ }
24
+ }
25
+ },
26
+ "additionalProperties": true
27
+ }
@@ -0,0 +1,79 @@
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "$id": "https://openship.dev/schemas/sources-manifest.schema.json",
4
+ "title": "OpenShip Sources v1 manifest",
5
+ "type": "object",
6
+ "required": ["openship", "capability", "digest", "project", "totals", "files"],
7
+ "properties": {
8
+ "openship": { "const": "1.0" },
9
+ "capability": { "const": "sources" },
10
+ "generatedAt": { "type": "string", "format": "date-time" },
11
+ "digest": { "$ref": "#/$defs/digest" },
12
+ "parent": { "$ref": "#/$defs/digest" },
13
+ "project": {
14
+ "type": "object",
15
+ "required": ["name", "description"],
16
+ "properties": {
17
+ "name": { "type": "string", "minLength": 1 },
18
+ "description": { "type": "string", "minLength": 1 },
19
+ "homepage": { "type": "string", "format": "uri" },
20
+ "repository": { "type": "string", "format": "uri" },
21
+ "license": { "type": "string", "minLength": 1 }
22
+ },
23
+ "additionalProperties": true
24
+ },
25
+ "commit": {
26
+ "type": "object",
27
+ "required": ["sha", "dirty"],
28
+ "properties": {
29
+ "sha": { "type": "string", "minLength": 1 },
30
+ "ref": { "type": "string" },
31
+ "committedAt": { "type": "string", "format": "date-time" },
32
+ "dirty": { "type": "boolean" }
33
+ },
34
+ "additionalProperties": true
35
+ },
36
+ "stack": { "type": "array", "items": { "type": "string" }, "uniqueItems": true },
37
+ "structure": { "type": "array", "items": { "type": "object", "required": ["path", "purpose"], "properties": { "path": { "type": "string" }, "purpose": { "type": "string" } }, "additionalProperties": true } },
38
+ "setup": { "type": "object", "additionalProperties": true },
39
+ "env": { "type": "array", "items": { "type": "string", "pattern": "^[A-Z][A-Z0-9_]*$" }, "uniqueItems": true },
40
+ "ignore": { "type": "array", "items": { "type": "string" }, "uniqueItems": true },
41
+ "ignoreNames": { "type": "array", "items": { "type": "string" }, "uniqueItems": true },
42
+ "fileSet": { "type": "string", "minLength": 1 },
43
+ "totals": {
44
+ "type": "object",
45
+ "required": ["files", "bytes"],
46
+ "properties": {
47
+ "files": { "type": "integer", "minimum": 0 },
48
+ "bytes": { "type": "integer", "minimum": 0 }
49
+ },
50
+ "additionalProperties": true
51
+ },
52
+ "files": {
53
+ "type": "array",
54
+ "items": { "$ref": "#/$defs/file" }
55
+ }
56
+ },
57
+ "$defs": {
58
+ "digest": { "type": "string", "pattern": "^sha256:[0-9a-f]{64}$" },
59
+ "path": { "type": "string", "minLength": 1, "maxLength": 512, "pattern": "^(?!/)(?!.*\\\\)(?!.*(?:^|/)\\.{1,2}(?:/|$))(?!.*//)[^\\u0000]+$" },
60
+ "file": {
61
+ "type": "object",
62
+ "required": ["path", "size", "sha256", "encoding", "mediaType", "type"],
63
+ "properties": {
64
+ "path": { "$ref": "#/$defs/path" },
65
+ "size": { "type": "integer", "minimum": 0 },
66
+ "sha256": { "type": "string", "pattern": "^[0-9a-f]{64}$" },
67
+ "encoding": { "enum": ["utf-8", "base64"] },
68
+ "mediaType": { "type": "string", "minLength": 1 },
69
+ "type": { "enum": ["file", "symlink"] },
70
+ "target": { "$ref": "#/$defs/path" }
71
+ },
72
+ "allOf": [
73
+ { "if": { "properties": { "type": { "const": "symlink" } }, "required": ["type"] }, "then": { "properties": { "target": { "$ref": "#/$defs/path" } }, "required": ["target"] } }
74
+ ],
75
+ "additionalProperties": true
76
+ }
77
+ },
78
+ "additionalProperties": true
79
+ }
@@ -0,0 +1,121 @@
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "$id": "https://openship.dev/schemas/systems.schema.json",
4
+ "title": "OpenShip Systems v1",
5
+ "type": "object",
6
+ "required": ["openship", "capability", "source", "system"],
7
+ "properties": {
8
+ "openship": { "const": "1.0" },
9
+ "capability": { "const": "systems" },
10
+ "source": {
11
+ "type": "object",
12
+ "required": ["manifest", "bundle"],
13
+ "properties": {
14
+ "manifest": { "$ref": "sources-manifest.schema.json" },
15
+ "bundle": { "$ref": "sources-bundle.schema.json" }
16
+ },
17
+ "additionalProperties": true
18
+ },
19
+ "system": {
20
+ "type": "object",
21
+ "required": ["id", "name", "rootNodeId", "nodes", "edges"],
22
+ "properties": {
23
+ "id": { "$ref": "#/$defs/id" },
24
+ "name": { "type": "string", "minLength": 1 },
25
+ "rootNodeId": { "$ref": "#/$defs/id" },
26
+ "metadata": { "type": "object", "additionalProperties": true },
27
+ "nodes": { "type": "array", "minItems": 1, "items": { "$ref": "#/$defs/node" } },
28
+ "edges": { "type": "array", "items": { "$ref": "#/$defs/edge" } },
29
+ "context": { "$ref": "#/$defs/context" }
30
+ },
31
+ "additionalProperties": true
32
+ }
33
+ },
34
+ "$defs": {
35
+ "id": { "type": "string", "pattern": "^[A-Za-z0-9._:-]+$" },
36
+ "digest": { "type": "string", "pattern": "^sha256:[0-9a-f]{64}$" },
37
+ "ownership": { "enum": ["first_party", "third_party"] },
38
+ "node": {
39
+ "type": "object",
40
+ "required": ["id", "kind", "name", "metadata"],
41
+ "properties": {
42
+ "id": { "$ref": "#/$defs/id" },
43
+ "kind": { "enum": ["Root", "Host", "Container", "Process", "Library"] },
44
+ "name": { "type": "string", "minLength": 1 },
45
+ "parentId": { "$ref": "#/$defs/id" },
46
+ "sourceSelectors": { "type": "array", "items": { "type": "string", "minLength": 1 }, "uniqueItems": true },
47
+ "metadata": {
48
+ "type": "object",
49
+ "required": ["ownership"],
50
+ "properties": {
51
+ "ownership": { "$ref": "#/$defs/ownership" }
52
+ },
53
+ "additionalProperties": true
54
+ }
55
+ },
56
+ "additionalProperties": true
57
+ },
58
+ "edge": {
59
+ "type": "object",
60
+ "required": ["id", "type", "fromNodeId", "toNodeId"],
61
+ "properties": {
62
+ "id": { "$ref": "#/$defs/id" },
63
+ "type": { "enum": ["Runtime", "Dataflow", "Dependency"] },
64
+ "fromNodeId": { "$ref": "#/$defs/id" },
65
+ "toNodeId": { "$ref": "#/$defs/id" },
66
+ "metadata": { "type": "object", "additionalProperties": true }
67
+ },
68
+ "additionalProperties": true
69
+ },
70
+ "document": {
71
+ "type": "object",
72
+ "required": ["kind", "hash", "title", "language", "text"],
73
+ "properties": {
74
+ "kind": { "enum": ["Document", "Skill", "Prompt"] },
75
+ "hash": { "$ref": "#/$defs/digest" },
76
+ "title": { "type": "string", "minLength": 1 },
77
+ "language": { "type": "string", "minLength": 1 },
78
+ "text": { "type": "string" },
79
+ "supersedes": { "$ref": "#/$defs/digest" }
80
+ },
81
+ "additionalProperties": true
82
+ },
83
+ "matrix": {
84
+ "type": "object",
85
+ "required": ["nodeId", "concern"],
86
+ "properties": {
87
+ "nodeId": { "$ref": "#/$defs/id" },
88
+ "concern": { "type": "string", "minLength": 1 },
89
+ "documentRefs": { "type": "array", "items": { "$ref": "#/$defs/digest" }, "uniqueItems": true },
90
+ "skillRefs": { "type": "array", "items": { "$ref": "#/$defs/digest" }, "uniqueItems": true }
91
+ },
92
+ "additionalProperties": true
93
+ },
94
+ "artifact": {
95
+ "type": "object",
96
+ "required": ["id", "nodeId", "concern", "type"],
97
+ "properties": {
98
+ "id": { "$ref": "#/$defs/id" },
99
+ "nodeId": { "$ref": "#/$defs/id" },
100
+ "concern": { "type": "string", "minLength": 1 },
101
+ "type": { "enum": ["Summary", "Docs", "Code"] },
102
+ "language": { "type": "string" },
103
+ "text": { "type": "string" },
104
+ "sourcePaths": { "type": "array", "items": { "type": "string" }, "uniqueItems": true }
105
+ },
106
+ "additionalProperties": true
107
+ },
108
+ "context": {
109
+ "type": "object",
110
+ "properties": {
111
+ "concerns": { "type": "array", "items": { "type": "string", "minLength": 1 }, "uniqueItems": true },
112
+ "documents": { "type": "array", "items": { "$ref": "#/$defs/document" } },
113
+ "matrix": { "type": "array", "items": { "$ref": "#/$defs/matrix" } },
114
+ "systemPromptRefs": { "type": "array", "items": { "$ref": "#/$defs/digest" }, "uniqueItems": true },
115
+ "artifacts": { "type": "array", "items": { "$ref": "#/$defs/artifact" } }
116
+ },
117
+ "additionalProperties": true
118
+ }
119
+ },
120
+ "additionalProperties": true
121
+ }
package/package.json ADDED
@@ -0,0 +1,52 @@
1
+ {
2
+ "name": "@openship/protocol",
3
+ "version": "0.0.1",
4
+ "description": "Canonical OpenShip 1.0 types, validators, consumer helpers, schemas, and skill assets.",
5
+ "type": "module",
6
+ "license": "MIT",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/openshipdev/openship.git",
10
+ "directory": "packages/protocol"
11
+ },
12
+ "engines": {
13
+ "node": ">=20"
14
+ },
15
+ "exports": {
16
+ ".": {
17
+ "types": "./src/index.d.ts",
18
+ "browser": "./src/index.js",
19
+ "node": "./src/index.js",
20
+ "import": "./src/index.js",
21
+ "default": "./src/index.js"
22
+ },
23
+ "./browser": {
24
+ "types": "./src/index.d.ts",
25
+ "default": "./src/index.js"
26
+ },
27
+ "./node": {
28
+ "types": "./src/index.d.ts",
29
+ "default": "./src/index.js"
30
+ },
31
+ "./schemas/*": "./dist/skill/references/schemas/*",
32
+ "./skill/*": "./dist/skill/*"
33
+ },
34
+ "bin": {
35
+ "openship": "bin/openship.mjs"
36
+ },
37
+ "files": [
38
+ "bin",
39
+ "dist",
40
+ "src"
41
+ ],
42
+ "dependencies": {
43
+ "@noble/hashes": "2.3.0"
44
+ },
45
+ "publishConfig": {
46
+ "access": "public"
47
+ },
48
+ "scripts": {
49
+ "build": "node scripts/prepare-package.mjs",
50
+ "test": "node scripts/prepare-package.mjs && node --test test/*.test.mjs"
51
+ }
52
+ }
package/src/index.d.ts ADDED
@@ -0,0 +1,36 @@
1
+ export type OpenShipEncoding = "utf-8" | "base64";
2
+ export type OpenShipCapability = "discovery" | "sources" | "changes" | "systems";
3
+ export interface SourceFileMetadata { path: string; size: number; sha256: string; encoding: OpenShipEncoding; mediaType: string; type: "file" | "symlink"; target?: string; [key: string]: unknown }
4
+ export interface SourcesManifest { openship: "1.0"; capability: "sources"; digest: string; project: { name: string; description: string; [key: string]: unknown }; totals: { files: number; bytes: number; [key: string]: unknown }; files: SourceFileMetadata[]; [key: string]: unknown }
5
+ export interface SourcesBundle { openship: "1.0"; capability: "sources"; digest: string; files: Record<string, { encoding: OpenShipEncoding; content: string; [key: string]: unknown }>; [key: string]: unknown }
6
+ export interface DiscoveryDocument { openship: "1.0"; capability: "discovery"; project: { name: string; description: string; [key: string]: unknown }; capabilities: { sources: { manifest: string; bundle: string; [key: string]: unknown }; systems?: { document: string; [key: string]: unknown }; changes?: { policy: string; submit: string; status: string; [key: string]: unknown }; [key: string]: unknown }; [key: string]: unknown }
7
+ export type SystemsNodeKind = "Root" | "Host" | "Container" | "Process" | "Library";
8
+ export type SystemsNodeOwnership = "first_party" | "third_party";
9
+ export interface SystemsNodeMetadata { ownership: SystemsNodeOwnership; [key: string]: unknown }
10
+ export interface SystemsNode { id: string; kind: SystemsNodeKind; name: string; parentId?: string; sourceSelectors?: string[]; metadata: SystemsNodeMetadata; [key: string]: unknown }
11
+ export interface SystemsGraph { id: string; name: string; rootNodeId: string; nodes: SystemsNode[]; edges: Array<Record<string, unknown>>; metadata?: Record<string, unknown>; context?: Record<string, unknown>; [key: string]: unknown }
12
+ export interface SystemsDocument { openship: "1.0"; capability: "systems"; source: { manifest: SourcesManifest; bundle: SourcesBundle; [key: string]: unknown }; system: SystemsGraph; [key: string]: unknown }
13
+ export interface VerifiedSourceFile { metadata: SourceFileMetadata; bytes: Uint8Array }
14
+ export interface VerifiedSources { manifest: SourcesManifest; bundle: SourcesBundle; files: VerifiedSourceFile[]; decodedBytes: number }
15
+ export interface FetchedOpenShip { origin: string; discovery: DiscoveryDocument; snapshot: { kind: "systems"; document: SystemsDocument } | { kind: "sources"; manifest: SourcesManifest; bundle: SourcesBundle }; verified: VerifiedSources }
16
+ export class OpenShipValidationError extends Error { path: string; code: string; constructor(path: string, message: string, code?: string) }
17
+ export function sha256Hex(value: string | Uint8Array): string;
18
+ export function decodeOpenShipBase64(value: string, path?: string): Uint8Array;
19
+ export function encodeOpenShipBase64(value: Uint8Array): string;
20
+ export function assertSafePath(value: unknown, path?: string): string;
21
+ export function compareUtf8(left: string, right: string): number;
22
+ export function matchOpenShipPattern(pattern: string, path: string): boolean;
23
+ export function computeSourcesDigest(files: SourceFileMetadata[]): string;
24
+ export function validateDiscovery(value: unknown): DiscoveryDocument;
25
+ export function validateSources(manifest: unknown, bundle: unknown, options?: { maxDecodedBytes?: number }): VerifiedSources;
26
+ export function validateSystems(value: unknown, options?: { maxDecodedBytes?: number }): SystemsDocument;
27
+ export function validateChangesDocument(value: unknown): Record<string, unknown>;
28
+ export function validateChangesSubmission(value: unknown): Record<string, unknown>;
29
+ export function validateChangesAccepted(value: unknown): Record<string, unknown>;
30
+ export function validateChangesStatus(value: unknown): Record<string, unknown>;
31
+ export function validateChangesPolicy(value: unknown): Record<string, unknown>;
32
+ export function validateChangesViolation(value: unknown): Record<string, unknown>;
33
+ export function normalizeOpenShipOrigin(origin: string, options?: { allowLoopbackHttp?: boolean }): string;
34
+ export function fetchOpenShip(origin: string, options?: { fetch?: typeof fetch; maxDecodedBytes?: number; allowLoopbackHttp?: boolean; preferSystems?: boolean }): Promise<FetchedOpenShip>;
35
+ export function composeChangesSubmission(base: VerifiedSources, current: VerifiedSources, input: { title: string; intent: string }): Record<string, unknown>;
36
+ export function diffSources(base: VerifiedSources, current: VerifiedSources): Array<{ path: string; operation: "create" | "replace" | "delete"; before: VerifiedSourceFile | null; after: VerifiedSourceFile | null }>;