sailkick-boat 0.29.0 → 0.30.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
@@ -363,6 +363,46 @@ at all. The raw channels are always recorded regardless, so the cloud can recomp
363
363
  history if the maths ever changes: the recorded channel is a materialisation, not the only
364
364
  truth.
365
365
 
366
+ ## Sails — the boat is the only writer
367
+
368
+ Sailkick records every instrument value but has no idea which sails are set, so the polar
369
+ estimator averages a full-main-and-genoa curve together with a three-reefs-and-staysail
370
+ one. Recording the plan as a time series is what will let it tell them apart.
371
+
372
+ `POST /api/sails {"plan":"genoa:0+main:2"}` publishes an ordinary SignalK delta on
373
+ `sails.plan`, and the gapless spool carries it to the cloud like any other value. The
374
+ **cloud refuses the same request** (`501 sail-write-not-here`), deliberately: one writer
375
+ keeps `<id>_raw` a faithful mirror of the boat's own SignalK, the write is offline-correct
376
+ for free — sail changes happen at sea, which is exactly when the cloud is unreachable —
377
+ and no Influx *write* token has to live in the cloud beside the password hashes.
378
+
379
+ ```
380
+ genoa:0+main:0 full main and full genoa
381
+ main:2+staysail:0 two reefs, staysail, no headsail
382
+ genoa:2+stormjib:0 genoa furled two steps AND the storm jib set
383
+ bare nothing up
384
+ ```
385
+
386
+ `<id>:<reefs>` per **set** sail, joined by `+`, **sorted by id**. Any combination is
387
+ expressible, which is the point — a cutter flies genoa and staysail together, heavy
388
+ weather means a partly-furled genoa *and* the storm jib, downwind means twin headsails. A
389
+ fixed slot per station cannot say any of that.
390
+
391
+ **Sorting is the contract**, so the write door validates by round-tripping through the
392
+ vendored encoder (`shared/engine/sails.js`, pinned by hash) and **refuses** anything
393
+ non-canonical rather than fixing it up. `main:2+genoa:0` names the right sails and hashes
394
+ differently from `genoa:0+main:2`; accepting it would split the polar cloud this feature
395
+ exists to unify — silently, and visible only much later as a mysteriously noisy polar. A
396
+ client sending it is using its own encoder, which is the actual bug.
397
+
398
+ `bare` rather than an empty string distinguishes "the crew says nothing is up" from "we
399
+ have no sail data", which is null. Under bare poles in a survival storm that difference is
400
+ real.
401
+
402
+ `/api/config` gains `sailPlanWritable: true` — a **capability**, not a deployment test:
403
+ the dev box runs the cloud server on a LAN and self-hosters run it as their edge, so "am I
404
+ the cloud?" is the wrong question. The screen reads only the capability.
405
+
366
406
  ## Alerts and alarms, evaluated on board
367
407
 
368
408
  Rules — anchor drag, wind over or under a threshold, a big wind shift, boat speed below
package/index.js CHANGED
@@ -12,6 +12,7 @@ const { createAisTargets } = require('./lib/ais/targets')
12
12
  const { createProfile } = require('./lib/profile')
13
13
  const { createPerf } = require('./lib/perf')
14
14
  const { createAlerts } = require('./lib/alerts')
15
+ const { createSails } = require('./lib/sails')
15
16
  const { createCloud } = require('./lib/cloud')
16
17
  const { resolveAccountConfig } = require('./lib/account')
17
18
 
@@ -109,6 +110,7 @@ module.exports = function (app) {
109
110
  let cloud = null
110
111
  let perf = null
111
112
  let alerts = null
113
+ let sails = null
112
114
  let proxyPort = null // what the launcher page needs to build its links
113
115
  let pairedSlug = null
114
116
  let statusTimer = null
@@ -425,6 +427,16 @@ module.exports = function (app) {
425
427
  }
426
428
  }
427
429
 
