Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/desktop/renderer-architecture.json
Original file line number Diff line number Diff line change
Expand Up @@ -891,7 +891,7 @@
"react": 1
},
"importSpecifiers": 148,
"nonTriviaTokens": 15617
"nonTriviaTokens": 15602
},
"src/renderer/use-app-shell-composer-quotes.ts": {
"importDeclarations": 2,
Expand Down
46 changes: 46 additions & 0 deletions apps/desktop/src/main/__tests__/desktop-slash-command.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

import { strict as assert } from 'node:assert';
import { describe, it } from 'node:test';
import { slashCommandsForSurface } from '@maka/core/slash-command-catalog';
import { desktopSlashCommandAvailability } from '../../renderer/desktop-slash-command.js';

const offered = (state: { hasSession: boolean; streaming: boolean }): readonly string[] =>
slashCommandsForSurface('desktop')
.filter(desktopSlashCommandAvailability(state))
.map(({ id }) => id);

describe('desktop slash command availability', () => {
it('withholds /compact while the Turn streams, and nothing else', () => {
const idle = offered({ hasSession: true, streaming: false });
assert.ok(idle.includes('compact'), 'an idle Session can compact its context');
assert.deepEqual(
offered({ hasSession: true, streaming: true }),
idle.filter((id) => id !== 'compact'),
);
});

it('offers only the commands that need no Session before one exists', () => {
// Spelled out rather than derived from the catalog: a new Desktop command
// reaching an empty composer is a decision, not a default.
assert.deepEqual(offered({ hasSession: false, streaming: false }), ['graph', 'swarm']);
assert.deepEqual(offered({ hasSession: false, streaming: true }), ['graph', 'swarm']);
});
});
14 changes: 8 additions & 6 deletions apps/desktop/src/renderer/app-shell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ import {
activeInteractionFor,
deriveComposerModelSwitchAvailability,
deriveTitlebarProjectName,
enqueueInteraction,
reconcileInteractions,
} from '@maka/ui';
import type { ConnectionEvent } from '@maka/core/connections';
Expand Down Expand Up @@ -106,7 +105,10 @@ import { useNewTaskChoice } from './use-new-task-choice';
import { SessionCollaborationDialog } from './session-collaboration-dialog';
import * as SessionCollaboration from './features/session-collaboration';
import { NEW_TASK_PENDING_KEY } from './pending-items';
import { parseDesktopSlashCommand } from './desktop-slash-command';
import {
desktopSlashCommandAvailability,
parseDesktopSlashCommand,
} from './desktop-slash-command';
import {
hasActiveTurnAtSubmit,
mergeWorkspaceReferences,
Expand Down Expand Up @@ -1324,11 +1326,11 @@ function AppShellContent({
: undefined;
const desktopSlashCommands = useMemo<readonly ComposerSlashCommandOption[]>(
() => {
const streaming = turnActive || activeStreamingLive;
const availableCommands = slashCommandsForSurface('desktop').filter(
({ id, session }) =>
(session === 'none' || Boolean(activeId))
&& !(streaming && id === 'compact'),
desktopSlashCommandAvailability({
hasSession: Boolean(activeId),
streaming: turnActive || activeStreamingLive,
}),
);
const presentation: Record<
SlashCommandIdForSurface<'desktop'>,
Expand Down
15 changes: 15 additions & 0 deletions apps/desktop/src/renderer/desktop-slash-command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/

import { parseGraphCommand, type ParsedGraphCommand } from '@maka/core/graph-command';
import type { SlashCommandSpec } from '@maka/core/slash-command-catalog';
import { parseSwarmCommand, type ParsedSwarmCommand } from '@maka/core/swarm-command';
import { parseSideChatCommand, type SideChatCommand } from './side-chat-command.js';

Expand All @@ -37,3 +38,17 @@ export function parseDesktopSlashCommand(input: string): DesktopSlashCommand | n
const swarm = parseSwarmCommand(input);
return swarm ? { kind: 'swarm', command: swarm } : null;
}

/**
* Which catalog commands the Desktop composer offers in the state it is in.
* `/compact` rewrites the context the running Turn is still reading from, so it
* is withheld while a stream is live; every other command only needs a Session
* to act on.
*/
export function desktopSlashCommandAvailability(state: {
hasSession: boolean;
streaming: boolean;
}): (command: Pick<SlashCommandSpec, 'id' | 'session'>) => boolean {
return ({ id, session }) =>
(session === 'none' || state.hasSession) && !(state.streaming && id === 'compact');
}