@immediately-run/dibber 0.6.0 → 0.7.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/README.md CHANGED
@@ -99,7 +99,8 @@ keeps working.
99
99
  Use `dibber new --title "…"` to file a ticket. Point `--body-file PATH` at a complete
100
100
  Markdown body. Dibber adds a filing entry if the body has no `## Status` section.
101
101
  Repeat `--field KEY=VALUE` to supply declared fields, with YAML values for lists
102
- and maps. `dibber set ID --field KEY=VALUE` updates fields declared by the store's
102
+ and maps. A key the store's `item.schema.json` requires is filled from its `default`,
103
+ when the schema gives one and the command does not; a value you give wins. `dibber set ID --field KEY=VALUE` updates fields declared by the store's
103
104
  `item.schema.json`. You can also give `set` a status. For a worked example, see
104
105
  [Keep where a ticket stands at the top](docs/current-state-field.md): a one-line field of your
105
106
  own that tells an agent reading a ticket's first lines where the work stands.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@immediately-run/dibber",
3
- "version": "0.6.0",
3
+ "version": "0.7.0",
4
4
  "description": "Git as your issue tracker, in an open format built on Markdown: the Dibber format's validator and command-line tool, plus agent skills.",
5
5
  "type": "module",
6
6
  "license": "Apache-2.0",
package/src/import.mjs CHANGED
@@ -4,7 +4,7 @@ import { extname, join } from 'node:path';
4
4
  import { parse } from 'csv-parse/sync';
5
5
  import { checkStore } from './check.mjs';
6
6
  import { rel } from './store.mjs';
7
- import { allocateTicketId, frontmatterYaml, Refusal, today } from './tickets.mjs';
7
+ import { allocateTicketId, frontmatterYaml, Refusal, schemaDefaults, today } from './tickets.mjs';
8
8
 
9
9
  const asArray = (value) => Array.isArray(value) ? value : value?.nodes ?? [];
10
10
  const present = (values) => values.filter((value) => value !== undefined && value !== null && value !== '');
@@ -184,6 +184,8 @@ export function importTickets(root, source, path, sourceUrl) {
184
184
  ...(issue.project && { project: issue.project }),
185
185
  ...(issue.assignee && { assignee: issue.assignee }),
186
186
  };
187
+ // A key the store schema requires and gives a default for ([DIB-43](../tickets/DIB-43.md)).
188
+ Object.assign(meta, schemaDefaults(store, meta));
187
189
  const filename = join(store.storeDir, `${issue.id}.md`);
188
190
  writeFileSync(filename, render(issue, meta, source, issue.originalUrl), { flag: 'wx' });
189
191
  written.push({ id: issue.id, original: issue.key, file: rel(root, filename), filename });
package/src/tickets.mjs CHANGED
@@ -121,17 +121,37 @@ export function frontmatterYaml(obj) {
121
121
  return doc.toString({ lineWidth: 0, flowCollectionPadding: false });
122
122
  }
123
123
 
124
- // Only declared keys are writable through --field ([DIB-33](../tickets/DIB-33.md)).
125
- function extensionFields(store, entries, readerOnly = false) {
124
+ /** The store's own `item.schema.json`, or `{}` when it has none (R-DIB-3). */
125
+ function storeSchema(store) {
126
126
  const path = join(store.storeDir, 'item.schema.json');
127
- let schema = {};
128
- if (existsSync(path)) {
129
- try {
130
- schema = JSON.parse(readFileSync(path, 'utf8'));
131
- } catch {
132
- throw new Refusal("the store's item.schema.json does not load");
133
- }
127
+ if (!existsSync(path)) return {};
128
+ try {
129
+ return JSON.parse(readFileSync(path, 'utf8'));
130
+ } catch {
131
+ throw new Refusal("the store's item.schema.json does not load");
134
132
  }
133
+ }
134
+
135
+ // Dibber writes these itself; a store schema's default never stands in for them.
136
+ const OWN_KEYS = new Set(['id', 'title', 'status', 'page']);
137
+
138
+ /** The keys the store schema requires that `meta` lacks and that the schema gives a `default`
139
+ * for, with those defaults ([DIB-43](../tickets/DIB-43.md)). A required key with no default is
140
+ * left for the check to refuse. */
141
+ export function schemaDefaults(store, meta) {
142
+ const schema = storeSchema(store);
143
+ const out = {};
144
+ for (const key of Array.isArray(schema?.required) ? schema.required : []) {
145
+ if (OWN_KEYS.has(key) || Object.hasOwn(meta, key)) continue;
146
+ const property = schema.properties?.[key];
147
+ if (property && typeof property === 'object' && Object.hasOwn(property, 'default')) out[key] = structuredClone(property.default);
148
+ }
149
+ return out;
150
+ }
151
+
152
+ // Only declared keys are writable through --field ([DIB-33](../tickets/DIB-33.md)).
153
+ function extensionFields(store, entries, readerOnly = false) {
154
+ const schema = storeSchema(store);
135
155
  const fields = new Map();
136
156
  for (const entry of entries ?? []) {
137
157
  const separator = entry.indexOf('=');
@@ -213,7 +233,8 @@ export function newTicket(root, opts) {
213
233
  if (opts.project) meta.project = opts.project;
214
234
  if (opts.assignee) meta.assignee = opts.assignee;
215
235
 
216
- meta = orderFields({ ...meta, ...Object.fromEntries(fields) }, keys);
236
+ const given = { ...meta, ...Object.fromEntries(fields) };
237
+ meta = orderFields({ ...given, ...schemaDefaults(store, given) }, keys);
217
238
 
218
239
  const date = today();
219
240
  const brief = opts.brief ? `**Brief:** ${opts.brief}\n` : '';