430
+ // The sail-plan write door. No config toggle: it is inert until the crew posts a
431
+ // plan, and a boat that cannot record its sails is the status quo this fixes.
432
+ try {
433
+ sails = createSails(app, { pluginId: plugin.id })
434
+ pOpts.sails = sails // proxy dispatches POST /api/sails and claims sailPlanWritable
435
+ } catch (e) {
436
+ (app.error || console.error)('[sailkick-boat] sails start failed: ' + e.message)
437
+ sails = null
438
+ }
439
+
428
440
  if (pOpts.history.enabled !== false) {
429
441
  try {
430
442
  // ringSource = the telemetry module: when no local InfluxDB token is set
@@ -530,6 +542,7 @@ module.exports = function (app) {
530
542
  if (profile) parts.push(profile.status())
531
543
  if (perf) parts.push(perf.status())
532
544
  if (alerts) parts.push(alerts.status())
545
+ if (sails) parts.push(sails.status())
533
546
  if (ais) parts.push(ais.status())
534
547
  if (backfill) parts.push(backfill.status())
535
548
  try { app.setPluginStatus(parts.join(' | ') || 'idle (both features off)') } catch {}
@@ -559,6 +572,7 @@ module.exports = function (app) {
559
572
  cloud = null
560
573
  perf = null
561
574
  alerts = null
575
+ sails = null
562
576
  proxyPort = null
563
577
  pairedSlug = null
564
578
  proxy = null
@@ -97,6 +97,7 @@ function createProxy (app, options) {
97
97
  aisTargets: options.aisTargets || null,
98
98
  profile: options.profile || null,
99
99
  alerts: options.alerts || null, // claims alertsEvaluatedHere in /api/config, see serveConfig
100
+ sails: options.sails || null, // the sail-plan write door; claims sailPlanWritable
100
101
  boat: options.boat || null, // { perfKey, slug } — patched into /api/config, see serveConfig
101
102
  openAccess: options.openAccess !== false
102
103
  }
@@ -266,6 +267,24 @@ function createProxy (app, options) {
266
267
  if (cfg.profile && cfg.profile.available() && cfg.profile.handles(req.url)) {
267
268
  return cfg.profile.handle(req, res)
268
269
  }
270
+ // Set which sails are up. The boat is the ONLY host that accepts this — the cloud
271
+ // answers 501 sail-write-not-here — because the plan reaches InfluxDB by being
272
+ // published as a SignalK delta here and spooled like every other value: one writer,
273
+ // offline-correct by construction, and no Influx write token in the cloud. Never
274
+ // proxied upstream, whatever the outcome.
275
+ if (req.method === 'POST' && cfg.sails && cfg.sails.available() &&
276
+ req.url.split('?')[0] === '/api/sails') {
277
+ return readJsonBody(req).then((body) => {
278
+ const r = cfg.sails.setPlan(body || {})
279
+ res.statusCode = r.ok ? 200 : (r.status || 400)
280
+ res.setHeader('Content-Type', 'application/json')
281
+ res.end(JSON.stringify(r.ok ? { ok: true, plan: r.plan, at: r.at } : { ok: false, code: r.code, message: r.message }))
282
+ }).catch((e) => {
283
+ res.statusCode = 500
284
+ res.setHeader('Content-Type', 'application/json')
285
+ res.end(JSON.stringify({ ok: false, code: 'sails-error', message: e.message }))
286
+ })
287
+ }
269
288
  // /api/config drives the app's login gate + Trends toggle. On the single-tenant
270
289
  // boat we serve it with auth turned off (no cloud login over the offline HTTP
271
290
  // mirror) and history forced on when we serve it locally. All other config passes
@@ -332,6 +351,14 @@ function createProxy (app, options) {
332
351
  // banner unless a host claims them — rules stored with nothing watching them is
333
352
  // the failure it is warning about. This plugin IS that host, on board, so say so.
334
353
  if (cfg.alerts && cfg.alerts.available()) j.alertsEvaluatedHere = true
354
+ // A CAPABILITY, not a deployment test: the sails screen is read-only unless a
355
+ // host says it can publish the delta. "Am I the cloud?" is the wrong question —
356
+ // the dev box runs the cloud server on a LAN and self-hosters run it as their
357
+ // edge, so a self-hosted single-boat cloud looks exactly like a boat otherwise.
358
+ if (cfg.sails && cfg.sails.available()) j.sailPlanWritable = true
359
+ // Display only. Nothing may branch on this — that is what the capability flags
360
+ // above are for; this exists so the UI can tell a human where data comes from.
361
+ j.deployment = 'boat'
335
362
  // The cloud fills `boat` only for a logged-in session, and the mirror forwards no
336
363
  // cookie — so it always arrived as null and the app had no identity. Harmless for
337
364
  // most of the UI, but public/engine/polar-cloud.js keys the performance data cloud
@@ -0,0 +1,86 @@
1
+ 'use strict'
2
+
3
+ // The sail plan write door — the one place a sail plan enters the system.
4
+ //
5
+ // Sailkick records every instrument value but has no idea which sails are set, so the
6
+ // polar estimator averages a full-main-and-genoa curve together with a
7
+ // three-reefs-and-staysail one. Recording the plan as a time series is what will let it
8
+ // tell them apart later.
9
+ //
10
+ // THE WRITE HAPPENS HERE AND NOWHERE ELSE. The app posts a plan to whichever server
11
+ // served it, and only the boat's mirror accepts one; the cloud answers 501
12
+ // `sail-write-not-here` so a stale client gets JSON it can show a human. The reasons are
13
+ // worth restating because they are the whole design:
14
+ //
15
+ // - <id>_raw stays a faithful mirror of the boat's own SignalK: one writer.
16
+ // - It is offline-correct for free. Sail changes happen at sea, which is exactly when
17
+ // the cloud is unreachable — the gapless spool already solves that, so the app needs
18
+ // no outbox of its own.
19
+ // - No Influx WRITE token has to live in the cloud next to the password hashes.
20
+ //
21
+ // Publishing is an ordinary SignalK delta on `sails.plan`, so everything downstream gets
22
+ // it for nothing: lib/sync spools it to the cloud bucket like any other value (string
23
+ // fields already work end to end — steering.autopilot.state proves it), the vendored
24
+ // mapper turns it into BoatState.sailPlan, and the app's sails screen renders identically
25
+ // on the boat and in the cloud.
26
+
27
+ const { isCanonicalPlan, decodePlan, describePlan, BARE } = require('./sails')
28
+
29
+ function createSails (app, options = {}) {
30
+ const log = (m) => (app.debug ? app.debug('[sails] ' + m) : console.log('[sailkick-boat:sails]', m))
31
+ const warn = (m) => (app.error ? app.error('[sailkick-boat:sails] ' + m) : console.error('[sailkick-boat:sails]', m))
32
+
33
+ let last = null // { plan, at } — what we published, for the status line
34
+ let writes = 0
35
+
36
+ // POST /api/sails { plan: "<canonical string>" } -> { ok, plan } | { ok:false, ... }
37
+ function setPlan (body) {
38
+ const plan = body && typeof body.plan === 'string' ? body.plan.trim() : null
39
+ if (!plan) {
40
+ return { ok: false, status: 400, code: 'bad-plan', message: 'body must be { plan: "<sail plan>" }' }
41
+ }
42
+ // Round-trip validation with the VENDORED encoder, so nothing that would decode
43
+ // differently than it was written ever reaches SignalK. The sort order is the whole
44
+ // contract — it is the key the polar work groups by — and "main:0+genoa:0" is
45
+ // exactly the kind of string that looks right and hashes wrong.
46
+ if (!isCanonicalPlan(plan)) {
47
+ return {
48
+ ok: false,
49
+ status: 400,
50
+ code: 'bad-plan',
51
+ message: `"${plan}" is not a canonical sail plan. Expected <id>:<reefs> per set sail, joined by "+", sorted by id (e.g. "genoa:0+main:2"), or "${BARE}".`
52
+ }
53
+ }
54
+ if (!app.handleMessage) {
55
+ return { ok: false, status: 503, code: 'no-signalk', message: 'this plugin cannot publish to SignalK' }
56
+ }
57
+ const at = new Date().toISOString()
58
+ try {
59
+ app.handleMessage(options.pluginId || 'sailkick-boat', {
60
+ updates: [{ timestamp: at, values: [{ path: 'sails.plan', value: plan }] }]
61
+ })
62
+ } catch (e) {
63
+ warn('could not publish the sail plan: ' + e.message)
64
+ return { ok: false, status: 500, code: 'publish-failed', message: e.message }
65
+ }
66
+ last = { plan, at }
67
+ writes++
68
+ // Worth a normal log line, not a debug one: this is crew input, and "when did we put
69
+ // the second reef in" is a question people ask afterwards.
70
+ log(`sails: ${describePlan(plan)} (${plan})`)
71
+ return { ok: true, plan, at }
72
+ }
73
+
74
+ function status () {
75
+ if (!last) return 'sails: none set yet'
76
+ return `sails: ${describePlan(last.plan)}${writes > 1 ? ` (${writes} changes)` : ''}`
77
+ }
78
+
79
+ // Mirrors lib/history / lib/alerts: the proxy asks before claiming, in /api/config,
80
+ // that this host can accept a sail plan.
81
+ function available () { return !!app.handleMessage }
82
+
83
+ return { setPlan, status, available, _last: () => last, _decode: decodePlan }
84
+ }
85
+
86
+ module.exports = { createSails }
@@ -0,0 +1,180 @@
1
+ // VENDORED from sailkick/shared/engine/sails.js @ 1571308 sha256:7965d2e3e610e9fd
2
+ // Do not edit here — fix upstream and re-vendor. ONE definition of how a sail plan is
3
+ // written down, or the same plan hashes two ways and silently splits the polar cloud
4
+ // this feature exists to unify — visible only much later, as a mysteriously noisy polar.
5
+ // test/sails.test.js replays the upstream suite against this copy to prove it matches.
6
+ //
7
+ // Converted ESM -> CommonJS ONLY (export keywords removed, module.exports appended).
8
+ // No logic changed.
9
+ //
10
+ // The boat is the ONLY writer of a sail plan: the app posts one to whichever server
11
+ // served it, and only this mirror accepts it (the cloud answers 501). That keeps
12
+ // <id>_raw a faithful mirror of the boat's own SignalK with one writer, makes the write
13
+ // offline-correct for free — sail changes happen at sea, which is exactly when the cloud
14
+ // is unreachable, and the gapless spool already solves that — and keeps an Influx write
15
+ // token out of the cloud next to the password hashes.
16
+
17
+ // Sail plan — ONE definition of how a sail plan is written down, shared by every host
18
+ // that records or reads one: the boat plugin (which publishes it onto SignalK) and the
19
+ // cloud (which displays it and will later group polar samples by it). Pure and
20
+ // dependency-free, like shared/engine/alerts.js, for the same reason: a second
21
+ // implementation that disagrees is the failure mode this file exists to prevent.
22
+ //
23
+ // THE ENCODING
24
+ //
25
+ // "genoa:0+main:0" full main and full genoa
26
+ // "main:2+staysail:0" two reefs, staysail, no headsail
27
+ // "genoa:2+stormjib:0" genoa furled two steps AND the storm jib set
28
+ // "bare" nothing up
29
+ //
30
+ // `<id>:<reefs>` per ACTIVE sail, joined by "+", SORTED BY ID. Only sails that are
31
+ // actually set appear — "main down" is simply the main's absence, not a `down` state.
32
+ // That is what lets any combination be expressed: a cutter's genoa + staysail, a
33
+ // heavy-weather partly-furled genoa + storm jib, twin headsails poled out downwind.
34
+ // A fixed slot per station cannot say any of those, which is why there isn't one.
35
+ //
36
+ // SORTING IS THE WHOLE CONTRACT. The string is the join key the polar work will group
37
+ // by, so the same sail plan MUST produce the same bytes every time. An encoder that
38
+ // emitted insertion order would split one polar cloud into several that look unrelated
39
+ // — silently, and only visible much later as a mysteriously noisy polar. Hence
40
+ // encodePlan sorts, and the round-trip tests assert it.
41
+ //
42
+ // `bare` (rather than "") distinguishes "the crew says nothing is up" from "we have no
43
+ // sail data at all", which is null/absent. Under bare poles in a survival storm that
44
+ // distinction is real information.
45
+
46
+ // A sail id: lowercase, url-safe, and free of the encoding's own delimiters.
47
+ const ID_RE = /^[a-z0-9][a-z0-9-]{0,31}$/;
48
+ const STATIONS = ['main', 'head', 'flying'];
49
+ const SAIL_STATIONS = STATIONS;
50
+ const BARE = 'bare';
51
+ const MAX_REEFS = 5;
52
+ const MAX_SAILS = 12; // a plan longer than this is a bug or an attack, not a rig
53
+
54
+ // The inventory a boat gets before anyone edits it. Deliberately over-complete: it is
55
+ // far easier to delete the sails you don't carry than to remember the ones you do.
56
+ // `reefs` is how many REDUCED steps the sail has below full — 0 means it is all-or-
57
+ // nothing (a spinnaker is up or it isn't). For a furling headsail these are furl steps.
58
+ const DEFAULT_INVENTORY = [
59
+ { id: 'main', name: 'Mainsail', station: 'main', reefs: 3 },
60
+ { id: 'genoa', name: 'Genoa', station: 'head', reefs: 2 },
61
+ { id: 'jib', name: 'Jib', station: 'head', reefs: 1 },
62
+ { id: 'staysail', name: 'Staysail', station: 'head', reefs: 0 },
63
+ { id: 'stormjib', name: 'Storm jib', station: 'head', reefs: 0 },
64
+ { id: 'trysail', name: 'Trysail', station: 'main', reefs: 0 },
65
+ { id: 'code0', name: 'Code 0', station: 'flying', reefs: 0 },
66
+ { id: 'spinnaker', name: 'Spinnaker', station: 'flying', reefs: 0 },
67
+ ];
68
+
69
+ // [{ id, reefs }] → the canonical string. Ignores entries with an unusable id, and
70
+ // clamps a negative/NaN reef count to 0 rather than emitting a string that won't parse:
71
+ // a UI bug must not be able to write an unreadable record into the boat's history.
72
+ function encodePlan(sails) {
73
+ if (!Array.isArray(sails)) return BARE;
74
+ const seen = new Map();
75
+ for (const s of sails) {
76
+ const id = typeof s?.id === 'string' ? s.id.trim().toLowerCase() : '';
77
+ if (!ID_RE.test(id)) continue;
78
+ const n = Number(s.reefs);
79
+ seen.set(id, Number.isFinite(n) ? Math.max(0, Math.min(MAX_REEFS, Math.round(n))) : 0);
80
+ }
81
+ if (!seen.size) return BARE;
82
+ return [...seen.entries()]
83
+ .sort((a, b) => (a[0] < b[0] ? -1 : a[0] > b[0] ? 1 : 0)) // byte order, not locale
84
+ .map(([id, reefs]) => `${id}:${reefs}`)
85
+ .join('+');
86
+ }
87
+
88
+ // The canonical string → [{ id, reefs }], in the string's own (sorted) order.
89
+ //
90
+ // Deliberately TOLERANT: history outlives the inventory. A sail deleted from the boat's
91
+ // inventory today still appears in every plan recorded before it went, and a decoder
92
+ // that threw would take the whole screen — and later the whole polar split — down with
93
+ // it. Unparseable segments are dropped; `null`/absent/unknown input decodes to [].
94
+ function decodePlan(str) {
95
+ if (typeof str !== 'string') return [];
96
+ const s = str.trim();
97
+ if (!s || s === BARE) return [];
98
+ const out = [];
99
+ const seen = new Set();
100
+ for (const seg of s.split('+').slice(0, MAX_SAILS)) {
101
+ const i = seg.indexOf(':');
102
+ if (i < 0) continue;
103
+ const id = seg.slice(0, i).trim().toLowerCase();
104
+ if (!ID_RE.test(id) || seen.has(id)) continue;
105
+ const reefs = Number(seg.slice(i + 1).trim());
106
+ if (!Number.isInteger(reefs) || reefs < 0 || reefs > MAX_REEFS) continue;
107
+ seen.add(id);
108
+ out.push({ id, reefs });
109
+ }
110
+ return out;
111
+ }
112
+
113
+ // True when the string is one this encoder could have produced. Used at the write door:
114
+ // the boat validates an incoming plan by round-tripping it, so nothing that would decode
115
+ // differently than it was written ever reaches SignalK.
116
+ function isCanonicalPlan(str) {
117
+ return typeof str === 'string' && encodePlan(decodePlan(str)) === str.trim();
118
+ }
119
+
120
+ // The key polar samples will be GROUPED BY. Identity today — the plan string already is
121
+ // the key. It exists as a named seam because the polar work will want to coarsen plans
122
+ // into equivalence classes (a code 0 barely changes the upwind curve; a reef does), and
123
+ // when it does, that decision belongs here next to the encoding rather than scattered
124
+ // through the estimator.
125
+ function sailPlanKey(str) {
126
+ return typeof str === 'string' && str.trim() ? str.trim() : null;
127
+ }
128
+
129
+ // Render a plan for a human: "2 reefs · Staysail". `inventory` supplies display names;
130
+ // a sail missing from it falls back to its id, so historical plans stay readable after
131
+ // the sail is deleted. Returns '—' for no data, 'Bare poles' for an explicit bare.
132
+ function describePlan(str, inventory = DEFAULT_INVENTORY) {
133
+ if (typeof str !== 'string' || !str.trim()) return '—';
134
+ if (str.trim() === BARE) return 'Bare poles';
135
+ const byId = new Map((inventory || []).map((s) => [s.id, s]));
136
+ const parts = decodePlan(str).map(({ id, reefs }) => {
137
+ const name = byId.get(id)?.name || id;
138
+ if (!reefs) return name;
139
+ // The main is reefed; a furling headsail is furled. Same integer, different word —
140
+ // saying "1 reef" about a genoa reads wrong to anyone who has actually sailed.
141
+ return byId.get(id)?.station === 'main'
142
+ ? `${reefs} reef${reefs > 1 ? 's' : ''}`
143
+ : `${name} −${reefs}`;
144
+ });
145
+ return parts.length ? parts.join(' · ') : 'Bare poles';
146
+ }
147
+
148
+ // Validate one INVENTORY item (not a plan) — the profile section's write guard, in the
149
+ // shape of validateRule() in shared/engine/alerts.js. A malformed sail stores looking
150
+ // fine and then silently mislabels every polar sample recorded against it, so it is
151
+ // rejected at the door rather than tolerated.
152
+ function validateSail(s) {
153
+ if (!s || typeof s !== 'object') return { ok: false, error: 'sail must be an object' };
154
+ const id = typeof s.id === 'string' ? s.id.trim().toLowerCase() : '';
155
+ if (!ID_RE.test(id)) {
156
+ return { ok: false, error: `sail id "${s.id}" must be lowercase letters, digits or dashes (max 32) — it is written into every recorded plan` };
157
+ }
158
+ if (typeof s.name !== 'string' || !s.name.trim() || s.name.length > 40) {
159
+ return { ok: false, error: 'sail name is required (max 40 characters)' };
160
+ }
161
+ if (!STATIONS.includes(s.station)) {
162
+ return { ok: false, error: `sail station "${s.station}" must be one of ${STATIONS.join(', ')}` };
163
+ }
164
+ if (!Number.isInteger(s.reefs) || s.reefs < 0 || s.reefs > MAX_REEFS) {
165
+ return { ok: false, error: `sail reefs must be a whole number between 0 and ${MAX_REEFS}` };
166
+ }
167
+ return { ok: true };
168
+ }
169
+
170
+ module.exports = {
171
+ encodePlan,
172
+ decodePlan,
173
+ isCanonicalPlan,
174
+ sailPlanKey,
175
+ describePlan,
176
+ validateSail,
177
+ DEFAULT_INVENTORY,
178
+ SAIL_STATIONS,
179
+ BARE
180
+ }
@@ -27,10 +27,10 @@
27
27
  // old path no longer existed. They now fail rather than skip when the checkout is present
28
28
  // and the file is not; a guard that disappears when its subject moves is not a guard.
29
29
 
30
- // sha256(app shared/engine/signalk-map.js)[0..12] as ported in v0.18.6
30
+ // sha256(app shared/engine/signalk-map.js)[0..12] as ported in v0.30.0 (the sails merge)
31
31
  const { request } = require('../net') // owned connection pool + real error codes
32
32
 
33
- const PINNED_APP_HASH = '3e42369c002b'
33
+ const PINNED_APP_HASH = 'fd79e3688591'
34
34
 
35
35
  function createContractCheck (app, options = {}) {
36
36
  const warn = (m) => (app.error ? app.error('[sailkick-boat:contract] ' + m) : console.error('[sailkick-boat:contract]', m))
@@ -1,12 +1,13 @@
1
- // VENDORED from sailkick/shared/engine/signalk-map.js @ dc57057 sha256:3e42369c002b7cb7
2
- // (the app moved it public/engine -> shared/engine in 8fd58cf; content and hash unchanged)
1
+ // VENDORED from sailkick/shared/engine/signalk-map.js @ 1571308 sha256:fd79e368859133d8
3
2
  // Do not edit here — fix upstream and re-vendor. One SignalK -> BoatState mapping, or
4
3
  // the boat and the app quietly disagree (it has drifted twice; both times silently).
5
4
  //
6
5
  // Converted ESM -> CommonJS ONLY. No logic changed.
7
6
  //
8
- // Re-vendored after b519a9f (course + depth precedence) and 348c3d9 (heading true
9
- // authoritative) — both of which came from findings handed over from this repo.
7
+ // Re-vendored after b519a9f (course + depth precedence), 348c3d9 (heading true
8
+ // authoritative) — both from findings handed over from this repo — and the sails merge
9
+ // (1571308), which adds the `sails.plan` case: the boat's mirror is the only writer of
10
+ // that path, so this copy has to understand what it publishes.
10
11
 
11
12
  // SignalK → BoatState mapping — pure, dependency-free, so it's shared by both
12
13
  // the client provider (public/ui/boat-panel.js, browser WebSocket) and the
@@ -152,6 +153,17 @@ function signalkValuesToPatch(values) {
152
153
  case 'navigation.datetime': // GNSS UTC time (from the satellites)
153
154
  if (typeof v.value === 'string') patch.gpsTime = v.value;
154
155
  break;
156
+ // Which sails are set — a canonical plan string (shared/engine/sails.js), not a
157
+ // sensor reading: the crew publishes it from the app. Kept VERBATIM here; this
158
+ // mapper stays pure string-passing and the encoding lives in one place.
159
+ //
160
+ // A null is SKIPPED, like every sensor path and unlike the course paths above:
161
+ // the plan is a step function, so "the source went quiet" must leave the last
162
+ // known plan standing, not blank it. "Nothing is up" is the explicit string
163
+ // `bare`, which is exactly why that sentinel exists.
164
+ case 'sails.plan':
165
+ if (typeof v.value === 'string' && v.value.trim()) patch.sailPlan = v.value.trim();
166
+ break;
155
167
  default:
156
168
  break; // ignore everything else
157
169
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sailkick-boat",
3
- "version": "0.29.0",
3
+ "version": "0.30.0",
4
4
  "description": "Run the sailkick app on board with no internet: charts, weather, climatology, trends and AIS all served from the boat itself. With a sailkick account it also syncs your metrics to the cloud in real time. Alpha, invite-only — info@sailkick.io",
5
5
  "main": "index.js",
6
6
  "scripts": {