@joiner-platform/cli 0.1.7 → 0.1.8
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
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@joiner-platform/cli",
|
|
3
|
-
"version": "0.1.
|
|
4
|
-
"gitHead": "
|
|
3
|
+
"version": "0.1.8",
|
|
4
|
+
"gitHead": "1772b17cd0dbb50de59223f22399e2e1131cd0c6",
|
|
5
5
|
"description": "The Joiner CLI: create, test, and publish Joiner tiles, with agent skills for coding agents.",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"joiner",
|
|
@@ -61,7 +61,7 @@ an older pin, so prefer the live result when upgrading:
|
|
|
61
61
|
|
|
62
62
|
<!-- begin: sdk-tarball-snippet (auto-generated by packages/poe-tiles-sdk/scripts/publish-tar.ts — do not edit by hand) -->
|
|
63
63
|
```json
|
|
64
|
-
"joiner-sdk": "https://misc-dev-uploads.quora-913.workers.dev/
|
|
64
|
+
"joiner-sdk": "https://misc-dev-uploads.quora-913.workers.dev/3f75e5830cbdcc3d24e8a2b6d368489e0233f3c5768d86afee490cf6a24d0da5"
|
|
65
65
|
```
|
|
66
66
|
<!-- end: sdk-tarball-snippet -->
|
|
67
67
|
|
|
@@ -482,8 +482,14 @@ the current user's id is present as an active row in the store's `$users`
|
|
|
482
482
|
table. It exits non-zero when the user is not an active member.
|
|
483
483
|
|
|
484
484
|
`stores schema` fetches the store schema, including all available mutators,
|
|
485
|
-
and prints
|
|
486
|
-
|
|
485
|
+
and prints CLI commands for checking access and dispatching each mutator and
|
|
486
|
+
action. Each dispatch command carries an example `--input` built from that
|
|
487
|
+
function's input schema: required fields only, with `"<fieldName>"` string
|
|
488
|
+
placeholders and numbers at the nearest allowed value to `0`. Replace the
|
|
489
|
+
placeholders before running it. When the input schema can't be read, or the
|
|
490
|
+
example would be too large for one shell argument (an array of more than 32
|
|
491
|
+
items, or more than 1 KiB of JSON), the command shows `--input '<json>'` and
|
|
492
|
+
its `--json` entry has no `inputExample`.
|
|
487
493
|
|
|
488
494
|
`stores mutate` fetches the store schema version, then sends a single mutation
|
|
489
495
|
push. It exits non-zero when the server reports a failed mutation.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
// Auto-generated by poe-tiles-sdk/scripts/publish-tar.ts — do not edit
|
|
2
|
-
// publishedAt: 2026-11-
|
|
2
|
+
// publishedAt: 2026-11-25T03:45:13.602Z
|
|
3
3
|
export const SDK_TARBALL_URL =
|
|
4
|
-
"https://misc-dev-uploads.quora-913.workers.dev/
|
|
4
|
+
"https://misc-dev-uploads.quora-913.workers.dev/3f75e5830cbdcc3d24e8a2b6d368489e0233f3c5768d86afee490cf6a24d0da5";
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
// owner: jyoung-q
|
|
2
|
+
import type { JSONValue } from "../client.js";
|
|
3
|
+
|
|
4
|
+
type Schema = { readonly [key: string]: unknown };
|
|
5
|
+
|
|
6
|
+
const NO_EXAMPLE = Symbol("no-example");
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Examples are printed as one shell argument, so a schema that needs a long
|
|
10
|
+
* input (a fixed 256x256 grid, say) gets the `'<json>'` placeholder instead.
|
|
11
|
+
* `MAX_ITEMS` bounds the work per array before the size check runs.
|
|
12
|
+
*/
|
|
13
|
+
const MAX_EXAMPLE_JSON_BYTES = 1024;
|
|
14
|
+
const MAX_ITEMS = 32;
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Builds a minimal input that matches a mutator or action's JSON Schema, for
|
|
18
|
+
* the copy-paste commands `stores schema` prints. Required object properties
|
|
19
|
+
* only; strings become `"<propertyName>"` placeholders.
|
|
20
|
+
*
|
|
21
|
+
* Returns `undefined` when the schema is not JSON Schema this can read (for
|
|
22
|
+
* example a serialized Zod instance) or the example would be longer than
|
|
23
|
+
* `MAX_EXAMPLE_JSON_BYTES` (UTF-8), so callers fall back to `'<json>'` rather than
|
|
24
|
+
* print an example the store would reject or the shell could not take.
|
|
25
|
+
*/
|
|
26
|
+
export function exampleInputFromJsonSchema(
|
|
27
|
+
schema: unknown,
|
|
28
|
+
): JSONValue | undefined {
|
|
29
|
+
const example = withinLength(exampleFor(schema, "string"));
|
|
30
|
+
return example === NO_EXAMPLE ? undefined : example;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function withinLength(
|
|
34
|
+
example: JSONValue | typeof NO_EXAMPLE,
|
|
35
|
+
): JSONValue | typeof NO_EXAMPLE {
|
|
36
|
+
return example !== NO_EXAMPLE &&
|
|
37
|
+
new TextEncoder().encode(JSON.stringify(example)).length <=
|
|
38
|
+
MAX_EXAMPLE_JSON_BYTES
|
|
39
|
+
? example
|
|
40
|
+
: NO_EXAMPLE;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function exampleFor(
|
|
44
|
+
schema: unknown,
|
|
45
|
+
label: string,
|
|
46
|
+
): JSONValue | typeof NO_EXAMPLE {
|
|
47
|
+
if (!isSchema(schema) || "def" in schema || "_zod" in schema) {
|
|
48
|
+
return NO_EXAMPLE;
|
|
49
|
+
}
|
|
50
|
+
if ("const" in schema) return schema["const"] as JSONValue;
|
|
51
|
+
const enumValues = schema["enum"];
|
|
52
|
+
if (Array.isArray(enumValues) && enumValues.length > 0) {
|
|
53
|
+
return enumValues[0] as JSONValue;
|
|
54
|
+
}
|
|
55
|
+
const branch = firstBranch(schema);
|
|
56
|
+
if (branch !== undefined) return exampleFor(branch, label);
|
|
57
|
+
return typedExample(schema, label);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function firstBranch(schema: Schema): unknown {
|
|
61
|
+
for (const key of ["anyOf", "oneOf"] as const) {
|
|
62
|
+
const branches = schema[key];
|
|
63
|
+
if (Array.isArray(branches) && branches.length > 0) return branches[0];
|
|
64
|
+
}
|
|
65
|
+
return undefined;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function typedExample(
|
|
69
|
+
schema: Schema,
|
|
70
|
+
label: string,
|
|
71
|
+
): JSONValue | typeof NO_EXAMPLE {
|
|
72
|
+
const type = Array.isArray(schema["type"])
|
|
73
|
+
? schema["type"][0]
|
|
74
|
+
: schema["type"];
|
|
75
|
+
switch (type) {
|
|
76
|
+
case "string":
|
|
77
|
+
return `<${label}>`;
|
|
78
|
+
case "number":
|
|
79
|
+
case "integer":
|
|
80
|
+
return numberExample(schema, type === "integer");
|
|
81
|
+
case "boolean":
|
|
82
|
+
return false;
|
|
83
|
+
case "null":
|
|
84
|
+
return null;
|
|
85
|
+
case "array":
|
|
86
|
+
return arrayExample(schema, label);
|
|
87
|
+
case "object":
|
|
88
|
+
return objectExample(schema);
|
|
89
|
+
default:
|
|
90
|
+
return NO_EXAMPLE;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/** 0, moved inside `minimum` / `maximum` and their exclusive forms. */
|
|
95
|
+
function numberExample(schema: Schema, integer: boolean): number {
|
|
96
|
+
const round = integer ? Math.ceil : (value: number) => value;
|
|
97
|
+
const roundDown = integer ? Math.floor : (value: number) => value;
|
|
98
|
+
const clamps: ReadonlyArray<
|
|
99
|
+
readonly [
|
|
100
|
+
string,
|
|
101
|
+
(value: number, bound: number) => boolean,
|
|
102
|
+
(bound: number) => number,
|
|
103
|
+
]
|
|
104
|
+
> = [
|
|
105
|
+
["minimum", (value, bound) => value < bound, round],
|
|
106
|
+
[
|
|
107
|
+
"exclusiveMinimum",
|
|
108
|
+
(value, bound) => value <= bound,
|
|
109
|
+
(bound) => roundDown(bound) + 1,
|
|
110
|
+
],
|
|
111
|
+
["maximum", (value, bound) => value > bound, roundDown],
|
|
112
|
+
[
|
|
113
|
+
"exclusiveMaximum",
|
|
114
|
+
(value, bound) => value >= bound,
|
|
115
|
+
(bound) => round(bound) - 1,
|
|
116
|
+
],
|
|
117
|
+
];
|
|
118
|
+
return clamps.reduce((value, [key, outside, inside]) => {
|
|
119
|
+
const bound = schema[key];
|
|
120
|
+
return typeof bound === "number" && outside(value, bound)
|
|
121
|
+
? inside(bound)
|
|
122
|
+
: value;
|
|
123
|
+
}, 0);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* One example per tuple position (`prefixItems`, or a draft-07 `items`
|
|
128
|
+
* array with `additionalItems` as the rest), then `items` examples up to `minItems`, or one when nothing else
|
|
129
|
+
* sets the length.
|
|
130
|
+
*/
|
|
131
|
+
function arrayExample(
|
|
132
|
+
schema: Schema,
|
|
133
|
+
label: string,
|
|
134
|
+
): JSONValue | typeof NO_EXAMPLE {
|
|
135
|
+
const { prefix, rest } = arrayParts(schema);
|
|
136
|
+
const result = examplesFor(prefix, label);
|
|
137
|
+
if (result === NO_EXAMPLE) return NO_EXAMPLE;
|
|
138
|
+
const minItems =
|
|
139
|
+
typeof schema["minItems"] === "number" ? schema["minItems"] : 0;
|
|
140
|
+
const restCount = Math.max(
|
|
141
|
+
minItems - result.length,
|
|
142
|
+
prefix.length === 0 ? 1 : 0,
|
|
143
|
+
);
|
|
144
|
+
if (restCount === 0) return withinLength(result);
|
|
145
|
+
if (!isSchema(rest)) {
|
|
146
|
+
return prefix.length === 0 && minItems === 0 ? [] : NO_EXAMPLE;
|
|
147
|
+
}
|
|
148
|
+
if (result.length + restCount > MAX_ITEMS) return NO_EXAMPLE;
|
|
149
|
+
const restExamples = examplesFor(Array(restCount).fill(rest), label);
|
|
150
|
+
return restExamples === NO_EXAMPLE
|
|
151
|
+
? NO_EXAMPLE
|
|
152
|
+
: withinLength([...result, ...restExamples]);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
function arrayParts(schema: Schema): { prefix: unknown[]; rest: unknown } {
|
|
156
|
+
const items = schema["items"];
|
|
157
|
+
if (Array.isArray(schema["prefixItems"])) {
|
|
158
|
+
return { prefix: schema["prefixItems"], rest: items };
|
|
159
|
+
}
|
|
160
|
+
if (Array.isArray(items)) {
|
|
161
|
+
return { prefix: items, rest: schema["additionalItems"] };
|
|
162
|
+
}
|
|
163
|
+
return { prefix: [], rest: items };
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
function examplesFor(
|
|
167
|
+
schemas: readonly unknown[],
|
|
168
|
+
label: string,
|
|
169
|
+
): JSONValue[] | typeof NO_EXAMPLE {
|
|
170
|
+
if (schemas.length > MAX_ITEMS) return NO_EXAMPLE;
|
|
171
|
+
const result: JSONValue[] = [];
|
|
172
|
+
for (const itemSchema of schemas) {
|
|
173
|
+
const value = exampleFor(itemSchema, label);
|
|
174
|
+
if (value === NO_EXAMPLE) return NO_EXAMPLE;
|
|
175
|
+
result.push(value);
|
|
176
|
+
}
|
|
177
|
+
return result;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
function objectExample(schema: Schema): JSONValue | typeof NO_EXAMPLE {
|
|
181
|
+
const properties = isSchema(schema["properties"]) ? schema["properties"] : {};
|
|
182
|
+
const required = Array.isArray(schema["required"])
|
|
183
|
+
? schema["required"].filter((key) => typeof key === "string")
|
|
184
|
+
: [];
|
|
185
|
+
const result: { [key: string]: JSONValue } = {};
|
|
186
|
+
for (const key of required) {
|
|
187
|
+
const value = exampleFor(properties[key], key);
|
|
188
|
+
if (value === NO_EXAMPLE) return NO_EXAMPLE;
|
|
189
|
+
result[key] = value;
|
|
190
|
+
}
|
|
191
|
+
return result;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
function isSchema(value: unknown): value is Schema {
|
|
195
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
196
|
+
}
|
package/src/commands/stores.ts
CHANGED
|
@@ -29,6 +29,7 @@ import {
|
|
|
29
29
|
parseNonNegativeIntegerOption,
|
|
30
30
|
parsePositiveIntegerOption,
|
|
31
31
|
} from "./parse-options.js";
|
|
32
|
+
import { exampleInputFromJsonSchema } from "./schema-input-example.js";
|
|
32
33
|
import { createStoreFilesCommands } from "./store-files.js";
|
|
33
34
|
|
|
34
35
|
const DEFAULT_MUTATE_TIMEOUT_MS = 15_000;
|
|
@@ -571,16 +572,16 @@ interface StoreSchemaCommands {
|
|
|
571
572
|
pull: string;
|
|
572
573
|
get: string;
|
|
573
574
|
scan: string;
|
|
574
|
-
mutators:
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
575
|
+
mutators: SchemaFunctionCommand[];
|
|
576
|
+
actions: SchemaFunctionCommand[];
|
|
577
|
+
}
|
|
578
|
+
|
|
579
|
+
interface SchemaFunctionCommand {
|
|
580
|
+
name: string;
|
|
581
|
+
description?: string;
|
|
582
|
+
/** A minimal input matching the function's JSON Schema, when one is readable. */
|
|
583
|
+
inputExample?: JSONValue;
|
|
584
|
+
command: string;
|
|
584
585
|
}
|
|
585
586
|
|
|
586
587
|
function buildSchemaCommands(result: StoreSchemaResult): StoreSchemaCommands {
|
|
@@ -589,53 +590,40 @@ function buildSchemaCommands(result: StoreSchemaResult): StoreSchemaCommands {
|
|
|
589
590
|
pull: `${cliName()} stores pull ${shellQuote(result.storeTypeId)} ${shellQuote(result.instanceId)} --after-version 0`,
|
|
590
591
|
get: `${cliName()} stores get ${shellQuote(result.storeTypeId)} ${shellQuote(result.instanceId)} '<tableName>' '<itemKey>'`,
|
|
591
592
|
scan: `${cliName()} stores scan ${shellQuote(result.storeTypeId)} ${shellQuote(result.instanceId)} '<tableName>' --limit 50`,
|
|
592
|
-
mutators: result.schema.mutators.map((mutator) =>
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
})),
|
|
599
|
-
actions: result.schema.actions.map((action) => ({
|
|
600
|
-
name: action.name,
|
|
601
|
-
...(action.description !== undefined
|
|
602
|
-
? { description: action.description }
|
|
603
|
-
: undefined),
|
|
604
|
-
command: actionCommandForSchema(result, action),
|
|
605
|
-
})),
|
|
593
|
+
mutators: result.schema.mutators.map((mutator) =>
|
|
594
|
+
schemaFunctionCommand(result, "mutate", mutator),
|
|
595
|
+
),
|
|
596
|
+
actions: result.schema.actions.map((action) =>
|
|
597
|
+
schemaFunctionCommand(result, "action", action),
|
|
598
|
+
),
|
|
606
599
|
};
|
|
607
600
|
}
|
|
608
601
|
|
|
609
|
-
function
|
|
602
|
+
function schemaFunctionCommand(
|
|
610
603
|
result: StoreSchemaResult,
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
)
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
"
|
|
633
|
-
|
|
634
|
-
shellQuote(result.instanceId),
|
|
635
|
-
shellQuote(action.name),
|
|
636
|
-
"--input",
|
|
637
|
-
"'<json>'",
|
|
638
|
-
].join(" ");
|
|
604
|
+
verb: "mutate" | "action",
|
|
605
|
+
fn: StoreMutatorSchemaInfo | StoreActionSchemaInfo,
|
|
606
|
+
): SchemaFunctionCommand {
|
|
607
|
+
const inputExample = exampleInputFromJsonSchema(fn.inputSchema);
|
|
608
|
+
const input =
|
|
609
|
+
inputExample === undefined
|
|
610
|
+
? "'<json>'"
|
|
611
|
+
: shellQuote(JSON.stringify(inputExample));
|
|
612
|
+
return {
|
|
613
|
+
name: fn.name,
|
|
614
|
+
...(fn.description !== undefined ? { description: fn.description } : {}),
|
|
615
|
+
...(inputExample !== undefined ? { inputExample } : {}),
|
|
616
|
+
command: [
|
|
617
|
+
cliName(),
|
|
618
|
+
"stores",
|
|
619
|
+
verb,
|
|
620
|
+
shellQuote(result.storeTypeId),
|
|
621
|
+
shellQuote(result.instanceId),
|
|
622
|
+
shellQuote(fn.name),
|
|
623
|
+
"--input",
|
|
624
|
+
input,
|
|
625
|
+
].join(" "),
|
|
626
|
+
};
|
|
639
627
|
}
|
|
640
628
|
|
|
641
629
|
function printSchemaResult(
|